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