From d0be7b851b7bcedce43ab31cc307f44ebf0a2f2e Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 23 Aug 2004 10:25:37 +0000 Subject: [PATCH] More 'cant find types' improved. --- .../ast/InterTypeFieldDeclaration.java | 6 ++++-- .../org/aspectj/weaver/WeaverMessages.java | 3 ++- weaver/src/org/aspectj/weaver/World.java | 20 +++++++++++++++++++ .../org/aspectj/weaver/bcel/BcelAdvice.java | 11 +++++++++- .../aspectj/weaver/bcel/BcelTypeMunger.java | 6 +++--- .../aspectj/weaver/patterns/ArgsPointcut.java | 8 +++++++- .../aspectj/weaver/weaver-messages.properties | 2 ++ 7 files changed, 48 insertions(+), 8 deletions(-) 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 cbfbc0c04..954a20f0a 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 @@ -233,9 +233,11 @@ public class InterTypeFieldDeclaration extends InterTypeDeclaration { codeStream.initializeMaxLocals(binding); if (isGetter) { if (onTypeBinding.isInterface()) { + TypeX declaringTX = sig.getDeclaringType(); + ResolvedTypeX declaringRTX = world.getWorld().resolve(declaringTX,munger.getSourceLocation()); MethodBinding readMethod = world.makeMethodBinding( AjcMemberMaker.interFieldInterfaceGetter( - sig, world.getWorld().resolve(sig.getDeclaringType()), aspectType)); + sig, declaringRTX, aspectType)); generateInterfaceReadBody(binding, readMethod, codeStream); } else { generateClassReadBody(binding, classField, codeStream); @@ -244,7 +246,7 @@ public class InterTypeFieldDeclaration extends InterTypeDeclaration { if (onTypeBinding.isInterface()) { MethodBinding writeMethod = world.makeMethodBinding( AjcMemberMaker.interFieldInterfaceSetter( - sig, world.getWorld().resolve(sig.getDeclaringType()), aspectType)); + sig, world.getWorld().resolve(sig.getDeclaringType(),munger.getSourceLocation()), aspectType)); generateInterfaceWriteBody(binding, writeMethod, codeStream); } else { generateClassWriteBody(binding, classField, codeStream); diff --git a/weaver/src/org/aspectj/weaver/WeaverMessages.java b/weaver/src/org/aspectj/weaver/WeaverMessages.java index c8351b5f7..df2f90376 100644 --- a/weaver/src/org/aspectj/weaver/WeaverMessages.java +++ b/weaver/src/org/aspectj/weaver/WeaverMessages.java @@ -75,7 +75,8 @@ public class WeaverMessages { public static final String CANT_FIND_TYPE_WITHINPCD = "cantFindTypeWithinpcd"; public static final String CANT_FIND_TYPE_DURING_AROUND_WEAVE = "cftDuringAroundWeave"; public static final String CANT_FIND_TYPE_DURING_AROUND_WEAVE_PREINIT = "cftDuringAroundWeavePreinit"; - + public static final String CANT_FIND_TYPE_EXCEPTION_TYPE = "cftExceptionType"; + public static final String CANT_FIND_TYPE_ARG_TYPE = "cftArgType"; public static final String DECP_BINARY_LIMITATION = "decpBinaryLimitation"; public static final String OVERWRITE_JSR45 = "overwriteJSR45"; diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 479a40c92..071af0678 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.WeakHashMap; import org.aspectj.asm.IHierarchy; +import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessageHandler; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.Message; @@ -66,6 +67,25 @@ public abstract class World { return ret; } + /** + * Attempt to resolve a type - the source location gives you some context in which + * resolution is taking place. In the case of an error where we can't find the + * type - we can then at least report why (source location) we were trying to resolve it. + */ + public ResolvedTypeX resolve(TypeX ty,ISourceLocation isl) { + ResolvedTypeX ret = resolve(ty,true); + if (ty == ResolvedTypeX.MISSING) { + IMessage msg = null; + if (isl!=null) { + msg = MessageUtil.error(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE,ty.getName()),isl); + } else { + msg = MessageUtil.error(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE,ty.getName())); + } + messageHandler.handleMessage(msg); + } + return ret; + } + public ResolvedTypeX resolve(TypeX ty) { return resolve(ty, false); } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java index 7de867168..76589720f 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java @@ -20,6 +20,8 @@ import java.util.Collections; import org.aspectj.apache.bcel.generic.InstructionFactory; import org.aspectj.apache.bcel.generic.InstructionHandle; import org.aspectj.apache.bcel.generic.InstructionList; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; import org.aspectj.weaver.Advice; import org.aspectj.weaver.AdviceKind; import org.aspectj.weaver.AjAttribute; @@ -30,6 +32,7 @@ import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedTypeX; import org.aspectj.weaver.Shadow; import org.aspectj.weaver.TypeX; +import org.aspectj.weaver.WeaverMessages; import org.aspectj.weaver.World; import org.aspectj.weaver.ast.Literal; import org.aspectj.weaver.ast.Test; @@ -173,7 +176,13 @@ public class BcelAdvice extends Advice { ResolvedTypeX error = world.getCoreType(TypeX.ERROR); for (int i=0, len=excs.length; i < len; i++) { - ResolvedTypeX t = world.resolve(excs[i]); + ResolvedTypeX t = world.resolve(excs[i],true); + if (t == ResolvedTypeX.MISSING) { + IMessage msg = new Message( + WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE,excs[i].getName()), + "",IMessage.ERROR,getSourceLocation(),null,null); + world.getMessageHandler().handleMessage(msg); + } if (!(runtimeException.isAssignableFrom(t) || error.isAssignableFrom(t))) { ret.add(t); } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 83b179643..a824e84d2 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -154,7 +154,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { LazyClassGen gen = weaver.getLazyClassGen(); ResolvedMember member = munger.getMember(); - ResolvedTypeX onType = weaver.getWorld().resolve(member.getDeclaringType()); + ResolvedTypeX onType = weaver.getWorld().resolve(member.getDeclaringType(),munger.getSourceLocation()); //System.out.println("munging: " + gen + " with " + member); if (onType.equals(gen.getType())) { if (member.getKind() == Member.FIELD) { @@ -376,7 +376,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { LazyClassGen gen = weaver.getLazyClassGen(); - ResolvedTypeX onType = weaver.getWorld().resolve(signature.getDeclaringType()); + ResolvedTypeX onType = weaver.getWorld().resolve(signature.getDeclaringType(),munger.getSourceLocation()); boolean onInterface = onType.isInterface(); if (onType.equals(gen.getType())) { @@ -652,7 +652,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { ResolvedMember field = munger.getSignature(); - ResolvedTypeX onType = weaver.getWorld().resolve(field.getDeclaringType()); + ResolvedTypeX onType = weaver.getWorld().resolve(field.getDeclaringType(),munger.getSourceLocation()); boolean onInterface = onType.isInterface(); if (onType.equals(gen.getType())) { diff --git a/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java index 6b6541758..179684bc3 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java @@ -163,7 +163,13 @@ public class ArgsPointcut extends NameBindingPointcut { TypeX argType = shadow.getArgType(i); TypePattern type = patterns[i]; if (!(type instanceof BindingTypePattern)) { - if (type.matchesInstanceof(shadow.getIWorld().resolve(argType)).alwaysTrue()) { + ResolvedTypeX argRTX = shadow.getIWorld().resolve(argType,true); + if (argRTX == ResolvedTypeX.MISSING) { + IMessage msg = new Message( + WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_ARG_TYPE,argType.getName()), + "",IMessage.ERROR,shadow.getSourceLocation(),null,new ISourceLocation[]{getSourceLocation()}); + } + if (type.matchesInstanceof(argRTX).alwaysTrue()) { continue; } } else { diff --git a/weaver/src/org/aspectj/weaver/weaver-messages.properties b/weaver/src/org/aspectj/weaver/weaver-messages.properties index 128016fb2..97a7e754d 100644 --- a/weaver/src/org/aspectj/weaver/weaver-messages.properties +++ b/weaver/src/org/aspectj/weaver/weaver-messages.properties @@ -78,6 +78,8 @@ cantFindCoreType=can''t find critical required type {0} cantFindTypeWithinpcd=Unable to find type {0} whilst processing within() pointcut at this source location cftDuringAroundWeave=Can't find type {0} whilst applying around advice cftDuringAroundWeavePreinit=Can't find type {0} whilst applying around advice to preinitialization join point +cftExceptionType=Can't find exception type {0} whilst processing advice +cftArgType=Can't find type {0} whilst processing args() pcd # Implementation limitations... decpBinaryLimitation=can''t use declare parents to change superclass of binary form ''{0}'' (implementation limitation) -- 2.39.5