Java Code Examples for javax.lang.model.util.ElementFilter#typesIn()

The following examples show how to use javax.lang.model.util.ElementFilter#typesIn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestJavacTaskScanner.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void run() {
    Iterable<? extends TypeElement> toplevels;
    toplevels = ElementFilter.typesIn(task.enter(task.parse()));
    for (TypeElement clazz : toplevels) {
        System.out.format("Testing %s:%n%n", clazz.getSimpleName());
        testParseType(clazz);
        testGetAllMembers(clazz);
        System.out.println();
        System.out.println();
        System.out.println();
    }

    System.out.println("#tokens: " + numTokens);
    System.out.println("#parseTypeElements: " + numParseTypeElements);
    System.out.println("#allMembers: " + numAllMembers);

    check(numTokens, "#Tokens", 1054);
    check(numParseTypeElements, "#parseTypeElements", 158);
    check(numAllMembers, "#allMembers", 52);
}
 
Example 2
Source File: T6458749.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    if (!renv.processingOver()) {
        for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) {
            System.out.printf("Element %s:%n", e.toString());
            try {
                for (TypeParameterElement tp : e.getTypeParameters()) {
                    System.out.printf("Type param %s", tp.toString());
                    if (! tp.getEnclosedElements().isEmpty()) {
                        throw new AssertionError("TypeParameterElement.getEnclosedElements() should return empty list");
                    }
                }
            } catch (NullPointerException npe) {
                throw new AssertionError("NPE from TypeParameterElement.getEnclosedElements()", npe);
            }
        }
    }
    return true;
}
 
Example 3
Source File: T6458749.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    if (!renv.processingOver()) {
        for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) {
            System.out.printf("Element %s:%n", e.toString());
            try {
                for (TypeParameterElement tp : e.getTypeParameters()) {
                    System.out.printf("Type param %s", tp.toString());
                    if (! tp.getEnclosedElements().isEmpty()) {
                        throw new AssertionError("TypeParameterElement.getEnclosedElements() should return empty list");
                    }
                }
            } catch (NullPointerException npe) {
                throw new AssertionError("NPE from TypeParameterElement.getEnclosedElements()", npe);
            }
        }
    }
    return true;
}
 
Example 4
Source File: T6458749.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    if (!renv.processingOver()) {
        for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) {
            System.out.printf("Element %s:%n", e.toString());
            try {
                for (TypeParameterElement tp : e.getTypeParameters()) {
                    System.out.printf("Type param %s", tp.toString());
                    if (! tp.getEnclosedElements().isEmpty()) {
                        throw new AssertionError("TypeParameterElement.getEnclosedElements() should return empty list");
                    }
                }
            } catch (NullPointerException npe) {
                throw new AssertionError("NPE from TypeParameterElement.getEnclosedElements()", npe);
            }
        }
    }
    return true;
}
 
Example 5
Source File: T6458749.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    if (!renv.processingOver()) {
        for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) {
            System.out.printf("Element %s:%n", e.toString());
            try {
                for (TypeParameterElement tp : e.getTypeParameters()) {
                    System.out.printf("Type param %s", tp.toString());
                    if (! tp.getEnclosedElements().isEmpty()) {
                        throw new AssertionError("TypeParameterElement.getEnclosedElements() should return empty list");
                    }
                }
            } catch (NullPointerException npe) {
                throw new AssertionError("NPE from TypeParameterElement.getEnclosedElements()", npe);
            }
        }
    }
    return true;
}
 
Example 6
Source File: T6458749.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    if (!renv.processingOver()) {
        for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) {
            System.out.printf("Element %s:%n", e.toString());
            try {
                for (TypeParameterElement tp : e.getTypeParameters()) {
                    System.out.printf("Type param %s", tp.toString());
                    if (! tp.getEnclosedElements().isEmpty()) {
                        throw new AssertionError("TypeParameterElement.getEnclosedElements() should return empty list");
                    }
                }
            } catch (NullPointerException npe) {
                throw new AssertionError("NPE from TypeParameterElement.getEnclosedElements()", npe);
            }
        }
    }
    return true;
}
 
Example 7
Source File: ImportProcessor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "# {0} - package name",
    "ERR_importPackageNotExists=Package {0} does not exist."
})
private void handleWildcard(String packName, boolean add) {
    PackageElement el = info.getElements().getPackageElement(packName);
    if (el == null) {
        if (current == null) {
            return;
        }
        int[] offsets = findPiContentOffsets(current);
        addError(
            new ErrorMark(offsets[0], offsets[1] - offsets[0], 
            "import-package-not-exists",
            ERR_importPackageNotExists(packName),
            packName)
        );
        return;
    }
    if (add) {
        allPackages.add(packName);
    }
    List<TypeElement> types = ElementFilter.typesIn(el.getEnclosedElements());

    for (TypeElement t : types) {
        addType(t.getSimpleName().toString(), packName);
    }
}
 
Example 8
Source File: WebBeansAnalysisTask.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void analyzeType(TypeElement typeElement , TypeElement parent ,
        WebBeansModel model , CompilationInfo info )
{
    ElementKind kind = typeElement.getKind();
    ModelAnalyzer analyzer = ANALIZERS.get( kind );
    if ( analyzer != null ){
        analyzer.analyze(typeElement, parent, model, getCancel(), getResult());
    }
    if ( isCancelled() ){
        return;
    }
    List<? extends Element> enclosedElements = typeElement.getEnclosedElements();
    List<TypeElement> types = ElementFilter.typesIn(enclosedElements);
    for (TypeElement innerType : types) {
        if ( innerType == null ){
            continue;
        }
        analyzeType(innerType, typeElement , model , info );
    }
    Set<Element> enclosedSet = new HashSet<Element>( enclosedElements );
    enclosedSet.removeAll( types );
    for(Element element : enclosedSet ){
        if ( element == null ){
            continue;
        }
        analyze(typeElement, model, element, info );
    }
}
 
Example 9
Source File: TestTreePath.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    final Trees trees = Trees.instance(this.processingEnv);
    for (Element element : ElementFilter.typesIn(roundEnv.getRootElements())) {
        checkTreePath(trees, element, 2);
        for (Element member : element.getEnclosedElements())
            checkTreePath(trees, member, 3);
    }
    return true;
}
 
Example 10
Source File: Test.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        for (TypeElement typeElt : ElementFilter.typesIn(roundEnv.getRootElements())) {
            messager.printMessage(Diagnostic.Kind.NOTE, "processing " + typeElt);
        }
    }
    return true;
}
 
Example 11
Source File: BeakerxDoclet.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean run(DocletEnvironment docEnv) {
  HashMap<String, ClassInspect> inspects = new HashMap<>();
  DocTrees docTrees = docEnv.getDocTrees();
  for (TypeElement t : ElementFilter.typesIn(docEnv.getIncludedElements())) {
    DocCommentTree docCommentTree = docTrees.getDocCommentTree(t);
    String comment = (docCommentTree != null) ? docCommentTree.getFullBody().toString() : "";
    ClassInspect classInspect = new ClassInspect(t.getSimpleName().toString(), t.getQualifiedName().toString(), comment);
    inspects.put(classInspect.getFullName(), classInspect);
    List<MethodInspect> constructors = new ArrayList<>();
    List<MethodInspect> methods = new ArrayList<>();
    for (Element ee : t.getEnclosedElements()) {
      if (ee.getModifiers().contains(Modifier.PUBLIC) || ee.getModifiers().contains(Modifier.PROTECTED)) {
        if (ee.getKind().equals(ElementKind.CONSTRUCTOR)) {
          constructors.add(getInspect(ee, docTrees));
        } else if (ee.getKind().equals(ElementKind.METHOD)) {
          methods.add(getInspect(ee, docTrees));
        }
      }
    }
    classInspect.setMethods(methods);
    classInspect.setConstructors(constructors);
  }
  SerializeInspect serializeInspect = new SerializeInspect();
  String json = serializeInspect.toJson(inspects);
  serializeInspect.saveToFile(json);
  return true;
}
 
Example 12
Source File: SlimConfigurationProcessor.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private Set<TypeElement> collectTypes(RoundEnvironment roundEnv,
		Predicate<TypeElement> typeSelectionCondition) {
	Set<TypeElement> types = new HashSet<>();
	for (TypeElement type : ElementFilter.typesIn(roundEnv.getRootElements())) {
		collectTypes(type, types, typeSelectionCondition);
	}
	return types;
}
 
Example 13
Source File: DupOk.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean run(DocletEnvironment root) {
    Set<TypeElement> classes = ElementFilter.typesIn(root.getIncludedElements());
    if (classes.size() != 2)
        throw new Error("1 " + Arrays.asList(classes));
    for (TypeElement clazz : classes) {
        if (getFields(clazz).size() != 1)
            throw new Error("2 " + clazz + " " + getFields(clazz));
    }
    return true;
}
 
Example 14
Source File: TypeProcOnly.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (TypeElement elem : ElementFilter.typesIn(roundEnv.getRootElements())) {
        elements.add(elem.getQualifiedName());
    }
    return false;
}
 
Example 15
Source File: Processor.java    From immutables with Apache License 2.0 5 votes vote down vote up
private void processTemplates(Set<? extends Element> templates) {
  for (TypeElement templateType : ElementFilter.typesIn(templates)) {
    try {
      generateTemplateType(templateType);
    } catch (Exception ex) {
      processingEnv.getMessager()
          .printMessage(Diagnostic.Kind.ERROR,
              ex.getMessage() + "\n\n" + Throwables.getStackTraceAsString(ex),
              templateType);
    }
  }
}
 
Example 16
Source File: Test.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        for (TypeElement typeElt : ElementFilter.typesIn(roundEnv.getRootElements())) {
            messager.printMessage(Diagnostic.Kind.NOTE, "processing " + typeElt);
        }
    }
    return true;
}
 
Example 17
Source File: TypeProcOnly.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (TypeElement elem : ElementFilter.typesIn(roundEnv.getRootElements())) {
        elements.add(elem.getQualifiedName());
    }
    return false;
}
 
Example 18
Source File: PackageProcessor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {
    for (TypeElement elem : ElementFilter.typesIn(roundEnv.getRootElements())) {
        elements.add(elem.getQualifiedName());
    }
    return false;
}
 
Example 19
Source File: UnusedImports.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitImport(ImportTree tree, Void d) {
    if (parseErrorInImport(tree)) {
        return super.visitImport(tree, null);
    }
    if (tree.getQualifiedIdentifier() == null ||
        tree.getQualifiedIdentifier().getKind() != Tree.Kind.MEMBER_SELECT) {
        return super.visitImport(tree, null);
    }
    MemberSelectTree qualIdent = (MemberSelectTree) tree.getQualifiedIdentifier();
    boolean assign = false;
    
    // static imports and star imports only use the qualifier part
    boolean star = isStar(tree);
    TreePath tp = tree.isStatic() || star ?
            new TreePath(new TreePath(getCurrentPath(), qualIdent), qualIdent.getExpression()) :
            new TreePath(getCurrentPath(), tree.getQualifiedIdentifier());
    Element decl = info.getTrees().getElement(tp);
    
    import2Highlight.put(tree, getCurrentPath());
    if (decl != null && !isErroneous(decl)) {
        if (!tree.isStatic()) {
            if (star) {
                List<TypeElement> types = ElementFilter.typesIn(decl.getEnclosedElements());
                for (TypeElement te : types) {
                    assign = true;
                    if (!element2Import.containsKey(te)) {
                        element2Import.put(te, tree);
                    }
                }
            } else {
                element2Import.put(decl, tree);
                importedBySingleImport.add(decl);
            }
        } else if (decl.getKind().isClass() || decl.getKind().isInterface()) {
            Name simpleName = star ? null : qualIdent.getIdentifier();

            for (Element e : info.getElements().getAllMembers((TypeElement) decl)) {
                if (!e.getModifiers().contains(Modifier.STATIC)) continue;
                if (simpleName != null && !e.getSimpleName().equals(simpleName)) {
                    continue;
                }
                if (!star || !element2Import.containsKey(e)) {
                    element2Import.put(e, tree);
                }
                assign = true;
            }
        }
    }
    if (!assign) {
        if (!tree.isStatic() && star) {
            unresolvablePackageImports.add(tree);
        } else {
            addUnresolvableImport(qualIdent.getIdentifier(), tree);
        }
    }
    super.visitImport(tree, null);
    return null;
}
 
Example 20
Source File: CompletionFailure.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean run(DocletEnvironment root) {
    Set<TypeElement> classes = ElementFilter.typesIn(root.getIncludedElements());
    if (classes.size() != 1)
        throw new Error("1 " + Arrays.asList(classes));
    return true;
}