}
}
}
-
- //??? timing is weird
- factory.getWorld().getCrosscuttingMembersSet().addOrReplaceAspect(typeX);
-
- if (typeX.getSuperclass().isAspect() && !typeX.getSuperclass().isExposedToWeaver()) {
- factory.getWorld().getCrosscuttingMembersSet().addOrReplaceAspect(typeX.getSuperclass());
- }
+
+ concreteName.getDeclaredPointcuts();
}
public PointcutDesignator pointcutDesignator;
private int declaredModifiers;
private String declaredName;
+
+ private ResolvedPointcutDefinition resolvedPointcutDeclaration = null;
public PointcutDeclaration(CompilationResult compilationResult) {
super(compilationResult);
pointcutDesignator.postParse(typeDec, this);
}
}
+
+ public void resolve(ClassScope upperScope) {
+ // this method should do nothing, use the entry point below...
+ }
+
+ public void resolvePointcut(ClassScope upperScope) {
+ super.resolve(upperScope);
+ }
+
public void resolveStatements() {
if (isAbstract()) {
this.modifiers |= AccSemicolonBody;
}
-
+
if (binding == null || ignoreFurtherInvestigation) return;
pointcutDesignator.finishResolveTypes(this, this.binding, arguments.length,
scope.enclosingSourceType());
}
-
+
+ //System.out.println("resolved: " + getPointcut() + ", " + getPointcut().state);
+ makeResolvedPointcutDefinition();
+ resolvedPointcutDeclaration.setPointcut(getPointcut());
super.resolveStatements();
}
public ResolvedPointcutDefinition makeResolvedPointcutDefinition() {
- //System.out.println("pc: " + getPointcut());
- ResolvedPointcutDefinition ret = new ResolvedPointcutDefinition(
+ if (resolvedPointcutDeclaration != null) return resolvedPointcutDeclaration;
+ //System.out.println("pc: " + getPointcut() + ", " + getPointcut().state);
+ resolvedPointcutDeclaration = new ResolvedPointcutDefinition(
EclipseFactory.fromBinding(this.binding.declaringClass),
declaredModifiers,
declaredName,
EclipseFactory.fromBindings(this.binding.parameters),
- getPointcut());
+ getPointcut()); //??? might want to use null
- ret.setPosition(sourceStart, sourceEnd);
- ret.setSourceContext(new EclipseSourceContext(compilationResult));
- return ret;
+ resolvedPointcutDeclaration.setPosition(sourceStart, sourceEnd);
+ resolvedPointcutDeclaration.setSourceContext(new EclipseSourceContext(compilationResult));
+ return resolvedPointcutDeclaration;
}
import java.util.*;
import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
import org.aspectj.asm.*;
import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.internal.Relationship;
import org.aspectj.bridge.IMessage;
import org.aspectj.weaver.*;
import org.aspectj.weaver.patterns.*;
+import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
}
// need to build inter-type declarations for all AspectDeclarations at this point
- for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
- SourceTypeBinding[] b = units[i].scope.topLevelTypes;
- for (int j = 0; j < b.length; j++) {
- buildInterTypeAndPerClause(b[j].scope);
- }
- }
+ for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
+ SourceTypeBinding[] b = units[i].scope.topLevelTypes;
+ for (int j = 0; j < b.length; j++) {
+ buildInterTypeAndPerClause(b[j].scope);
+ }
+ }
+ for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
+ SourceTypeBinding[] b = units[i].scope.topLevelTypes;
+ for (int j = 0; j < b.length; j++) {
+ resolvePointcutDeclarations(b[j].scope);
+ }
+ }
+
+ for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
+ SourceTypeBinding[] b = units[i].scope.topLevelTypes;
+ for (int j = 0; j < b.length; j++) {
+ addCrosscuttingStructures(b[j].scope);
+ }
+ }
factory.finishTypeMungers();
// now do weaving
for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
weaveInterTypeDeclarations(units[i].scope, typeMungers, declareParents);
- units[i] = null; // release unnecessary reference to the parsed unit
+ units[i] = null; // release unnecessary reference to the parsed unit
}
-
+
stepCompleted = BUILD_FIELDS_AND_METHODS;
lastCompletedUnitIndex = lastUnitIndex;
}
pendingTypesToWeave.clear();
}
+ private void addCrosscuttingStructures(ClassScope s) {
+ TypeDeclaration dec = s.referenceContext;
+
+ if (dec instanceof AspectDeclaration) {
+ ResolvedTypeX typeX = factory.fromEclipse(dec.binding);
+ factory.getWorld().getCrosscuttingMembersSet().addOrReplaceAspect(typeX);
+
+ if (typeX.getSuperclass().isAspect() && !typeX.getSuperclass().isExposedToWeaver()) {
+ factory.getWorld().getCrosscuttingMembersSet().addOrReplaceAspect(typeX.getSuperclass());
+ }
+ }
+
+ SourceTypeBinding sourceType = s.referenceContext.binding;
+ ReferenceBinding[] memberTypes = sourceType.memberTypes;
+ for (int i = 0, length = memberTypes.length; i < length; i++) {
+ addCrosscuttingStructures(((SourceTypeBinding) memberTypes[i]).scope);
+ }
+ }
+
+ private void resolvePointcutDeclarations(ClassScope s) {
+ TypeDeclaration dec = s.referenceContext;
+ SourceTypeBinding sourceType = s.referenceContext.binding;
+
+ AbstractMethodDeclaration[] methods = dec.methods;
+ boolean initializedMethods = false;
+ if (methods != null) {
+ for (int i=0; i < methods.length; i++) {
+ if (methods[i] instanceof PointcutDeclaration) {
+ if (!initializedMethods) {
+ sourceType.methods(); //force initialization
+ initializedMethods = true;
+ }
+ ((PointcutDeclaration)methods[i]).resolvePointcut(s);
+ }
+ }
+ }
+
+ ReferenceBinding[] memberTypes = sourceType.memberTypes;
+ for (int i = 0, length = memberTypes.length; i < length; i++) {
+ resolvePointcutDeclarations(((SourceTypeBinding) memberTypes[i]).scope);
+ }
+ }
+
+
+
private void buildInterTypeAndPerClause(ClassScope s) {
TypeDeclaration dec = s.referenceContext;
<compile files="InterPerCall.java"/>
<run class="InterPerCall"/>
</ajc-test>
+
+ <ajc-test dir="bugs/declareBinding"
+ pr="42740"
+ title="declare error fails on pointcuts composed from multiple classes">
+ <compile files="SampleExceptionHandling1.java">
+ <message line="2" kind="error" text="no checked exceptions"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="bugs/declareSoftWithin"
+ pr="42740"
+ title="declare error fails on pointcuts composed from multiple classes">
+ <compile files="aspects/Softener.aj,test/NoSoftener.java"/>
+ <run class="test.NoSoftener"/>
+ </ajc-test>
</suite>
--- /dev/null
+public class SampleExceptionHandling1 {
+ public void mumble() throws java.io.IOException { } // CE expected
+}
+
+
+/** @author Ron Bodkin */
+aspect Library {
+ public pointcut executionsThrowingChecked() :
+ execution(* *(..) throws (Exception+ && !RuntimeException));
+}
+
+/** @author Ron Bodkin */
+aspect SampleExceptionHandling {
+ public pointcut scope() : within(SampleExceptionHandling1);
+
+ public pointcut executionsThrowingChecked() :
+ Library.executionsThrowingChecked() && scope();
+
+ declare error : executionsThrowingChecked():
+ "no checked exceptions";
+}
\ No newline at end of file
--- /dev/null
+package aspects;\r
+\r
+import test.NoSoftener;\r
+\r
+/**\r
+ * @author Ron Bodkin\r
+ * @author Jim Hugunin\r
+ */\r
+public aspect Softener extends SoftLib {\r
+ public pointcut scope() : within(NoSoftener);\r
+}\r
+\r
+abstract aspect SoftLib {\r
+ abstract pointcut scope();\r
+\r
+ public pointcut callsThrowingChecked() : call(* *(..)) && scope();\r
+ declare soft: NoSuchMethodException: callsThrowingChecked();\r
+}
\ No newline at end of file
--- /dev/null
+package test;
+import java.lang.reflect.Constructor;
+import org.aspectj.testing.Tester;
+
+/**
+ * @author Ron Bodkin
+ * @author Jim Hugunin
+ */
+public class NoSoftener {
+ public static void main(String[] args) {
+ Throwable wrapped = null;
+ try {
+ new NoSoftener().foo(Integer.class);
+ } catch (org.aspectj.lang.SoftException se) {
+ wrapped = se.getWrappedThrowable();
+ }
+ Tester.checkNonNull(wrapped, "exception thrown");
+ Tester.check(wrapped instanceof NoSuchMethodException,
+ "must be NoSuchMethodException");
+
+ }
+
+ public void foo(Class clazz) {
+ Class[] keyArgType = {};
+ Constructor ctor = clazz.getConstructor(keyArgType);
+ }
+}
\ No newline at end of file
new ResolvedPointcutDefinition(TypeX.OBJECT, 0, "missing",
TypeX.NONE, Pointcut.makeMatchesNothing(Pointcut.RESOLVED));
+ public void setPointcut(Pointcut pointcut) {
+ this.pointcut = pointcut;
+ }
+
}