static Element getElement(CompilationInfo cinfo, Tree tree) { return cinfo.getTrees().getElement(getTreePath(cinfo, tree)); }
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; }
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; }
Element element = compilationInfo.getTrees().getElement(errorPath); if ( element == null || element.getSimpleName() == null || errorPath.getLeaf().getKind() != Kind.IDENTIFIER ) if ( parentPath.getLeaf().getKind() != Kind.ANNOTATION ){ return Collections.<Fix>emptyList(); Element annotation = compilationInfo.getTrees().getElement(parentPath); TreePath path = parentPath; while (path != null ){ Tree leaf = path.getLeaf(); Kind leafKind = leaf.getKind(); if ( TreeUtilities.CLASS_TREE_KINDS.contains(leafKind) ){ Element clazz = compilationInfo.getTrees().getElement(path); if ( clazz != null && clazz.getKind() == ElementKind.CLASS ) Element var = compilationInfo.getTrees().getElement(path); if ( var == null ){ return null; if ( var.getKind() == ElementKind.FIELD && (parent instanceof TypeElement)) Element method = compilationInfo.getTrees().getElement(path); if ( method != null && method.getKind() == ElementKind.METHOD){ return analyzeMethodParameter( compilationInfo , (ExecutableElement)method , annotation );
ClassTree clazz = null; for (Tree typeDecl : cu.getTypeDecls()) { if (TreeUtilities.CLASS_TREE_KINDS.contains(typeDecl.getKind())) { ClassTree candidate = (ClassTree) typeDecl; if (candidate.getModifiers().getFlags().contains(javax.lang.model.element.Modifier.PUBLIC)) { clazz = candidate; break; Element classElement = cc.getTrees().getElement(cc.getTrees().getPath(cu, clazz)); for (VariableElement variable : ElementFilter.fieldsIn(classElement.getEnclosedElements())) { String name = variable.getSimpleName().toString();
if (superT != null) { TreePath superTPath = controller.getTrees().getPath(controller.getCompilationUnit(), superT); Element superEl = controller.getTrees().getElement(superTPath); while (superEl != null && superEl.getKind() == ElementKind.CLASS) { TypeElement superClassEl = (TypeElement) superEl; classList.add(0, superClassEl); for (TypeElement cls : classList) { for (ExecutableElement el : ElementFilter.methodsIn(cls.getEnclosedElements())) { if (el.getModifiers().contains(Modifier.PUBLIC)) { org.jdesktop.application.Action ann = el.getAnnotation(org.jdesktop.application.Action.class); if (ann != null) {
public Void visitClass(ClassTree ct, Void _) { TreePath path = getCurrentPath(); treePathByClass.put(ct,path); TypeElement e = (TypeElement) trees.getElement(path); if(e!=null) { classes.put(e.getQualifiedName().toString(), path); // make sure we have descendants tree built for all compilation units getParsedType(e); // remember packages that have compilation units in it Element p = e.getEnclosingElement(); if(p.getKind()==ElementKind.PACKAGE) packages.add((PackageElement) p); } return super.visitClass(ct, _); } };
CompilationUnitTree cu = cc.getCompilationUnit(); Trees trees = cc.getTrees(); if (tree.getKind() == Tree.Kind.EXTENDS_WILDCARD) { tree = ((WildcardTree)tree).getBound(); Element el = trees.getElement(path); if ((el != null) && ((el.getKind() == ElementKind.CLASS) || (el.getKind() == ElementKind.INTERFACE))) { TypeElement tel = (TypeElement) el; typeName = tel.getQualifiedName().toString(); if (tree.getKind() == Tree.Kind.PARAMETERIZED_TYPE) { List<? extends Tree> params = ((ParameterizedTypeTree)tree).getTypeArguments(); List<? extends TypeParameterElement> elems = tel.getTypeParameters();
private void insideMemberReference(Env env) throws IOException { TreePath path = env.getPath(); MemberReferenceTree mr = (MemberReferenceTree) path.getLeaf(); TokenSequence<JavaTokenId> ts = findLastNonWhitespaceToken(env, mr, env.getOffset()); if (ts != null) { Element e = trees.getElement(expPath); addMethodReferences(env, type, e); if (e == null || e.getKind().isClass() || e.getKind().isInterface()) { addKeyword(env, NEW_KEYWORD, SPACE, false);
while (tp != null && tp.getLeaf().getKind() != Kind.METHOD) { tp = tp.getParentPath(); Element element = controller.getTrees().getElement(tp); List<? extends AnnotationMirror> allAnnotationMirrors = elements.getAllAnnotationMirrors(element); for (Iterator<? extends AnnotationMirror> it = allAnnotationMirrors.iterator(); it.hasNext();) {
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)) {
private static ExpressionTree findImplementIdentifier (Trees trees, TreePath classTreePath, String fullyQualifiedName) { ClassTree clazz = (ClassTree) classTreePath.getLeaf (); for (Tree tree : clazz.getImplementsClause ()) { Element element = trees.getElement (new TreePath (classTreePath, tree)); if (equalsElementWithFQN (element, fullyQualifiedName)) return (ExpressionTree) tree; } return null; }
if (modifiers.getKind() == Kind.MODIFIERS) { annotations = ((ModifiersTree) modifiers).getAnnotations(); } else if (modifiers.getKind() == Kind.COMPILATION_UNIT) { annotations = ((CompilationUnitTree) modifiers).getPackageAnnotations(); } else { Element e = copy.getTrees().getElement(tp); if (modifiers.getKind() == Kind.MODIFIERS) { return make.addModifiersAnnotation((ModifiersTree) modifiers, newAnnotation); } else if (modifiers.getKind() == Kind.COMPILATION_UNIT) {
controller.toPhase(Phase.ELEMENTS_RESOLVED); Trees trees = controller.getTrees(); AnnotationTree at = (AnnotationTree) annotationPath.getLeaf(); Element annTypeElement = trees.getElement(new TreePath(annotationPath, at.getAnnotationType())); Element el = null; TreePath pPath = annotationPath.getParentPath(); if (pPath.getLeaf().getKind() == Tree.Kind.COMPILATION_UNIT) { el = trees.getElement(pPath); } else { pPath = pPath.getParentPath(); Tree.Kind pKind = pPath.getLeaf().getKind(); if (TreeUtilities.CLASS_TREE_KINDS.contains(pKind) || pKind == Tree.Kind.METHOD || pKind == Tree.Kind.VARIABLE) { el = trees.getElement(pPath); if (el != null && annTypeElement != null && annTypeElement.getKind() == ANNOTATION_TYPE) { ExecutableElement memberElement = null; for (Element e : ((TypeElement) annTypeElement).getEnclosedElements()) { if (e.getKind() == METHOD && attributeName.contentEquals(e.getSimpleName())) { memberElement = (ExecutableElement) e; break;
public void run(CompilationController control) throws Exception { if (JavaSource.Phase.ELEMENTS_RESOLVED.compareTo(control.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED))<=0) { Elements elements = control.getElements(); Trees trees = control.getTrees(); Types types = control.getTypes(); TypeElement applet = elements.getTypeElement("java.applet.Applet"); //NOI18N TypeElement japplet = elements.getTypeElement("javax.swing.JApplet"); //NOI18N CompilationUnitTree cu = control.getCompilationUnit(); List<? extends Tree> topLevels = cu.getTypeDecls(); for (Tree topLevel : topLevels) { if (topLevel.getKind() == Tree.Kind.CLASS) { TypeElement type = (TypeElement) trees.getElement(TreePath.getPath(cu, topLevel)); if (type != null) { Set<Modifier> modifiers = type.getModifiers(); if (modifiers.contains(Modifier.PUBLIC) && ((applet != null && types.isSubtype(type.asType(), applet.asType())) || (japplet != null && types.isSubtype(type.asType(), japplet.asType())))) { result[0] = true; break; } } } } } }
continue; switch (e.getKind()) { case METHOD: case ENUM_CONSTANT: pkg = packageName != null ? (PackageElement)trees.getElement(TreePath.getPath(cut, packageName)) : null; if (pkg == null && packageName != null) { pkg = elements.getPackageElement(elements.getName(packageName.toString())); boolean isStatic = false; Element el = null; switch (e.getKind()) { case PACKAGE: el = e; case ENUM: case INTERFACE: if (e.getEnclosingElement().getKind() == ElementKind.PACKAGE) el = e.getEnclosingElement(); break; if (explicitNamedImports.contains(currentToImportElement)) cnt = 0; if (cnt == -2) {
@Override public Void visitIdentifier(IdentifierTree node, Void p) { if (!map.containsKey(node.getName())) { Element element = trees.getElement(getCurrentPath()); if (element != null && (element.getKind().isClass() || element.getKind().isInterface()) && element.asType().getKind() != TypeKind.ERROR) { map.put(node.getName(), (TypeElement) element); } } return super.visitIdentifier(node, p); }
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; }
boolean junit3 = (testcase != null && typeElement != null) ? controller.getTypes().isSubtype(typeElement.asType(), testcase.asType()) : false; TreePath tp = controller.getTreeUtilities().pathFor(caretPosition); while (tp != null && tp.getLeaf().getKind() != Kind.METHOD) { tp = tp.getParentPath(); Element element = controller.getTrees().getElement(tp); String mn = element.getSimpleName().toString(); if (junit3){
@Override public Void visitClass(ClassTree t, Void v) { if (variableElement == null) { // try to find the component's field variable in the class List<? extends Tree> members = (List<? extends Tree>) t.getMembers(); Iterator<? extends Tree> it = members.iterator(); while(it.hasNext()){ Tree tr = it.next(); if (tr.getKind() == Tree.Kind.VARIABLE) { Trees trees = info.getTrees(); TreePath path = new TreePath(getCurrentPath(), tr); Element el = trees.getElement(path); if (el != null) { // Issue 185420 String sname = el.getSimpleName().toString(); if(sname.equals(this.member)){ this.handle = TreePathHandle.create(path, info); variableElement = el; if (findUsages) { usagesPositions = new ArrayList<Integer>(); } } } } } } if (findUsages) { super.visitClass(t, v); } return null; }