Fixing UI of several node kinds: constructor (fixing the name), methods (ignoring parameters), synchronized and switch (should not include '()'), ignoring synthetic trees.
1.1 --- a/java.breadcrumbs/src/org/netbeans/modules/java/breadcrumbs/NodeImpl.java Wed Aug 08 15:09:00 2012 +0200
1.2 +++ b/java.breadcrumbs/src/org/netbeans/modules/java/breadcrumbs/NodeImpl.java Wed Aug 08 21:27:15 2012 +0200
1.3 @@ -161,6 +161,8 @@
1.4 return super.getOpenedIcon(type);
1.5 }
1.6
1.7 + private static final String CONSTRUCTOR_NAME = "<init>";
1.8 +
1.9 public static Node createBreadcrumbs(final CompilationInfo info, TreePath path) {
1.10 final Trees trees = info.getTrees();
1.11 final SourcePositions sp = trees.getSourcePositions();
1.12 @@ -176,7 +178,14 @@
1.13 case ANNOTATION_TYPE:
1.14 return new NodeImpl(tph, iconFor(info, path), ((ClassTree) leaf).getSimpleName().toString(), info.getFileObject(), pos);
1.15 case METHOD:
1.16 - return new NodeImpl(tph, iconFor(info, path), ((MethodTree) leaf).getName().toString(), info.getFileObject(), pos);
1.17 + MethodTree mt = (MethodTree) leaf;
1.18 + CharSequence name;
1.19 + if (mt.getName().contentEquals(CONSTRUCTOR_NAME)) {
1.20 + name = ((ClassTree) path.getParentPath().getLeaf()).getSimpleName();
1.21 + } else {
1.22 + name = mt.getName();
1.23 + }
1.24 + return new NodeImpl(tph, iconFor(info, path), name.toString(), info.getFileObject(), pos);
1.25 case VARIABLE:
1.26 return new NodeImpl(tph, iconFor(info, path), ((VariableTree) leaf).getName().toString(), info.getFileObject(), pos);
1.27 case CASE:
1.28 @@ -232,17 +241,13 @@
1.29 case SWITCH:
1.30 sb = new StringBuilder("switch "); //NOI18N
1.31 sb.append("<font color=").append(COLOR).append(">"); // NOI18N
1.32 - sb.append("("); //NOI18N
1.33 sb.append(escape(((SwitchTree) leaf).getExpression().toString()));
1.34 - sb.append(")"); //NOI18N
1.35 sb.append("</font>"); //NOI18N
1.36 return new NodeImpl(tph, null, sb.toString(), info.getFileObject(), (int) sp.getStartPosition(path.getCompilationUnit(), leaf));
1.37 case SYNCHRONIZED:
1.38 sb = new StringBuilder("synchronized "); //NOI18N
1.39 sb.append("<font color=").append(COLOR).append(">"); // NOI18N
1.40 - sb.append("("); //NOI18N
1.41 sb.append(escape(((SynchronizedTree) leaf).getExpression().toString()));
1.42 - sb.append(")"); //NOI18N
1.43 sb.append("</font>"); //NOI18N
1.44 return new NodeImpl(tph, null, sb.toString(), info.getFileObject(), (int) sp.getStartPosition(path.getCompilationUnit(), leaf));
1.45 case TRY:
1.46 @@ -305,6 +310,7 @@
1.47 @Override public Void scan(Tree node, TreePath p) {
1.48 if (node == null) return null;
1.49 p = new TreePath(p, node);
1.50 + if (cc.getTreeUtilities().isSynthetic(p)) return null;
1.51 Node n = createBreadcrumbs(cc, p);
1.52 if (n != null) {
1.53 toPopulate.add(n);
1.54 @@ -313,6 +319,9 @@
1.55 }
1.56 return null;
1.57 }
1.58 + @Override public Void visitMethod(MethodTree node, TreePath p) {
1.59 + return scan(node.getBody(), p);
1.60 + }
1.61 }, tp);
1.62 }
1.63 }, true);