summaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core
diff options
context:
space:
mode:
authoraclement <aclement>2006-09-14 14:54:19 +0000
committeraclement <aclement>2006-09-14 14:54:19 +0000
commit9a4f0495f37f6637578724c4e5aed87f9fcb4674 (patch)
tree855c362f03500c0ce83d7eda092ac3e8735ad42f /org.aspectj.ajdt.core
parentc4eb5d590ba2578692bc8408e3f4880e71d737b6 (diff)
downloadaspectj-9a4f0495f37f6637578724c4e5aed87f9fcb4674.tar.gz
aspectj-9a4f0495f37f6637578724c4e5aed87f9fcb4674.zip
Fix for 157057: expanded EclipseResolvedMember to work for fields as well as methods and finished off a little more of its implementation relating to annotations. I have put an exception guard in for something that has been missing implementation for a while - so that may trigger when this build gets out into the wild...
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java15
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java80
2 files changed, 75 insertions, 20 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
index f9ca2c98a..69f13ce99 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
@@ -551,13 +551,14 @@ public class EclipseFactory {
// AMC these next two lines shouldn't be needed once we sort out generic types properly in the world map
ResolvedType realDeclaringType = world.resolve(fromBinding(receiverType));
if (realDeclaringType.isRawType()) realDeclaringType = realDeclaringType.getGenericType();
- return new ResolvedMemberImpl(
- Member.FIELD,
- realDeclaringType,
- binding.modifiers,
- world.resolve(fromBinding(binding.type)),
- new String(binding.name),
- UnresolvedType.NONE);
+ ResolvedMemberImpl ret = new EclipseResolvedMember(binding,
+ Member.FIELD,
+ realDeclaringType,
+ binding.modifiers,
+ world.resolve(fromBinding(binding.type)),
+ new String(binding.name),
+ UnresolvedType.NONE);
+ return ret;
}
public TypeBinding makeTypeBinding(UnresolvedType typeX) {
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java
index 38dca6826..7ea58fa42 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java
@@ -14,13 +14,17 @@ package org.aspectj.ajdt.internal.compiler.lookup;
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.Argument;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.Binding;
+import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
import org.aspectj.weaver.AnnotationX;
import org.aspectj.weaver.ResolvedMemberImpl;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
+import org.aspectj.weaver.World;
/**
* In the pipeline world, we can be weaving before all types have come through from compilation.
@@ -32,37 +36,66 @@ public class EclipseResolvedMember extends ResolvedMemberImpl {
private static String[] NO_ARGS = new String[]{};
- private MethodBinding realBinding;
+ private Binding realBinding;
private String[] argumentNames;
+ private World w;
+ private ResolvedType[] cachedAnnotationTypes;
public EclipseResolvedMember(MethodBinding binding, Kind memberKind, ResolvedType realDeclaringType, int modifiers, UnresolvedType type, String string, UnresolvedType[] types, UnresolvedType[] types2) {
super(memberKind,realDeclaringType,modifiers,type,string,types,types2);
this.realBinding = binding;
+ this.w = realDeclaringType.getWorld();
+ }
+
+ public EclipseResolvedMember(FieldBinding binding, Kind field, ResolvedType realDeclaringType, int modifiers, ResolvedType type, String string, UnresolvedType[] none) {
+ super(field,realDeclaringType,modifiers,type,string,none);
+ this.realBinding = binding;
+ this.w = realDeclaringType.getWorld();
+ }
+
+
+ public boolean hasAnnotation(UnresolvedType ofType) {
+ ResolvedType[] annotationTypes = getAnnotationTypes();
+ if (annotationTypes==null) return false;
+ for (int i = 0; i < annotationTypes.length; i++) {
+ ResolvedType type = annotationTypes[i];
+ if (type.equals(ofType)) return true;
+ }
+ return false;
}
public AnnotationX[] getAnnotations() {
long abits = realBinding.getAnnotationTagBits(); // ensure resolved
- TypeDeclaration typeDecl = ((SourceTypeBinding)realBinding.declaringClass).scope.referenceContext;
- AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(realBinding);
- Annotation[] annos = methodDecl.annotations; // this is what to add
+ Annotation[] annos = getEclipseAnnotations();
if (annos==null) return null;
- return super.getAnnotations();
+ // TODO errr missing in action - we need to implement this! Probably using something like EclipseAnnotationConvertor - itself not finished ;)
+ throw new RuntimeException("not yet implemented - please raise an AJ bug");
+// return super.getAnnotations();
}
public ResolvedType[] getAnnotationTypes() {
- long abits = realBinding.getAnnotationTagBits(); // ensure resolved
- TypeDeclaration typeDecl = ((SourceTypeBinding)realBinding.declaringClass).scope.referenceContext;
- AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(realBinding);
- Annotation[] annos = methodDecl.annotations; // this is what to add
- if (annos==null) return null;
- return super.getAnnotationTypes();
+ if (cachedAnnotationTypes == null) {
+ long abits = realBinding.getAnnotationTagBits(); // ensure resolved
+ Annotation[] annos = getEclipseAnnotations();
+ if (annos==null) {
+ cachedAnnotationTypes = ResolvedType.EMPTY_RESOLVED_TYPE_ARRAY;
+ } else {
+ cachedAnnotationTypes = new ResolvedType[annos.length];
+ for (int i = 0; i < annos.length; i++) {
+ Annotation type = annos[i];
+ cachedAnnotationTypes[i] = w.resolve(UnresolvedType.forSignature(new String(type.resolvedType.signature())));
+ }
+ }
+ }
+ return cachedAnnotationTypes;
}
+
public String[] getParameterNames() {
if (argumentNames!=null) return argumentNames;
- TypeDeclaration typeDecl = ((SourceTypeBinding)realBinding.declaringClass).scope.referenceContext;
- AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(realBinding);
+ TypeDeclaration typeDecl = getTypeDeclaration();
+ AbstractMethodDeclaration methodDecl = typeDecl.declarationOf((MethodBinding)realBinding);
Argument[] args = (methodDecl==null?null:methodDecl.arguments); // dont like this - why isnt the method found sometimes? is it because other errors are being reported?
if (args==null) {
argumentNames=NO_ARGS;
@@ -75,4 +108,25 @@ public class EclipseResolvedMember extends ResolvedMemberImpl {
return argumentNames;
}
+ private Annotation[] getEclipseAnnotations() {
+ if (realBinding instanceof MethodBinding) {
+ AbstractMethodDeclaration methodDecl = getTypeDeclaration().declarationOf((MethodBinding)realBinding);
+ return methodDecl.annotations;
+ } else if (realBinding instanceof FieldBinding) {
+ FieldDeclaration fieldDecl = getTypeDeclaration().declarationOf((FieldBinding)realBinding);
+ return fieldDecl.annotations;
+ }
+ return null;
+ }
+
+ private TypeDeclaration getTypeDeclaration() {
+ if (realBinding instanceof MethodBinding) {
+ return ((SourceTypeBinding)((MethodBinding)realBinding).declaringClass).scope.referenceContext;
+
+ } else if (realBinding instanceof FieldBinding) {
+ return ((SourceTypeBinding)((FieldBinding)realBinding).declaringClass).scope.referenceContext;
+ }
+ return null;
+ }
+
}