diff options
author | aclement <aclement> | 2005-10-27 16:05:48 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-10-27 16:05:48 +0000 |
commit | ae3e83163186bb018b5bad55771e6384fad52802 (patch) | |
tree | 7e221caf13fc1d5ca5cc9374a71795250aaec982 | |
parent | 426188d738b9dfbca6b75f68accf853b76dad1cd (diff) | |
download | aspectj-ae3e83163186bb018b5bad55771e6384fad52802.tar.gz aspectj-ae3e83163186bb018b5bad55771e6384fad52802.zip |
Fixes for pr113947.
8 files changed, 55 insertions, 10 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java index b70c2a2d5..2decb4cc0 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java @@ -226,7 +226,8 @@ public class InterTypeConstructorDeclaration extends InterTypeDeclaration { ResolvedType declaringTypeX = world.fromEclipse(onTypeBinding); ResolvedType aspectType = world.fromEclipse(classScope.referenceContext.binding); - + if (interTypeScope==null) return null; // We encountered a problem building the scope, don't continue - error already reported + // This signature represents what we want consumers of the targetted type to 'see' ResolvedMember signature = world.makeResolvedMemberForITD(binding,onTypeBinding,interTypeScope.getRecoveryAliases()); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java index 01f3aceb7..2de741e10 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java @@ -35,6 +35,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding; +import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedTypeMunger; @@ -338,7 +339,7 @@ public abstract class InterTypeDeclaration extends AjMethodDeclaration { * they have to be resolved against the ontype, not the aspect containing the ITD. */ public void ensureScopeSetup() { - if (scopeSetup) return; // don't do it agai + if (scopeSetup) return; // don't do it again MethodScope scope = this.scope; TypeReference ot = onType; @@ -353,6 +354,15 @@ public abstract class InterTypeDeclaration extends AjMethodDeclaration { // resolve it ReferenceBinding rb = (ReferenceBinding)ot.getTypeBindingPublic(scope.parent); + if (rb instanceof TypeVariableBinding) { + scope.problemReporter().signalError(sourceStart,sourceEnd, + "Cannot make inter-type declarations on type variables, use an interface and declare parents"); + this.ignoreFurtherInvestigation=true; + rb = new ProblemReferenceBinding(rb.compoundName,((TypeVariableBinding)rb).firstBound.enclosingType(),0); + return; + } + + // if resolution failed, give up - someone else is going to report an error if (rb instanceof ProblemReferenceBinding) return; diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java index 6d473e7fe..5ed1217ee 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java @@ -199,6 +199,9 @@ public class InterTypeFieldDeclaration extends InterTypeDeclaration { declaringType = declaringType.getGenericType(); } + if (interTypeScope==null) return null; // We encountered a problem building the scope, don't continue - error already reported + + // Build a half correct resolvedmember (makeResolvedMember understands tvars) then build a fully correct sig from it ResolvedMember sigtemp = world.makeResolvedMemberForITD(binding,onTypeBinding,interTypeScope.getRecoveryAliases()); ResolvedMember sig = new ResolvedMemberImpl(Member.FIELD,declaringType,declaredModifiers, diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java index cf2da9f10..b6f0c8415 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java @@ -180,9 +180,12 @@ public class InterTypeMethodDeclaration extends InterTypeDeclaration { //return null; throw new AbortCompilationUnit(compilationResult,null); } + if (isTargetAnnotation(classScope,"method")) return null; // Error message output in isTargetAnnotation if (isTargetEnum(classScope,"method")) return null; // Error message output in isTargetEnum + if (interTypeScope==null) return null; // We encountered a problem building the scope, don't continue - error already reported + // This signature represents what we want consumers of the targetted type to 'see' // must use the factory method to build it since there may be typevariables from the binding // referred to in the parameters/returntype diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeFieldBinding.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeFieldBinding.java index e45e15c1c..7487cce49 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeFieldBinding.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeFieldBinding.java @@ -19,6 +19,7 @@ import org.aspectj.weaver.UnresolvedType; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.InvocationSite; +import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Scope; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; @@ -57,8 +58,15 @@ public class InterTypeFieldBinding extends FieldBinding { SourceTypeBinding invocationType = scope.invocationType(); //System.out.println("receiver: " + receiverType + ", " + invocationType); + ReferenceBinding declaringType = declaringClass; - if (invocationType == declaringClass) return true; + // FIXME asc what about parameterized types and private ITD generic fields on interfaces? + + // Don't work with a raw type, work with the generic type + if (declaringClass.isRawType()) + declaringType = ((RawTypeBinding)declaringClass).type; + + if (invocationType == declaringType) return true; // if (invocationType.isPrivileged) { @@ -74,9 +82,9 @@ public class InterTypeFieldBinding extends FieldBinding { if (isPrivate()) { // answer true if the receiverType is the declaringClass // AND the invocationType and the declaringClass have a common enclosingType - if (receiverType != declaringClass) return false; + if (receiverType != declaringType) return false; - if (invocationType != declaringClass) { + if (invocationType != declaringType) { ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { @@ -84,7 +92,7 @@ public class InterTypeFieldBinding extends FieldBinding { temp = temp.enclosingType(); } - ReferenceBinding outerDeclaringClass = declaringClass; + ReferenceBinding outerDeclaringClass = declaringType; temp = outerDeclaringClass.enclosingType(); while (temp != null) { outerDeclaringClass = temp; diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeScope.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeScope.java index 800ed82e8..4e1f1f1da 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeScope.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeScope.java @@ -58,6 +58,9 @@ public class InterTypeScope extends ClassScope { else throw new BCException("In parameterized type "+onType+", can't handle reference binding "+rb); } else if (onType instanceof ProblemReferenceBinding) { return null; + } else if (onType instanceof TypeVariableBinding) { + // Problem will have already been reported, cant ITD on a type variable. + return null; } throw new BCException("can't handle: " + onType); diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index 1829956cf..a47dfca3b 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -51,8 +51,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testITDCtor_pr112783() { runTest("Problem with constructor ITDs");} */ - public void testUnboundFormal_pr112027() { runTest("unexpected error unboundFormalInPC");} - public void testCCEGenerics_pr113445() { runTest("Generics ClassCastException");} + public void testUnboundFormal_pr112027() { runTest("unexpected error unboundFormalInPC");} + public void testCCEGenerics_pr113445() { runTest("Generics ClassCastException");} + public void testMatthewsAspect_pr113947_1() { runTest("maws generic aspect - 1");} + public void testMatthewsAspect_pr113947_2() { runTest("maws generic aspect - 2");} public void testBadDecp_pr110788_1() { runTest("bad generic decp - 1");} public void testBadDecp_pr110788_2() { runTest("bad generic decp - 2");} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 78e4d9318..e1adcc731 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -11,7 +11,22 @@ <compile files="pr112783.aj" options="-1.5"/> </ajc-test> - + <ajc-test dir="bugs150/pr113947/case1" title="maws generic aspect - 1"> + <compile files="AbstractListSupport.java,AnotherItem.java,Item.java,LinkedList.java,LinkedListItem.java,ListItem.java,StringList.java" options="-1.5"> + <!-- the 'static ref' messages are a bit poor and ought to be eliminated... --> + <message kind="error" line="6" text="Cannot make a static reference to the non-static type M"/> + <message kind="error" line="6" text="Cannot make inter-type declarations on type variables"/> + <message kind="error" line="8" text="Cannot make a static reference to the non-static type I"/> + <message kind="error" line="8" text="Cannot make inter-type declarations on type variables"/> + <message kind="error" line="12" text="Cannot make a static reference to the non-static type M"/> + <message kind="error" line="12" text="Cannot make inter-type declarations on type variables"/> + </compile> + </ajc-test> + + <ajc-test dir="bugs150/pr113947/case2" title="maws generic aspect - 2"> + <compile files="AbstractListSupport.java" options="-1.5"/><!--,AnotherItem.java,Item.java,LinkedList.java,LinkedListItem.java,ListItem.java,StringList.java" options="-1.5"/--> + </ajc-test> + <ajc-test dir="bugs150/pr99191" title="declare annotation on non existent type - 1"> <compile files="pr99191_1.java" options="-1.5"> <message kind="error" line="4" text="The field 'int C.noSuchField' does not exist"/> @@ -52,7 +67,7 @@ <message kind="warning" text="void C.<init>(int) - already has an annotation of type Annotation, cannot add a second instance [Xlint:elementAlreadyAnnotated]"/> </compile> </ajc-test> - + <ajc-test dir="bugs150/pr113630/case1" title="IncompatibleClassChangeError - errorscenario"> <compile files="Bean.java,BeanTestCase.java,javaBean.java,propertyChanger.java,PropertySupportAspect5.aj" options="-1.5"> <message kind="warning" line="9" text="Failing match because annotation 'javaBean' on type 'Bean' has SOURCE retention. Matching allowed when RetentionPolicy is CLASS or RUNTIME"/> |