aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhugunin <jhugunin>2004-01-07 17:00:52 +0000
committerjhugunin <jhugunin>2004-01-07 17:00:52 +0000
commit97ab1e91dfba52187c14f0f7e5fdf6fafd9966c4 (patch)
tree1758e455c1531ab3a1507ec22ff33cb64ac3286c
parentcda2dd4f82306debf0a2c04eb98586fac50cd696 (diff)
downloadaspectj-97ab1e91dfba52187c14f0f7e5fdf6fafd9966c4.tar.gz
aspectj-97ab1e91dfba52187c14f0f7e5fdf6fafd9966c4.zip
fix for Bugzilla Bug 41952
XLint warning for call PCD's using subtype of defining type also added extraSourceLocations to IMessage+ for message with multiple source lines
-rw-r--r--bridge/src/org/aspectj/bridge/IMessage.java2
-rw-r--r--bridge/src/org/aspectj/bridge/Message.java71
-rw-r--r--bridge/src/org/aspectj/bridge/MessageUtil.java55
-rw-r--r--bridge/src/org/aspectj/bridge/SourceLocation.java2
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java7
-rw-r--r--testing/src/org/aspectj/testing/xml/SoftMessage.java8
-rw-r--r--tests/ajcTests.xml54
-rw-r--r--tests/bugs/DeclaringTypeWarning.java23
-rw-r--r--tests/new/CallTypesI.java4
-rw-r--r--tests/new/IndeterminateArg.java3
-rw-r--r--tests/new/IndeterminateArgType.java3
-rw-r--r--weaver/src/org/aspectj/weaver/Checker.java4
-rw-r--r--weaver/src/org/aspectj/weaver/Lint.java14
-rw-r--r--weaver/src/org/aspectj/weaver/XlintDefault.properties4
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/AndPointcut.java4
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java2
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java101
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/NotPointcut.java2
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/OrPointcut.java4
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/Pointcut.java8
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java7
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java28
22 files changed, 323 insertions, 87 deletions
diff --git a/bridge/src/org/aspectj/bridge/IMessage.java b/bridge/src/org/aspectj/bridge/IMessage.java
index 7fddcb089..1848e0e31 100644
--- a/bridge/src/org/aspectj/bridge/IMessage.java
+++ b/bridge/src/org/aspectj/bridge/IMessage.java
@@ -124,4 +124,6 @@ public interface IMessage {
* join point's static part.
*/
public String getDetails();
+
+ public List getExtraSourceLocations();
}
diff --git a/bridge/src/org/aspectj/bridge/Message.java b/bridge/src/org/aspectj/bridge/Message.java
index 408a2d4f3..975d0c70d 100644
--- a/bridge/src/org/aspectj/bridge/Message.java
+++ b/bridge/src/org/aspectj/bridge/Message.java
@@ -18,6 +18,10 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
/**
@@ -30,6 +34,7 @@ public class Message implements IMessage { // XXX toString or renderer?
private final Throwable thrown;
private final ISourceLocation sourceLocation;
private final String details;
+ private final List/*SourceLocation*/ extraSourceLocations;
/** convenience for constructing failure messages */
public static Message fail(String message, Throwable thrown) {
@@ -60,20 +65,19 @@ public class Message implements IMessage { // XXX toString or renderer?
* and thrown is null.
*/
public Message(String message, String details, IMessage.Kind kind,
- ISourceLocation sourceLocation) {
+ ISourceLocation sourceLocation, Throwable thrown, ISourceLocation[] extraSourceLocations) {
this.details = details;
- this.message = message;
+ this.message = (message==null) ? thrown.getMessage() : message;
this.kind = kind;
this.sourceLocation = sourceLocation;
- this.thrown = null;
- if (null == message) {
- if (null != thrown) {
- message = thrown.getMessage();
- }
- if (null == message) {
- throw new IllegalArgumentException("null message");
- }
+ this.thrown = thrown;
+
+ if (extraSourceLocations != null) {
+ this.extraSourceLocations = Arrays.asList(extraSourceLocations);
}
+ else {
+ this.extraSourceLocations = Collections.EMPTY_LIST;
+ }
if (null == kind) {
throw new IllegalArgumentException("null kind");
}
@@ -92,22 +96,23 @@ public class Message implements IMessage { // XXX toString or renderer?
*/
public Message(String message, IMessage.Kind kind, Throwable thrown,
ISourceLocation sourceLocation) {
- this.message = message;
- this.kind = kind;
- this.thrown = thrown;
- this.sourceLocation = sourceLocation;
- this.details = "";
- if (null == message) {
- if (null != thrown) {
- message = thrown.getMessage();
- }
- if (null == message) {
- throw new IllegalArgumentException("null message");
- }
- }
- if (null == kind) {
- throw new IllegalArgumentException("null kind");
- }
+ this(message, "", kind, sourceLocation, thrown, null );
+// this.message = message;
+// this.kind = kind;
+// this.thrown = thrown;
+// this.sourceLocation = sourceLocation;
+// this.details = "";
+// if (null == message) {
+// if (null != thrown) {
+// message = thrown.getMessage();
+// }
+// if (null == message) {
+// throw new IllegalArgumentException("null message");
+// }
+// }
+// if (null == kind) {
+// throw new IllegalArgumentException("null kind");
+// }
}
/** @return the kind of this message */
@@ -165,16 +170,9 @@ public class Message implements IMessage { // XXX toString or renderer?
}
public String toString() {
- return Message.renderToString(this);
+ return MessageUtil.renderMessage(this,false);
}
- public static String renderToString(IMessage message) {
- ISourceLocation loc = message.getSourceLocation();
- String locString = (null == loc ? "" : " at " + loc);
- Throwable thrown = message.getThrown();
- return message.getKind() + locString + ": " + message.getMessage()
- + (null == thrown ? "" : render(thrown));
- }
public static String render(Throwable thrown) { // XXX cf LangUtil.debugStr
if (null == thrown) return "null throwable";
@@ -200,4 +198,9 @@ public class Message implements IMessage { // XXX toString or renderer?
public String getDetails() {
return details;
}
+
+ public List getExtraSourceLocations() {
+ return extraSourceLocations;
+ }
+
}
diff --git a/bridge/src/org/aspectj/bridge/MessageUtil.java b/bridge/src/org/aspectj/bridge/MessageUtil.java
index 9dbb09e44..7a3fea2d0 100644
--- a/bridge/src/org/aspectj/bridge/MessageUtil.java
+++ b/bridge/src/org/aspectj/bridge/MessageUtil.java
@@ -759,28 +759,49 @@ public class MessageUtil {
if (null == message) {
return "((IMessage) null)";
}
- StringBuffer result = new StringBuffer();
-
- result.append(message.getKind().toString());
- result.append(" ");
+
+ ISourceLocation loc = message.getSourceLocation();
+ String locString = (null == loc ? "" : " at " + loc);
- String messageString = message.getMessage();
- if (!LangUtil.isEmpty(messageString)) {
- result.append(messageString);
- result.append(" ");
+ String result = message.getKind() + locString + " " + message.getMessage();
+
+ Throwable thrown = message.getThrown();
+ if (thrown != null) {
+ result += " -- " + LangUtil.renderExceptionShort(thrown);
+ result += "\n" + LangUtil.renderException(thrown, elide);
}
-
- ISourceLocation loc = message.getSourceLocation();
- if ((null != loc) && (loc != ISourceLocation.EMPTY)) {
- result.append("at " + renderSourceLocation(loc));
+
+ if (message.getExtraSourceLocations().isEmpty()) {
+ return result;
}
- Throwable thrown = message.getThrown();
- if (null != thrown) {
- result.append(" -- " + LangUtil.renderExceptionShort(thrown));
- result.append("\n" + LangUtil.renderException(thrown, elide));
+ else {
+ return addExtraSourceLocations(message, result);
}
- return result.toString();
}
+
+ public static String addExtraSourceLocations(
+ IMessage message,
+ String baseMessage)
+ {
+ StringWriter buf = new StringWriter();
+ PrintWriter writer = new PrintWriter(buf);
+ writer.println(baseMessage);
+ for (Iterator iter = message.getExtraSourceLocations().iterator(); iter.hasNext();) {
+ ISourceLocation element = (ISourceLocation) iter.next();
+ writer.print("\tsee also: " + element.toString());
+ if (iter.hasNext()) {
+ writer.println();
+ }
+ }
+ try { buf.close(); }
+ catch (IOException ioe) {}
+ return buf.getBuffer().toString();
+ }
+
+
+
+
+
/**
* Render ISourceLocation to String, ignoring empty elements
diff --git a/bridge/src/org/aspectj/bridge/SourceLocation.java b/bridge/src/org/aspectj/bridge/SourceLocation.java
index 882d8af1b..c44d0b942 100644
--- a/bridge/src/org/aspectj/bridge/SourceLocation.java
+++ b/bridge/src/org/aspectj/bridge/SourceLocation.java
@@ -135,7 +135,7 @@ public class SourceLocation implements ISourceLocation, java.io.Serializable {
sb.append(sourceFile.getPath());
sb.append(":");
}
- sb.append("" + startLine + "-" + endLine);
+ sb.append(startLine); //"" + startLine + "-" + endLine);
if (!noColumn) {
sb.append(":" + column);
}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java b/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java
index 101fef62b..44f730a42 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java
@@ -432,7 +432,12 @@ public class Main {
sb.append(Main.renderExceptionForUser(thrown));
}
- return sb.toString();
+ if (message.getExtraSourceLocations().isEmpty()) {
+ return sb.toString();
+ } else {
+ return MessageUtil.addExtraSourceLocations(message, sb.toString());
+ }
+
}
public boolean isIgnoring(IMessage.Kind kind) {
diff --git a/testing/src/org/aspectj/testing/xml/SoftMessage.java b/testing/src/org/aspectj/testing/xml/SoftMessage.java
index e798f8f05..f11e55966 100644
--- a/testing/src/org/aspectj/testing/xml/SoftMessage.java
+++ b/testing/src/org/aspectj/testing/xml/SoftMessage.java
@@ -15,6 +15,7 @@
package org.aspectj.testing.xml;
import java.io.File;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -287,4 +288,11 @@ public class SoftMessage implements IMessage { // XXX mutable dup of Message
public void setDetails(String string) {
details = string;
}
+
+ /* (non-Javadoc)
+ * @see org.aspectj.bridge.IMessage#getExtraSourceLocations()
+ */
+ public List getExtraSourceLocations() {
+ return Collections.EMPTY_LIST;
+ }
}
diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml
index 1d386867c..5aab76ba8 100644
--- a/tests/ajcTests.xml
+++ b/tests/ajcTests.xml
@@ -2786,7 +2786,7 @@
<ajc-test dir="design/calls" title="calls: calls(...)"
keywords="from-resolved_10x">
- <compile files="Simple.java"/>
+ <compile files="Simple.java" options="-Xlint:ignore"/>
<run class="Simple"/>
</ajc-test>
@@ -3508,7 +3508,7 @@
<ajc-test dir="new"
title="Does the matrix coverage thing for the new method signatures"
keywords="from-resolved_10x">
- <compile files="MethodSignatures.java" options="-1.4"/>
+ <compile files="MethodSignatures.java" options="-1.4,-Xlint:ignore"/>
<run class="MethodSignatures" vm="1.4"/>
</ajc-test>
@@ -3531,7 +3531,7 @@
this behavior. -->
<ajc-test dir="new" title="correct types of parameters at call-sites"
keywords="from-resolved_10x">
- <compile files="CallTypes.java" options="-1.4"/>
+ <compile files="CallTypes.java" options="-1.4,-Xlint:ignore"/>
<run class="CallTypes" vm="1.4"/>
</ajc-test>
@@ -3698,7 +3698,7 @@
<ajc-test dir="new"
title="target type matching with messy interface hierarchies"
keywords="from-resolved_10x">
- <compile files="CallTypesI.java" options="-1.4"/>
+ <compile files="CallTypesI.java" options="-1.4,-Xlint:ignore"/>
<run class="CallTypesI" vm="1.4"/>
</ajc-test>
@@ -3806,7 +3806,7 @@
<ajc-test dir="new" pr="519" title="Exception planning advice"
keywords="from-resolved_10x">
- <compile files="PR519.java"/>
+ <compile files="PR519.java" options="-Xlint:ignore"/>
<run class="PR519"/>
</ajc-test>
@@ -4223,14 +4223,14 @@
<ajc-test dir="new" pr="654"
title="Overriding method implementations using introduction on interfaces"
keywords="from-resolved_10x,fail-unimplemented">
- <compile files="IntroductionsOverriding.java"/>
+ <compile files="IntroductionsOverriding.java" options="-Xlint:ignore" />
<run class="IntroductionsOverriding"/>
</ajc-test>
<ajc-test dir="new" pr="654"
title="more coverage for around and concrete methods on interfaces"
keywords="from-resolved_10x">
- <compile files="MultiAndAround.java"/>
+ <compile files="MultiAndAround.java" options="-Xlint:ignore"/>
<run class="MultiAndAround"/>
</ajc-test>
@@ -4267,7 +4267,7 @@
<ajc-test dir="new" pr="695"
title="! and declaring types with callee-side call join points"
keywords="from-resolved_10x">
- <compile files="NotAndDeclaringTypes.java"/>
+ <compile files="NotAndDeclaringTypes.java" options="-Xlint:ignore"/>
<run class="NotAndDeclaringTypes"/>
</ajc-test>
@@ -5037,7 +5037,7 @@
<ajc-test dir="base/test131"
title="various forms of package name pattern matching work"
keywords="from-broken14usejavac">
- <compile files="Driver.java,p1/C1.java,p1/p2/C2.java"/>
+ <compile files="Driver.java,p1/C1.java,p1/p2/C2.java" />
<run class="Driver"/>
</ajc-test>
@@ -6821,7 +6821,7 @@
<message kind="error" line="20" text="incompatible type"/>
</compile>
</ajc-test>
-
+
<ajc-test dir="bugs" pr="49250"
title="alias getCause for getWrappedThrowable in SoftException">
<compile files="GetCauseOnSoftException.java" options="-Xlint:warning">
@@ -6849,5 +6849,39 @@
<message kind="error" line="10" text="ref"/>
</compile>
</ajc-test>
+
+ <ajc-test dir="bugs"
+ title="XLint warning for call PCD's using subtype of defining type"
+ pr="41952"
+ >
+ <compile
+ files="DeclaringTypeWarning.java" >
+ <!-- Should test for extra source locations lines 12 and 14 -->
+ <message kind="warning" line="6"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="bugs"
+ title="(-Xlint:ignore) XLint warning for call PCD's using subtype of defining type"
+ pr="41952"
+ >
+ <compile
+ options="-Xlint:ignore"
+ files="DeclaringTypeWarning.java" >
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="bugs"
+ title="(-1.4) XLint warning for call PCD's using subtype of defining type"
+ pr="41952"
+ >
+ <compile
+ options="-1.4"
+ files="DeclaringTypeWarning.java" >
+ <!-- Should test for extra source locations line 14 -->
+ <message kind="warning" line="6"/>
+ <message kind="error" line="12" />
+ </compile>
+ </ajc-test>
</suite>
diff --git a/tests/bugs/DeclaringTypeWarning.java b/tests/bugs/DeclaringTypeWarning.java
new file mode 100644
index 000000000..d61e1fbe5
--- /dev/null
+++ b/tests/bugs/DeclaringTypeWarning.java
@@ -0,0 +1,23 @@
+
+class A { void run() {} }
+class B extends A {}
+aspect C {
+ before() : runB() { } // warn here
+ pointcut runB(): call(void B.run());
+ before() : call(int B.run()) {}
+}
+public class DeclaringTypeWarning {
+ public static void main(String[] args) {
+ // ok with -1.4; otherwise, becomes A.run in bytecode
+ new B().run();
+ // never works - compile-time type of reference is A, not B
+ ((A) new B()).run();
+ }
+}
+aspect D {
+ declare error : call(void B.run()) : // warn here
+ "This should be the only error";
+
+ declare error : call(int B.run()) :
+ "This error should not happen";
+}
diff --git a/tests/new/CallTypesI.java b/tests/new/CallTypesI.java
index 7ab225106..f9b770ac2 100644
--- a/tests/new/CallTypesI.java
+++ b/tests/new/CallTypesI.java
@@ -53,7 +53,7 @@ interface I1a extends I0 { }
interface I1b extends I0 { }
-interface I2 extends I1a, I1b {}
+////interface I2 extends I1a, I1b {}
class C0 {
@@ -74,9 +74,11 @@ aspect A {
before(): call(void C0.mC()) {
noteAdvice += "static c0, ";
}
+
before(): call(void C1a.mC()) || call(void C1a.mI()) {
noteAdvice += "static c1a, ";
}
+
before(): call(void C1b.mC()) || call(void C1b.mI()) {
noteAdvice += "static c1b, ";
}
diff --git a/tests/new/IndeterminateArg.java b/tests/new/IndeterminateArg.java
index db54c82de..e0b0bfc36 100644
--- a/tests/new/IndeterminateArg.java
+++ b/tests/new/IndeterminateArg.java
@@ -120,7 +120,8 @@ aspect A {
T.e(name);
}
- pointcut safe() : (call(C+.new(..)) || call(* C+.*(..)));
+ pointcut safe() : (call(C+.new(..))) ||
+ (call(* *.*(..)) && target(C));
// XXX should encode slots, range: a0o1 = args(Object); a3o2Start = args(Object, Object, *)
pointcut none() : args();
pointcut o1() : args(Object);
diff --git a/tests/new/IndeterminateArgType.java b/tests/new/IndeterminateArgType.java
index 4beb1301e..6a4c58323 100644
--- a/tests/new/IndeterminateArgType.java
+++ b/tests/new/IndeterminateArgType.java
@@ -97,7 +97,8 @@ aspect A {
T.e(name);
}
- pointcut safe() : call(Safe+.new(..)) || call(* Safe+.*(..));
+ pointcut safe() : (call(Safe+.new(..))) ||
+ (call(* *.*(..)) && target(Safe));
pointcut o1End() : args(.., Object);
pointcut s1End() : args(.., String);
diff --git a/weaver/src/org/aspectj/weaver/Checker.java b/weaver/src/org/aspectj/weaver/Checker.java
index 0e30723b4..3baa45175 100644
--- a/weaver/src/org/aspectj/weaver/Checker.java
+++ b/weaver/src/org/aspectj/weaver/Checker.java
@@ -49,7 +49,9 @@ public class Checker extends ShadowMunger {
msg,
shadow.toString(),
isError ? IMessage.ERROR : IMessage.WARNING,
- shadow.getSourceLocation());
+ shadow.getSourceLocation(),
+ null,
+ new ISourceLocation[]{this.getSourceLocation()});
world.getMessageHandler().handleMessage(message);
AsmRelationshipProvider.checkerMunger(world.getModel(), shadow, this);
diff --git a/weaver/src/org/aspectj/weaver/Lint.java b/weaver/src/org/aspectj/weaver/Lint.java
index 3b3db4c60..5a2d1c566 100644
--- a/weaver/src/org/aspectj/weaver/Lint.java
+++ b/weaver/src/org/aspectj/weaver/Lint.java
@@ -46,7 +46,10 @@ public class Lint {
public final Kind shadowNotInStructure =
new Kind("shadowNotInStructure", "the shadow for this join point is not exposed in the structure model: {0}");
-
+
+ public final Kind unmatchedSuperTypeInCall =
+ new Kind("unmatchedSuperTypeInCall", "does not match because declaring type is {0}, if match desired use target({1})");
+
public Lint(World world) {
this.world = world;
}
@@ -149,5 +152,14 @@ public class Lint {
text += " [Xlint:" + name + "]";
world.getMessageHandler().handleMessage(new Message(text, kind, null, location));
}
+
+ public void signal(String[] infos, ISourceLocation location, ISourceLocation[] extraLocations) {
+ if (kind == null) return;
+
+ String text = MessageFormat.format(message, infos );
+ text += " [Xlint:" + name + "]";
+ world.getMessageHandler().handleMessage(
+ new Message(text, "", kind, location, null, extraLocations));
+ }
}
}
diff --git a/weaver/src/org/aspectj/weaver/XlintDefault.properties b/weaver/src/org/aspectj/weaver/XlintDefault.properties
index 59d6d2f28..10da55a66 100644
--- a/weaver/src/org/aspectj/weaver/XlintDefault.properties
+++ b/weaver/src/org/aspectj/weaver/XlintDefault.properties
@@ -5,4 +5,6 @@ unresolvableMember = warning
typeNotExposedToWeaver = warning
-shadowNotInStructure = ignore \ No newline at end of file
+shadowNotInStructure = ignore
+
+unmatchedSuperTypeInCall = warning
diff --git a/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java b/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java
index 5dc127aaf..b3202774a 100644
--- a/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/AndPointcut.java
@@ -85,8 +85,8 @@ public class AndPointcut extends Pointcut {
}
public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
- return new AndPointcut(left.concretize1(inAspect, bindings),
- right.concretize1(inAspect, bindings));
+ return new AndPointcut(left.concretize(inAspect, bindings),
+ right.concretize(inAspect, bindings));
}
public Pointcut getLeft() {
diff --git a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java
index ef5929888..1da25d363 100644
--- a/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java
+++ b/weaver/src/org/aspectj/weaver/patterns/ExactTypePattern.java
@@ -73,7 +73,7 @@ public class ExactTypePattern extends TypePattern {
public String toString() {
//Thread.currentThread().dumpStack();
- return "ExactTypePattern(" + type.toString() + (includeSubtypes ? "+" : "") + ")";
+ return type.toString() + (includeSubtypes ? "+" : "");
}
public TypePattern resolveBindings(IScope scope, Bindings bindings,
boolean allowBinding, boolean requireExactType)
diff --git a/weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java b/weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java
index 8be3671f0..1dca9d036 100644
--- a/weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/KindedPointcut.java
@@ -13,23 +13,43 @@
package org.aspectj.weaver.patterns;
-import java.io.*;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import org.aspectj.bridge.ISourceLocation;
import org.aspectj.util.FuzzyBoolean;
-import org.aspectj.weaver.*;
+import org.aspectj.weaver.Checker;
+import org.aspectj.weaver.ISourceContext;
+import org.aspectj.weaver.IntMap;
+import org.aspectj.weaver.ResolvedTypeX;
+import org.aspectj.weaver.Shadow;
+import org.aspectj.weaver.ShadowMunger;
+import org.aspectj.weaver.TypeX;
+import org.aspectj.weaver.World;
import org.aspectj.weaver.ast.Literal;
import org.aspectj.weaver.ast.Test;
public class KindedPointcut extends Pointcut {
Shadow.Kind kind;
SignaturePattern signature;
+
+ private ShadowMunger munger = null; // only set after concretization
- public KindedPointcut(
- Shadow.Kind kind,
- SignaturePattern signature) {
- this.kind = kind;
- this.signature = signature;
- }
+ public KindedPointcut(
+ Shadow.Kind kind,
+ SignaturePattern signature) {
+ this.kind = kind;
+ this.signature = signature;
+ }
+ public KindedPointcut(
+ Shadow.Kind kind,
+ SignaturePattern signature,
+ ShadowMunger munger)
+ {
+ this(kind, signature);
+ this.munger = munger;
+ }
public FuzzyBoolean fastMatch(ResolvedTypeX type) {
return FuzzyBoolean.MAYBE;
@@ -37,11 +57,70 @@ public class KindedPointcut extends Pointcut {
public FuzzyBoolean match(Shadow shadow) {
if (shadow.getKind() != kind) return FuzzyBoolean.NO;
- if (!signature.matches(shadow.getSignature(), shadow.getIWorld())) return FuzzyBoolean.NO;
+ if (!signature.matches(shadow.getSignature(), shadow.getIWorld())){
+ if(kind == Shadow.MethodCall) {
+ warnOnConfusingSig(shadow);
+ }
+ return FuzzyBoolean.NO;
+ }
return FuzzyBoolean.YES;
}
+ private void warnOnConfusingSig(Shadow shadow) {
+ // no warnings for declare error/warning
+ if (munger instanceof Checker) return;
+
+ World world = shadow.getIWorld();
+
+ // warning never needed if the declaring type is any
+ TypeX exactDeclaringType = signature.getDeclaringType().getExactType();
+
+ ResolvedTypeX shadowDeclaringType =
+ shadow.getSignature().getDeclaringType().resolve(world);
+
+ if (signature.getDeclaringType().isStar()
+ || exactDeclaringType== ResolvedTypeX.MISSING)
+ return;
+
+ // warning not needed if match type couldn't ever be the declaring type
+ if (!shadowDeclaringType.isAssignableFrom(exactDeclaringType)) {
+ return;
+ }
+
+ // if the method in the declaring type is *not* visible to the
+ // exact declaring type then warning not needed.
+ int shadowModifiers = shadow.getSignature().getModifiers(world);
+ if (!ResolvedTypeX
+ .isVisible(
+ shadowModifiers,
+ shadowDeclaringType,
+ exactDeclaringType.resolve(world))) {
+ return;
+ }
+
+ SignaturePattern nonConfusingPattern =
+ new SignaturePattern(
+ signature.getKind(),
+ signature.getModifiers(),
+ signature.getReturnType(),
+ TypePattern.ANY,
+ signature.getName(),
+ signature.getParameterTypes(),
+ signature.getThrowsPattern());
+
+ if (nonConfusingPattern
+ .matches(shadow.getSignature(), shadow.getIWorld())) {
+ shadow.getIWorld().getLint().unmatchedSuperTypeInCall.signal(
+ new String[] {
+ shadow.getSignature().getDeclaringType().toString(),
+ signature.getDeclaringType().toString()
+ },
+ this.getSourceLocation(),
+ new ISourceLocation[] {shadow.getSourceLocation()} );
+ }
+ }
+
public boolean equals(Object other) {
if (!(other instanceof KindedPointcut)) return false;
KindedPointcut o = (KindedPointcut)other;
@@ -102,7 +181,9 @@ public class KindedPointcut extends Pointcut {
}
public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
- return new KindedPointcut(kind, signature);
+ Pointcut ret = new KindedPointcut(kind, signature, bindings.getEnclosingAdvice());
+ ret.copyLocationFrom(this);
+ return ret;
}
public Shadow.Kind getKind() {
diff --git a/weaver/src/org/aspectj/weaver/patterns/NotPointcut.java b/weaver/src/org/aspectj/weaver/patterns/NotPointcut.java
index d10eea34f..02884b22c 100644
--- a/weaver/src/org/aspectj/weaver/patterns/NotPointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/NotPointcut.java
@@ -91,7 +91,7 @@ public class NotPointcut extends Pointcut {
}
public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
- return new NotPointcut(body.concretize1(inAspect, bindings));
+ return new NotPointcut(body.concretize(inAspect, bindings));
}
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java b/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java
index 1e6c2b378..9e4eae4fb 100644
--- a/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/OrPointcut.java
@@ -88,8 +88,8 @@ public class OrPointcut extends Pointcut {
}
public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
- return new OrPointcut(left.concretize1(inAspect, bindings),
- right.concretize1(inAspect, bindings));
+ return new OrPointcut(left.concretize(inAspect, bindings),
+ right.concretize(inAspect, bindings));
}
public Pointcut getLeft() {
diff --git a/weaver/src/org/aspectj/weaver/patterns/Pointcut.java b/weaver/src/org/aspectj/weaver/patterns/Pointcut.java
index 0e1e2ba91..126a43b84 100644
--- a/weaver/src/org/aspectj/weaver/patterns/Pointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/Pointcut.java
@@ -122,13 +122,19 @@ public abstract class Pointcut extends PatternNode {
public Pointcut concretize(ResolvedTypeX inAspect, IntMap bindings) {
- assertState(RESOLVED);
+ //!!! add this test -- assertState(RESOLVED);
Pointcut ret = this.concretize1(inAspect, bindings);
+ if (shouldCopyLocationForConcretize()) ret.copyLocationFrom(this);
ret.state = CONCRETE;
return ret;
}
+ protected boolean shouldCopyLocationForConcretize() {
+ return true;
+ }
+
+
/**
* Resolves and removes ReferencePointcuts, replacing with basic ones
*
diff --git a/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java b/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java
index 1b9848ccf..e73e24e82 100644
--- a/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java
@@ -271,7 +271,7 @@ public class ReferencePointcut extends Pointcut {
newBindings.copyContext(bindings);
newBindings.pushEnclosingDefinition(pointcutDec);
try {
- return pointcutDec.getPointcut().concretize1(searchStart, newBindings);
+ return pointcutDec.getPointcut().concretize(searchStart, newBindings);
} finally {
newBindings.popEnclosingDefinitition();
}
@@ -280,6 +280,11 @@ public class ReferencePointcut extends Pointcut {
concretizing = false;
}
}
+
+ // We want to keep the original source location, not the reference location
+ protected boolean shouldCopyLocationForConcretize() {
+ return false;
+ }
public boolean equals(Object other) {
if (!(other instanceof ReferencePointcut)) return false;
diff --git a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java
index d6db93f10..64a3f66b7 100644
--- a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java
+++ b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java
@@ -238,4 +238,32 @@ public class SignaturePattern extends PatternNode {
return ret;
}
+ /**
+ * @return
+ */
+ public ModifiersPattern getModifiers() {
+ return modifiers;
+ }
+
+ /**
+ * @return
+ */
+ public TypePatternList getParameterTypes() {
+ return parameterTypes;
+ }
+
+ /**
+ * @return
+ */
+ public TypePattern getReturnType() {
+ return returnType;
+ }
+
+ /**
+ * @return
+ */
+ public ThrowsPattern getThrowsPattern() {
+ return throwsPattern;
+ }
+
}