From: Andy Clement Date: Tue, 7 Oct 2014 00:35:51 +0000 (-0700) Subject: Fix 436653: conditional aspect activation plus various polish X-Git-Tag: V1_8_3~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c8e951296c5f95e82d4c7c3f8eb9b0a647014e20;p=aspectj.git 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. --- diff --git a/ajdoc/.isJava5 b/ajdoc/.isJava5 new file mode 100644 index 000000000..136d06384 --- /dev/null +++ b/ajdoc/.isJava5 @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ajdoc/.settings/org.eclipse.jdt.core.prefs b/ajdoc/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 12ff67cd1..000000000 --- a/ajdoc/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Oct 06 08:32:56 PDT 2005 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.3 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java index bad35529f..04af19f2d 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -224,7 +224,20 @@ class HtmlDecorator { classStartIndex = fileContents.toString().indexOf("

\nClass "); br = false; } - if (classStartIndex != -1) { + if (classStartIndex == -1) { + // Java8 looks more like this: + //

Class A

+ classStartIndex = fileContents.toString().indexOf("

", classStartIndex); + if (classEndIndex != -1) { + // Convert it to "

Aspect A

" + String classLine = fileContents.toString().substring(classStartIndex, classEndIndex); + String aspectLine = classLine.replaceAll("Class ","Aspect "); + fileContents.delete(classStartIndex, classEndIndex); + fileContents.insert(classStartIndex, aspectLine); + } + } + else if (classStartIndex != -1) { int classEndIndex = fileContents.toString().indexOf("", classStartIndex); if (classStartIndex != -1 && classEndIndex != -1) { String classLine = fileContents.toString().substring(classStartIndex, classEndIndex); @@ -249,6 +262,19 @@ class HtmlDecorator { fileContents.insert(secondClassStartIndex, sb.toString()); } } + else { + // Java8: + //
static class ClassA.InnerAspect
+					classStartIndex = fileContents.toString().indexOf("class ");
+					int classEndIndex = fileContents.toString().indexOf("", classStartIndex);
+					if (classEndIndex != -1) {
+						// Convert it to "aspect ClassA.InnerAspect"
+						String classLine = fileContents.toString().substring(classStartIndex, classEndIndex);
+						String aspectLine = "aspect"+fileContents.substring(classStartIndex+5,classEndIndex);
+						fileContents.delete(classStartIndex, classEndIndex);
+						fileContents.insert(classStartIndex, aspectLine);
+					}
+				}
 			}
 		}
 		file.delete();
diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
index 10e22fbf6..dbe5125c5 100644
--- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
+++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
@@ -50,20 +50,18 @@ public class AjdocOutputChecker {
 	}
 
 	/**
-	 * Returns those strings from the given array which aren't in the
-	 * html file
+	 * Returns those strings from the given array which aren't in the html file.
 	 * 
 	 * @param htmlFile
 	 * @param an array of requiredStrings
 	 * @return a List of those strings not found
 	 * @throws Exception
 	 */	
-	public static List /*String*/ getMissingStringsInFile(File htmlFile,
-			String[] requiredStrings) throws Exception {
-		List missingStrings = new ArrayList();
+	public static List getMissingStringsInFile(File htmlFile, String[] requiredStrings) throws Exception {
+		List missingStrings = new ArrayList();
 		for (int i = 0; i < requiredStrings.length; i++) {
 			String string = requiredStrings[i];
-			if (!containsString(htmlFile,string)) {
+			if (!containsString(htmlFile, string)) {
 				missingStrings.add(string);
 			}
 		}
diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
index 0c0a0f268..afa27b319 100644
--- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
+++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
@@ -14,8 +14,11 @@
 import java.io.File;
 import java.util.List;
 
+import org.aspectj.util.FileUtil;
 import org.aspectj.util.LangUtil;
 
+import com.sun.org.apache.xml.internal.serializer.utils.Utils;
+
 
 /**
  * A long way to go until full coverage, but this is the place to add more.
@@ -128,14 +131,39 @@ public class CoverageTestCase extends AjdocTestCase {
         
 		// ensure that the file is entitled "Aspect ClassA.InnerAspect" rather
 		// than "Class ClassA.InnerAspect"
-		String[] strings = { "Aspect ClassA.InnerAspect",
+		
+		String[] strings = null;
+		if (LangUtil.is18VMOrGreater()) {
+			strings = new String[] {
+				"Aspect ClassA.InnerAspect",
+				"
static aspect ClassA.InnerAspect",
+				"Class ClassA.InnerAspect",
+				"
static class ClassA.InnerAspect"};
+		}
+		else {
+			strings = new String[] {
+				"Aspect ClassA.InnerAspect",
 				"
static aspect ClassA.InnerAspect
extends java.lang.Object", "Class ClassA.InnerAspect", "
static class ClassA.InnerAspect
extends java.lang.Object"}; - List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); - assertEquals("There should be 2 missing strings",2,missing.size()); - assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class ClassA.InnerAspect")); - assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class ClassA.InnerAspect
extends java.lang.Object")); + } + List missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); + StringBuilder buf = new StringBuilder(); + for (String str:missingStrings) { + buf.append(str).append("\n"); + } + buf.append("HTMLFILE=\n").append(htmlFile).append("\n"); + assertEquals("There should be 2 missing strings:\n"+buf.toString(), 2, missingStrings.size()); + assertTrue(htmlFile.getName() + " should not have Class as it's title", + missingStrings.contains("Class ClassA.InnerAspect")); + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFile.getName() + " should not have class in its subtitle", + missingStrings.contains("
static class ClassA.InnerAspect"));
+		}
+		else {
+			assertTrue(htmlFile.getName() + " should not have class in its subtitle",
+					missingStrings.contains("
static class ClassA.InnerAspect
extends java.lang.Object")); + } // get the html file for the enclosing class File htmlFileClass = new File(getAbsolutePathOutdir() + "/foo/ClassA.html"); @@ -146,14 +174,33 @@ public class CoverageTestCase extends AjdocTestCase { // ensure that the file is entitled "Class ClassA" and // has not been changed to "Aspect ClassA" - String[] classStrings = { "Class ClassA", - "public abstract class ClassA
extends java.lang.Object
", + String[] classStrings = null; + + if (LangUtil.is18VMOrGreater()) { + classStrings = new String[] { + "Class ClassA", + "public abstract class ClassA", "Aspect ClassA", - "public abstract aspect ClassA
extends java.lang.Object
"}; + "public abstract aspect ClassA"}; + } + else { + classStrings = new String[] { + "Class ClassA", + "public abstract class ClassA
extends java.lang.Object
", + "Aspect ClassA", + "public abstract aspect ClassA
extends java.lang.Object
"}; + } List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); - assertEquals("There should be 2 missing strings",2,classMissing.size()); + assertEquals("There should be 2 missing strings:\n"+classMissing,2,classMissing.size()); assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect ClassA")); - assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("public abstract aspect ClassA
extends java.lang.Object
")); + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public abstract aspect ClassA")); + } + else { + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public abstract aspect ClassA
extends java.lang.Object
")); + } } /** @@ -623,15 +670,32 @@ public class CoverageTestCase extends AjdocTestCase { // ensure that the file is entitled "Aspect PkgVisibleClass.NestedAspect" rather // than "Class PkgVisibleClass.NestedAspect" - String[] strings = { "Aspect PkgVisibleClass.NestedAspect", - "
static aspect PkgVisibleClass.NestedAspect
extends java.lang.Object", - "Class PkgVisibleClass.NestedAspect", - "
static class PkgVisibleClass.NestedAspect
extends java.lang.Object"}; - List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); + String[] strings = null; + if (LangUtil.is18VMOrGreater()) { + strings = new String[] { + "Aspect PkgVisibleClass.NestedAspect", + "
static aspect PkgVisibleClass.NestedAspect",
+					"Class PkgVisibleClass.NestedAspect",
+					"
static class PkgVisibleClass.NestedAspect"};
+		}
+		else {
+			strings = new String[] { 
+					"Aspect PkgVisibleClass.NestedAspect",
+					"
static aspect PkgVisibleClass.NestedAspect
extends java.lang.Object", + "Class PkgVisibleClass.NestedAspect", + "
static class PkgVisibleClass.NestedAspect
extends java.lang.Object"}; + } + List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); assertEquals("There should be 2 missing strings",2,missing.size()); assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class PkgVisibleClass.NestedAspect")); - assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class PkgVisibleClass.NestedAspect
extends java.lang.Object")); - + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFile.getName() + " should not have class in its subtitle", + missing.contains("
static class PkgVisibleClass.NestedAspect"));
+		}
+		else {
+			assertTrue(htmlFile.getName() + " should not have class in its subtitle",
+					missing.contains("
static class PkgVisibleClass.NestedAspect
extends java.lang.Object")); + } // get the html file for the enclosing class File htmlFileClass = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.html"); if (!htmlFileClass.exists()) { @@ -641,14 +705,33 @@ public class CoverageTestCase extends AjdocTestCase { // ensure that the file is entitled "Class PkgVisibleClass" and // has not been changed to "Aspect PkgVisibleClass" - String[] classStrings = { "Class PkgVisibleClass", - "class PkgVisibleClass
extends java.lang.Object", - "Aspect PkgVisibleClass", - "aspect PkgVisibleClass
extends java.lang.Object
"}; - List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); + String[] classStrings = null; + if (LangUtil.is18VMOrGreater()) { + classStrings = new String[] { + "Class PkgVisibleClass", + "
class PkgVisibleClass",
+				"Aspect PkgVisibleClass",
+				"
aspect PkgVisibleClass"};
+		}
+		else {
+			classStrings = new String[] {
+					"Class PkgVisibleClass",
+					"class PkgVisibleClass
extends java.lang.Object", + "Aspect PkgVisibleClass", + "aspect PkgVisibleClass
extends java.lang.Object
"}; + } + List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); assertEquals("There should be 2 missing strings",2,classMissing.size()); - assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect PkgVisibleClass")); - assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("aspect PkgVisibleClass
extends java.lang.Object
")); + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title", + classMissing.contains("Aspect PkgVisibleClass")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("
aspect PkgVisibleClass"));
+		}
+		else {
+			assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect PkgVisibleClass"));
+			assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("aspect PkgVisibleClass
extends java.lang.Object
")); + } } /** @@ -668,14 +751,31 @@ public class CoverageTestCase extends AjdocTestCase { } // ensure that the file is entitled "Aspect ClassWithNestedAspect.NestedAspect" // rather than "Class ClassWithNestedAspect.NestedAspect" - String[] strings = { "Aspect ClassWithNestedAspect.NestedAspect", - "
static aspect ClassWithNestedAspect.NestedAspect
extends java.lang.Object", + String[] strings = null; + if (LangUtil.is18VMOrGreater()) { + strings = new String [] { + "Aspect ClassWithNestedAspect.NestedAspect", + "
static aspect ClassWithNestedAspect.NestedAspect",
 				"Class ClassWithNestedAspect.NestedAspect",
-				"
static class ClassWithNestedAspect.NestedAspect
extends java.lang.Object"}; - List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); + "
static class ClassWithNestedAspect.NestedAspect"};
+		}
+		else {
+			strings = new String [] {
+					"Aspect ClassWithNestedAspect.NestedAspect",
+					"
static a;spect ClassWithNestedAspect.NestedAspect
extends java.lang.Object", + "Class ClassWithNestedAspect.NestedAspect", + "
static class ClassWithNestedAspect.NestedAspect
extends java.lang.Object"}; + } + List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); assertEquals("There should be 2 missing strings",2,missing.size()); assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class ClassWithNestedAspect.NestedAspect")); - assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class ClassWithNestedAspect.NestedAspect
extends java.lang.Object")); + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFile.getName() + " should not have class in its subtitle", + missing.contains("
static class ClassWithNestedAspect.NestedAspect"));
+		}
+		else {
+			assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class ClassWithNestedAspect.NestedAspect
extends java.lang.Object")); + } // get the html file for the enclosing class File htmlFileClass = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html"); @@ -686,17 +786,35 @@ public class CoverageTestCase extends AjdocTestCase { // ensure that the file is entitled "Class ClassWithNestedAspect" and // has not been changed to "Aspect ClassWithNestedAspect" - String[] classStrings = { "Class ClassWithNestedAspect", - "public class ClassWithNestedAspect
extends java.lang.Object", - "Aspect ClassWithNestedAspect", - "public aspect ClassWithNestedAspect
extends java.lang.Object"}; - List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); + String[] classStrings = null; + if (LangUtil.is18VMOrGreater()) { + classStrings = new String[] { + "Class ClassWithNestedAspect", + "public class ClassWithNestedAspect", + "Aspect ClassWithNestedAspect", + "public aspect ClassWithNestedAspect"}; + } + else { + classStrings = new String[] { + "Class ClassWithNestedAspect", + "public class ClassWithNestedAspect
extends java.lang.Object", + "Aspect ClassWithNestedAspect", + "public aspect ClassWithNestedAspect
extends java.lang.Object"}; + } + List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); assertEquals("There should be 2 missing strings",2,classMissing.size()); - assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title", - classMissing.contains("Aspect ClassWithNestedAspect")); - assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", - classMissing.contains("public aspect ClassWithNestedAspect
extends java.lang.Object")); - + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title", + classMissing.contains("Aspect ClassWithNestedAspect")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public aspect ClassWithNestedAspect")); + } + else { + assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title", + classMissing.contains("Aspect ClassWithNestedAspect")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public aspect ClassWithNestedAspect
extends java.lang.Object")); + } } /** diff --git a/aspectj5rt/java5-src/org/aspectj/lang/annotation/RequiredTypes.java b/aspectj5rt/java5-src/org/aspectj/lang/annotation/RequiredTypes.java new file mode 100644 index 000000000..d83b1bb73 --- /dev/null +++ b/aspectj5rt/java5-src/org/aspectj/lang/annotation/RequiredTypes.java @@ -0,0 +1,30 @@ +/* ******************************************************************* + * Copyright (c) 2014 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * ******************************************************************/ +package org.aspectj.lang.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Can be specified on an aspect to ensure that particular types must be accessible before + * the aspect will be 'activated'. The array value should be a list of fully qualified + * type names as strings, for example "com.foo.Bar". Useful in an aspect library that + * includes a number of aspects, only a few of which should ever be active depending + * upon what is on the classpath. + * + * @author Andy Clement + * @since 1.8.3 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface RequiredTypes { + String[] value(); +} 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 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 sourceRoots = new ArrayList(); 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 fails; + public List infos; + public List warnings; + public List errors; + public List 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 infos, List warnings, + List errors, List fails, List 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.emptyList() : warnings); + this.errors = ((errors == null) ? Collections.emptyList() : errors); + this.fails = ((fails == null) ? Collections.emptyList() : fails); + this.weaves = ((weaves == null) ? Collections.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 infos, List warnings, List 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 warnings, List 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 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 extraFails = copyAll(result.getFailMessages()); List extraInfos = copyAll(result.getInfoMessages()); List extraWarnings = copyAll(result.getWarningMessages()); @@ -873,12 +890,12 @@ public class AjcTestCase extends TestCase { return ret; } - private List copyAll(List in) { + private List copyAll(List in) { if (in == Collections.EMPTY_LIST) return in; - List out = new ArrayList(); - for (Iterator iter = in.iterator(); iter.hasNext();) { + List out = new ArrayList(); + for (Iterator 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 expected, List actual, List missingElements, List 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 messages) { if (!messages.isEmpty()) { buff.append("Missing expected "); buff.append(type); buff.append(" messages:\n"); - for (Iterator iter = messages.iterator(); iter.hasNext();) { + for (Iterator iter = messages.iterator(); iter.hasNext();) { buff.append("\t"); buff.append(iter.next().toString()); buff.append("\n"); diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/BCException.java b/org.aspectj.matcher/src/org/aspectj/weaver/BCException.java index 5e378343c..81bf607ed 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/BCException.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/BCException.java @@ -20,6 +20,7 @@ import org.aspectj.bridge.context.CompilationAndWeavingContext; /** * Exception to use inside the bcweaver. */ +@SuppressWarnings("serial") public class BCException extends RuntimeException { Throwable thrown; diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceTypeDelegate.java b/org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceTypeDelegate.java index a9db7b699..f928b729b 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceTypeDelegate.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/BoundedReferenceTypeDelegate.java @@ -78,6 +78,10 @@ class BoundedReferenceTypeDelegate extends AbstractReferenceTypeDelegate { public AnnotationAJ[] getAnnotations() { return resolvedTypeX.getAnnotations(); } + + public boolean hasAnnotations() { + return resolvedTypeX.hasAnnotations(); + } public ResolvedType[] getAnnotationTypes() { return resolvedTypeX.getAnnotationTypes(); diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java b/org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java index e396b4025..5d08467d0 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/GeneratedReferenceTypeDelegate.java @@ -91,6 +91,10 @@ public class GeneratedReferenceTypeDelegate extends AbstractReferenceTypeDelegat public AnnotationAJ[] getAnnotations() { throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate"); } + + public boolean hasAnnotations() { + throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate"); + } public ResolvedType[] getAnnotationTypes() { throw new UnsupportedOperationException("Not supported for GeneratedReferenceTypeDelegate"); diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java index 538bd940f..9791b8083 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java @@ -200,6 +200,11 @@ public class ReferenceType extends ResolvedType { return getDelegate().getAnnotations(); } + @Override + public boolean hasAnnotations() { + return getDelegate().hasAnnotations(); + } + @Override public void addAnnotation(AnnotationAJ annotationX) { if (annotations == null) { diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java index 6ed155ed6..e07c032e6 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceTypeDelegate.java @@ -143,4 +143,6 @@ public interface ReferenceTypeDelegate { public boolean hasBeenWoven(); + public boolean hasAnnotations(); + } \ No newline at end of file diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java index 9746fea81..c053f5119 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java @@ -925,6 +925,11 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl public AnnotationAJ[] getAnnotations() { throw new RuntimeException("ResolvedType.getAnnotations() should never be called"); } + + public boolean hasAnnotations() { + throw new RuntimeException("ResolvedType.getAnnotations() should never be called"); + } + /** * Note: Only overridden by ReferenceType subtype diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/WeaverStateInfo.java b/org.aspectj.matcher/src/org/aspectj/weaver/WeaverStateInfo.java index aea2f806d..b9fc99da8 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/WeaverStateInfo.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/WeaverStateInfo.java @@ -137,7 +137,7 @@ public class WeaverStateInfo { case UNTOUCHED: throw new RuntimeException("unexpected UNWOVEN"); case WOVEN: - return new WeaverStateInfo(Collections.EMPTY_LIST, true, isReweavable, isReweavableCompressed, isReweavableDiff); + return new WeaverStateInfo(Collections.emptyList(), true, isReweavable, isReweavableCompressed, isReweavableDiff); case EXTENDED: boolean isCompressed = false; if (s.isAtLeast169()) { @@ -145,7 +145,7 @@ public class WeaverStateInfo { } int n = s.readShort(); - List l = new ArrayList(); + List l = new ArrayList(); for (int i = 0; i < n; i++) { // conditional on version UnresolvedType aspectType = null; diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ArgsPointcut.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ArgsPointcut.java index c10e090d4..a5d3569c2 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ArgsPointcut.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ArgsPointcut.java @@ -133,11 +133,11 @@ public class ArgsPointcut extends NameBindingPointcut { * @see org.aspectj.weaver.patterns.NameBindingPointcut#getBindingTypePatterns() */ public List getBindingTypePatterns() { - List l = new ArrayList(); + List l = new ArrayList(); TypePattern[] pats = arguments.getTypePatterns(); for (int i = 0; i < pats.length; i++) { if (pats[i] instanceof BindingTypePattern) { - l.add(pats[i]); + l.add((BindingTypePattern)pats[i]); } } return l; diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/BasicTokenSource.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/BasicTokenSource.java index 9e2a62618..ccde927f4 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/BasicTokenSource.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/BasicTokenSource.java @@ -84,7 +84,7 @@ public class BasicTokenSource implements ITokenSource { char[] chars = input.toCharArray(); int i = 0; - List tokens = new ArrayList(); + List tokens = new ArrayList(); while (i < chars.length) { char ch = chars[i++]; diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java index 3a7e31d6f..988239e98 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java @@ -194,6 +194,10 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega // no annotations in Java 1.4 return AnnotationAJ.EMPTY_ARRAY; } + + public boolean hasAnnotations() { + return false; + } /* * (non-Javadoc) diff --git a/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java b/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java index 2d3669748..532588363 100644 --- a/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java +++ b/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java @@ -664,6 +664,7 @@ public abstract class CommonAdvancedPointcutExpressionTests extends TestCase { return null; } + @SuppressWarnings("unused") private void checkAlwaysMatches(String pointcutExpression, String type, String methodName, String methodSignature) { StandardPointcutExpression ex = pointcutParser.parsePointcutExpression(pointcutExpression); assertNotNull(ex); @@ -674,6 +675,7 @@ public abstract class CommonAdvancedPointcutExpressionTests extends TestCase { assertTrue(b); } + @SuppressWarnings("unused") private void checkNeverMatches(String pointcutExpression, String type, String methodName, String methodSignature) { StandardPointcutExpression ex = pointcutParser.parsePointcutExpression(pointcutExpression); assertNotNull(ex); diff --git a/org.aspectj.matcher/testsrc/org/aspectj/weaver/CommonWorldTests.java b/org.aspectj.matcher/testsrc/org/aspectj/weaver/CommonWorldTests.java index faa42b9ed..ff6c56a34 100644 --- a/org.aspectj.matcher/testsrc/org/aspectj/weaver/CommonWorldTests.java +++ b/org.aspectj.matcher/testsrc/org/aspectj/weaver/CommonWorldTests.java @@ -194,7 +194,7 @@ public abstract class CommonWorldTests extends TestCase { } protected void mungersTest(ResolvedType ty, ShadowMunger[] x) { - List l = (List) ty.getDeclaredShadowMungers(); + List l = ty.getDeclaredShadowMungers(); ShadowMunger[] array = (ShadowMunger[]) l.toArray(new ShadowMunger[l.size()]); TestUtil.assertSetEquals(ty + " mungers:", x, array); } diff --git a/org.aspectj.matcher/testsrc/org/aspectj/weaver/TestUtils.java b/org.aspectj.matcher/testsrc/org/aspectj/weaver/TestUtils.java index 456cd2bfc..ac4c46cb7 100644 --- a/org.aspectj.matcher/testsrc/org/aspectj/weaver/TestUtils.java +++ b/org.aspectj.matcher/testsrc/org/aspectj/weaver/TestUtils.java @@ -287,7 +287,7 @@ public class TestUtils { public static String[] parseIds(String str) { if (str.length() == 0) return ZERO_STRINGS; - List l = new ArrayList(); + List l = new ArrayList(); int start = 0; while (true) { int i = str.indexOf(',', start); diff --git a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java index af16d09f6..705674cb3 100644 --- a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java +++ b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java @@ -141,6 +141,7 @@ public class ArgsTestCase extends TestCase { assertFalse("no match expected", sMatch.matchesJoinPoint(thisOjb, targetObj, args).matches()); } + @SuppressWarnings("unused") private static class A { public void anInt(int i) { } @@ -150,6 +151,7 @@ public class ArgsTestCase extends TestCase { } + @SuppressWarnings("unused") private static class B extends A { public void x(A a) { } @@ -158,6 +160,7 @@ public class ArgsTestCase extends TestCase { } } + @SuppressWarnings("unused") private static class C { public void z(A a, C c) { } diff --git a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ModifiersPatternTestCase.java b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ModifiersPatternTestCase.java index fa561149e..265ee4b0a 100644 --- a/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ModifiersPatternTestCase.java +++ b/org.aspectj.matcher/testsrc/org/aspectj/weaver/patterns/ModifiersPatternTestCase.java @@ -16,12 +16,8 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; import org.aspectj.weaver.CompressingDataOutputStream; -import org.aspectj.weaver.ConstantPoolReader; -import org.aspectj.weaver.ConstantPoolWriter; import org.aspectj.weaver.VersionedDataInputStream; import org.aspectj.weaver.World; import org.aspectj.weaver.reflect.ReflectionWorld; diff --git a/testing/newsrc/org/aspectj/testing/CompileSpec.java b/testing/newsrc/org/aspectj/testing/CompileSpec.java index 6d42149ff..540c678a5 100644 --- a/testing/newsrc/org/aspectj/testing/CompileSpec.java +++ b/testing/newsrc/org/aspectj/testing/CompileSpec.java @@ -293,16 +293,16 @@ public class CompileSpec implements ITestStep { } protected AjcTestCase.MessageSpec buildMessageSpec() { - List infos = null; - List warnings = new ArrayList(); - List errors = new ArrayList(); - List fails = new ArrayList(); - List weaveInfos = new ArrayList(); + List infos = null; + List warnings = new ArrayList(); + List errors = new ArrayList(); + List fails = new ArrayList(); + List weaveInfos = new ArrayList(); for (Iterator iter = expected.iterator(); iter.hasNext();) { ExpectedMessageSpec exMsg = (ExpectedMessageSpec) iter.next(); String kind = exMsg.getKind(); if (kind.equals("info")) { - if (infos == null) infos = new ArrayList(); + if (infos == null) infos = new ArrayList(); infos.add(exMsg.toMessage()); } else if (kind.equals("warning")) { warnings.add(exMsg.toMessage()); diff --git a/tests/bugs183/436653/A.java b/tests/bugs183/436653/A.java new file mode 100644 index 000000000..9f4b93d84 --- /dev/null +++ b/tests/bugs183/436653/A.java @@ -0,0 +1 @@ +public class A {} diff --git a/tests/bugs183/436653/AnnoX.java b/tests/bugs183/436653/AnnoX.java new file mode 100644 index 000000000..19c10457f --- /dev/null +++ b/tests/bugs183/436653/AnnoX.java @@ -0,0 +1,10 @@ +import org.aspectj.lang.annotation.*; + +@RequiredTypes("A") +@Aspect +class X { + @Before("execution(* Code.*(..))") + public void m() { + System.out.println("x"); + } +} diff --git a/tests/bugs183/436653/B.java b/tests/bugs183/436653/B.java new file mode 100644 index 000000000..b90c4517f --- /dev/null +++ b/tests/bugs183/436653/B.java @@ -0,0 +1 @@ +public class B {} diff --git a/tests/bugs183/436653/Code.java b/tests/bugs183/436653/Code.java new file mode 100644 index 000000000..866a01f1d --- /dev/null +++ b/tests/bugs183/436653/Code.java @@ -0,0 +1,3 @@ +public class Code { + public void m() {} +} diff --git a/tests/bugs183/436653/Runner.java b/tests/bugs183/436653/Runner.java new file mode 100644 index 000000000..7705eccd5 --- /dev/null +++ b/tests/bugs183/436653/Runner.java @@ -0,0 +1,11 @@ +public class Runner { + public static void main(String []argv) { + new Code().m(); + } +} + +class Code { + public void m() { + System.out.println("Code.m() running"); + } +} diff --git a/tests/bugs183/436653/X.java b/tests/bugs183/436653/X.java new file mode 100644 index 000000000..0f19a6190 --- /dev/null +++ b/tests/bugs183/436653/X.java @@ -0,0 +1,6 @@ +import org.aspectj.lang.annotation.*; + +@RequiredTypes("A") +aspect X { + before(): execution(* Code.*(..)) {System.out.println("x");} +} diff --git a/tests/bugs183/436653/XA.java b/tests/bugs183/436653/XA.java new file mode 100644 index 000000000..fc4029829 --- /dev/null +++ b/tests/bugs183/436653/XA.java @@ -0,0 +1,7 @@ +import org.aspectj.lang.annotation.*; + +aspect XA { + @SuppressAjWarnings("adviceDidNotMatch") + before(): execution(* A.*(..)) {} +} + diff --git a/tests/bugs183/436653/XA2.java b/tests/bugs183/436653/XA2.java new file mode 100644 index 000000000..94748bd28 --- /dev/null +++ b/tests/bugs183/436653/XA2.java @@ -0,0 +1,9 @@ +import org.aspectj.lang.annotation.*; + +// Aspect deactivated if A is missing +@RequiredTypes("A") +aspect XA2 { + @SuppressAjWarnings("adviceDidNotMatch") + before(): execution(* A.*(..)) {} +} + diff --git a/tests/bugs183/436653/XA3.java b/tests/bugs183/436653/XA3.java new file mode 100644 index 000000000..483d310ae --- /dev/null +++ b/tests/bugs183/436653/XA3.java @@ -0,0 +1,9 @@ +import org.aspectj.lang.annotation.*; + +// Aspect deactivated if A or B is missing (although aspect only really needs A) +@RequiredTypes({"A","B"}) +aspect XA2 { + @SuppressAjWarnings("adviceDidNotMatch") + before(): execution(* A.*(..)) {} +} + diff --git a/tests/bugs183/436653/XB.java b/tests/bugs183/436653/XB.java new file mode 100644 index 000000000..4bcf903ca --- /dev/null +++ b/tests/bugs183/436653/XB.java @@ -0,0 +1,6 @@ +import org.aspectj.lang.annotation.*; + +aspect XB { + before(): execution(* B.*(..)) {} +} + diff --git a/tests/bugs183/436653/XCode.java b/tests/bugs183/436653/XCode.java new file mode 100644 index 000000000..d3985fc20 --- /dev/null +++ b/tests/bugs183/436653/XCode.java @@ -0,0 +1,7 @@ +import org.aspectj.lang.annotation.*; + +aspect XCode { + @SuppressAjWarnings("adviceDidNotMatch") + before(): execution(* Cod*.*(..)) {} +} + diff --git a/tests/bugs183/436653/aop.xml b/tests/bugs183/436653/aop.xml new file mode 100644 index 000000000..aa7d74b40 --- /dev/null +++ b/tests/bugs183/436653/aop.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/bugs183/436653/aop2.xml b/tests/bugs183/436653/aop2.xml new file mode 100644 index 000000000..aa7d74b40 --- /dev/null +++ b/tests/bugs183/436653/aop2.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/bugs183/436653/bin/Code.class b/tests/bugs183/436653/bin/Code.class new file mode 100644 index 000000000..3cb964043 Binary files /dev/null and b/tests/bugs183/436653/bin/Code.class differ diff --git a/tests/java5/annotations/itds/AtItd3.aj b/tests/java5/annotations/itds/AtItd3.aj index bc6c671f9..c3412cf56 100644 --- a/tests/java5/annotations/itds/AtItd3.aj +++ b/tests/java5/annotations/itds/AtItd3.aj @@ -22,7 +22,8 @@ public class AtItd3 { Annotation aa = m.getAnnotation(Ann.class); System.err.println("Ann.class retrieved is: "+aa); - if (!aa.toString().equals("@Ann(id=goodbye, anInt=4)")) + if (!aa.toString().equals("@Ann(id=goodbye, anInt=4)")) // < Java8 order + if (!aa.toString().equals("@Ann(anInt=4, id=goodbye)")) // Java8 order throw new RuntimeException("Incorrect output, expected:"+ "@Ann(id=goodbye, anInt=4) but got "+aa.toString()); diff --git a/tests/java5/ataspectj/ajc-ant.xml b/tests/java5/ataspectj/ajc-ant.xml index 4f2e9f36c..0730d7b85 100644 --- a/tests/java5/ataspectj/ajc-ant.xml +++ b/tests/java5/ataspectj/ajc-ant.xml @@ -10,7 +10,7 @@ - - @@ -125,7 +125,7 @@ - @@ -171,7 +171,7 @@ - diff --git a/tests/java5/ataspectj/annotationGen/SA.aj b/tests/java5/ataspectj/annotationGen/SA.aj new file mode 100644 index 000000000..5ca3d661a --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/SA.aj @@ -0,0 +1,14 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect SA { + + public static void main(String[] args) { + Annotation[] annotations = SA.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation but has "+annotations.length); + Aspect aspectAnnotation = (Aspect) annotations[0]; +System.out.println(aspectAnnotation); + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + +} diff --git a/tests/java5/ataspectj/annotationGen/SA.class b/tests/java5/ataspectj/annotationGen/SA.class new file mode 100644 index 000000000..1ce9f8f94 Binary files /dev/null and b/tests/java5/ataspectj/annotationGen/SA.class differ diff --git a/tests/java5/ataspectj/annotationGen/SimpleAspect.aj b/tests/java5/ataspectj/annotationGen/SimpleAspect.aj index 34f6954dc..731ef5ca9 100644 --- a/tests/java5/ataspectj/annotationGen/SimpleAspect.aj +++ b/tests/java5/ataspectj/annotationGen/SimpleAspect.aj @@ -5,9 +5,9 @@ public aspect SimpleAspect { public static void main(String[] args) { Annotation[] annotations = SimpleAspect.class.getAnnotations(); - if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation but has "+annotations.length); Aspect aspectAnnotation = (Aspect) annotations[0]; if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); } -} \ No newline at end of file +} diff --git a/tests/java5/ataspectj/annotationGen/SimpleAspect.class b/tests/java5/ataspectj/annotationGen/SimpleAspect.class new file mode 100644 index 000000000..a5d815f04 Binary files /dev/null and b/tests/java5/ataspectj/annotationGen/SimpleAspect.class differ diff --git a/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java b/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java index 443018bb6..ff9e59339 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java @@ -119,9 +119,9 @@ public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("JDK14 LTW with XML"); } - public void testJ14LTWWithASPECTPATH() { - runTest("JDK14 LTW with ASPECTPATH"); - } +// public void testJ14LTWWithASPECTPATH() { +// runTest("JDK14 LTW with ASPECTPATH"); +// } //public void testDiscardingWovenTypes() { diff --git a/tests/src/org/aspectj/systemtest/ajc170/ajc170.xml b/tests/src/org/aspectj/systemtest/ajc170/ajc170.xml index 6e95476ed..37963fc15 100644 --- a/tests/src/org/aspectj/systemtest/ajc170/ajc170.xml +++ b/tests/src/org/aspectj/systemtest/ajc170/ajc170.xml @@ -181,10 +181,10 @@ - + - - + + @@ -199,13 +199,13 @@ - - - + + + - + diff --git a/tests/src/org/aspectj/systemtest/ajc173/ajc173.xml b/tests/src/org/aspectj/systemtest/ajc173/ajc173.xml index f882d71c7..7c2b88a54 100644 --- a/tests/src/org/aspectj/systemtest/ajc173/ajc173.xml +++ b/tests/src/org/aspectj/systemtest/ajc173/ajc173.xml @@ -9,7 +9,7 @@ - + diff --git a/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java b/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java index ed7c74aee..412fc00eb 100644 --- a/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc183/Ajc183Tests.java @@ -21,6 +21,38 @@ import org.aspectj.testing.XMLBasedAjcTestCase; */ public class Ajc183Tests extends org.aspectj.testing.XMLBasedAjcTestCase { + public void testSuppressTypeNotFound_436653() { + runTest("suppress type not found"); + } + + public void testSuppressTypeNotFound_436653_2() { + runTest("suppress type not found 2"); + } + + public void testSuppressTypeNotFound_436653_3() { + runTest("suppress type not found 3"); + } + + public void testSuppressTypeNotFound_436653_4() { + runTest("suppress type not found 4"); + } + + public void testSuppressTypeNotFound_436653_5() { + runTest("suppress type not found 5"); + } + + public void testSuppressTypeNotFound_436653_6() { + runTest("suppress type not found 6"); + } + + public void testSuppressTypeNotFound_436653_7() { + runTest("suppress type not found 7"); + } + + public void testSuppressTypeNotFound_436653_8() { + runTest("suppress type not found 8"); + } + public void testConstantPool_445395_0() { runTest("constant pool 0"); } diff --git a/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml b/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml index b08be60a9..163ce443e 100644 --- a/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml +++ b/tests/src/org/aspectj/systemtest/ajc183/ajc183.xml @@ -2,6 +2,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java b/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java index 14e880a0a..9b6c11e90 100644 --- a/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java +++ b/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java @@ -241,7 +241,7 @@ public class AjdeInteractionTestbed extends TestCase { File projectBase = new File(sandboxDir, pname); ICompilerConfiguration icc = compiler.getCompilerConfiguration(); List currentFiles = icc.getProjectSourceFiles(); - List filesForCompilation = new ArrayList(); + List filesForCompilation = new ArrayList(); collectUpFiles(projectBase, projectBase, filesForCompilation); boolean changed = false; for (int i = 0; i < filesForCompilation.size(); i++) { diff --git a/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjTestCompilerConfiguration.java b/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjTestCompilerConfiguration.java index f355e1557..562291c69 100644 --- a/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjTestCompilerConfiguration.java +++ b/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjTestCompilerConfiguration.java @@ -33,7 +33,7 @@ public class MultiProjTestCompilerConfiguration implements ICompilerConfiguratio private Set aspectPath = null; private Map sourcePathResources = null; private IOutputLocationManager outputLocationManager = null; - private List dependants; + private List dependants; private Map javaOptionsMap; private Set inpath; private String encoding = null; @@ -41,9 +41,9 @@ public class MultiProjTestCompilerConfiguration implements ICompilerConfiguratio private String processor; private String processorPath; private String nonstandardoptions; - private List modifiedFiles; - private List modifiedDirs; - private List projectSourceFiles = new ArrayList(); + private List modifiedFiles; + private List modifiedDirs; + private List projectSourceFiles = new ArrayList(); private List xmlConfigFiles = new ArrayList(); private String projectPath; @@ -129,7 +129,7 @@ public class MultiProjTestCompilerConfiguration implements ICompilerConfiguratio return xmlConfigFiles; } - public List getProjectSourceFilesChanged() { + public List getProjectSourceFilesChanged() { log("ICompilerConfiguration.getProjectSourceFilesChanged()"); return modifiedFiles; } @@ -146,7 +146,7 @@ public class MultiProjTestCompilerConfiguration implements ICompilerConfiguratio public void addDependancy(String projectItDependsOn) { if (dependants == null) { - dependants = new ArrayList(); + dependants = new ArrayList(); } dependants.add(projectItDependsOn); } @@ -187,19 +187,19 @@ public class MultiProjTestCompilerConfiguration implements ICompilerConfiguratio this.changed |= ICompilerConfiguration.NONSTANDARDOPTIONS_CHANGED; } - public void setProjectSourceFiles(List projectSourceFiles) { + public void setProjectSourceFiles(List projectSourceFiles) { this.projectSourceFiles = projectSourceFiles; this.changed |= ICompilerConfiguration.PROJECTSOURCEFILES_CHANGED; } - public void setProjectXmlConfigFiles(List xmlConfigFiles) { + public void setProjectXmlConfigFiles(List xmlConfigFiles) { this.xmlConfigFiles = xmlConfigFiles; this.changed |= ICompilerConfiguration.XMLCONFIG_CHANGED; } public void addProjectSourceFileChanged(File f) { if (this.modifiedFiles == null) { - this.modifiedFiles = new ArrayList(); + this.modifiedFiles = new ArrayList(); } if (f != null) { modifiedFiles.add(f); @@ -208,7 +208,7 @@ public class MultiProjTestCompilerConfiguration implements ICompilerConfiguratio public void addClasspathEntryChanged(String f) { if (this.modifiedDirs == null) { - this.modifiedDirs = new ArrayList(); + this.modifiedDirs = new ArrayList(); } if (f != null) { modifiedDirs.add(f); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java index 2286a06cf..5c1ae918b 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java @@ -587,6 +587,11 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { ensureAnnotationsUnpacked(); return annotations; } + + public boolean hasAnnotations() { + ensureAnnotationsUnpacked(); + return annotations.length != 0; + } public boolean hasAnnotation(UnresolvedType ofType) { // Due to re-entrancy we may be in the middle of unpacking the annotations already... in which case use this slow diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java index 4dfb30e68..4f0dfe1bc 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java @@ -1016,11 +1016,52 @@ public class BcelWorld extends World implements Repository { @Override public boolean hasUnsatisfiedDependency(ResolvedType aspectType) { + String aspectName = aspectType.getName(); + + if (aspectType.hasAnnotations()) { + AnnotationAJ[] annos = aspectType.getAnnotations(); + for (AnnotationAJ anno: annos) { + if (anno.getTypeName().equals("org.aspectj.lang.annotation.RequiredTypes")) { + String values = anno.getStringFormOfValue("value"); // Example: "[A,org.foo.Bar]" + if (values != null && values.length() > 2) { + values = values.substring(1,values.length()-1); + StringTokenizer tokenizer = new StringTokenizer(values,","); + boolean anythingMissing = false; + while (tokenizer.hasMoreElements()) { + String requiredTypeName = tokenizer.nextToken(); + ResolvedType rt = resolve(UnresolvedType.forName(requiredTypeName)); + if (rt.isMissing()) { + if (!getMessageHandler().isIgnoring(IMessage.INFO)) { + getMessageHandler().handleMessage( + MessageUtil.info("deactivating aspect '" + aspectName + "' as it requires type '" + + requiredTypeName + "' which cannot be found on the classpath")); + } + anythingMissing = true; + if (aspectRequiredTypes == null) { + aspectRequiredTypes = new HashMap(); + } + // Record that it has an invalid type reference + aspectRequiredTypes.put(aspectName,requiredTypeName); + } + } + if (anythingMissing) { + return true; + } + else { + return false; + } + } + else { + // no value specified for annotation + return false; + } + } + } + } if (aspectRequiredTypes == null) { // no aspects require anything, so there can be no unsatisfied dependencies return false; } - String aspectName = aspectType.getName(); if (!aspectRequiredTypesProcessed.contains(aspectName)) { String requiredTypeName = aspectRequiredTypes.get(aspectName); if (requiredTypeName==null) { @@ -1053,7 +1094,7 @@ public class BcelWorld extends World implements Repository { if (aspectRequiredTypes == null) { aspectRequiredTypes = new HashMap(); } - aspectRequiredTypes.put(aspectClassName, requiredType); + aspectRequiredTypes.put(aspectClassName,requiredType); } /** diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java index e7332b73c..111d7e54d 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java @@ -13,6 +13,8 @@ package org.aspectj.weaver.bcel; import java.lang.reflect.Modifier; +import java.util.Objects; +import java.util.function.Consumer; import org.aspectj.weaver.Advice; import org.aspectj.weaver.BcweaverTests; @@ -108,11 +110,20 @@ public class WorldTestCase extends CommonWorldTests { modifiersTest(iter, abstractPublic | Modifier.INTERFACE); fieldsTest(iter, ResolvedMember.NONE); - methodsTest(iter, new Member[] { MemberImpl.method(iter, 0, "hasNext", "()Z"), MemberImpl.method(iter, 0, "remove", "()V"), - MemberImpl.method(iter, 0, "next", "()Ljava/lang/Object;"), }); + methodsTest(iter, new Member[] { + MemberImpl.method(iter, 0, "hasNext", "()Z"), + MemberImpl.method(iter, 0, "remove", "()V"), + MemberImpl.method(iter, 0, "next", "()Ljava/lang/Object;"), + MemberImpl.method(iter, 0, "forEachRemaining", "(Ljava/util/function/Consumer;)V") +// default void forEachRemaining(Consumer action) { +// Objects.requireNonNull(action); +// while (hasNext()) +// action.accept(next()); +// } + }); ResolvedMember remove = iter.lookupMethod(MemberImpl.method(iter, 0, "remove", "()V")); assertNotNull("iterator doesn't have remove", remove); - modifiersTest(remove, abstractPublic | Modifier.INTERFACE); + modifiersTest(remove, Modifier.PUBLIC | Modifier.INTERFACE); // no longer abstract in Java8 (default instead) exceptionsTest(remove, UnresolvedType.NONE); ResolvedMember clone = iter.lookupMethod(MemberImpl.method(UnresolvedType.OBJECT, 0, "clone", "()Ljava/lang/Object;")); diff --git a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java index 2782bddb5..e9606790a 100644 --- a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java +++ b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java @@ -92,6 +92,14 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends ReflectionBasedR } return annotations; } + + @Override + public boolean hasAnnotations() { + if (annotations == null) { + annotations = annotationFinder.getAnnotations(getBaseClass(), getWorld()); + } + return annotations.length != 0; + } @Override public boolean hasAnnotation(UnresolvedType ofType) {