}
}
}
-// Class<?>[] classes = clazz.getDeclaredClasses();
-// for(Class<?> c : classes) {
-// if (c.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
-// if (c.getInterfaces().length == 0) continue;
-// AjType<?> targetType = AjTypeSystem.getAjType((Class<?>)c.getInterfaces()[0]);
-// Method[] meths = c.getDeclaredMethods();
-// for (Method m : meths) {
-// if (!Modifier.isPublic(m.getModifiers()) && publicOnly) continue;
-// InterTypeMethodDeclaration itdm =
-// new InterTypeMethodDeclarationImpl(
-// this,targetType,m);
-// toList.add(itdm);
-// }
-// }
-// }
}
}
return;
//AV: I think it is meaningless
//@AJ decp is interface driven ie no field
-// if (isAspect()) {
-// for (Field f : clazz.getDeclaredFields()) {
-// if (!f.getType().isInterface()) continue;
-// if (!Modifier.isPublic(f.getModifiers()) || !Modifier.isStatic(f.getModifiers())) continue;
-// if (f.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
-// for (Field itdF : f.getType().getDeclaredFields()) {
-// if (!Modifier.isPublic(itdF.getModifiers()) && publicOnly) continue;
-// InterTypeFieldDeclaration itdf = new InterTypeFieldDeclarationImpl(
-// this, AjTypeSystem.getAjType(f.getType()), itdF
-// );
-// toList.add(itdf);
-// }
-// }
-// }
-//---old impl.
-// Class<?>[] classes = clazz.getDeclaredClasses();
-// for(Class<?> c : classes) {
-// if (c.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
-// if (c.getInterfaces().length == 0) continue;
-// AjType<?> targetType = AjTypeSystem.getAjType((Class<?>)c.getInterfaces()[0]);
-// Field[] fields = c.getDeclaredFields();
-// for (Field f : fields) {
-// if (!Modifier.isPublic(f.getModifiers()) && publicOnly) continue;
-// InterTypeFieldDeclaration itdf =
-// new InterTypeFieldDeclarationImpl(
-// this,targetType,f);
-// toList.add(itdf);
-// }
-// }
-// }
-// }
}
+
/* (non-Javadoc)
* @see org.aspectj.lang.reflect.AjType#getDeclaredITDConstructor(java.lang.Class, java.lang.Class...)
*/
toList.add(decp);
}
}
-//
-// Class<?>[] classes = clazz.getDeclaredClasses();
-// for (Class<?> c : classes) {
-// if (c.isAnnotationPresent(org.aspectj.lang.annotation.DeclareParents.class)) {
-// org.aspectj.lang.annotation.DeclareParents ann = c.getAnnotation(org.aspectj.lang.annotation.DeclareParents.class);
-// if (c.getInterfaces().length == 0) continue;
-// String parentType = c.getInterfaces()[0].getName();
-// DeclareParentsImpl decp = new DeclareParentsImpl(
-// ann.value(),
-// parentType,
-// false,
-// this
-// );
-// toList.add(decp);
-// }
-// }
}
/* (non-Javadoc)
import java.util.Set;
import java.util.Iterator;
+/**
+ * Type munger for @AspectJ ITD declare parents ie with an interface AND an implementation.
+ * Given the aspect that has a field public static Interface fieldI = ... // impl.
+ * we will weave in the Interface' methods and delegate to the aspect public static field fieldI
+ *
+ * Note: this munger DOES NOT handles the interface addition to the target classes - a regular Parent kinded munger
+ * must be added in coordination.
+ */
public class MethodDelegateTypeMunger extends ResolvedTypeMunger {
+ /**
+ * The field in the aspect that hosts the mixin instance
+ */
private final ResolvedMember aspectFieldDelegate;
+ /**
+ * Type pattern this munger applies to
+ */
private final TypePattern typePattern;
+ /**
+ * Construct a new type munger for @AspectJ ITD
+ *
+ * @param signature
+ * @param aspect
+ * @param fieldName
+ * @param typePattern
+ */
public MethodDelegateTypeMunger(ResolvedMember signature, ResolvedType aspect, String fieldName, TypePattern typePattern) {
super(MethodDelegate, signature);
this.typePattern = typePattern;
return aspectFieldDelegate;
}
-// public ResolvedMember getInterMethodBody(UnresolvedType aspectType) {
-// return AjcMemberMaker.interMethodBody(signature, aspectType);
-// }
-//
-// public ResolvedMember getInterMethodDispatcher(UnresolvedType aspectType) {
-// return AjcMemberMaker.interMethodDispatcher(signature, aspectType);
-// }
-
public void write(DataOutputStream s) throws IOException {
;//FIXME AVITD needed as changes public signature throw new RuntimeException("unimplemented");
}
// ResolvedTypeMunger munger = new MethodDelegateTypeMunger(rmi, superMethodsCalled);
// if (sLoc != null) munger.setSourceLocation(sLoc);
// return munger;
-// }
-//
-// public ResolvedMember getMatchingSyntheticMember(Member member, ResolvedType aspectType) {
-// ResolvedMember ret = AjcMemberMaker.interMethodDispatcher(getSignature(), aspectType);
-// if (ResolvedType.matches(ret, member)) return getSignature();
-// return super.getMatchingSyntheticMember(member, aspectType);
// }
+ /**
+ * Match based on given type pattern, only classes can be matched
+ *
+ * @param matchType
+ * @param aspectType
+ * @return true if match
+ */
public boolean matches(ResolvedType matchType, ResolvedType aspectType) {
// match only on class
if (matchType.isEnum() || matchType.isInterface() || matchType.isAnnotation()) {
return typePattern.matchesStatically(matchType);
}
+ /**
+ * Needed for reweavable
+ *
+ * @return true
+ */
public boolean changesPublicSignature() {
return true;
}
* @return list of AjAttributes, always empty for now
*/
public static List readAj5FieldAttributes(Field field, BcelField bField, ResolvedType type, ISourceContext context, IMessageHandler msgHandler) {
- //TODO use ? if (field.getName().startsWith(NameMangler.PREFIX)) return Collections.EMPTY_LIST; // already dealt with by ajc...
-//
-// // bypass primitive type fields - useless for @DeclareParents/Implements (interface)
-// if (bField.getType().isPrimitiveType()) return Collections.EMPTY_LIST;
-//
-// AjAttributeFieldStruct struct = new AjAttributeFieldStruct(field, bField, type, context, msgHandler);
-// Attribute[] attributes = field.getAttributes();
-//
-// boolean hasAtAspectJAnnotation = false;
-// for (int i = 0; i < attributes.length; i++) {
-// Attribute attribute = attributes[i];
-// try {
-// if (acceptAttribute(attribute)) {
-// RuntimeAnnotations rvs = (RuntimeAnnotations) attribute;
-// hasAtAspectJAnnotation = hasAtAspectJAnnotation || handleDeclareImplementsAnnotation(
-// rvs, struct//, preResolvedPointcut//FIXME add in src layer
-// );
-// }
-// } catch (Exception e) {
-//
-// }
-// }
-//
- return Collections.EMPTY_LIST;//struct.ajAttributes;
+ // Note: field annotation are for ITD and DEOW - processed at class level directly
+ return Collections.EMPTY_LIST;
}
/**
boolean satisfiedByITD = false;
for (Iterator ii = newParentTarget.getType().getInterTypeMungersIncludingSupers().iterator(); ii.hasNext(); ) {
ConcreteTypeMunger m = (ConcreteTypeMunger)ii.next();
- if (m.getMunger().getKind() == ResolvedTypeMunger.Method) {//FIXME AVITD was instanceof
+ if (m.getMunger().getKind() == ResolvedTypeMunger.Method) {
ResolvedMember sig = m.getSignature();
if (!Modifier.isAbstract(sig.getModifiers())) {
if (ResolvedType
}
}
} else if (m.getMunger().getKind() == ResolvedTypeMunger.MethodDelegate) {
- satisfiedByITD = true;//FIXME AVITD that should be enough, no need to check more
+ satisfiedByITD = true;//AV - that should be enough, no need to check more
}
}
if (!satisfiedByITD) {
return true;
}
return false;
-// else if (onInterface && !Modifier.isAbstract(unMangledInterMethod.getModifiers())) {
-//
-// // This means the 'gen' should be the top most implementor
-// // - if it is *not* then something went wrong after we worked
-// // out that it was the top most implementor (see pr49657)
-// if (!gen.getType().isTopmostImplementor(onType)) {
-// ResolvedType rtx = gen.getType().getTopmostImplementor(onType);
-// if (!rtx.isExposedToWeaver()) {
-// ISourceLocation sLoc = munger.getSourceLocation();
-// weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(
-// WeaverMessages.format(WeaverMessages.ITD_NON_EXPOSED_IMPLEMENTOR,rtx,getAspectType().getName()),
-// (sLoc==null?getAspectType().getSourceLocation():sLoc)));
-// } else {
-// // XXX what does this state mean?
-// // We have incorrectly identified what is the top most implementor and its not because
-// // a type wasn't exposed to the weaver
-// }
-// return false;
-// } else {
-//
-// ResolvedMember mangledInterMethod =
-// AjcMemberMaker.interMethod(unMangledInterMethod, aspectType, false);
-//
-// LazyMethodGen mg = makeMethodGen(gen, mangledInterMethod);
-// if (mungingInterface) {
-// // we want the modifiers of the ITD to be used for all *implementors* of the
-// // interface, but the method itself we add to the interface must be public abstract
-// mg.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT);
-// }
-//
-// Type[] paramTypes = BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes());
-// Type returnType = BcelWorld.makeBcelType(mangledInterMethod.getReturnType());
-//
-// InstructionList body = mg.getBody();
-// InstructionFactory fact = gen.getFactory();
-// int pos = 0;
-//
-// if (!mangledInterMethod.isStatic()) {
-// body.append(InstructionFactory.createThis());
-// pos++;
-// }
-// for (int i = 0, len = paramTypes.length; i < len; i++) {
-// Type paramType = paramTypes[i];
-// body.append(InstructionFactory.createLoad(paramType, pos));
-// pos+=paramType.getSize();
-// }
-// body.append(Utility.createInvoke(fact, weaver.getWorld(), interMethodBody));
-// body.append(InstructionFactory.createReturn(returnType));
-// mg.definingType = onType;
-//
-// weaver.addOrReplaceLazyMethodGen(mg);
-//
-// addNeededSuperCallMethods(weaver, onType, munger.getSuperMethodsCalled());
-//
-// return true;
-// }
-// } else {
-// return false;
-// }
}
private ResolvedMember getRealMemberForITDFromAspect(ResolvedType aspectType,ResolvedMember lookingFor,boolean isCtorRelated) {