diff options
author | Andy Clement <aclement@gopivotal.com> | 2014-10-06 17:35:51 -0700 |
---|---|---|
committer | Andy Clement <aclement@gopivotal.com> | 2014-10-06 17:35:51 -0700 |
commit | c8e951296c5f95e82d4c7c3f8eb9b0a647014e20 (patch) | |
tree | 2eaed5b80ad735e4c91e424098e35e221f4fea44 /org.aspectj.ajdt.core | |
parent | 102173fc11fc6648ed8f2283d3c5ad535e412c73 (diff) | |
download | aspectj-c8e951296c5f95e82d4c7c3f8eb9b0a647014e20.tar.gz aspectj-c8e951296c5f95e82d4c7c3f8eb9b0a647014e20.zip |
Fix 436653: conditional aspect activation plus various polish
Modified test expectation system so it is possible to say
the test cares about one particular message and the rest
do not matter (prefix message string with '*') - crude but
quick.
Polished many places to exploit generics
Upgraded all the tests to work on Java8 - some serious changes
regarding ajdoc on Java8. Hopefully it has stayed backwards
compatible with earlier JDK versions (e.g. if using AspectJ 1.8.3+
with a JDK less than 8) but no explicit testing done for this.
Diffstat (limited to 'org.aspectj.ajdt.core')
4 files changed, 63 insertions, 33 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index d1529859c..f6316cd00 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -413,7 +413,7 @@ public class BuildArgParser extends Main { if (args.size() > nextArgIndex) { // buildConfig.getAjOptions().put(AjCompilerOptions.OPTION_Inpath, CompilerOptions.PRESERVE); - List inPath = buildConfig.getInpath(); + List<File> inPath = buildConfig.getInpath(); StringTokenizer st = new StringTokenizer(((ConfigParser.Arg) args.get(nextArgIndex)).getValue(), File.pathSeparator); while (st.hasMoreTokens()) { @@ -475,7 +475,7 @@ public class BuildArgParser extends Main { buildConfig.setMakeReflectable(true); } else if (arg.equals("-sourceroots")) { if (args.size() > nextArgIndex) { - List sourceRoots = new ArrayList(); + List<File> sourceRoots = new ArrayList<File>(); StringTokenizer st = new StringTokenizer(((ConfigParser.Arg) args.get(nextArgIndex)).getValue(), File.pathSeparator); while (st.hasMoreTokens()) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java index c9e992b5b..e5201a3e9 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java @@ -211,6 +211,10 @@ public class AspectDeclaration extends TypeDeclaration { // For e37 moved the check down to this level return; } + if ((binding.tagBits & TagBits.AnnotationResolved) != 0) { + // possibly resolution occurred during hasUnsatisfiedDependency()... + binding.tagBits = (binding.tagBits & ~TagBits.AnnotationResolved); + } Annotation atAspectAnnotation = AtAspectJAnnotationFactory.createAspectAnnotation(perClause.toDeclarationString(), declarationSourceStart); Annotation privilegedAnnotation = null; @@ -230,6 +234,7 @@ public class AspectDeclaration extends TypeDeclaration { System.arraycopy(old, 0, annotations, 0, old.length); System.arraycopy(toAdd, 0, annotations, old.length, toAdd.length); } + TypeDeclaration.resolveAnnotations(staticInitializerScope, annotations, binding); } public void generateCode(ClassFile enclosingClassFile) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java index d24ff7a3c..9b04c6d1f 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java @@ -682,7 +682,7 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate { */ public AnnotationAJ[] getAnnotations() { int declarationAnnoCount = (declaration.annotations == null ? 0 : declaration.annotations.length); - if (annotations != null && annotations.length==declarationAnnoCount) { + if (annotations != null && annotations.length == declarationAnnoCount) { return annotations; // only do this once } if (!annotationsFullyResolved || annotations.length!=declarationAnnoCount) { @@ -700,6 +700,10 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate { } return annotations; } + + public boolean hasAnnotations() { + return (declaration.annotations != null && declaration.annotations.length != 0); + } /** * Convert one eclipse annotation into an AnnotationX object containing an AnnotationAJ object. diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java index c8bb6c1b6..d444c4d09 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java @@ -138,6 +138,7 @@ public class AjcTestCase extends TestCase { private String text; private String sourceFileName; private ISourceLocation[] seeAlsos; + public boolean careAboutOtherMessages = true; /** * Create a message that will match any compiler message on the given line. @@ -153,6 +154,11 @@ public class AjcTestCase extends TestCase { public Message(int line, String text) { this.line = line; this.text = text; + if (this.text != null && text.startsWith("*")) { + // Don't care what other messages are around + this.careAboutOtherMessages = false; + this.text = this.text.substring(1); + } } /** @@ -181,6 +187,11 @@ public class AjcTestCase extends TestCase { this.sourceFileName = srcFileName.toString(); } this.text = text; + if (this.text != null && text.startsWith("*")) { + // Don't care what other messages are around + this.careAboutOtherMessages = false; + this.text = this.text.substring(1); + } this.seeAlsos = seeAlso; } @@ -189,6 +200,11 @@ public class AjcTestCase extends TestCase { */ public Message(String text) { this.text = text; + if (this.text != null && text.startsWith("*")) { + // Don't care what other messages are around + this.careAboutOtherMessages = false; + this.text = this.text.substring(1); + } } /** @@ -288,11 +304,11 @@ public class AjcTestCase extends TestCase { Collections.EMPTY_LIST, Collections.EMPTY_LIST); boolean ignoreInfos = true; - public List fails; - public List infos; - public List warnings; - public List errors; - public List weaves; + public List<AjcTestCase.Message> fails; + public List<AjcTestCase.Message> infos; + public List<AjcTestCase.Message> warnings; + public List<AjcTestCase.Message> errors; + public List<AjcTestCase.Message> weaves; /** * Set to true to enable or disable comparison of information messages. @@ -317,24 +333,25 @@ public class AjcTestCase extends TestCase { * @param errors The set of error messages to test for - can pass null to indicate empty set. * @param fails The set of fail or abort messages to test for - can pass null to indicate empty set. */ - public MessageSpec(List infos, List warnings, List errors, List fails, List weaves) { + public MessageSpec(List<AjcTestCase.Message> infos, List<AjcTestCase.Message> warnings, + List<AjcTestCase.Message> errors, List<AjcTestCase.Message> fails, List<AjcTestCase.Message> weaves) { if (infos != null) { this.infos = infos; ignoreInfos = false; } else { - this.infos = Collections.EMPTY_LIST; + this.infos = Collections.emptyList(); } - this.warnings = ((warnings == null) ? Collections.EMPTY_LIST : warnings); - this.errors = ((errors == null) ? Collections.EMPTY_LIST : errors); - this.fails = ((fails == null) ? Collections.EMPTY_LIST : fails); - this.weaves = ((weaves == null) ? Collections.EMPTY_LIST : weaves); + this.warnings = ((warnings == null) ? Collections.<AjcTestCase.Message>emptyList() : warnings); + this.errors = ((errors == null) ? Collections.<AjcTestCase.Message>emptyList() : errors); + this.fails = ((fails == null) ? Collections.<AjcTestCase.Message>emptyList() : fails); + this.weaves = ((weaves == null) ? Collections.<AjcTestCase.Message>emptyList() : weaves); } /** * Create a message specification to test a CompilationResult for a given set of info, warning, and error messages. The * presence of any fail or abort messages in a CompilationResult will be a test failure. */ - public MessageSpec(List infos, List warnings, List errors) { + public MessageSpec(List<AjcTestCase.Message> infos, List<AjcTestCase.Message> warnings, List<AjcTestCase.Message> errors) { this(infos, warnings, errors, null, null); } @@ -342,7 +359,7 @@ public class AjcTestCase extends TestCase { * Create a message specification to test a CompilationResult for a given set of warning, and error messages. The presence * of any fail or abort messages in a CompilationResult will be a test failure. Informational messages will be ignored. */ - public MessageSpec(List warnings, List errors) { + public MessageSpec(List<AjcTestCase.Message> warnings, List<AjcTestCase.Message> errors) { this(null, warnings, errors, null, null); } } @@ -424,11 +441,11 @@ public class AjcTestCase extends TestCase { public void assertMessages(CompilationResult result, String message, MessageSpec expected) { if (result == null) fail("Attempt to compare null compilation results against expected."); - List missingFails = copyAll(expected.fails); - List missingInfos = copyAll(expected.infos); - List missingWarnings = copyAll(expected.warnings); - List missingErrors = copyAll(expected.errors); - List missingWeaves = copyAll(expected.weaves); + List<AjcTestCase.Message> missingFails = copyAll(expected.fails); + List<AjcTestCase.Message> missingInfos = copyAll(expected.infos); + List<AjcTestCase.Message> missingWarnings = copyAll(expected.warnings); + List<AjcTestCase.Message> missingErrors = copyAll(expected.errors); + List<AjcTestCase.Message> missingWeaves = copyAll(expected.weaves); List<IMessage> extraFails = copyAll(result.getFailMessages()); List<IMessage> extraInfos = copyAll(result.getInfoMessages()); List<IMessage> extraWarnings = copyAll(result.getWarningMessages()); @@ -873,12 +890,12 @@ public class AjcTestCase extends TestCase { return ret; } - private List copyAll(List in) { + private <T> List<T> copyAll(List<T> in) { if (in == Collections.EMPTY_LIST) return in; - List out = new ArrayList(); - for (Iterator iter = in.iterator(); iter.hasNext();) { + List<T> out = new ArrayList<T>(); + for (Iterator<T> iter = in.iterator(); iter.hasNext();) { out.add(iter.next()); } return out; @@ -893,25 +910,29 @@ public class AjcTestCase extends TestCase { * @param missingElements the missing messages, when passed in must contain all of the expected messages * @param extraElements the additional messages, when passed in must contain all of the actual messages */ - private void compare(List expected, List actual, List missingElements, List extraElements) { - for (Iterator expectedIter = expected.iterator(); expectedIter.hasNext();) { - Message expectedMessage = (Message) expectedIter.next(); - for (Iterator actualIter = actual.iterator(); actualIter.hasNext();) { - IMessage actualMessage = (IMessage) actualIter.next(); + private void compare(List<AjcTestCase.Message> expected, List<IMessage> actual, List<AjcTestCase.Message> missingElements, List<IMessage> extraElements) { + for (Message expectedMessage: expected) { + for (IMessage actualMessage: actual) { if (expectedMessage.matches(actualMessage)) { - missingElements.remove(expectedMessage); - extraElements.remove(actualMessage); + if (expectedMessage.careAboutOtherMessages) { + missingElements.remove(expectedMessage); + extraElements.remove(actualMessage); + } + else { + missingElements.clear(); + extraElements.clear(); + } } } } } - private void addMissing(StringBuffer buff, String type, List messages) { + private void addMissing(StringBuffer buff, String type, List<AjcTestCase.Message> messages) { if (!messages.isEmpty()) { buff.append("Missing expected "); buff.append(type); buff.append(" messages:\n"); - for (Iterator iter = messages.iterator(); iter.hasNext();) { + for (Iterator<AjcTestCase.Message> iter = messages.iterator(); iter.hasNext();) { buff.append("\t"); buff.append(iter.next().toString()); buff.append("\n"); |