Java Code Examples for javax.annotation.processing.RoundEnvironment#getRootElements()

The following examples show how to use javax.annotation.processing.RoundEnvironment#getRootElements() . 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: DelegateProcessor.java    From Fourinone with Apache License 2.0 6 votes vote down vote up
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for(TypeElement te:annotations){
          note("annotation:"+te.toString());
      }
      
      Set<? extends Element> elements = roundEnv.getRootElements();
      for(Element e:elements){
	List enclosedElems = e.getEnclosedElements();
	List<ExecutableElement> ees = ElementFilter.methodsIn(enclosedElems);
          for(ExecutableElement ee:ees){
		note("--ExecutableElement name is "+ee.getSimpleName());
              List<? extends AnnotationMirror> as = ee.getAnnotationMirrors();
		note("--as="+as);
              for(AnnotationMirror am:as){
			Map map= am.getElementValues();
			Set<ExecutableElement> ks = map.keySet();
                  for(ExecutableElement k:ks){
                      AnnotationValue av = (AnnotationValue)map.get(k);
                      note("----"+ee.getSimpleName()+"."+k.getSimpleName()+"="+av.getValue());
                  }
              }
          }
      }
      return false;
  }
 
Example 2
Source File: BasicAnnoTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    TestElementScanner s = new TestElementScanner();
    for (Element e: roundEnv.getRootElements()) {
        s.scan(e);
    }
    return true;
}
 
Example 3
Source File: BasicAnnoTests.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) {
    TestElementScanner s = new TestElementScanner();
    for (Element e: roundEnv.getRootElements()) {
        s.scan(e);
    }
    return true;
}
 
Example 4
Source File: ErrorProcessor.java    From compile-testing with Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  for (Element element : roundEnv.getRootElements()) {
    messager.printMessage(Kind.ERROR, "expected error!", element);
    messager.printMessage(Kind.ERROR, "another expected error!");
  }
  return false;
}
 
Example 5
Source File: Processor.java    From Java-9-Programming-By-Example with MIT License 5 votes vote down vote up
@Override
public boolean process(final Set<? extends TypeElement> annotations,
		final RoundEnvironment roundEnv) {
	for (final Element rootElement : roundEnv.getRootElements()) {
		try {
			processClass(rootElement);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	return false;
}
 
Example 6
Source File: MessagerDiags.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
    Messager messager = processingEnv.getMessager();
    for (Element e : roundEnv.getRootElements()) {
        messager.printMessage(WARNING, WRN_NO_SOURCE);
        messager.printMessage(WARNING, WRN_WITH_SOURCE, e);
        messager.printMessage(WARNING, WRN_NO_SOURCE);
    }
    return false;
}
 
Example 7
Source File: TestGetScope.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Trees trees = Trees.instance(processingEnv);
    if (round++ == 0) {
        for (Element e: roundEnv.getRootElements()) {
            TreePath p = trees.getPath(e);
            new Scanner().scan(p, trees);
        }
    }
    return false;
}
 
Example 8
Source File: MessagerDiags.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
    Messager messager = processingEnv.getMessager();
    for (Element e : roundEnv.getRootElements()) {
        messager.printMessage(WARNING, WRN_NO_SOURCE);
        messager.printMessage(WARNING, WRN_WITH_SOURCE, e);
        messager.printMessage(WARNING, WRN_NO_SOURCE);
    }
    return false;
}
 
Example 9
Source File: SimpleServiceTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized boolean process(
    Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  for (Element rootElement : roundEnv.getRootElements()) {
    if (!rootElement.asType().toString().equals(SimpleServiceGrpc.class.getCanonicalName())) {
      continue;
    }

    Map<String, RpcMethod> methodToAnnotation = new HashMap<>();
    for (Element enclosedElement : rootElement.getEnclosedElements()) {
      RpcMethod annotation = enclosedElement.getAnnotation(RpcMethod.class);
      if (annotation != null) {
        methodToAnnotation.put(enclosedElement.getSimpleName().toString(), annotation);
      }
    }

    verifyRpcMethodAnnotation(
        SimpleServiceGrpc.getUnaryRpcMethod(), methodToAnnotation.get("getUnaryRpcMethod"));
    verifyRpcMethodAnnotation(
        SimpleServiceGrpc.getServerStreamingRpcMethod(),
        methodToAnnotation.get("getServerStreamingRpcMethod"));
    verifyRpcMethodAnnotation(
        SimpleServiceGrpc.getClientStreamingRpcMethod(),
        methodToAnnotation.get("getClientStreamingRpcMethod"));
    verifyRpcMethodAnnotation(
        SimpleServiceGrpc.getBidiStreamingRpcMethod(),
        methodToAnnotation.get("getBidiStreamingRpcMethod"));

    processedClass = true;
  }
  return false;
}
 
Example 10
Source File: AnnotationProcessor.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
	if (!delayedWarnings.isEmpty()) {
		Set<? extends Element> rootElements = roundEnv.getRootElements();
		if (!rootElements.isEmpty()) {
			Element firstRoot = rootElements.iterator().next();
			for (String warning : delayedWarnings) processingEnv.getMessager().printMessage(Kind.WARNING, warning, firstRoot);
			delayedWarnings.clear();
		}
	}
	
	for (ProcessorDescriptor proc : active) proc.process(annotations, roundEnv);
	
	return false;
}
 
Example 11
Source File: Test.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e : roundEnv.getRootElements()) {
        checker.scan(checker.trees.getPath(e), null);
    }
    return true;
}
 
Example 12
Source File: ReferenceTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e: roundEnv.getRootElements()) {
        new DocCommentScanner(trees.getPath(e)).scan();
    }
    return true;
}
 
Example 13
Source File: ReferenceTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e: roundEnv.getRootElements()) {
        new DocCommentScanner(trees.getPath(e)).scan();
    }
    return true;
}
 
Example 14
Source File: Test.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e : roundEnv.getRootElements()) {
        checker.scan(checker.trees.getPath(e), null);
    }
    return true;
}
 
Example 15
Source File: ErrorProcessor.java    From Moxy with MIT License 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
	for (Element element : roundEnv.getRootElements()) {
		if (element.getSimpleName().toString().equals("InjectPresenterTypeBehaviorView")) {
			for (Element element1 : element.getEnclosedElements()) {
				System.out.println("EnclosedElements: " + element1.getSimpleName());
				ImmutableList<String> of = ImmutableList.of("mPresenterIdLocalPresenter", "mTagLocalPresenter", "mFactoryLocalPresenter", "mFactoryTagPresenter");
				if (of.contains(element1.getSimpleName().toString())) {
					messager.printMessage(Diagnostic.Kind.ERROR, "expected error!", element1);
				}
			}
		}
	}
	return true;
}
 
Example 16
Source File: Test.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e : roundEnv.getRootElements()) {
        checker.scan(checker.trees.getPath(e), null);
    }
    return true;
}
 
Example 17
Source File: BasicAnnoTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    TestElementScanner s = new TestElementScanner();
    for (Element e: roundEnv.getRootElements()) {
        s.scan(e);
    }
    return true;
}
 
Example 18
Source File: ClassChecker.java    From java-master with Apache License 2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    Set<? extends Element> elements = roundEnv.getRootElements();
    ClassScanner scanner8 = new ClassScanner();
    for (Element element : elements) {
        scanner8.scan(element);
    }
    return false;
}
 
Example 19
Source File: MessagerDiags.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations,
                       RoundEnvironment roundEnv) {
    Messager messager = processingEnv.getMessager();
    for (Element e : roundEnv.getRootElements()) {
        messager.printMessage(WARNING, WRN_NO_SOURCE);
        messager.printMessage(WARNING, WRN_WITH_SOURCE, e);
        messager.printMessage(WARNING, WRN_NO_SOURCE);
    }
    return false;
}
 
Example 20
Source File: SourceTreeModel.java    From Akatsuki with Apache License 2.0 4 votes vote down vote up
public static SourceTreeModel fromRound(ProcessorContext context, RoundEnvironment roundEnv,
		Set<Class<? extends Annotation>> classes) {

	// final Set<Element> elements = new HashSet<>();
	// for (Class<? extends Annotation> clazz : classes) {
	// elements.addAll(roundEnv.getElementsAnnotatedWith(clazz));
	// }

	ArrayList<Element> list = new ArrayList<>();
	for (Element root : roundEnv.getRootElements()) {
		collectElements(list, root, classes);
	}

	Map<String, SourceClassModel> classNameMap = new HashMap<>();
	int processed = 0;
	boolean verifyOnly = false;
	for (Element element : list) {

		// skip if error
		if (!annotatedElementValid(context, element)
				|| !enclosingClassValid(context, element)) {
			verifyOnly = true;
			continue;
		}

		// >= 1 error has occurred, we're in verify mode
		if (!verifyOnly) {
			final TypeElement enclosingClass = (TypeElement) element.getEnclosingElement();

			if (context.config().fieldAllowed(element)) {
				final SourceClassModel model = classNameMap.computeIfAbsent(
						enclosingClass.getQualifiedName().toString(),
						k -> new SourceClassModel(context, enclosingClass));
				Set<Class<? extends Annotation>> annotationClasses = classes.stream()
						.filter(c -> element.getAnnotation(c) != null)
						.collect(Collectors.toSet());
				model.fields.add(new FieldModel((VariableElement) element, annotationClasses));
				Log.verbose(context, "Element marked", element);
			} else {
				Log.verbose(context, "Element skipped", element);
			}
		}
		processed++;
	}

	Collection<SourceClassModel> models = classNameMap.values();
	if (processed != list.size()) {
		context.messager().printMessage(Kind.NOTE,
				(list.size() - processed)
						+ " error(s) occurred, no files are generated after the first "
						+ "error has occurred.");
	} else {
		// stage 2, initialize them all
		models.forEach(model -> model.linkParent(classNameMap));
		models.forEach(model -> model.findChildren(classNameMap, roundEnv));

		models.forEach(SourceClassModel::markHiddenFields);
	}

	return verifyOnly ? null : new SourceTreeModel(context, new ArrayList<>(models));
}