* This field goes on top-most implementers of the interface the field is declared onto
*/
public static ResolvedMember interFieldInterfaceField(ResolvedMember field, UnresolvedType onClass, UnresolvedType aspectType) {
-// return new ResolvedMemberImpl(Member.FIELD, onClass, makePublicNonFinal(field.getModifiers()), field.getReturnType(),
-// NameMangler.interFieldInterfaceField(aspectType, field.getDeclaringType(), field.getName()), UnresolvedType.NONE,
-// UnresolvedType.NONE);
-
- // TODO what about non public fields, can you have those?
- return interFieldClassField(field,aspectType,true);
+ return new ResolvedMemberImpl(Member.FIELD, onClass, makePublicNonFinal(field.getModifiers()), field.getReturnType(),
+ NameMangler.interFieldInterfaceField(aspectType, field.getDeclaringType(), field.getName()), UnresolvedType.NONE,
+ UnresolvedType.NONE);
}
/**
return false;
}
- if (m1.getKind() == Member.FIELD && m1.getDeclaringType().equals(m2.getDeclaringType())) {
- return true ;
+ if (m1.getKind() == Member.FIELD) {
+ return m1.getDeclaringType().equals(m2.getDeclaringType());
} else if (m1.getKind() == Member.POINTCUT) {
return true;
}
}
}
- boolean needsAdding = true;
- boolean needsToBeAddedEarlier = false;
// now compare to existingMungers
for (Iterator<ConcreteTypeMunger> i = interTypeMungers.iterator(); i.hasNext();) {
ConcreteTypeMunger existingMunger = i.next();
if (conflictingSignature(existingMunger.getSignature(), munger.getSignature())) {
- // System.err.println("match " + munger + " with " + existingMunger);
+ // System.err.println("match " + munger + " with " +
+ // existingMunger);
if (isVisible(munger.getSignature().getModifiers(), munger.getAspectType(), existingMunger.getAspectType())) {
// System.err.println(" is visible");
int c = compareMemberPrecedence(sig, existingMunger.getSignature());
if (c < 0) {
// the existing munger dominates the new munger
checkLegalOverride(munger.getSignature(), existingMunger.getSignature(), 0x11, null);
- needsAdding = false;
-// return;
- if (munger.getSignature().getKind()==Member.FIELD &&
- munger.getSignature().getDeclaringType().resolve(world).isInterface()) {
- needsAdding=true;
- }
- break;
+ return;
} else if (c > 0) {
// the new munger dominates the existing one
checkLegalOverride(existingMunger.getSignature(), munger.getSignature(), 0x11, null);
- if (munger.getSignature().getKind()==Member.FIELD &&
- munger.getSignature().getDeclaringType().resolve(world).isInterface()) {
- needsToBeAddedEarlier = true;
- } else {
- i.remove();
- }
+ i.remove();
break;
} else {
interTypeConflictError(munger, existingMunger);
// we are adding the parameterized form of the ITD to the list of
// mungers. Within it, the munger knows the original declared
// signature for the ITD so it can be retrieved.
- if (needsAdding) {
- if (!needsToBeAddedEarlier) {
- interTypeMungers.add(munger);
- } else {
- interTypeMungers.add(0,munger);
- }
- }
+ interTypeMungers.add(munger);
}
/**
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.Field;
import org.aspectj.apache.bcel.classfile.Signature;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.generic.FieldGen;
LazyMethodGen mg1 = makeMethodGen(gen, AjcMemberMaker.interFieldInterfaceSetter(field, onType, aspectType));
gen.addMethodGen(mg1);
} else {
- if (gen.fieldExists(field.getName())) return false;
-
weaver.addInitializer(this);
ResolvedMember newField = AjcMemberMaker.interFieldClassField(field, aspectType,
munger.version == NewFieldTypeMunger.VersionTwo);
}
return true;
} else if (onInterface && gen.getType().isTopmostImplementor(onType)) {
- // we know that we can't be static since we don't allow statics on interfaces
+ // wew know that we can't be static since we don't allow statics on
+ // interfaces
if (Modifier.isStatic(field.getModifiers())) {
throw new RuntimeException("unimplemented");
}
-
-
+ weaver.addInitializer(this);
+ // System.err.println("impl body on " + gen.getType() + " for " +
+ // munger);
+
Type fieldType = BcelWorld.makeBcelType(field.getType());
- String fieldname = field.getName();
- if (!gen.fieldExists(fieldname)) {
- weaver.addInitializer(this);
- // System.err.println("impl body on " + gen.getType() + " for " +
- // munger);
-
-
- FieldGen fg = makeFieldGen(gen, AjcMemberMaker.interFieldInterfaceField(field, onType, aspectType));
-
- if (annotationsOnRealMember != null) {
- for (int i = 0; i < annotationsOnRealMember.length; i++) {
- AnnotationAJ annotationX = annotationsOnRealMember[i];
- AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
- AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true);
- fg.addAnnotation(ag);
- }
+
+ FieldGen fg = makeFieldGen(gen, AjcMemberMaker.interFieldInterfaceField(field, onType, aspectType));
+
+ if (annotationsOnRealMember != null) {
+ for (int i = 0; i < annotationsOnRealMember.length; i++) {
+ AnnotationAJ annotationX = annotationsOnRealMember[i];
+ AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
+ AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true);
+ fg.addAnnotation(ag);
}
- fieldname = fg.getName();
- gen.addField(fg, getSourceLocation());
}
+
+ gen.addField(fg, getSourceLocation());
// this uses a shadow munger to add init method to constructors
// weaver.getShadowMungers().add(makeInitCallShadowMunger(initMethod)
// );
InstructionList il = new InstructionList();
InstructionFactory fact = gen.getFactory();
if (Modifier.isStatic(field.getModifiers())) {
- il.append(fact.createFieldAccess(gen.getClassName(), fieldname, fieldType, Constants.GETSTATIC));
+ il.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.GETSTATIC));
} else {
il.append(InstructionConstants.ALOAD_0);
- il.append(fact.createFieldAccess(gen.getClassName(), fieldname, fieldType, Constants.GETFIELD));
+ il.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.GETFIELD));
}
il.append(InstructionFactory.createReturn(fieldType));
mg.getBody().insert(il);
InstructionList il1 = new InstructionList();
if (Modifier.isStatic(field.getModifiers())) {
il1.append(InstructionFactory.createLoad(fieldType, 0));
- il1.append(fact.createFieldAccess(gen.getClassName(), fieldname, fieldType, Constants.PUTSTATIC));
+ il1.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.PUTSTATIC));
} else {
il1.append(InstructionConstants.ALOAD_0);
il1.append(InstructionFactory.createLoad(fieldType, 1));
- il1.append(fact.createFieldAccess(gen.getClassName(), fieldname, fieldType, Constants.PUTFIELD));
+ il1.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.PUTFIELD));
}
il1.append(InstructionFactory.createReturn(Type.VOID));
mg1.getBody().insert(il1);