diff options
author | aclement <aclement> | 2005-05-04 09:22:43 +0000 |
---|---|---|
committer | aclement <aclement> | 2005-05-04 09:22:43 +0000 |
commit | abc9a58ac59f0ee427039e26cb44952cbef5e24b (patch) | |
tree | 8693a41b3f3bfe1268ffd8384a88ef57d8356d4c /weaver | |
parent | 92a416462cb5a21b595c05861030dc591359945f (diff) | |
download | aspectj-abc9a58ac59f0ee427039e26cb44952cbef5e24b.tar.gz aspectj-abc9a58ac59f0ee427039e26cb44952cbef5e24b.zip |
Impl of enhancement 92906 from Andrew Huff. -showWeaveInfo for declare annotation
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java | 66 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java | 20 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/Utility.java | 21 |
3 files changed, 106 insertions, 1 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index fc5668c24..c966e346c 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -51,6 +51,7 @@ import org.aspectj.apache.bcel.generic.Select; import org.aspectj.apache.bcel.generic.Type; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; +import org.aspectj.bridge.WeaveMessage; import org.aspectj.util.FuzzyBoolean; import org.aspectj.util.PartialOrder; import org.aspectj.weaver.AjAttribute; @@ -457,6 +458,8 @@ class BcelClassWeaver implements IClassWeaver { if (doesAlreadyHaveAnnotation(mg.getMemberView(),decaM,reportedProblems)) continue; // skip this one... mg.addAnnotation(decaM.getAnnotationX()); AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaM.getSourceLocation(),clazz.getName(),mg.getMethod()); + + reportMethodCtorWeavingMessage(clazz, mg, decaM); isChanged = true; modificationOccured = true; } else { @@ -488,6 +491,52 @@ class BcelClassWeaver implements IClassWeaver { } return isChanged; } + + // TAG: WeavingMessage + private void reportMethodCtorWeavingMessage(LazyClassGen clazz, LazyMethodGen mg, DeclareAnnotation decaM) { + if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){ + StringBuffer parmString = new StringBuffer("("); + Type[] args = mg.getMethod().getArgumentTypes(); + for (int i = 0; i < args.length; i++) { + Type type2 = args[i]; + String s = org.aspectj.apache.bcel.classfile.Utility.signatureToString(type2.getSignature()); + if (s.lastIndexOf(".")!=-1) s =s.substring(s.lastIndexOf(".")+1); + parmString.append(s); + if ((i+1)<args.length) parmString.append(","); + } + parmString.append(")"); + String methodName = mg.getMethod().getName(); + StringBuffer sig = new StringBuffer(); + sig.append(org.aspectj.apache.bcel.classfile.Utility.accessToString(mg.getMethod().getAccessFlags()) ); + sig.append(" "); + sig.append(mg.getMethod().getReturnType().toString()); + sig.append(" "); + sig.append(clazz.getName()); + sig.append("."); + sig.append(methodName.equals("<init>")?"new":methodName); + sig.append(parmString); + + StringBuffer loc = new StringBuffer(); + if (clazz.getFileName()==null) { + loc.append("no debug info available"); + } else { + loc.append(clazz.getFileName()); + if (mg.getDeclarationLineNumber()!=-1) { + loc.append(":"+mg.getDeclarationLineNumber()); + } + } + getWorld().getMessageHandler().handleMessage( + WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES, + new String[]{ + sig.toString(), + loc.toString(), + decaM.getAnnotationString(), + methodName.startsWith("<init>")?"constructor":"method", + decaM.getAspect().toString(), + Utility.beautifyLocation(decaM.getSourceLocation()) + })); + } + } /** * Looks through a list of declare annotation statements and only returns @@ -710,6 +759,7 @@ class BcelClassWeaver implements IClassWeaver { if (doesAlreadyHaveAnnotation(aBcelField,decaF,reportedProblems)) continue; // skip this one... aBcelField.addAnnotation(decaF.getAnnotationX()); AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaF.getSourceLocation(),clazz.getName(),fields[fieldCounter]); + reportFieldAnnotationWeavingMessage(clazz, fields, fieldCounter, decaF); isChanged = true; modificationOccured = true; } else { @@ -741,6 +791,22 @@ class BcelClassWeaver implements IClassWeaver { } return isChanged; } + + // TAG: WeavingMessage + private void reportFieldAnnotationWeavingMessage(LazyClassGen clazz, Field[] fields, int fieldCounter, DeclareAnnotation decaF) { + if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){ + Field theField = fields[fieldCounter]; + world.getMessageHandler().handleMessage( + WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES, + new String[]{ + theField.toString() + "' of type '" + clazz.getName(), + clazz.getFileName(), + decaF.getAnnotationString(), + "field", + decaF.getAspect().toString(), + Utility.beautifyLocation(decaF.getSourceLocation())})); + } + } /** * Check if a resolved member (field/method/ctor) already has an annotation, if it diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java index 29e57b1b2..028b229b0 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java @@ -51,6 +51,7 @@ import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.Message; import org.aspectj.bridge.MessageUtil; import org.aspectj.bridge.SourceLocation; +import org.aspectj.bridge.WeaveMessage; import org.aspectj.util.FileUtil; import org.aspectj.util.FuzzyBoolean; import org.aspectj.weaver.Advice; @@ -1199,6 +1200,7 @@ public class BcelWeaver implements IWeaver { } } + /** * Apply a declare @type - return true if we change the type */ @@ -1206,9 +1208,25 @@ public class BcelWeaver implements IWeaver { boolean didSomething = false; if (decA.matches(onType)) { - //FIXME asc important this should be guarded by the 'already has annotation' check below but isn't since the compiler is producing classfiles with deca affected things in... + // FIXME asc important this should be guarded by the 'already has annotation' check below but isn't since the compiler is producing classfiles with deca affected things in... AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decA.getSourceLocation(),onType.getSourceLocation()); + // FIXME asc same comment above applies here + // TAG: WeavingMessage + if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){ + getWorld().getMessageHandler().handleMessage( + WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES, + new String[]{ + onType.toString(), + Utility.beautifyLocation(onType.getSourceLocation()), + decA.getAnnotationString(), + "type", + decA.getAspect().toString(), + Utility.beautifyLocation(decA.getSourceLocation()) + })); + } + + if (onType.hasAnnotation(decA.getAnnotationX().getSignature())) { // FIXME asc Could put out a lint here for an already annotated type - the problem is that it may have // picked up the annotation during 'source weaving' in which case the message is misleading. Leaving it diff --git a/weaver/src/org/aspectj/weaver/bcel/Utility.java b/weaver/src/org/aspectj/weaver/bcel/Utility.java index 48e23e90f..e2a6c74d7 100644 --- a/weaver/src/org/aspectj/weaver/bcel/Utility.java +++ b/weaver/src/org/aspectj/weaver/bcel/Utility.java @@ -49,6 +49,7 @@ import org.aspectj.apache.bcel.generic.SWITCH; import org.aspectj.apache.bcel.generic.Select; import org.aspectj.apache.bcel.generic.TargetLostException; import org.aspectj.apache.bcel.generic.Type; +import org.aspectj.bridge.ISourceLocation; import org.aspectj.weaver.AnnotationX; import org.aspectj.weaver.BCException; import org.aspectj.weaver.Member; @@ -60,6 +61,26 @@ public class Utility { private Utility() { super(); } + + /* + * Ensure we report a nice source location - particular in the case + * where the source info is missing (binary weave). + */ + public static String beautifyLocation(ISourceLocation isl) { + StringBuffer nice = new StringBuffer(); + if (isl==null || isl.getSourceFile()==null || isl.getSourceFile().getName().indexOf("no debug info available")!=-1) { + nice.append("no debug info available"); + } else { + // can't use File.getName() as this fails when a Linux box encounters a path created on Windows and vice-versa + int takeFrom = isl.getSourceFile().getPath().lastIndexOf('/'); + if (takeFrom == -1) { + takeFrom = isl.getSourceFile().getPath().lastIndexOf('\\'); + } + nice.append(isl.getSourceFile().getPath().substring(takeFrom +1)); + if (isl.getLine()!=0) nice.append(":").append(isl.getLine()); + } + return nice.toString(); + } public static Instruction createSuperInvoke( |