< prev index next >
test/langtools/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 21,37 ****
* questions.
*/
/*
* @test
! * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 8030049 8038080 8032230
* @summary Tests that getElementsAnnotatedWith works properly.
* @author Joseph D. Darcy
* @library /tools/javac/lib
* @modules java.compiler
* jdk.compiler
* @build JavacTestingAbstractProcessor
* @compile TestElementsAnnotatedWith.java
* @compile InheritedAnnotation.java
* @compile TpAnno.java
* @compile Anno.java
* @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java
--- 21,38 ----
* questions.
*/
/*
* @test
! * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 8030049 8038080 8032230 8190886
* @summary Tests that getElementsAnnotatedWith works properly.
* @author Joseph D. Darcy
* @library /tools/javac/lib
* @modules java.compiler
* jdk.compiler
* @build JavacTestingAbstractProcessor
+ * @compile annot/AnnotatedElementInfo.java annot/MarkerAnnot.java
* @compile TestElementsAnnotatedWith.java
* @compile InheritedAnnotation.java
* @compile TpAnno.java
* @compile Anno.java
* @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java
*** 39,53 ****
--- 40,64 ----
* @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java
* @compile -processor TestElementsAnnotatedWith -proc:only C2.java
* @compile -processor TestElementsAnnotatedWith -proc:only Foo.java
* @compile -processor TestElementsAnnotatedWith -proc:only TypeParameterAnnotations.java
* @compile -processor TestElementsAnnotatedWith -proc:only ParameterAnnotations.java
+ * @compile -processor TestElementsAnnotatedWith -proc:only pkg/package-info.java
+ * @compile -processor TestElementsAnnotatedWith -proc:only mod/quux/package-info.java
+ * @compile -processor TestElementsAnnotatedWith -proc:only mod/quux/Quux.java
+ * @compile mod/quux/Quux.java mod/quux/package-info.java
+ * @compile -processor TestElementsAnnotatedWith -proc:only -AsingleModuleMode=true mod/module-info.java
* @compile/fail/ref=ErroneousAnnotations.out -processor TestElementsAnnotatedWith -proc:only -XDrawDiagnostics ErroneousAnnotations.java
* @compile Foo.java
* @compile/process -processor TestElementsAnnotatedWith -proc:only Foo
*/
+ // * @compile mod/quux/package-info.java mod/quux/Quux.java
+ // * @compile -processor TestElementsAnnotatedWith -proc:only mod/module-info.java
+
+
+ import annot.AnnotatedElementInfo;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
*** 146,157 ****
*
* 3) Verify the result of getElementsAnnotatedWithAny({X, Y}) is equal to
* getElementsAnnotatedWith(X) UNION getElementsAnnotatedWith(Y).
*/
void checkSetOfAnnotatedElements(RoundEnvironment re) {
- TypeElement annotatedElemInfoElem = elements.getTypeElement("AnnotatedElementInfo");
-
// For the "Any" methods, search for both the expected
// annotation and AnnotatedElementInfo and verify the return
// set is the union of searching for AnnotatedElementInfo and
// the other annotation
Set<? extends Element> resultsMeta = Collections.emptySet();
--- 157,166 ----
*** 160,191 ****
Set<? extends Element> resultsMetaAnyMulti = Collections.emptySet();
Set<? extends Element> resultsBase = Collections.emptySet();
Set<? extends Element> resultsBaseAny = Collections.emptySet();
Set<? extends Element> resultsBaseAnyMulti = Collections.emptySet();
if (!re.processingOver()) {
testNonAnnotations(re);
// Verify AnnotatedElementInfo is present on the first
// specified type.
! TypeElement firstType = typesIn(re.getRootElements()).iterator().next();
AnnotatedElementInfo annotatedElemInfo =
! firstType.getAnnotation(AnnotatedElementInfo.class);
boolean failed = false;
Objects.requireNonNull(annotatedElemInfo,
! "Missing AnnotatedElementInfo annotation on " + firstType);
// Verify that the annotation information is as expected.
Set<String> expectedNames =
new HashSet<>(Arrays.asList(annotatedElemInfo.names()));
String annotationName = annotatedElemInfo.annotationName();
! TypeElement annotationTypeElem = elements.getTypeElement(annotationName);
resultsMeta = re.getElementsAnnotatedWith(annotationTypeElem);
resultsMetaAny = re.getElementsAnnotatedWithAny(annotationTypeElem);
resultsMetaMulti.addAll(resultsMeta);
resultsMetaMulti.addAll(re.getElementsAnnotatedWith(annotatedElemInfoElem));
--- 169,225 ----
Set<? extends Element> resultsMetaAnyMulti = Collections.emptySet();
Set<? extends Element> resultsBase = Collections.emptySet();
Set<? extends Element> resultsBaseAny = Collections.emptySet();
Set<? extends Element> resultsBaseAnyMulti = Collections.emptySet();
+
+ boolean singleModuleMode = processingEnv.getOptions().get("singleModuleMode") != null;
+
+ TypeElement annotatedElemInfoElem = null;
+
if (!re.processingOver()) {
testNonAnnotations(re);
// Verify AnnotatedElementInfo is present on the first
// specified type.
! Element firstElement = re.getRootElements().iterator().next();
AnnotatedElementInfo annotatedElemInfo =
! firstElement.getAnnotation(AnnotatedElementInfo.class);
!
! ModuleElement moduleContext;
! // DEBUGGING
! if (firstElement.getKind() == ElementKind.MODULE) {
! elements.printElements(new java.io.OutputStreamWriter(System.out) , firstElement);
! System.out.println("AnnotatedElementInfo module: " + AnnotatedElementInfo.class.getModule());
!
! for (AnnotationMirror am : firstElement.getAnnotationMirrors()){
! System.out.print("\t" + am.toString());
! System.out.println("\t in module " + elements.getModuleOf(am.getAnnotationType().asElement()).toString());
! }
! moduleContext = (ModuleElement)firstElement;
! } else {
! moduleContext = elements.getModuleElement(""); // unnamed module
! }
!
!
! annotatedElemInfoElem =
! elements.getTypeElement(moduleContext, "annot.AnnotatedElementInfo");
boolean failed = false;
Objects.requireNonNull(annotatedElemInfo,
! "Missing AnnotatedElementInfo annotation on " + firstElement);
// Verify that the annotation information is as expected.
Set<String> expectedNames =
new HashSet<>(Arrays.asList(annotatedElemInfo.names()));
String annotationName = annotatedElemInfo.annotationName();
! TypeElement annotationTypeElem = elements.getTypeElement(moduleContext,
! annotationName);
resultsMeta = re.getElementsAnnotatedWith(annotationTypeElem);
resultsMetaAny = re.getElementsAnnotatedWithAny(annotationTypeElem);
resultsMetaMulti.addAll(resultsMeta);
resultsMetaMulti.addAll(re.getElementsAnnotatedWith(annotatedElemInfoElem));
*** 227,237 ****
if (!resultsBase.equals(resultsBaseAny)) {
failed = true;
System.err.printf("Inconsistent Base with vs withAny results");
}
! if (!resultsMeta.equals(resultsBase)) {
failed = true;
System.err.println("Base and Meta sets unequal;\n meta: " + resultsMeta +
"\nbase: " + resultsBase);
}
--- 261,271 ----
if (!resultsBase.equals(resultsBaseAny)) {
failed = true;
System.err.printf("Inconsistent Base with vs withAny results");
}
! if (!singleModuleMode && !resultsMeta.equals(resultsBase)) {
failed = true;
System.err.println("Base and Meta sets unequal;\n meta: " + resultsMeta +
"\nbase: " + resultsBase);
}
*** 239,249 ****
failed = true;
System.err.println("MetaMultAny and MetaMulti sets unequal;\n meta: " + resultsMeta +
"\nbase: " + resultsBase);
}
! if (!resultsBaseAnyMulti.equals(resultsMetaAnyMulti)) {
failed = true;
System.err.println("BaseMulti and MetaMulti sets unequal;\n meta: " + resultsMeta +
"\nbase: " + resultsBase);
}
--- 273,283 ----
failed = true;
System.err.println("MetaMultAny and MetaMulti sets unequal;\n meta: " + resultsMeta +
"\nbase: " + resultsBase);
}
! if (!singleModuleMode && !resultsBaseAnyMulti.equals(resultsMetaAnyMulti)) {
failed = true;
System.err.println("BaseMulti and MetaMulti sets unequal;\n meta: " + resultsMeta +
"\nbase: " + resultsBase);
}
*** 253,268 ****
--- 287,305 ----
}
} else {
// If processing is over without an error, the specified
// elements should be empty so an empty set should be
// returned.
+ if (!singleModuleMode) {
+ annotatedElemInfoElem = elements.getTypeElement("AnnotatedElementInfo");
throwOnNonEmpty(re.getElementsAnnotatedWith(annotatedElemInfoElem), "resultsMeta");
throwOnNonEmpty(re.getElementsAnnotatedWithAny(annotatedElemInfoElem), "resultsMetaAny");
throwOnNonEmpty(re.getElementsAnnotatedWith(AnnotatedElementInfo.class), "resultsBase");
throwOnNonEmpty(re.getElementsAnnotatedWithAny(Set.of(AnnotatedElementInfo.class)), "resultsBaseAny");
}
}
+ }
private void throwOnNonEmpty(Set<? extends Element> results, String message) {
if (!results.isEmpty()) {
throw new RuntimeException("Nonempty " + message + "\t" + results);
}
< prev index next >