From 5526c123cdb6a8a92f0f5b0af66e7e65d13988ef Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 26 Jul 2006 15:23:57 +0000 Subject: [PATCH] pipeline changes: new kind of ResolvedMember for Eclipsey members --- .../lookup/EclipseResolvedMember.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java 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 new file mode 100644 index 000000000..38dca6826 --- /dev/null +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java @@ -0,0 +1,78 @@ +/* ******************************************************************* + * Copyright (c) 2006 Contributors + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + * ******************************************************************/ +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.TypeDeclaration; +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; + +/** + * In the pipeline world, we can be weaving before all types have come through from compilation. + * In some cases this means the weaver will want to ask questions of eclipse types and this + * subtype of ResolvedMemberImpl is here to answer some of those questions - it is backed by + * the real eclipse MethodBinding object and can translate from Eclipse -> Weaver information. + */ +public class EclipseResolvedMember extends ResolvedMemberImpl { + + private static String[] NO_ARGS = new String[]{}; + + private MethodBinding realBinding; + private String[] argumentNames; + + 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; + } + + 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 + if (annos==null) return null; + 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(); + } + + + public String[] getParameterNames() { + if (argumentNames!=null) return argumentNames; + TypeDeclaration typeDecl = ((SourceTypeBinding)realBinding.declaringClass).scope.referenceContext; + AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(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; + } else { + argumentNames = new String[args.length]; + for (int i = 0; i < argumentNames.length; i++) { + argumentNames[i] = new String(methodDecl.arguments[i].name); + } + } + return argumentNames; + } + +} -- 2.39.5