summaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-06-03 09:46:09 +0000
committeravasseur <avasseur>2005-06-03 09:46:09 +0000
commit845da1dc8a6a8154330a63fe6da5710bfa3dfc83 (patch)
tree2c13811c52d3743af23a964bad662405a582d7d3 /org.aspectj.ajdt.core
parent06842bd47c5c56f4513fbc162856fea9267de7d2 (diff)
downloadaspectj-845da1dc8a6a8154330a63fe6da5710bfa3dfc83.tar.gz
aspectj-845da1dc8a6a8154330a63fe6da5710bfa3dfc83.zip
perClause inheritance in @AJ (in ajdt module), fixed FIXME AV
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java126
-rw-r--r--org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java6
2 files changed, 113 insertions, 19 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
index 2b9c61fbe..88b552b59 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
@@ -1,13 +1,14 @@
/* *******************************************************************
* Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Common Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * PARC initial implementation
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * PARC initial implementation
+ * Alexandre Vasseur support for @AJ perClause
* ******************************************************************/
@@ -22,10 +23,13 @@ import org.aspectj.bridge.IMessage;
import org.aspectj.weaver.*;
import org.aspectj.weaver.patterns.PerClause;
import org.aspectj.weaver.patterns.PerSingleton;
+import org.aspectj.weaver.patterns.PerFromSuper;
import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral;
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.*;
/**
@@ -35,6 +39,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.*;
*/
public class EclipseSourceType extends ResolvedTypeX.ConcreteName {
private static final char[] pointcutSig = "Lorg/aspectj/lang/annotation/Pointcut;".toCharArray();
+ private static final char[] aspectSig = "Lorg/aspectj/lang/annotation/Aspect;".toCharArray();
protected ResolvedPointcutDefinition[] declaredPointcuts = null;
protected ResolvedMember[] declaredMethods = null;
protected ResolvedMember[] declaredFields = null;
@@ -68,18 +73,19 @@ public class EclipseSourceType extends ResolvedTypeX.ConcreteName {
public boolean isAspect() {
- return declaration instanceof AspectDeclaration;
+ final boolean isCodeStyle = declaration instanceof AspectDeclaration;
+ return isCodeStyle?isCodeStyle:isAnnotationStyleAspect();
}
- // FIXME ATAJ isAnnotationStyleAspect() needs implementing?
public boolean isAnnotationStyleAspect() {
if (declaration.annotations == null) {
return false;
}
- for (int i = 0; i < declaration.annotations.length; i++) {
- Annotation annotation = declaration.annotations[i];
- // do something there
- ;
+ ResolvedTypeX[] annotations = getAnnotationTypes();
+ for (int i = 0; i < annotations.length; i++) {
+ if ("org.aspectj.lang.annotation.Aspect".equals(annotations[i].getName())) {
+ return true;
+ }
}
return false;
}
@@ -338,9 +344,97 @@ public class EclipseSourceType extends ResolvedTypeX.ConcreteName {
//should probably be: ((AspectDeclaration)declaration).perClause;
// but we don't need this level of detail, and working with real per clauses
// at this stage of compilation is not worth the trouble
- return new PerSingleton();
+ if (!isAnnotationStyleAspect()) {
+ return new PerSingleton();
+ } else {
+ // for @Aspect, we do need the real kind though we don't need the real perClause
+ PerClause.Kind kind = getPerClauseForTypeDeclaration(declaration);
+ //returning a perFromSuper is enough to get the correct kind.. (that's really a hack - AV)
+ return new PerFromSuper(kind);
+ }
}
-
+
+ PerClause.Kind getPerClauseForTypeDeclaration(TypeDeclaration typeDeclaration) {
+ Annotation[] annotations = typeDeclaration.annotations;
+ for (int i = 0; i < annotations.length; i++) {
+ Annotation annotation = annotations[i];
+ if (CharOperation.equals(aspectSig, annotation.resolvedType.signature())) {
+ // found @Aspect(...)
+ if (annotation.memberValuePairs() == null || annotation.memberValuePairs().length == 0) {
+ // it is an @Aspect or @Aspect()
+ // needs to use PerFromSuper if declaration extends a super aspect
+ PerClause.Kind kind = lookupPerClauseKind(typeDeclaration.binding.superclass);
+ // if no super aspect, we have a @Aspect() means singleton
+ if (kind == null) {
+ return PerClause.SINGLETON;
+ } else {
+ return kind;
+ }
+ } else if (annotation instanceof SingleMemberAnnotation) {
+ // it is an @Aspect(...something...)
+ SingleMemberAnnotation theAnnotation = (SingleMemberAnnotation)annotation;
+ String clause = new String(((StringLiteral)theAnnotation.memberValue).source());//TODO cast safe ?
+ if (clause.startsWith("perthis(")) {
+ return PerClause.PEROBJECT;
+ } else if (clause.startsWith("pertarget(")) {
+ return PerClause.PEROBJECT;
+ } else if (clause.startsWith("percflow(")) {
+ return PerClause.PERCFLOW;
+ } else if (clause.startsWith("percflowbelow(")) {
+ return PerClause.PERCFLOW;
+ } else if (clause.startsWith("pertypewithin(")) {
+ return PerClause.PERTYPEWITHIN;
+ } else if (clause.startsWith("issingleton(")) {
+ return PerClause.SINGLETON;
+ } else {
+ eclipseWorld().showMessage(IMessage.ABORT,
+ "cannot determine perClause '" + clause + "'",
+ new EclipseSourceLocation(typeDeclaration.compilationResult, typeDeclaration.sourceStart, typeDeclaration.sourceEnd), null);
+ return PerClause.SINGLETON;//fallback strategy just to avoid NPE
+ }
+ } else {
+ eclipseWorld().showMessage(IMessage.ABORT,
+ "@Aspect annotation is expected to be SingleMemberAnnotation with 'String value()' as unique element",
+ new EclipseSourceLocation(typeDeclaration.compilationResult, typeDeclaration.sourceStart, typeDeclaration.sourceEnd), null);
+ return PerClause.SINGLETON;//fallback strategy just to avoid NPE
+ }
+ }
+ }
+ return null;//no @Aspect annotation at all (not as aspect)
+ }
+
+ // adapted from AspectDeclaration
+ private PerClause.Kind lookupPerClauseKind(ReferenceBinding binding) {
+ final PerClause.Kind kind;
+ if (binding instanceof BinaryTypeBinding) {
+ ResolvedTypeX superTypeX = factory.fromEclipse(binding);
+ PerClause perClause = superTypeX.getPerClause();
+ // clause is null for non aspect classes since coming from BCEL attributes
+ if (perClause != null) {
+ kind = superTypeX.getPerClause().getKind();
+ } else {
+ kind = null;
+ }
+ } else if (binding instanceof SourceTypeBinding ) {
+ SourceTypeBinding sourceSc = (SourceTypeBinding)binding;
+ if (sourceSc.scope.referenceContext instanceof AspectDeclaration) {
+ //code style
+ kind = ((AspectDeclaration)sourceSc.scope.referenceContext).perClause.getKind();
+ } else if (sourceSc.scope.referenceContext instanceof TypeDeclaration) {
+ // if @Aspect: perFromSuper, else if @Aspect(..) get from anno value, else null
+ kind = getPerClauseForTypeDeclaration((TypeDeclaration)(sourceSc.scope.referenceContext));
+ } else {
+ //XXX should not happen
+ kind = null;
+ }
+ } else {
+ //XXX need to handle this too
+ kind = null;
+ }
+ return kind;
+ }
+
+
protected Collection getDeclares() {
return declares;
}
diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java
index 9e5f8cc2d..8f4d0dfb5 100644
--- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java
+++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java
@@ -46,11 +46,11 @@ public class Ajc {
private static final String TESTER_PATH =
".."+File.separator+"testing-client"+File.separator+"bin" + File.pathSeparator +
".."+File.separator+"runtime"+File.separator+"bin" + File.pathSeparator +
- //FIXME AV - can someone tell why those jar needs to be there ??
+ //TODO AV - done, remove comments: can someone tell why those jar needs to be there ??
// 1/ see the line before: bin/ will take precedence..
// 2/ see below - aspectj5rt is added last which makes it UNconsistent with the way runtime is handled here..
- ".."+File.separator+"lib"+File.separator+"test"+File.separator+"aspectjrt.jar"+ File.pathSeparator+
- ".."+File.separator+"lib"+File.separator+"test"+File.separator+"testing-client.jar" + File.pathSeparator +
+ //".."+File.separator+"lib"+File.separator+"test"+File.separator+"aspectjrt.jar"+ File.pathSeparator+
+ //".."+File.separator+"lib"+File.separator+"test"+File.separator+"testing-client.jar" + File.pathSeparator +
".."+File.separator+"aspectj5rt"+File.separator+"bin" + File.pathSeparator
+ File.pathSeparator+ ".."+File.separator+"lib"+File.separator+"junit"+File.separator+"junit.jar"
+ File.pathSeparator+ ".."+File.separator+"bridge"+File.separator+"bin"