// TAG: WeavingMessage
if (changed && worthReporting && munger != null && !weaver.getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)) {
String tName = weaver.getLazyClassGen().getType().getSourceLocation().getSourceFile().getName();
- if (tName.indexOf("no debug info available") != -1)
+ if (tName.indexOf("no debug info available") != -1) {
tName = "no debug info available";
- else
+ } else {
tName = getShortname(weaver.getLazyClassGen().getType().getSourceLocation().getSourceFile().getPath());
+ }
String fName = getShortname(getAspectType().getSourceLocation().getSourceFile().getPath());
if (munger.getKind().equals(ResolvedTypeMunger.Parent)) {
// This message could come out of AjLookupEnvironment.addParent
ResolvedMember superMethod = (ResolvedMember) iter.next();
if (!superMethod.getName().equals("<init>")) {
LazyMethodGen subMethod = findMatchingMethod(newParentTarget, superMethod);
- if (subMethod != null && !subMethod.isBridgeMethod()) { // FIXME
- // asc
- // is
- // this
- // safe
- // for
- // all
- // bridge
- // methods
- // ?
+ // FIXME asc is this safe for all bridge methods?
+ if (subMethod != null && !subMethod.isBridgeMethod()) {
if (!(subMethod.isSynthetic() && superMethod.isSynthetic())) {
if (!(subMethod.isStatic() && subMethod.getName().startsWith("access$"))) { // ignore generated
// accessors
}
}
}
- if (!cont)
+ if (!cont) {
return false; // A rule was violated and an error message already
- // reported
+ // reported
+ }
if (newParent.isClass()) { // Changing the supertype
- if (!attemptToModifySuperCalls(weaver, newParentTarget, newParent))
+ if (!attemptToModifySuperCalls(weaver, newParentTarget, newParent)) {
return false;
+ }
newParentTarget.setSuperClass(newParent);
} else { // Adding a new interface
newParentTarget.addInterface(newParent, getSourceLocation());
* The main part of implementing declare parents extends. Modify super ctor calls to target the new type.
*/
public boolean attemptToModifySuperCalls(BcelClassWeaver weaver, LazyClassGen newParentTarget, ResolvedType newParent) {
- String currentParent = newParentTarget.getSuperClass().getName();// getName();
- if (newParent.getGenericType() != null)
+ ResolvedType currentParentType = newParentTarget.getSuperClass();
+ if (currentParentType.getGenericType() != null) {
+ currentParentType = currentParentType.getGenericType();
+ }
+ String currentParent = currentParentType.getName();
+ if (newParent.getGenericType() != null) {
newParent = newParent.getGenericType(); // target new super calls at
- // the generic type if its
- // raw or parameterized
- List mgs = newParentTarget.getMethodGens();
+ }
+ // the generic type if its raw or parameterized
+ List<LazyMethodGen> mgs = newParentTarget.getMethodGens();
// Look for ctors to modify
- for (Iterator iter = mgs.iterator(); iter.hasNext();) {
- LazyMethodGen aMethod = (LazyMethodGen) iter.next();
-
+ for (LazyMethodGen aMethod : mgs) {
if (aMethod.getName().equals("<init>")) {
InstructionList insList = aMethod.getBody();
InstructionHandle handle = insList.getStart();
InvokeInstruction invokeSpecial = (InvokeInstruction) handle.getInstruction();
if (invokeSpecial.getClassName(cpg).equals(currentParent)
&& invokeSpecial.getMethodName(cpg).equals("<init>")) {
- // System.err.println(
- // "Transforming super call '<init>"
- // +sp.getSignature(cpg)+"'");
+ // System.err.println("Transforming super call '<init>" + invokeSpecial.getSignature(cpg) + "'");
// 1. Check there is a ctor in the new parent with
// the same signature
if (newCtor == null) {
- // 2. Check ITDCs to see if the necessary ctor
- // is provided that way
+ // 2. Check ITDCs to see if the necessary ctor is provided that way
boolean satisfiedByITDC = false;
for (Iterator ii = newParentTarget.getType().getInterTypeMungersIncludingSupers().iterator(); ii
.hasNext()
sb.append("(");
for (int i = 0; i < ctorArgs.length; i++) {
String argtype = ctorArgs[i].toString();
- if (argtype.lastIndexOf(".") != -1)
+ if (argtype.lastIndexOf(".") != -1) {
sb.append(argtype.substring(argtype.lastIndexOf(".") + 1));
- else
+ } else {
sb.append(argtype);
- if (i + 1 < ctorArgs.length)
+ }
+ if (i + 1 < ctorArgs.length) {
sb.append(",");
+ }
}
sb.append(")");
return sb.toString();
for (int i = 0; i < mems.length; i++) {
ResolvedMember rm = mems[i];
if (rm.getName().equals("<init>")) {
- if (rm.getSignature().equals(signature))
+ if (rm.getSignature().equals(signature)) {
return rm;
+ }
}
}
return null;
ResolvedMember member = munger.getMember();
ResolvedType onType = weaver.getWorld().resolve(member.getDeclaringType(), munger.getSourceLocation());
- if (onType.isRawType())
+ if (onType.isRawType()) {
onType = onType.getGenericType();
+ }
// System.out.println("munging: " + gen + " with " + member);
if (onType.equals(gen.getType())) {
if (classWeaver.getWorld().isInJava5Mode()) {
AnnotationAJ annotationsOnRealMember[] = null;
ResolvedType toLookOn = aspectType;
- if (aspectType.isRawType())
+ if (aspectType.isRawType()) {
toLookOn = aspectType.getGenericType();
+ }
ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn, memberHoldingAnyAnnotations, false);
- if (realMember == null)
+ if (realMember == null) {
throw new BCException("Couldn't find ITD holder member '" + memberHoldingAnyAnnotations + "' on aspect "
+ aspectType);
+ }
annotationsOnRealMember = realMember.getAnnotations();
if (annotationsOnRealMember != null) {
ResolvedMember mungerSignature = munger.getSignature();
ResolvedMember toBridgeTo = munger.getDeclaredSignature().parameterizedWith(null,
mungerSignature.getDeclaringType().resolve(getWorld()), false, munger.getTypeVariableAliases());
- if (!toBridgeTo.getReturnType().getErasureSignature().equals(mungerSignature.getReturnType().getErasureSignature()))
+ if (!toBridgeTo.getReturnType().getErasureSignature().equals(mungerSignature.getReturnType().getErasureSignature())) {
needsbridging = true;
+ }
UnresolvedType[] originalParams = toBridgeTo.getParameterTypes();
UnresolvedType[] newParams = mungerSignature.getParameterTypes();
for (int ii = 0; ii < originalParams.length; ii++) {
- if (!originalParams[ii].getErasureSignature().equals(newParams[ii].getErasureSignature()))
+ if (!originalParams[ii].getErasureSignature().equals(newParams[ii].getErasureSignature())) {
needsbridging = true;
+ }
}
if (needsbridging) {
createBridge(classWeaver, unMangledInterMethod, classGen, toBridgeTo);
ResolvedMember member = localMethods[i];
if (member.getName().equals(localMethodName)) {
// Check the params
- if (member.getParameterSignature().equals(localParameterSig))
+ if (member.getParameterSignature().equals(localParameterSig)) {
alreadyDone = true;
+ }
}
}
if (member.getName().equals(lookingFor.getName())) {
UnresolvedType[] memberParams = member.getGenericParameterTypes();
if (memberParams.length == lookingForParams.length) {
- if (debug)
+ if (debug) {
System.err.println("Reviewing potential candidates: " + member);
+ }
boolean matchOK = true;
// If not related to a ctor ITD then the name is enough to
// confirm we have the
ResolvedType pMember = memberParams[j].resolve(world);
ResolvedType pLookingFor = lookingForParams[j].resolve(world);
- if (pMember.isTypeVariableReference())
+ if (pMember.isTypeVariableReference()) {
pMember = ((TypeVariableReference) pMember).getTypeVariable().getFirstBound().resolve(world);
- if (pMember.isParameterizedType() || pMember.isGenericType())
+ }
+ if (pMember.isParameterizedType() || pMember.isGenericType()) {
pMember = pMember.getRawType().resolve(aspectType.getWorld());
+ }
- if (pLookingFor.isTypeVariableReference())
+ if (pLookingFor.isTypeVariableReference()) {
pLookingFor = ((TypeVariableReference) pLookingFor).getTypeVariable().getFirstBound()
.resolve(world);
- if (pLookingFor.isParameterizedType() || pLookingFor.isGenericType())
+ }
+ if (pLookingFor.isParameterizedType() || pLookingFor.isGenericType()) {
pLookingFor = pLookingFor.getRawType().resolve(world);
+ }
- if (debug)
+ if (debug) {
System.err.println("Comparing parameter " + j + " member=" + pMember + " lookingFor="
+ pLookingFor);
+ }
if (!pMember.equals(pLookingFor)) {
matchOK = false;
}
}
}
- if (matchOK)
+ if (matchOK) {
realMember = member;
+ }
}
}
}
- if (debug && realMember == null)
+ if (debug && realMember == null) {
System.err.println("Didn't find a match");
+ }
return realMember;
}
// superMethod.getDeclaringType() + ", " + gen.getType());
boolean isSuper = !superMethod.getDeclaringType().equals(gen.getType());
String dispatchName;
- if (isSuper)
+ if (isSuper) {
dispatchName = NameMangler.superDispatchMethod(onType, superMethod.getName());
- else
+ } else {
dispatchName = NameMangler.protectedDispatchMethod(onType, superMethod.getName());
+ }
superMethod = superMethod.resolve(weaver.getWorld());
LazyMethodGen dispatcher = makeDispatcher(gen, dispatchName, superMethod, weaver.getWorld(), isSuper);
ResolvedMember newConstructorMember = newConstructorTypeMunger.getSyntheticConstructor();
ResolvedType onType = newConstructorMember.getDeclaringType().resolve(weaver.getWorld());
- if (onType.isRawType())
+ if (onType.isRawType()) {
onType = onType.getGenericType();
+ }
if (onType.isAnnotation()) {
signalError(WeaverMessages.ITDC_ON_ANNOTATION_NOT_ALLOWED, weaver, onType);
return false;
}
- if (!onType.equals(currentClass.getType()))
+ if (!onType.equals(currentClass.getType())) {
return false;
+ }
ResolvedMember explicitConstructor = newConstructorTypeMunger.getExplicitConstructor();
// int declaredParameterCount =
Type returnType = BcelWorld.makeBcelType(superMethod.getReturnType());
int modifiers = Modifier.PUBLIC;
- if (onGen.isInterface())
+ if (onGen.isInterface()) {
modifiers |= Modifier.ABSTRACT;
+ }
LazyMethodGen mg = new LazyMethodGen(modifiers, returnType, dispatchName, paramTypes, UnresolvedType.getNames(superMethod
.getExceptions()), onGen);
InstructionList body = mg.getBody();
- if (onGen.isInterface())
+ if (onGen.isInterface()) {
return mg;
+ }
// assert (!superMethod.isStatic())
InstructionFactory fact = onGen.getFactory();
ResolvedMember field = munger.getSignature();
ResolvedType onType = weaver.getWorld().resolve(field.getDeclaringType(), munger.getSourceLocation());
- if (onType.isRawType())
+ if (onType.isRawType()) {
onType = onType.getGenericType();
+ }
boolean onInterface = onType.isInterface();
} else if (onInterface && gen.getType().isTopmostImplementor(onType)) {
// wew know that we can't be static since we don't allow statics on
// interfaces
- if (field.isStatic())
+ if (field.isStatic()) {
throw new RuntimeException("unimplemented");
+ }
weaver.addInitializer(this);
// System.err.println("impl body on " + gen.getType() + " for " +
// munger);
munger.getSignature().getDeclaringType().resolve(getWorld()), false, munger.getTypeVariableAliases());
boolean needsbridging = false;
if (!toBridgeTo.getReturnType().getErasureSignature().equals(
- munger.getSignature().getReturnType().getErasureSignature()))
+ munger.getSignature().getReturnType().getErasureSignature())) {
needsbridging = true;
+ }
if (needsbridging) {
ResolvedMember bridgingGetter = AjcMemberMaker.interFieldInterfaceGetter(toBridgeTo, gen.getType(), aspectType);
createBridgeMethodForITDF(weaver, gen, itdfieldGetter, bridgingGetter);
@Override
public boolean equals(Object other) {
- if (!(other instanceof BcelTypeMunger))
+ if (!(other instanceof BcelTypeMunger)) {
return false;
+ }
BcelTypeMunger o = (BcelTypeMunger) other;
return ((o.getMunger() == null) ? (getMunger() == null) : o.getMunger().equals(getMunger()))
&& ((o.getAspectType() == null) ? (getAspectType() == null) : o.getAspectType().equals(getAspectType()));