aboutsummaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-09-26 15:05:01 +0000
committeracolyer <acolyer>2005-09-26 15:05:01 +0000
commitd485f9bcc4df37aef60863fceb88654bbd32b680 (patch)
tree1341f68a69f16d1a6b0f86d840ee8a5553c8d091 /weaver
parent4afdcf2612e94ce3c07ab0db5b20ea73134ac632 (diff)
downloadaspectj-d485f9bcc4df37aef60863fceb88654bbd32b680.tar.gz
aspectj-d485f9bcc4df37aef60863fceb88654bbd32b680.zip
fix for pr108123 and pr106500 - better diagnostics and exceptions, plus support for -Xdev:Pinpoint
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/BCException.java6
-rw-r--r--weaver/src/org/aspectj/weaver/World.java18
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java8
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelShadow.java2
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java4
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java25
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java6
7 files changed, 61 insertions, 8 deletions
diff --git a/weaver/src/org/aspectj/weaver/BCException.java b/weaver/src/org/aspectj/weaver/BCException.java
index d282e9d65..161d0ed90 100644
--- a/weaver/src/org/aspectj/weaver/BCException.java
+++ b/weaver/src/org/aspectj/weaver/BCException.java
@@ -16,6 +16,8 @@ package org.aspectj.weaver;
import java.io.PrintStream;
import java.io.PrintWriter;
+import org.aspectj.bridge.context.CompilationAndWeavingContext;
+
/**
* Exception to use inside the bcweaver.
*/
@@ -26,10 +28,10 @@ public class BCException extends RuntimeException {
}
public BCException(String s) {
- super(s);
+ super(s + "\n" + CompilationAndWeavingContext.getCurrentContext());
}
public BCException(String s, Throwable thrown) {
- super(s);
+ this(s);
this.thrown = thrown;
}
public void printStackTrace() {
diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java
index dcb18a3fc..87ed3e648 100644
--- a/weaver/src/org/aspectj/weaver/World.java
+++ b/weaver/src/org/aspectj/weaver/World.java
@@ -29,6 +29,7 @@ import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.IMessage.Kind;
+import org.aspectj.bridge.context.PinpointingMessageHandler;
import org.aspectj.weaver.UnresolvedType.TypeKind;
import org.aspectj.weaver.patterns.DeclarePrecedence;
import org.aspectj.weaver.patterns.PerClause;
@@ -69,6 +70,9 @@ public abstract class World implements Dump.INode {
/** XhasMember option setting passed down to weaver */
private boolean XhasMember = false;
+ /** Xpinpoint controls whether we put out developer info showing the source of messages */
+ private boolean Xpinpoint = false;
+
/** When behaving in a Java 5 way autoboxing is considered */
private boolean behaveInJava5Way = false;
@@ -504,7 +508,11 @@ public abstract class World implements Dump.INode {
}
public void setMessageHandler(IMessageHandler messageHandler) {
- this.messageHandler = messageHandler;
+ if (this.isInPinpointMode()) {
+ this.messageHandler = new PinpointingMessageHandler(messageHandler);
+ } else {
+ this.messageHandler = messageHandler;
+ }
}
/**
@@ -602,6 +610,14 @@ public abstract class World implements Dump.INode {
XhasMember = b;
}
+ public boolean isInPinpointMode() {
+ return Xpinpoint;
+ }
+
+ public void setPinpointMode(boolean b) {
+ this.Xpinpoint = b;
+ }
+
public void setBehaveInJava5Way(boolean b) {
behaveInJava5Way = b;
}
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
index 6c17184b7..a6fe494f3 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
@@ -57,6 +57,8 @@ import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.WeaveMessage;
+import org.aspectj.bridge.context.CompilationAndWeavingContext;
+import org.aspectj.bridge.context.ContextToken;
import org.aspectj.util.PartialOrder;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AjcMemberMaker;
@@ -1726,9 +1728,11 @@ class BcelClassWeaver implements IClassWeaver {
private boolean match(BcelShadow shadow, List shadowAccumulator) {
//System.err.println("match: " + shadow);
+ ContextToken shadowMatchToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.MATCHING_SHADOW, shadow);
boolean isMatched = false;
for (Iterator i = shadowMungers.iterator(); i.hasNext(); ) {
ShadowMunger munger = (ShadowMunger)i.next();
+ ContextToken mungerMatchToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.MATCHING_POINTCUT, munger.getPointcut());
if (munger.match(shadow, world)) {
WeaverMetrics.recordMatchResult(true);// Could pass: munger
@@ -1741,9 +1745,11 @@ class BcelClassWeaver implements IClassWeaver {
} else {
WeaverMetrics.recordMatchResult(false); // Could pass: munger
}
+ CompilationAndWeavingContext.leavingPhase(mungerMatchToken);
}
if (isMatched) shadowAccumulator.add(shadow);
+ CompilationAndWeavingContext.leavingPhase(shadowMatchToken);
return isMatched;
}
@@ -1759,7 +1765,9 @@ class BcelClassWeaver implements IClassWeaver {
for (Iterator i = shadows.iterator(); i.hasNext(); ) {
BcelShadow shadow = (BcelShadow)i.next();
+ ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.IMPLEMENTING_ON_SHADOW,shadow);
shadow.implement();
+ CompilationAndWeavingContext.leavingPhase(tok);
}
mg.matchedShadows = null;
}
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
index c13b8df83..0045130a0 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
@@ -2822,7 +2822,7 @@ public class BcelShadow extends Shadow {
public LazyMethodGen extractMethod(String newMethodName, int visibilityModifier, ShadowMunger munger) {
LazyMethodGen.assertGoodBody(range.getBody(), newMethodName);
- if (!getKind().allowsExtraction()) throw new BCException();
+ if (!getKind().allowsExtraction()) throw new BCException("Attempt to extract method from a shadow kind that does not support this operation (" + getKind() + ")");
LazyMethodGen freshMethod = createMethodGen(newMethodName,visibilityModifier);
// System.err.println("******");
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
index 997c57418..19cfd39a1 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
@@ -34,6 +34,8 @@ import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.WeaveMessage;
+import org.aspectj.bridge.context.CompilationAndWeavingContext;
+import org.aspectj.bridge.context.ContextToken;
import org.aspectj.weaver.AjcMemberMaker;
import org.aspectj.weaver.AnnotationOnTypeMunger;
import org.aspectj.weaver.AnnotationX;
@@ -71,6 +73,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
}
public boolean munge(BcelClassWeaver weaver) {
+ ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.MUNGING_WITH, this);
boolean changed = false;
boolean worthReporting = true;
@@ -150,6 +153,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
}
}
+ CompilationAndWeavingContext.leavingPhase(tok);
return changed;
}
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
index 3549d4872..1aefee5b9 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
@@ -52,6 +52,8 @@ import org.aspectj.bridge.Message;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.SourceLocation;
import org.aspectj.bridge.WeaveMessage;
+import org.aspectj.bridge.context.CompilationAndWeavingContext;
+import org.aspectj.bridge.context.ContextToken;
import org.aspectj.util.FileUtil;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.Advice;
@@ -952,10 +954,12 @@ public class BcelWeaver implements IWeaver {
// variation of "weave" that sources class files from an external source.
public Collection weave(IClassFileProvider input) throws IOException {
+ ContextToken weaveToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING, "");
Collection wovenClassNames = new ArrayList();
IWeaveRequestor requestor = input.getRequestor();
requestor.processingReweavableState();
+ ContextToken reweaveToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE,"");
prepareToProcessReweavableState();
// clear all state from files we'll be reweaving
for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
@@ -965,10 +969,16 @@ public class BcelWeaver implements IWeaver {
// null return from getClassType() means the delegate is an eclipse source type - so
// there *cant* be any reweavable state... (he bravely claimed...)
- if (classType !=null)
+ if (classType !=null) {
+ ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE, className);
processReweavableStateIfPresent(className, classType);
+ CompilationAndWeavingContext.leavingPhase(tok);
+ }
}
+ CompilationAndWeavingContext.leavingPhase(reweaveToken);
+
+ ContextToken typeMungingToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS,"");
requestor.addingTypeMungers();
// We process type mungers in two groups, first mungers that change the type
@@ -993,7 +1003,10 @@ public class BcelWeaver implements IWeaver {
addNormalTypeMungers(className);
}
+ CompilationAndWeavingContext.leavingPhase(typeMungingToken);
+
requestor.weavingAspects();
+ ContextToken aspectToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_ASPECTS, "");
// first weave into aspects
for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
UnwovenClassFile classFile = (UnwovenClassFile)i.next();
@@ -1004,8 +1017,10 @@ public class BcelWeaver implements IWeaver {
wovenClassNames.add(className);
}
}
+ CompilationAndWeavingContext.leavingPhase(aspectToken);
requestor.weavingClasses();
+ ContextToken classToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_CLASSES, "");
// then weave into non-aspects
for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
UnwovenClassFile classFile = (UnwovenClassFile)i.next();
@@ -1016,6 +1031,7 @@ public class BcelWeaver implements IWeaver {
wovenClassNames.add(className);
}
}
+ CompilationAndWeavingContext.leavingPhase(classToken);
addedClasses = new ArrayList();
deletedTypenames = new ArrayList();
@@ -1024,6 +1040,7 @@ public class BcelWeaver implements IWeaver {
warnOnUnmatchedAdvice();
requestor.weaveCompleted();
+ CompilationAndWeavingContext.leavingPhase(weaveToken);
return wovenClassNames;
}
@@ -1119,7 +1136,9 @@ public class BcelWeaver implements IWeaver {
weaveParentsFor(typesForWeaving,rtxI.getName());
}
}
+ ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_DECLARE_PARENTS,rtx.getName());
weaveParentTypeMungers(rtx); // Now do this type
+ CompilationAndWeavingContext.leavingPhase(tok);
typesForWeaving.remove(typeToWeave); // and remove it from the list of those to process
}
@@ -1168,6 +1187,7 @@ public class BcelWeaver implements IWeaver {
private void weaveAndNotify(UnwovenClassFile classFile, BcelObjectType classType,
IWeaveRequestor requestor) throws IOException {
+ ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_TYPE, classType.getResolvedTypeX().getName());
LazyClassGen clazz = weaveWithoutDump(classFile,classType);
classType.finishedWith();
//clazz is null if the classfile was unchanged by weaving...
@@ -1179,6 +1199,7 @@ public class BcelWeaver implements IWeaver {
} else {
requestor.acceptResult(classFile);
}
+ CompilationAndWeavingContext.leavingPhase(tok);
}
/** helper method - will return NULL if the underlying delegate is an EclipseSourceType and not a BcelObjectType */
@@ -1379,6 +1400,7 @@ public class BcelWeaver implements IWeaver {
}
public void weaveNormalTypeMungers(ResolvedType onType) {
+ ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS, onType.getName());
if (onType.isRawType() || onType.isParameterizedType()) onType = onType.getGenericType();
for (Iterator i = typeMungerList.iterator(); i.hasNext(); ) {
ConcreteTypeMunger m = (ConcreteTypeMunger)i.next();
@@ -1386,6 +1408,7 @@ public class BcelWeaver implements IWeaver {
onType.addInterTypeMunger(m);
}
}
+ CompilationAndWeavingContext.leavingPhase(tok);
}
diff --git a/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java b/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java
index 4cd3ee58a..b3de2d417 100644
--- a/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java
+++ b/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java
@@ -148,7 +148,7 @@ public class ClassPathManager {
try {
if (fis!=null) fis.close();
} catch (IOException ioe) {
- throw new BCException("Can't close class file : "+file.getName()+": "+ioe.toString());
+ throw new BCException("Can't close class file : "+file.getName(),ioe);
} finally {
fis = null;
}
@@ -250,7 +250,7 @@ public class ClassPathManager {
zipFile = new ZipFile(file);
openArchives.add(zipFile);
} catch (IOException ioe) {
- throw new BCException("Can't open archive: "+file.getName()+": "+ioe.toString());
+ throw new BCException("Can't open archive: "+file.getName(),ioe);
}
}
@@ -272,7 +272,7 @@ public class ClassPathManager {
openArchives.remove(zipFile);
zipFile.close();
} catch (IOException ioe) {
- throw new BCException("Can't close archive: "+file.getName()+": "+ioe.toString());
+ throw new BCException("Can't close archive: "+file.getName(),ioe);
} finally {
zipFile = null;
}