private String getPackageName(CompilationInfo cinfo) { Element e = cinfo.getTrees().getElement(new TreePath(cinfo.getCompilationUnit())); if (e != null && e.getKind() == ElementKind.PACKAGE) { return ((PackageElement) e).getQualifiedName().toString(); } return null; }
static Element getElement(CompilationInfo cinfo, Tree tree) { return cinfo.getTrees().getElement(getTreePath(cinfo, tree)); }
private boolean canSkip(TreePath path) { if (cinfo.getTreeUtilities().isSynthetic(path)) { return false; } Element el = cinfo.getTrees().getElement(path); if (el != null && elementAndNames.containsKey(el)) { TreePath declPath = cinfo.getTrees().getPath(el); if(declPath.getLeaf().equals(path.getLeaf())) { return true; } } return false; }
public Void visitNewClass(NewClassTree node, Set<TypeMirror> p) { super.visitNewClass(node, p); Element el = info.getTrees().getElement(getCurrentPath()); if (el != null && el.getKind() == ElementKind.CONSTRUCTOR) p.addAll(((ExecutableElement)el).getThrownTypes()); return null; }
(int) info.getTrees().getSourcePositions().getStartPosition(cu, tree.getLeaf()), (int) info.getTrees().getSourcePositions().getEndPosition(cu, tree.getLeaf()) }); if ((decl.getKind().isField() && !isSerialSpecField(info, decl)) || isLocalVariableClosure(decl)) { if (!hasAllTypes(uses, EnumSet.of(UseTypes.READ, UseTypes.WRITE))) { u.spec.add(ColoringAttributes.UNUSED); if ((decl.getKind() == ElementKind.CONSTRUCTOR && !decl.getModifiers().contains(Modifier.PRIVATE)) || decl.getKind() == ElementKind.METHOD) { if (!(hasAllTypes(uses, EnumSet.of(UseTypes.EXECUTE)) || isSerializationMethod(info, (ExecutableElement)decl))) { u.spec.add(ColoringAttributes.UNUSED); Token t = v.tree2Token.get(u.tree.getLeaf());
@Override public Void visitNewClass(NewClassTree node, Stack<Tree> p) { if (instantRename) { return super.visitNewClass(node, p); } Element el = info.getTrees().getElement(getCurrentPath()); if (toFind.equals(el) && node.getIdentifier() != null) { Token<JavaTokenId> t = Utilities.getToken(info, doc, new TreePath(getCurrentPath(), node.getIdentifier())); if (t != null) usages.add(t); return null; } if (el != null && toFind.equals(el.getEnclosingElement())) { return null; } return super.visitNewClass(node, p); }
public static ErrorDescription computeWarning(HintContext context) { TreePath tp = context.getPath(); ClassTree cls = (ClassTree) tp.getLeaf(); CompilationInfo info = context.getInfo(); SourcePositions sourcePositions = info.getTrees().getSourcePositions(); int startPos = (int) sourcePositions.getStartPosition(tp.getCompilationUnit(), cls); int caret = context.getCaretLocation();
public Void visitThrow(ThrowTree node, Set<TypeMirror> p) { super.visitThrow(node, p); TypeMirror tm = info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getExpression())); if (tm != null) { if (tm.getKind() == TypeKind.DECLARED) p.add(tm); else if (tm.getKind() == TypeKind.UNION) p.addAll(((UnionType)tm).getAlternatives()); } return null; }
@Override public Boolean visitMethodInvocation(MethodInvocationTree tree, Stack<Tree> d) { Element el = info.getTrees().getElement(new TreePath(getCurrentPath(), tree.getMethodSelect())); if (el == null) { System.err.println("Warning: decl == null"); System.err.println("tree=" + tree); } if (el != null && el.getKind() == ElementKind.METHOD) { for (TypeMirror m : ((ExecutableElement) el).getThrownTypes()) { addToExceptionsMap(m, tree); } } super.visitMethodInvocation(tree, d); return null; }
public Void visitMethodInvocation(MethodInvocationTree node, Set<TypeMirror> p) { super.visitMethodInvocation(node, p); Element el = info.getTrees().getElement(getCurrentPath()); if (el != null && el.getKind() == ElementKind.METHOD) p.addAll(((ExecutableElement)el).getThrownTypes()); return null; }
public void handleDeclaration() { Element found = info.getTrees().getElement(getCurrentPath()); if ( element.equals( found ) ) { declTree = getCurrentPath().getLeaf(); } }
private void handlePotentialVariable(TreePath tree) { Element el = info.getTrees().getElement(tree); if (toFind.equals(el)) { Token<JavaTokenId> t = Utilities.getToken(info, doc, tree); if (t != null) usages.add(t); } }
public static ErrorDescription computeWarning(HintContext context) { final TreePath tp = context.getPath(); final MethodTree method = (MethodTree) tp.getLeaf(); if (method.getModifiers().getFlags().contains(Modifier.PRIVATE)) { return null; SourcePositions sourcePositions = info.getTrees().getSourcePositions(); int startPos = (int) sourcePositions.getStartPosition(tp.getCompilationUnit(), method); int caret = context.getCaretLocation();
@Override public void run(CompilationInfo p) throws Exception { final CompilationUnitTree compilationUnitTree = p.getCompilationUnit(); final TreePath rootPath = new TreePath(compilationUnitTree); mappedElementExtractor = new MappedElementExtractor(p.getFileObject(), compilationUnitTree, p.getTrees(), rootPath); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { targetModel.refresh(compilationUnitTree.accept(mappedElementExtractor, null)); table.setModel(targetModel); } }); } }
public static List<Integer> getElementPosition(CompilationInfo info, Tree tree){ SourcePositions srcPos = info.getTrees().getSourcePositions(); if (TreeUtilities.CLASS_TREE_KINDS.contains(tree.getKind())){ startTree = ((ClassTree)tree).getModifiers(); } else if (tree.getKind() == Tree.Kind.METHOD){ startTree = ((MethodTree)tree).getReturnType(); } else if (tree.getKind() == Tree.Kind.VARIABLE){ startTree = ((VariableTree)tree).getType();
while (it.hasNext()) { Tree tr = it.next(); if (tr.getKind() == Tree.Kind.VARIABLE) { Trees trees = myInfo.getTrees(); TreePath path = new TreePath(getCurrentPath(), tr); Element el = trees.getElement(path); String sname = el.getSimpleName().toString(); if (sname.equals(myMember)) { myFieldHandle = TreePathHandle.create(path, myInfo); } else if (tr.getKind() == Tree.Kind.METHOD) { Trees trees = myInfo.getTrees(); TreePath path = new TreePath(getCurrentPath(), tr); Element el = trees.getElement(path); String sname = el.getSimpleName().toString(); if (sname.equals(myMethod)) {
@Override public Boolean visitNewClass(NewClassTree tree, Stack<Tree> d) { Element el = info.getTrees().getElement(getCurrentPath()); if (el != null && el.getKind() == ElementKind.CONSTRUCTOR) { for (TypeMirror m : ((ExecutableElement) el).getThrownTypes()) { addToExceptionsMap(m, tree); } } return null; }
CompilationInfo info = context.getInfo(); TreePath treePath = context.getPath(); Element el = info.getTrees().getElement(treePath); if (el == null) { return null; return null; Tree t = treePath.getLeaf(); int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), t); int end = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), t);