aoqi@0: /* aoqi@0: * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 7151010 8006547 8007766 8029017 aoqi@0: * @summary Default test cases for running combinations for Target values aoqi@0: * @build Helper aoqi@0: * @run main TargetAnnoCombo aoqi@0: */ aoqi@0: aoqi@0: import java.util.Set; aoqi@0: import java.util.List; aoqi@0: import java.io.IOException; aoqi@0: import java.lang.annotation.ElementType; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Arrays; aoqi@0: import java.util.EnumSet; aoqi@0: import javax.tools.Diagnostic; aoqi@0: import javax.tools.DiagnosticCollector; aoqi@0: import javax.tools.JavaFileObject; aoqi@0: aoqi@0: import static java.lang.annotation.ElementType.ANNOTATION_TYPE; aoqi@0: import static java.lang.annotation.ElementType.CONSTRUCTOR; aoqi@0: import static java.lang.annotation.ElementType.FIELD; aoqi@0: import static java.lang.annotation.ElementType.METHOD; aoqi@0: import static java.lang.annotation.ElementType.PARAMETER; aoqi@0: import static java.lang.annotation.ElementType.TYPE; aoqi@0: import static java.lang.annotation.ElementType.PACKAGE; aoqi@0: import static java.lang.annotation.ElementType.LOCAL_VARIABLE; aoqi@0: import static java.lang.annotation.ElementType.TYPE_USE; aoqi@0: import static java.lang.annotation.ElementType.TYPE_PARAMETER; aoqi@0: aoqi@0: public class TargetAnnoCombo { aoqi@0: aoqi@0: static final String TESTPKG = "testpkg"; aoqi@0: aoqi@0: // Set it to true to get more debug information including base and container aoqi@0: // target sets for a given test case. aoqi@0: static final boolean DEBUG = false; aoqi@0: aoqi@0: // Define constant target sets to be used for the combination of the target values. aoqi@0: final static Set noSet = null; aoqi@0: final static Set empty = EnumSet.noneOf(ElementType.class); aoqi@0: aoqi@0: // [TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, aoqi@0: // PACKAGE, TYPE_PARAMETER, TYPE_USE] aoqi@0: final static Set allTargets = EnumSet.allOf(ElementType.class); aoqi@0: aoqi@0: // [TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, aoqi@0: // PACKAGE] aoqi@0: final static Set jdk7 = EnumSet.range(TYPE, PACKAGE); aoqi@0: aoqi@0: // [TYPE_USE, TYPE_PARAMETER] aoqi@0: final static Set jdk8 = EnumSet.range(TYPE_PARAMETER, TYPE_USE); aoqi@0: aoqi@0: // List of test cases to run. This list is created in generate(). aoqi@0: // To run a specific test cases add case number in @run main line. aoqi@0: List testCases = new ArrayList(); aoqi@0: aoqi@0: int errors = 0; aoqi@0: aoqi@0: // Identify test cases that fail. aoqi@0: enum IgnoreKind { aoqi@0: RUN, aoqi@0: IGNORE aoqi@0: }; aoqi@0: aoqi@0: private class TestCase { aoqi@0: aoqi@0: private Set baseAnnotations; aoqi@0: private Set containerAnnotations; aoqi@0: private IgnoreKind ignore; aoqi@0: aoqi@0: public TestCase(Set baseAnnotations, Set containerAnnotations) { aoqi@0: this(baseAnnotations, containerAnnotations, IgnoreKind.RUN); aoqi@0: } aoqi@0: aoqi@0: public TestCase(Set baseAnnotations, Set containerAnnotations, aoqi@0: IgnoreKind ignoreKind) { aoqi@0: this.baseAnnotations = baseAnnotations; aoqi@0: this.containerAnnotations = containerAnnotations; aoqi@0: this.ignore = ignoreKind; aoqi@0: } aoqi@0: aoqi@0: public Set getBaseAnnotations() { aoqi@0: return baseAnnotations; aoqi@0: } aoqi@0: aoqi@0: public Set getContainerAnnotations() { aoqi@0: return containerAnnotations; aoqi@0: } aoqi@0: aoqi@0: public boolean isIgnored() { aoqi@0: return ignore == IgnoreKind.IGNORE; aoqi@0: } aoqi@0: aoqi@0: // Determine if a testCase should compile or not. aoqi@0: private boolean isValidSubSet() { aoqi@0: /* aoqi@0: * RULE 1: conAnnoTarget should be a subset of baseAnnoTarget aoqi@0: * RULE 2: For empty @Target ({}) - annotation cannot be applied anywhere aoqi@0: * - Empty sets for both is valid aoqi@0: * - Empty baseTarget set is invalid with non-empty conTarget set aoqi@0: * - Non-empty baseTarget set is valid with empty conTarget set aoqi@0: * RULE 3: For no @Target specified - annotation can be applied to any JDK 7 targets aoqi@0: * - No @Target for both is valid aoqi@0: * - No @Target for baseTarget set with @Target conTarget set is valid aoqi@0: * - @Target for baseTarget set with no @Target for conTarget is invalid aoqi@0: */ aoqi@0: aoqi@0: aoqi@0: /* If baseAnno has no @Target, Foo can be either applied to @Target specified aoqi@0: * for container annotation else will be applicable for all default targets aoqi@0: * if no @Target is present for container annotation. aoqi@0: * In both cases, the set will be a valid set with no @Target for base annotation aoqi@0: */ aoqi@0: if (baseAnnotations == null) { aoqi@0: if (containerAnnotations == null) { aoqi@0: return true; aoqi@0: } aoqi@0: return !(containerAnnotations.contains(TYPE_USE) || aoqi@0: containerAnnotations.contains(TYPE_PARAMETER)); aoqi@0: } aoqi@0: aoqi@0: Set tempBaseSet = EnumSet.noneOf(ElementType.class); aoqi@0: tempBaseSet.addAll(baseAnnotations); aoqi@0: aoqi@0: // If BaseAnno has TYPE, then ANNOTATION_TYPE is allowed by default. aoqi@0: if (baseAnnotations.contains(TYPE)) { aoqi@0: tempBaseSet.add(ANNOTATION_TYPE); aoqi@0: } aoqi@0: aoqi@0: // If BaseAnno has TYPE_USE, then add the extra allowed types aoqi@0: if (baseAnnotations.contains(TYPE_USE)) { aoqi@0: tempBaseSet.add(ANNOTATION_TYPE); aoqi@0: tempBaseSet.add(TYPE); aoqi@0: tempBaseSet.add(TYPE_PARAMETER); aoqi@0: } aoqi@0: aoqi@0: // If containerAnno has no @Target, only valid case if baseAnnoTarget has aoqi@0: // all targets defined else invalid set. aoqi@0: if (containerAnnotations == null) { aoqi@0: return tempBaseSet.containsAll(jdk7); aoqi@0: } aoqi@0: aoqi@0: // At this point, neither conAnnoTarget or baseAnnoTarget are null. aoqi@0: if (containerAnnotations.isEmpty()) { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: // At this point, conAnnoTarget is non-empty. aoqi@0: if (baseAnnotations.isEmpty()) { aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: // At this point, neither conAnnoTarget or baseAnnoTarget are empty. aoqi@0: return tempBaseSet.containsAll(containerAnnotations); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static void main(String args[]) throws Exception { aoqi@0: TargetAnnoCombo tac = new TargetAnnoCombo(); aoqi@0: // Generates all test cases to be run. aoqi@0: tac.generate(); aoqi@0: List cases = new ArrayList(); aoqi@0: for (int i = 0; i < args.length; i++) { aoqi@0: cases.add(Integer.parseInt(args[i])); aoqi@0: } aoqi@0: if (cases.isEmpty()) { aoqi@0: tac.run(); aoqi@0: } else { aoqi@0: for (int index : cases) { aoqi@0: tac.executeTestCase(tac.testCases.get(index), index); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private void generate() { aoqi@0: // Adding test cases to run. aoqi@0: testCases.addAll(Arrays.asList( aoqi@0: // No base target against no container target. aoqi@0: new TestCase(noSet, noSet), aoqi@0: // No base target against empty container target. aoqi@0: new TestCase(noSet, empty), aoqi@0: // No base target against TYPE_USE only container target. aoqi@0: new TestCase(noSet, less(jdk8, TYPE_PARAMETER)), aoqi@0: // No base target against TYPE_PARAMETER only container target. aoqi@0: new TestCase(noSet, less(jdk8, TYPE_USE)), aoqi@0: // No base target against TYPE_USE + TYPE_PARAMETER only container target. aoqi@0: new TestCase(noSet, jdk8), aoqi@0: // No base target against TYPE_USE + some selection of jdk7 targets. aoqi@0: new TestCase(noSet, aoqi@0: plus(EnumSet.range(TYPE, LOCAL_VARIABLE), TYPE_USE)), aoqi@0: // No base target against TYPE_PARAMETER + some selection of jdk7 targets. aoqi@0: new TestCase(noSet, aoqi@0: plus(EnumSet.range(TYPE, LOCAL_VARIABLE), TYPE_PARAMETER)), aoqi@0: // No base target against each jdk7 target alone as container target. aoqi@0: new TestCase(noSet, plus(empty, TYPE)), aoqi@0: new TestCase(noSet, plus(empty, PARAMETER)), aoqi@0: new TestCase(noSet, plus(empty, PACKAGE)), aoqi@0: new TestCase(noSet, plus(empty, METHOD)), aoqi@0: new TestCase(noSet, plus(empty, LOCAL_VARIABLE)), aoqi@0: new TestCase(noSet, plus(empty, FIELD)), aoqi@0: new TestCase(noSet, plus(empty, CONSTRUCTOR)), aoqi@0: new TestCase(noSet, plus(empty, ANNOTATION_TYPE)), aoqi@0: // Empty base target against no container target. aoqi@0: new TestCase(empty, noSet), aoqi@0: // Empty base target against empty container target. aoqi@0: new TestCase(empty, empty), aoqi@0: // Empty base target against any lone container target. aoqi@0: new TestCase(empty, plus(empty, TYPE)), aoqi@0: new TestCase(empty, plus(empty, PARAMETER)), aoqi@0: new TestCase(empty, plus(empty, PACKAGE)), aoqi@0: new TestCase(empty, plus(empty, METHOD)), aoqi@0: new TestCase(empty, plus(empty, LOCAL_VARIABLE)), aoqi@0: new TestCase(empty, plus(empty, FIELD)), aoqi@0: new TestCase(empty, plus(empty, CONSTRUCTOR)), aoqi@0: new TestCase(empty, plus(empty, ANNOTATION_TYPE)), aoqi@0: new TestCase(empty, less(jdk8, TYPE_USE)), aoqi@0: new TestCase(empty, less(jdk8, TYPE_PARAMETER)), aoqi@0: // No container target against all all-but one jdk7 targets. aoqi@0: new TestCase(less(jdk7, TYPE), noSet), aoqi@0: new TestCase(less(jdk7, PARAMETER), noSet), aoqi@0: new TestCase(less(jdk7, PACKAGE), noSet), aoqi@0: new TestCase(less(jdk7, METHOD), noSet), aoqi@0: new TestCase(less(jdk7, LOCAL_VARIABLE), noSet), aoqi@0: new TestCase(less(jdk7, FIELD), noSet), aoqi@0: new TestCase(less(jdk7, CONSTRUCTOR), noSet), aoqi@0: new TestCase(less(jdk7, ANNOTATION_TYPE), noSet), aoqi@0: // No container against all but TYPE and ANNOTATION_TYPE aoqi@0: new TestCase(less(jdk7, TYPE, ANNOTATION_TYPE), noSet), aoqi@0: // No container against jdk7 targets. aoqi@0: new TestCase(jdk7, noSet), aoqi@0: // No container against jdk7 targets plus one or both of TYPE_USE, TYPE_PARAMETER aoqi@0: new TestCase(plus(jdk7, TYPE_USE), noSet), aoqi@0: new TestCase(plus(jdk7, TYPE_PARAMETER), noSet), aoqi@0: new TestCase(allTargets, noSet), aoqi@0: // Empty container target against any lone target. aoqi@0: new TestCase(plus(empty, TYPE), empty), aoqi@0: new TestCase(plus(empty, PARAMETER), empty), aoqi@0: new TestCase(plus(empty, PACKAGE), empty), aoqi@0: new TestCase(plus(empty, METHOD), empty), aoqi@0: new TestCase(plus(empty, LOCAL_VARIABLE), empty), aoqi@0: new TestCase(plus(empty, FIELD), empty), aoqi@0: new TestCase(plus(empty, CONSTRUCTOR), empty), aoqi@0: new TestCase(plus(empty, ANNOTATION_TYPE), empty), aoqi@0: new TestCase(plus(empty, TYPE_USE), empty), aoqi@0: new TestCase(plus(empty, TYPE_PARAMETER), empty), aoqi@0: // All base targets against all container targets. aoqi@0: new TestCase(allTargets, allTargets), aoqi@0: // All base targets against all but one container targets. aoqi@0: new TestCase(allTargets, less(allTargets, TYPE)), aoqi@0: new TestCase(allTargets, less(allTargets, PARAMETER)), aoqi@0: new TestCase(allTargets, less(allTargets, PACKAGE)), aoqi@0: new TestCase(allTargets, less(allTargets, METHOD)), aoqi@0: new TestCase(allTargets, less(allTargets, LOCAL_VARIABLE)), aoqi@0: new TestCase(allTargets, less(allTargets, FIELD)), aoqi@0: new TestCase(allTargets, less(allTargets, CONSTRUCTOR)), aoqi@0: new TestCase(allTargets, less(allTargets, ANNOTATION_TYPE)), aoqi@0: new TestCase(allTargets, less(allTargets, TYPE_USE)), aoqi@0: new TestCase(allTargets, less(allTargets, TYPE_PARAMETER)), aoqi@0: // All container targets against all but one base targets. aoqi@0: new TestCase(less(allTargets, TYPE), allTargets), aoqi@0: new TestCase(less(allTargets, PARAMETER), allTargets), aoqi@0: new TestCase(less(allTargets, PACKAGE), allTargets), aoqi@0: new TestCase(less(allTargets, METHOD), allTargets), aoqi@0: new TestCase(less(allTargets, LOCAL_VARIABLE), allTargets), aoqi@0: new TestCase(less(allTargets, FIELD), allTargets), aoqi@0: new TestCase(less(allTargets, CONSTRUCTOR), allTargets), aoqi@0: new TestCase(less(allTargets, ANNOTATION_TYPE), allTargets), aoqi@0: new TestCase(less(allTargets, TYPE_USE), allTargets), aoqi@0: new TestCase(less(allTargets, TYPE_PARAMETER), allTargets))); aoqi@0: // Generates 100 test cases for any lone base target contained in Set aoqi@0: // allTargets against any lone container target. aoqi@0: for (ElementType b : allTargets) { aoqi@0: for (ElementType c : allTargets) { aoqi@0: testCases.add(new TestCase(plus(empty, b), plus(empty, c))); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void run() throws Exception { aoqi@0: int testCtr = 0; aoqi@0: for (TestCase tc : testCases) { aoqi@0: if (!tc.isIgnored()) { aoqi@0: executeTestCase(tc, testCases.indexOf(tc)); aoqi@0: testCtr++; aoqi@0: } aoqi@0: } aoqi@0: System.out.println("Total tests run: " + testCtr); aoqi@0: if (errors > 0) { aoqi@0: throw new Exception(errors + " errors found"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private void executeTestCase(TestCase testCase, int index) { aoqi@0: debugPrint("Test case number = " + index); aoqi@0: debugPrint(" => baseAnnoTarget = " + testCase.getBaseAnnotations()); aoqi@0: debugPrint(" => containerAnnoTarget = " + testCase.getContainerAnnotations()); aoqi@0: aoqi@0: String className = "TC" + index; aoqi@0: boolean shouldCompile = testCase.isValidSubSet(); aoqi@0: Iterable files = getFileList(className, testCase, shouldCompile); aoqi@0: // Get result of compiling test src file(s). aoqi@0: boolean result = getCompileResult(className, shouldCompile, files); aoqi@0: // List test src code if test fails. aoqi@0: if (!result) { aoqi@0: System.out.println("FAIL: Test " + index); aoqi@0: try { aoqi@0: for (JavaFileObject f : files) { aoqi@0: System.out.println("File: " + f.getName() + "\n" + f.getCharContent(true)); aoqi@0: } aoqi@0: } catch (IOException ioe) { aoqi@0: System.out.println("Exception: " + ioe); aoqi@0: } aoqi@0: } else { aoqi@0: debugPrint("PASS: Test " + index); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: // Create src code and corresponding JavaFileObjects. aoqi@0: private Iterable getFileList(String className, aoqi@0: TestCase testCase, boolean shouldCompile) { aoqi@0: Set baseAnnoTarget = testCase.getBaseAnnotations(); aoqi@0: Set conAnnoTarget = testCase.getContainerAnnotations(); aoqi@0: String srcContent = ""; aoqi@0: String pkgInfoContent = ""; aoqi@0: String template = Helper.template; aoqi@0: String baseTarget = "", conTarget = ""; aoqi@0: aoqi@0: String target = Helper.ContentVars.TARGET.getVal(); aoqi@0: if (baseAnnoTarget != null) { aoqi@0: String tmp = target.replace("#VAL", convertToString(baseAnnoTarget).toString()); aoqi@0: baseTarget = tmp.replace("[", "{").replace("]", "}"); aoqi@0: } aoqi@0: if (conAnnoTarget != null) { aoqi@0: String tmp = target.replace("#VAL", convertToString(conAnnoTarget).toString()); aoqi@0: conTarget = tmp.replace("[", "{").replace("]", "}"); aoqi@0: } aoqi@0: aoqi@0: String annoData = Helper.ContentVars.IMPORTSTMTS.getVal() aoqi@0: + conTarget aoqi@0: + Helper.ContentVars.CONTAINER.getVal() aoqi@0: + baseTarget aoqi@0: + Helper.ContentVars.REPEATABLE.getVal() aoqi@0: + Helper.ContentVars.BASE.getVal(); aoqi@0: aoqi@0: JavaFileObject pkgInfoFile = null; aoqi@0: aoqi@0: // If shouldCompile = true and no @Target is specified for container annotation, aoqi@0: // then all 8 ElementType enum constants are applicable as targets for aoqi@0: // container annotation. aoqi@0: if (shouldCompile && conAnnoTarget == null) { aoqi@0: Set copySet = EnumSet.noneOf(ElementType.class); aoqi@0: copySet.addAll(jdk7); aoqi@0: conAnnoTarget = copySet; aoqi@0: } aoqi@0: aoqi@0: if (shouldCompile) { aoqi@0: boolean isPkgCasePresent = conAnnoTarget.contains(PACKAGE); aoqi@0: String repeatableAnno = Helper.ContentVars.BASEANNO.getVal() aoqi@0: + " " + Helper.ContentVars.BASEANNO.getVal(); aoqi@0: for (ElementType s : conAnnoTarget) { aoqi@0: String replaceStr = "/*" + s.name() + "*/"; aoqi@0: if (s.name().equalsIgnoreCase("PACKAGE")) { aoqi@0: //Create packageInfo file. aoqi@0: String pkgInfoName = TESTPKG + "." + "package-info"; aoqi@0: pkgInfoContent = repeatableAnno + "\npackage " + TESTPKG + ";" + annoData; aoqi@0: pkgInfoFile = Helper.getFile(pkgInfoName, pkgInfoContent); aoqi@0: } else { aoqi@0: template = template.replace(replaceStr, repeatableAnno); aoqi@0: if (!isPkgCasePresent) { aoqi@0: srcContent = template.replace( aoqi@0: "/*ANNODATA*/", annoData).replace("#ClassName", className); aoqi@0: } else { aoqi@0: replaceStr = "/*PACKAGE*/"; aoqi@0: String tmp = template.replace(replaceStr, "package " + TESTPKG + ";"); aoqi@0: srcContent = tmp.replace("#ClassName", className); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: // For invalid cases, compilation should fail at declaration site. aoqi@0: template = "class #ClassName {}"; aoqi@0: srcContent = annoData + template.replace("#ClassName", className); aoqi@0: } aoqi@0: JavaFileObject srcFile = Helper.getFile(className, srcContent); aoqi@0: Iterable files = null; aoqi@0: if (pkgInfoFile != null) { aoqi@0: files = Arrays.asList(pkgInfoFile, srcFile); aoqi@0: } else { aoqi@0: files = Arrays.asList(srcFile); aoqi@0: } aoqi@0: return files; aoqi@0: } aoqi@0: aoqi@0: // Compile the test source file(s) and return test result. aoqi@0: private boolean getCompileResult(String className, boolean shouldCompile, aoqi@0: Iterable files) { aoqi@0: aoqi@0: DiagnosticCollector diagnostics = aoqi@0: new DiagnosticCollector(); aoqi@0: Helper.compileCode(diagnostics, files); aoqi@0: // Test case pass or fail. aoqi@0: boolean ok = false; aoqi@0: String errMesg = ""; aoqi@0: int numDiags = diagnostics.getDiagnostics().size(); aoqi@0: if (numDiags == 0) { aoqi@0: if (shouldCompile) { aoqi@0: debugPrint("Test passed, compiled as expected."); aoqi@0: ok = true; aoqi@0: } else { aoqi@0: errMesg = "Test failed, compiled unexpectedly."; aoqi@0: ok = false; aoqi@0: } aoqi@0: } else { aoqi@0: if (shouldCompile) { aoqi@0: // did not compile. aoqi@0: errMesg = "Test failed, did not compile."; aoqi@0: ok = false; aoqi@0: } else { aoqi@0: // Error in compilation as expected. aoqi@0: String expectedErrKey = "compiler.err.invalid.repeatable." aoqi@0: + "annotation.incompatible.target"; aoqi@0: for (Diagnostic d : diagnostics.getDiagnostics()) { aoqi@0: if ((d.getKind() == Diagnostic.Kind.ERROR) aoqi@0: && d.getCode().contains(expectedErrKey)) { aoqi@0: // Error message as expected. aoqi@0: debugPrint("Error message as expected."); aoqi@0: ok = true; aoqi@0: break; aoqi@0: } else { aoqi@0: // error message is incorrect. aoqi@0: ok = false; aoqi@0: } aoqi@0: } aoqi@0: if (!ok) { aoqi@0: errMesg = "Incorrect error received when compiling " aoqi@0: + className + ", expected: " + expectedErrKey; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (!ok) { aoqi@0: error(errMesg); aoqi@0: for (Diagnostic d : diagnostics.getDiagnostics()) { aoqi@0: System.out.println(" Diags: " + d); aoqi@0: } aoqi@0: } aoqi@0: return ok; aoqi@0: } aoqi@0: aoqi@0: private Set less(Set base, ElementType... sub) { aoqi@0: Set res = EnumSet.noneOf(ElementType.class); aoqi@0: res.addAll(base); aoqi@0: for (ElementType t : sub) { aoqi@0: res.remove(t); aoqi@0: } aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: private Set plus(Set base, ElementType... add) { aoqi@0: Set res = EnumSet.noneOf(ElementType.class); aoqi@0: res.addAll(base); aoqi@0: for (ElementType t : add) { aoqi@0: res.add(t); aoqi@0: } aoqi@0: return res; aoqi@0: } aoqi@0: aoqi@0: // Iterate target set and add "ElementType." in front of every target type. aoqi@0: private List convertToString(Set annoTarget) { aoqi@0: if (annoTarget == null) { aoqi@0: return null; aoqi@0: } aoqi@0: List annoTargets = new ArrayList(); aoqi@0: for (ElementType e : annoTarget) { aoqi@0: annoTargets.add("ElementType." + e.name()); aoqi@0: } aoqi@0: return annoTargets; aoqi@0: } aoqi@0: aoqi@0: private void debugPrint(String string) { aoqi@0: if (DEBUG) { aoqi@0: System.out.println(string); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private void error(String msg) { aoqi@0: System.out.println("ERROR: " + msg); aoqi@0: errors++; aoqi@0: } aoqi@0: } aoqi@0: