import java.util.Collections;
import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
+import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
import org.aspectj.ajdt.internal.compiler.lookup.EclipseTypeMunger;
import org.aspectj.ajdt.internal.compiler.lookup.InterTypeScope;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
+import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.NewMemberClassTypeMunger;
import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.ResolvedTypeMunger;
/**
* Represents an intertype member class declaration.
// The target type for this inner class
private TypeReference onType;
private ReferenceBinding onTypeResolvedBinding;
+ private NewMemberClassTypeMunger newMemberClassTypeMunger;
protected InterTypeScope interTypeScope;
// When set to true, the scope hierarchy for the field/method declaration has been correctly modified to include an intertype
// scope which resolves things relative to the targeted type.
super(compilationResult);
}
+ public ResolvedTypeMunger getMunger() {
+ return newMemberClassTypeMunger;
+ }
+
@Override
public void resolve(ClassScope aspectScope) {
resolveOnType(aspectScope);
throw new IllegalStateException();
}
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void generateAttributes(ClassFile classFile) {
+ // classFile.extraAttributes.add(new EclipseAttributeAdapter(makeAttribute()));
+ super.generateAttributes(classFile);
+ }
+
+ public AjAttribute getAttribute() {
+ // if there were problems then there is nothing to return
+ if (newMemberClassTypeMunger == null) {
+ return null;
+ }
+ return new AjAttribute.TypeMunger(newMemberClassTypeMunger);
+ }
+
/**
* Called just before the compiler is going to start resolving elements of a declaration, this method adds an intertype scope so
* that elements of the type targeted by the ITD can be resolved. For example, if type variables are referred to in the ontype
// TODO [inner] use the interTypeScope.getRecoveryAliases
// TODO [inner] should mark it in the aspect as unreachable - it is not to be considered part of the aspect
- NewMemberClassTypeMunger newMemberClassTypeMunger = new NewMemberClassTypeMunger(declaringType, new String(this.name));
+ newMemberClassTypeMunger = new NewMemberClassTypeMunger(declaringType, new String(this.name));
+ newMemberClassTypeMunger.setSourceLocation(new EclipseSourceLocation(compilationResult, sourceStart, sourceEnd));
ResolvedType aspectType = world.fromEclipse(classScope.referenceContext.binding);
return new EclipseTypeMunger(world, newMemberClassTypeMunger, aspectType, null);
}
import org.aspectj.weaver.WeaverStateInfo;
import org.aspectj.weaver.World;
import org.aspectj.weaver.bcel.AtAjAttributes.LazyResolvedPointcutDefinition;
+import org.aspectj.weaver.patterns.Declare;
import org.aspectj.weaver.patterns.FormalBinding;
import org.aspectj.weaver.patterns.ParserException;
import org.aspectj.weaver.patterns.PatternParser;
protected ResolvedMember[] declaredMethods = null;
protected ResolvedMember[] declaredFields = null;
- public List declares = new ArrayList();
- public List typeMungers = new ArrayList();
+ public List<Declare> declares = new ArrayList<Declare>();
+ public List<EclipseTypeMunger> typeMungers = new ArrayList<EclipseTypeMunger>();
private final EclipseFactory factory;
}
public boolean isAnonymous() {
- if (declaration.binding != null)
+ if (declaration.binding != null) {
return declaration.binding.isAnonymousType();
+ }
return ((declaration.modifiers & (ASTNode.IsAnonymousType | ASTNode.IsLocalType)) != 0);
}
public boolean isNested() {
- if (declaration.binding != null)
+ if (declaration.binding != null) {
return (declaration.binding.isMemberType());
+ }
return ((declaration.modifiers & ASTNode.IsMemberType) != 0);
}
public ResolvedType getOuterClass() {
- if (declaration.enclosingType == null)
+ if (declaration.enclosingType == null) {
return null;
+ }
return eclipseWorld().fromEclipse(declaration.enclosingType.binding);
}
/** Returns "" if there is a problem */
private String getPointcutStringFromAnnotationStylePointcut(AbstractMethodDeclaration amd) {
Annotation[] ans = amd.annotations;
- if (ans == null)
+ if (ans == null) {
return "";
+ }
for (int i = 0; i < ans.length; i++) {
- if (ans[i].resolvedType == null)
+ if (ans[i].resolvedType == null) {
continue; // XXX happens if we do this very early from
+ }
// buildInterTypeandPerClause
// may prevent us from resolving references made in @Pointcuts to
// an @Pointcut in a code-style aspect
char[] sig = ans[i].resolvedType.signature();
if (CharOperation.equals(pointcutSig, sig)) {
- if (ans[i].memberValuePairs().length == 0)
+ if (ans[i].memberValuePairs().length == 0) {
return ""; // empty pointcut expression
+ }
Expression expr = ans[i].memberValuePairs()[0].value;
if (expr instanceof StringLiteral) {
StringLiteral sLit = ((StringLiteral) expr);
}
private boolean isAnnotationStylePointcut(Annotation[] annotations) {
- if (annotations == null)
+ if (annotations == null) {
return false;
+ }
for (int i = 0; i < annotations.length; i++) {
- if (annotations[i].resolvedType == null)
+ if (annotations[i].resolvedType == null) {
continue; // XXX happens if we do this very early from
+ }
// buildInterTypeandPerClause
// may prevent us from resolving references made in @Pointcuts to
// an @Pointcut in a code-style aspect
}
public ResolvedType getSuperclass() {
- if (binding.isInterface())
+ if (binding.isInterface()) {
return getResolvedTypeX().getWorld().getCoreType(UnresolvedType.OBJECT);
+ }
// XXX what about java.lang.Object
return eclipseWorld().fromEclipse(binding.superclass());
}
}
protected void fillDeclaredMembers() {
- List declaredPointcuts = new ArrayList();
- List declaredMethods = new ArrayList();
- List declaredFields = new ArrayList();
+ List<ResolvedMember> declaredPointcuts = new ArrayList<ResolvedMember>();
+ List<ResolvedMember> declaredMethods = new ArrayList<ResolvedMember>();
+ List<ResolvedMember> declaredFields = new ArrayList<ResolvedMember>();
binding.methods(); // the important side-effect of this call is to make
// sure bindings are completed
if (methods != null) {
for (int i = 0, len = methods.length; i < len; i++) {
AbstractMethodDeclaration amd = methods[i];
- if (amd == null || amd.ignoreFurtherInvestigation)
+ if (amd == null || amd.ignoreFurtherInvestigation) {
continue;
+ }
if (amd instanceof PointcutDeclaration) {
PointcutDeclaration d = (PointcutDeclaration) amd;
ResolvedPointcutDefinition df = d.makeResolvedPointcutDefinition(factory);
- if (df!=null) {
+ if (df != null) {
declaredPointcuts.add(df);
}
} else if (amd instanceof InterTypeDeclaration) {
} else if ((amd.annotations != null) && isAnnotationStylePointcut(amd.annotations)) {
// consider pointcuts defined via annotations
ResolvedPointcutDefinition df = makeResolvedPointcutDefinition(amd);
- if (df != null)
+ if (df != null) {
declaredPointcuts.add(df);
+ }
} else {
- if (amd.binding == null || !amd.binding.isValidBinding())
+ if (amd.binding == null || !amd.binding.isValidBinding()) {
continue;
+ }
ResolvedMember member = factory.makeResolvedMember(amd.binding);
if (unit != null) {
boolean positionKnown = true;
if (amd.binding.sourceMethod() == null) {
if (amd.binding.declaringClass instanceof SourceTypeBinding) {
SourceTypeBinding stb = ((SourceTypeBinding) amd.binding.declaringClass);
- if (stb.scope == null || stb.scope.referenceContext == null)
+ if (stb.scope == null || stb.scope.referenceContext == null) {
positionKnown = false;
+ }
}
}
if (positionKnown) { // pr229829
declaredFields.add(factory.makeResolvedMember(f));
}
- this.declaredPointcuts = (ResolvedPointcutDefinition[]) declaredPointcuts
- .toArray(new ResolvedPointcutDefinition[declaredPointcuts.size()]);
- this.declaredMethods = (ResolvedMember[]) declaredMethods.toArray(new ResolvedMember[declaredMethods.size()]);
- this.declaredFields = (ResolvedMember[]) declaredFields.toArray(new ResolvedMember[declaredFields.size()]);
+ this.declaredPointcuts = declaredPointcuts.toArray(new ResolvedPointcutDefinition[declaredPointcuts.size()]);
+ this.declaredMethods = declaredMethods.toArray(new ResolvedMember[declaredMethods.size()]);
+ this.declaredFields = declaredFields.toArray(new ResolvedMember[declaredFields.size()]);
}
private ResolvedPointcutDefinition makeResolvedPointcutDefinition(AbstractMethodDeclaration md) {
- if (md.binding == null)
+ if (md.binding == null) {
return null; // there is another error that has caused this...
- // pr138143
+ // pr138143
+ }
EclipseSourceContext eSourceContext = new EclipseSourceContext(md.compilationResult);
Pointcut pc = null;
private static final char[] proceedingJoinPoint = "Lorg/aspectj/lang/ProceedingJoinPoint;".toCharArray();
private FormalBinding[] buildFormalAdviceBindingsFrom(AbstractMethodDeclaration mDecl) {
- if (mDecl.arguments == null)
+ if (mDecl.arguments == null) {
return new FormalBinding[0];
- if (mDecl.binding == null)
+ }
+ if (mDecl.binding == null) {
return new FormalBinding[0];
+ }
EclipseFactory factory = EclipseFactory.fromScopeLookupEnvironment(mDecl.scope);
String extraArgName = "";// maybeGetExtraArgName();
FormalBinding[] ret = new FormalBinding[mDecl.arguments.length];
* fields - see bug 129613
*/
public ResolvedMember[] getDeclaredFields() {
- if (declaredFields == null)
+ if (declaredFields == null) {
fillDeclaredMembers();
+ }
return declaredFields;
}
* - see bug 129613
*/
public ResolvedMember[] getDeclaredMethods() {
- if (declaredMethods == null)
+ if (declaredMethods == null) {
fillDeclaredMembers();
+ }
return declaredMethods;
}
public ResolvedMember[] getDeclaredPointcuts() {
- if (declaredPointcuts == null)
+ if (declaredPointcuts == null) {
fillDeclaredMembers();
+ }
return declaredPointcuts;
}
// now check all inherited pointcuts to be sure that they're handled
// reasonably
- if (sawError || !isAspect())
+ if (sawError || !isAspect()) {
return;
+ }
// find all pointcuts that override ones from super and check override
// is legal
public String getRetentionPolicy() {
if (isAnnotation()) {
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationRetentionMASK) == TagBits.AnnotationRuntimeRetention)
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationRetentionMASK) == TagBits.AnnotationRuntimeRetention) {
return "RUNTIME";
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationRetentionMASK) == TagBits.AnnotationSourceRetention)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationRetentionMASK) == TagBits.AnnotationSourceRetention) {
return "SOURCE";
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationRetentionMASK) == TagBits.AnnotationClassRetention)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationRetentionMASK) == TagBits.AnnotationClassRetention) {
return "CLASS";
+ }
}
return null;
}
}
public AnnotationTargetKind[] getAnnotationTargetKinds() {
- if (discoveredAnnotationTargetKinds)
+ if (discoveredAnnotationTargetKinds) {
return annotationTargetKinds;
+ }
discoveredAnnotationTargetKinds = true;
annotationTargetKinds = null; // null means we have no idea or the
// @Target annotation hasn't been used
// }
// return targetKind;
if (isAnnotation()) {
- List targetKinds = new ArrayList();
+ List<AnnotationTargetKind> targetKinds = new ArrayList<AnnotationTargetKind>();
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationForAnnotationType) != 0)
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationForAnnotationType) != 0) {
targetKinds.add(AnnotationTargetKind.ANNOTATION_TYPE);
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationForConstructor) != 0)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationForConstructor) != 0) {
targetKinds.add(AnnotationTargetKind.CONSTRUCTOR);
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationForField) != 0)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationForField) != 0) {
targetKinds.add(AnnotationTargetKind.FIELD);
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationForLocalVariable) != 0)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationForLocalVariable) != 0) {
targetKinds.add(AnnotationTargetKind.LOCAL_VARIABLE);
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationForMethod) != 0)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationForMethod) != 0) {
targetKinds.add(AnnotationTargetKind.METHOD);
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationForPackage) != 0)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationForPackage) != 0) {
targetKinds.add(AnnotationTargetKind.PACKAGE);
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationForParameter) != 0)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationForParameter) != 0) {
targetKinds.add(AnnotationTargetKind.PARAMETER);
- if ((binding.getAnnotationTagBits() & TagBits.AnnotationForType) != 0)
+ }
+ if ((binding.getAnnotationTagBits() & TagBits.AnnotationForType) != 0) {
targetKinds.add(AnnotationTargetKind.TYPE);
+ }
if (!targetKinds.isEmpty()) {
annotationTargetKinds = new AnnotationTargetKind[targetKinds.size()];
- return (AnnotationTargetKind[]) targetKinds.toArray(annotationTargetKinds);
+ return targetKinds.toArray(annotationTargetKinds);
}
}
return annotationTargetKinds;
annotationsResolved = true;
}
Annotation[] as = declaration.annotations;
- if (as == null)
+ if (as == null) {
return false;
+ }
for (int i = 0; i < as.length; i++) {
Annotation annotation = as[i];
if (annotation.resolvedType == null) {
* (RetentionPolicy, Target).
*/
public AnnotationAJ[] getAnnotations() {
- if (annotations != null)
+ if (annotations != null) {
return annotations; // only do this once
+ }
getAnnotationTypes(); // forces resolution and sets resolvedAnnotations
Annotation[] as = declaration.annotations;
if (as == null || as.length == 0) {
// ---------------------------------
public ResolvedType[] getAnnotationTypes() {
- if (resolvedAnnotations != null)
+ if (resolvedAnnotations != null) {
return resolvedAnnotations;
+ }
// Make sure they are resolved
if (!annotationsResolved) {
TypeDeclaration.resolveAnnotations(declaration.staticInitializerScope, declaration.annotations, binding);
if (!isAnnotationStyleAspect()) {
if (declaration instanceof AspectDeclaration) {
PerClause pc = ((AspectDeclaration) declaration).perClause;
- if (pc != null)
+ if (pc != null) {
return pc;
+ }
}
return new PerSingleton();
} else {
// real perClause
// at least try to get the right perclause
PerClause pc = null;
- if (declaration instanceof AspectDeclaration)
+ if (declaration instanceof AspectDeclaration) {
pc = ((AspectDeclaration) declaration).perClause;
+ }
if (pc == null) {
PerClause.Kind kind = getPerClauseForTypeDeclaration(declaration);
// returning a perFromSuper is enough to get the correct kind..
// !
// it is an @Aspect(...something...)
NormalAnnotation theAnnotation = (NormalAnnotation) annotation;
- if (theAnnotation.memberValuePairs == null || theAnnotation.memberValuePairs.length < 1)
+ if (theAnnotation.memberValuePairs == null || theAnnotation.memberValuePairs.length < 1) {
return PerClause.SINGLETON;
+ }
String clause = new String(((StringLiteral) theAnnotation.memberValuePairs[0].value).source());// TODO
// cast
// safe
}
public TypeVariable[] getTypeVariables() {
- if (declaration.typeParameters == null)
+ if (declaration.typeParameters == null) {
return new TypeVariable[0];
+ }
TypeVariable[] typeVariables = new TypeVariable[declaration.typeParameters.length];
for (int i = 0; i < typeVariables.length; i++) {
typeVariables[i] = typeParameter2TypeVariable(declaration.typeParameters[i]);
return typeVariables;
}
- private TypeVariable typeParameter2TypeVariable(TypeParameter aTypeParameter) {
- String name = new String(aTypeParameter.name);
- ReferenceBinding superclassBinding = aTypeParameter.binding.superclass;
+ private TypeVariable typeParameter2TypeVariable(TypeParameter typeParameter) {
+ String name = new String(typeParameter.name);
+ ReferenceBinding superclassBinding = typeParameter.binding.superclass;
UnresolvedType superclass = UnresolvedType.forSignature(new String(superclassBinding.signature()));
UnresolvedType[] superinterfaces = null;
- ReferenceBinding[] superInterfaceBindings = aTypeParameter.binding.superInterfaces;
+ ReferenceBinding[] superInterfaceBindings = typeParameter.binding.superInterfaces;
if (superInterfaceBindings != null) {
superinterfaces = new UnresolvedType[superInterfaceBindings.length];
for (int i = 0; i < superInterfaceBindings.length; i++) {
}
// XXX what about lower binding?
TypeVariable tv = new TypeVariable(name, superclass, superinterfaces);
- tv.setDeclaringElement(factory.fromBinding(aTypeParameter.binding.declaringElement));
- tv.setRank(aTypeParameter.binding.rank);
+ tv.setDeclaringElement(factory.fromBinding(typeParameter.binding.declaringElement));
+ tv.setRank(typeParameter.binding.rank);
return tv;
}