public Map<Name, ? extends Element> getForwardReferences() { if (refs == null) { refs = new HashMap<>(); for (Element ref : SourceUtils.getForwardReferences(path, offset, sourcePositions, controller.getTrees())) { refs.put(ref.getSimpleName(), ref); } } return refs; }
@Override T run(CompilationController controller, ClassTree classTree, TypeElement classElement) { for (ExecutableElement el : ElementFilter.methodsIn(classElement.getEnclosedElements())) { if (el.getSimpleName().toString().equals(methodName) && el.getModifiers().contains(Modifier.PUBLIC)) { MethodTree mTree = controller.getTrees().getTree(el); return run(controller, mTree, el); } } return null; }
/** * A convenience method for converting a <code>ClassTree</code> to the * corresponding <code>TypeElement</code>, if any. */ static TypeElement classTree2TypeElement(CompilationController controller, ClassTree classTree) { assert controller != null; assert classTree != null; TreePath classTreePath = controller.getTrees().getPath(controller.getCompilationUnit(), classTree); return (TypeElement)controller.getTrees().getElement(classTreePath); }
public TypeElement visitClass(ClassTree node, Void p) { try { return (TypeElement)controller.getTrees().getElement(getCurrentPath()); } catch (NullPointerException e) { Exceptions.printStackTrace(e); return null; } } };
public boolean isAccessible(Scope scope, Element member, TypeMirror type, boolean selectSuper) { if (!checkAccessibility) { return true; } if (type.getKind() != TypeKind.DECLARED) { return member.getModifiers().contains(PUBLIC); } if (getController().getTrees().isAccessible(scope, member, (DeclaredType) type)) { return true; } return selectSuper && member.getModifiers().contains(PROTECTED) && !member.getModifiers().contains(STATIC) && !member.getKind().isClass() && !member.getKind().isInterface() && getController().getTrees().isAccessible(scope, (TypeElement) ((DeclaredType) type).asElement()) && (member.getKind() != METHOD || getController().getElementUtilities().getImplementationOf((ExecutableElement) member, (TypeElement) ((DeclaredType) type).asElement()) == member); }
@Override Integer run(CompilationController controller, MethodTree methodTree, ExecutableElement methodElement) { return (int) controller.getTrees().getSourcePositions().getEndPosition( controller.getCompilationUnit(), methodTree); } }.execute();
@Override Integer run(CompilationController controller, MethodTree methodTree, ExecutableElement methodElement) { return (int) controller.getTrees().getSourcePositions().getEndPosition( controller.getCompilationUnit(), methodTree); } }.execute();
@Override Integer run(CompilationController controller, ClassTree classTree, TypeElement classElement) { return (int) controller.getTrees().getSourcePositions().getEndPosition( controller.getCompilationUnit(), classTree); } }.execute();
@Override Integer run(CompilationController controller, MethodTree methodTree, ExecutableElement methodElement) { return (int) controller.getTrees().getSourcePositions().getStartPosition( controller.getCompilationUnit(), methodTree); } }.execute();
@Override public void run(CompilationController controller) throws Exception { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); for (Tree t: controller.getCompilationUnit().getTypeDecls()) { if (TreeUtilities.CLASS_TREE_KINDS.contains(t.getKind())) { ClassTree classT = (ClassTree) t; if (sourceFile.getName().equals(classT.getSimpleName().toString())) { TreePath classTPath = controller.getTrees().getPath(controller.getCompilationUnit(), classT); TypeElement classEl = (TypeElement) controller.getTrees().getElement(classTPath); result = run(controller, classT, classEl); return; } } } } }
static boolean isViewClass(ClassTree classT, CompilationController controller) { Trees trees = controller.getTrees(); TreePath classTPath = trees.getPath(controller.getCompilationUnit(), classT); TypeElement classEl = (TypeElement) trees.getElement(classTPath); TypeElement appEl = controller.getElements().getTypeElement("org.jdesktop.application.View"); // NOI18N Types types = controller.getTypes(); TypeMirror tm1 = types.erasure(classEl.asType()); TypeMirror tm2 = types.erasure(appEl.asType()); return types.isSubtype(tm1, tm2); }
private static TypeElement getTypeElement(CompilationController ci, String binaryName, String[] classExcludeNames) { ClassScanner cs = new ClassScanner(ci.getTrees(), ci.getElements(), binaryName, classExcludeNames); TypeElement te = cs.scan(ci.getCompilationUnit(), null); if (te != null) { return te; } else { return null; } }
@Override public void run(ResultIterator resultIterator) throws Exception { Result res = resultIterator.getParserResult(offset); if (res == null) { return; } CompilationController controller = CompilationController.get(res); if (controller == null || controller.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { return; } TreePath path = controller.getTreeUtilities().pathFor(offset); javax.lang.model.element.Element elem = controller.getTrees().getElement(path); ElementKind kind = elem.getKind(); if (kind == ElementKind.CLASS || kind == ElementKind.ENUM || kind == ElementKind.ANNOTATION_TYPE) { result[0] = elem.asType().toString(); } } });
@Override public void run(ResultIterator resultIterator) throws Exception { Result res = resultIterator.getParserResult(offset); if (res == null) { return; } CompilationController controller = CompilationController.get(res); if (controller == null || controller.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { return; } TreePath path = controller.getTreeUtilities().pathFor(offset); javax.lang.model.element.Element elem = controller.getTrees().getElement(path); ElementKind kind = elem.getKind(); if (kind == ElementKind.CLASS || kind == ElementKind.ENUM || kind == ElementKind.ANNOTATION_TYPE) { result[0] = elem.asType().toString(); } } });
@Override public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.ELEMENTS_RESOLVED); Trees trees = compilationController.getTrees(); CompilationUnitTree compilationUnitTree = compilationController.getCompilationUnit(); List<? extends Tree> typeDecls = compilationUnitTree.getTypeDecls(); for (Tree tree : typeDecls) { Element element = trees.getElement(trees.getPath(compilationUnitTree, tree)); if (element != null && element.getKind() == ElementKind.CLASS && element.getSimpleName().contentEquals(fo.getName())) { long pos = trees.getSourcePositions().getStartPosition(compilationUnitTree, tree); line[0] = compilationUnitTree.getLineMap().getLineNumber(pos); break; } } } }, true);
public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.ELEMENTS_RESOLVED); Trees trees = compilationController.getTrees(); CompilationUnitTree compilationUnitTree = compilationController.getCompilationUnit(); List<?extends Tree> typeDecls = compilationUnitTree.getTypeDecls(); for (Tree tree : typeDecls) { Element element = trees.getElement(trees.getPath(compilationUnitTree, tree)); if (element != null && element.getKind() == ElementKind.CLASS && element.getSimpleName().contentEquals(fo.getName())){ long pos = trees.getSourcePositions().getStartPosition(compilationUnitTree, tree); line[0] = compilationUnitTree.getLineMap().getLineNumber(pos); break; } } } }, true);
@Override public void run(CompilationController compilationController) throws Exception { compilationController.toPhase(Phase.ELEMENTS_RESOLVED); Trees trees = compilationController.getTrees(); CompilationUnitTree compilationUnitTree = compilationController.getCompilationUnit(); List<? extends Tree> typeDecls = compilationUnitTree.getTypeDecls(); for (Tree tree : typeDecls) { Element element = trees.getElement(trees.getPath(compilationUnitTree, tree)); if (element != null && element.getKind() == ElementKind.CLASS && element.getSimpleName().contentEquals(fo.getName())) { long pos = trees.getSourcePositions().getStartPosition(compilationUnitTree, tree); line[0] = compilationUnitTree.getLineMap().getLineNumber(pos); break; } } } }, true);
@Override public void run(CompilationController controller) throws Exception { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); Element element = handles[0].resolve(controller); Trees trees = controller.getTrees(); Tree tree = trees.getTree(element); SourcePositions sourcePositions = trees.getSourcePositions(); offset[0] = (int) sourcePositions.getStartPosition(controller.getCompilationUnit(), tree); } }, true);
@Override public void run(CompilationController controller) throws Exception { controller.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); Element element = handles[0].resolve(controller); Trees trees = controller.getTrees(); Tree tree = trees.getTree(element); SourcePositions sourcePositions = trees.getSourcePositions(); offset[0] = (int) sourcePositions.getStartPosition(controller.getCompilationUnit(), tree); } }, true);
@Override public void run(CompilationController controller) throws Exception { controller.toPhase( Phase.ELEMENTS_RESOLVED ); int dot = component.getCaret().getDot(); TreePath tp = controller.getTreeUtilities().pathFor(dot); Element contextElement = controller.getTrees().getElement(tp ); if ( contextElement == null ){ StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage( WebBeansActionHelper.class, "LBL_ElementNotFound")); return; } context[0] = contextElement; } }, true );