*/
private final List<BcelShadow> initializationShadows = new ArrayList<BcelShadow>();
- private BcelClassWeaver(BcelWorld world, LazyClassGen clazz, List shadowMungers, List<ConcreteTypeMunger> typeMungers,
- List lateTypeMungers) {
+ private BcelClassWeaver(BcelWorld world, LazyClassGen clazz, List<ShadowMunger> shadowMungers,
+ List<ConcreteTypeMunger> typeMungers, List lateTypeMungers) {
super();
// assert world == clazz.getType().getWorld()
this.world = world;
if (p != null) {
String s = p.getProperty(World.xsetCAPTURE_ALL_CONTEXT, "false");
captureLowLevelContext = s.equalsIgnoreCase("true");
- if (captureLowLevelContext)
+ if (captureLowLevelContext) {
world.getMessageHandler().handleMessage(
MessageUtil.info("[" + World.xsetCAPTURE_ALL_CONTEXT
+ "=true] Enabling collection of low level context for debug/crash messages"));
+ }
}
checkedXsetForLowLevelContextCapturing = true;
}
}
- private List[] perKindShadowMungers;
+ private List<ShadowMunger>[] perKindShadowMungers;
private boolean canMatchBodyShadows = false;
// private boolean canMatchInitialization = false;
- private void fastMatchShadowMungers(List shadowMungers) {
+ private void fastMatchShadowMungers(List<ShadowMunger> shadowMungers) {
// beware the annoying property that SHADOW_KINDS[i].getKey == (i+1) !
perKindShadowMungers = new List[Shadow.MAX_SHADOW_KIND + 1];
for (int i = 0; i < perKindShadowMungers.length; i++) {
- perKindShadowMungers[i] = new ArrayList(0);
+ perKindShadowMungers[i] = new ArrayList<ShadowMunger>(0);
}
- for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) {
- ShadowMunger munger = (ShadowMunger) iter.next();
-
+ for (ShadowMunger munger : shadowMungers) {
int couldMatchKinds = munger.getPointcut().couldMatchKinds();
for (int i = 0; i < Shadow.SHADOW_KINDS.length; i++) {
Shadow.Kind kind = Shadow.SHADOW_KINDS[i];
- if (kind.isSet(couldMatchKinds))
+ if (kind.isSet(couldMatchKinds)) {
perKindShadowMungers[kind.getKey()].add(munger);
+ }
}
// Set couldMatchKinds = munger.getPointcut().couldMatchKinds();
}
private boolean addSuperInitializer(ResolvedType onType) {
- if (onType.isRawType() || onType.isParameterizedType())
+ if (onType.isRawType() || onType.isParameterizedType()) {
onType = onType.getGenericType();
+ }
IfaceInitList l = addedSuperInitializers.get(onType);
- if (l != null)
+ if (l != null) {
return false;
+ }
l = new IfaceInitList(onType);
addedSuperInitializers.put(onType, l);
return true;
public void addInitializer(ConcreteTypeMunger cm) {
NewFieldTypeMunger m = (NewFieldTypeMunger) cm.getMunger();
ResolvedType onType = m.getSignature().getDeclaringType().resolve(world);
- if (onType.isRawType())
+ if (onType.isRawType()) {
onType = onType.getGenericType();
+ }
if (m.getSignature().isStatic()) {
addedClassInitializers.add(cm);
public int compareTo(Object other) {
IfaceInitList o = (IfaceInitList) other;
- if (onType.isAssignableFrom(o.onType))
+ if (onType.isAssignableFrom(o.onType)) {
return +1;
- else if (o.onType.isAssignableFrom(onType))
+ } else if (o.onType.isAssignableFrom(onType)) {
return -1;
- else
+ } else {
return 0;
+ }
}
public int fallbackCompareTo(Object other) {
}
public void addOrReplaceLazyMethodGen(LazyMethodGen mg) {
- if (alreadyDefined(clazz, mg))
+ if (alreadyDefined(clazz, mg)) {
return;
+ }
for (Iterator i = addedLazyMethodGens.iterator(); i.hasNext();) {
LazyMethodGen existing = (LazyMethodGen) i.next();
// remove abstract modifier
int mods = member.getModifiers();
- if (Modifier.isAbstract(mods))
+ if (Modifier.isAbstract(mods)) {
mods = mods - Modifier.ABSTRACT;
+ }
LazyMethodGen ret = new LazyMethodGen(mods, BcelWorld.makeBcelType(member.getReturnType()), member.getName(), BcelWorld
.makeBcelTypes(member.getParameterTypes()), UnresolvedType.getNames(member.getExceptions()), gen);
Type paramType = paramTypes[i];
body.append(InstructionFactory.createLoad(paramType, pos));
if (!newParamTypes[i].equals(paramTypes[i])) {
- if (world.forDEBUG_bridgingCode)
+ if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging: Cast " + newParamTypes[i] + " from " + paramTypes[i]);
+ }
body.append(fact.createCast(paramTypes[i], newParamTypes[i]));
}
pos += paramType.getSize();
boolean isChanged = false;
// we want to "touch" all aspects
- if (clazz.getType().isAspect())
+ if (clazz.getType().isAspect()) {
isChanged = true;
+ }
// start by munging all typeMungers
for (ConcreteTypeMunger o : typeMungers) {
boolean typeMungerAffectedType = munger.munge(this);
if (typeMungerAffectedType) {
isChanged = true;
- if (inReweavableMode || clazz.getType().isAspect())
+ if (inReweavableMode || clazz.getType().isAspect()) {
aspectsAffectingType.add(munger.getAspectType().getName());
+ }
}
}
// now we weave all but the initialization shadows
for (Iterator i = methodGens.iterator(); i.hasNext();) {
LazyMethodGen mg = (LazyMethodGen) i.next();
- if (!mg.hasBody())
+ if (!mg.hasBody()) {
continue;
+ }
implement(mg);
}
// Repeat next step until nothing left to inline...cant go on
// infinetly as compiler will have detected and reported
// "Recursive constructor invocation"
- while (inlineSelfConstructors(methodGens))
+ while (inlineSelfConstructors(methodGens)) {
;
+ }
positionAndImplement(initializationShadows);
}
boolean typeMungerAffectedType = munger.munge(this);
if (typeMungerAffectedType) {
isChanged = true;
- if (inReweavableMode || clazz.getType().isAspect())
+ if (inReweavableMode || clazz.getType().isAspect()) {
aspectsAffectingType.add(munger.getAspectType().getName());
+ }
}
}
}
for (Iterator i = methodGens.iterator(); i.hasNext();) {
LazyMethodGen mg = (LazyMethodGen) i.next();
BcelMethod bM = mg.getMemberView();
- if (bM != null)
+ if (bM != null) {
bM.wipeJoinpointSignatures();
+ }
}
return isChanged;
* @return true if there is an overrides rather than a 'hides' relationship
*/
static boolean isVisibilityOverride(int methodMods, ResolvedMember inheritedMethod, boolean inSamePackage) {
- if (inheritedMethod.isStatic())
+ if (inheritedMethod.isStatic()) {
return false;
- if (methodMods == inheritedMethod.getModifiers())
+ }
+ if (methodMods == inheritedMethod.getModifiers()) {
return true;
+ }
- if (inheritedMethod.isPrivate())
+ if (inheritedMethod.isPrivate()) {
return false;
+ }
boolean isPackageVisible = !inheritedMethod.isPrivate() && !inheritedMethod.isProtected() && !inheritedMethod.isPublic();
- if (isPackageVisible && !inSamePackage)
+ if (isPackageVisible && !inSamePackage) {
return false;
+ }
return true;
}
public static ResolvedMember checkForOverride(ResolvedType typeToCheck, String mname, String mparams, String mrettype,
int mmods, String mpkg, UnresolvedType[] methodParamsArray) {
- if (typeToCheck == null)
+ if (typeToCheck == null) {
return null;
- if (typeToCheck instanceof MissingResolvedTypeWithKnownSignature)
+ }
+ if (typeToCheck instanceof MissingResolvedTypeWithKnownSignature) {
return null; // we just can't tell !
+ }
- if (typeToCheck.getWorld().forDEBUG_bridgingCode)
+ if (typeToCheck.getWorld().forDEBUG_bridgingCode) {
System.err.println(" Bridging:checking for override of " + mname + " in " + typeToCheck);
+ }
String packageName = typeToCheck.getPackageName();
- if (packageName == null)
+ if (packageName == null) {
packageName = "";
+ }
boolean inSamePackage = packageName.equals(mpkg); // used when looking
// at visibility
// rules
// check
ResolvedMember isOverriding = isOverriding(typeToCheck, methodThatMightBeGettingOverridden, mname, mrettype, mmods,
inSamePackage, methodParamsArray);
- if (isOverriding != null)
+ if (isOverriding != null) {
return isOverriding;
+ }
}
// was: List l = typeToCheck.getInterTypeMungers();
List l = (typeToCheck.isRawType() ? typeToCheck.getGenericType().getInterTypeMungers() : typeToCheck.getInterTypeMungers());
if (o instanceof BcelTypeMunger) {
BcelTypeMunger element = (BcelTypeMunger) o;
if (element.getMunger() instanceof NewMethodTypeMunger) {
- if (typeToCheck.getWorld().forDEBUG_bridgingCode)
+ if (typeToCheck.getWorld().forDEBUG_bridgingCode) {
System.err.println("Possible ITD candidate " + element);
+ }
ResolvedMember aMethod = element.getSignature();
ResolvedMember isOverriding = isOverriding(typeToCheck, aMethod, mname, mrettype, mmods, inSamePackage,
methodParamsArray);
- if (isOverriding != null)
+ if (isOverriding != null) {
return isOverriding;
+ }
}
}
}
- if (typeToCheck.equals(UnresolvedType.OBJECT))
+ if (typeToCheck.equals(UnresolvedType.OBJECT)) {
return null;
+ }
ResolvedType superclass = typeToCheck.getSuperclass();
ResolvedMember overriddenMethod = checkForOverride(superclass, mname, mparams, mrettype, mmods, mpkg, methodParamsArray);
- if (overriddenMethod != null)
+ if (overriddenMethod != null) {
return overriddenMethod;
+ }
ResolvedType[] interfaces = typeToCheck.getDeclaredInterfaces();
for (int i = 0; i < interfaces.length; i++) {
ResolvedType anInterface = interfaces[i];
overriddenMethod = checkForOverride(anInterface, mname, mparams, mrettype, mmods, mpkg, methodParamsArray);
- if (overriddenMethod != null)
+ if (overriddenMethod != null) {
return overriddenMethod;
+ }
}
return null;
}
*/
public static boolean calculateAnyRequiredBridgeMethods(BcelWorld world, LazyClassGen clazz) {
world.ensureAdvancedConfigurationProcessed();
- if (!world.isInJava5Mode())
+ if (!world.isInJava5Mode()) {
return false; // just double check... the caller should have already
+ }
// verified this
- if (clazz.isInterface())
+ if (clazz.isInterface()) {
return false; // dont bother if we're an interface
+ }
boolean didSomething = false; // set if we build any bridge methods
// So what methods do we have right now in this class?
// This is the local method that we *might* have to bridge to
LazyMethodGen bridgeToCandidate = (LazyMethodGen) methods.get(i);
- if (bridgeToCandidate.isBridgeMethod())
+ if (bridgeToCandidate.isBridgeMethod()) {
continue; // Doh!
+ }
String name = bridgeToCandidate.getName();
String psig = bridgeToCandidate.getParameterSignature();
String rsig = bridgeToCandidate.getReturnType().getSignature();
// if (bridgeToCandidate.isAbstract()) continue;
- if (bridgeToCandidate.isStatic())
+ if (bridgeToCandidate.isStatic()) {
continue; // ignore static methods
- if (name.endsWith("init>"))
+ }
+ if (name.endsWith("init>")) {
continue; // Skip constructors and static initializers
+ }
- if (world.forDEBUG_bridgingCode)
+ if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging: Determining if we have to bridge to " + clazz.getName() + "." + name + ""
+ bridgeToCandidate.getSignature());
+ }
// Let's take a look at the superclass
ResolvedType theSuperclass = clazz.getSuperClass();
// Check superinterfaces
String[] interfaces = clazz.getInterfaceNames();
for (int j = 0; j < interfaces.length; j++) {
- if (world.forDEBUG_bridgingCode)
+ if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging:checking superinterface " + interfaces[j]);
+ }
ResolvedType interfaceType = world.resolve(interfaces[j]);
overriddenMethod = checkForOverride(interfaceType, name, psig, rsig, bridgeToCandidate.getAccessFlags(), clazz
.getPackageName(), bm);
createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod);
methodsSet.add(key);
didSomething = true;
- if (world.forDEBUG_bridgingCode)
+ if (world.forDEBUG_bridgingCode) {
System.err.println("Bridging:bridging to " + overriddenMethod);
+ }
continue; // look at the next method
}
}
// deal with all the other methods...
List<LazyMethodGen> members = clazz.getMethodGens();
List<DeclareAnnotation> decaMs = getMatchingSubset(allDecams, clazz.getType());
- if (decaMs.isEmpty())
+ if (decaMs.isEmpty()) {
return false; // nothing to do
+ }
if (!members.isEmpty()) {
Set<DeclareAnnotation> unusedDecams = new HashSet<DeclareAnnotation>();
unusedDecams.addAll(decaMs);
// against it
unusedDecams.remove(decaM);
} else {
- if (!decaM.isStarredAnnotationPattern())
+ if (!decaM.isStarredAnnotationPattern()) {
worthRetrying.add(decaM); // an annotation is
- // specified that
- // might be put on
- // by a subsequent
- // decaf
+ // specified that
+ // might be put on
+ // by a subsequent
+ // decaf
+ }
}
}
for (int i = 0; i < paramTypes.length; i++) {
UnresolvedType type = paramTypes[i];
String s = org.aspectj.apache.bcel.classfile.Utility.signatureToString(type.getSignature());
- if (s.lastIndexOf('.') != -1)
+ if (s.lastIndexOf('.') != -1) {
s = s.substring(s.lastIndexOf('.') + 1);
+ }
parmString.append(s);
- if ((i + 1) < paramTypes.length)
+ if ((i + 1) < paramTypes.length) {
parmString.append(",");
+ }
}
parmString.append(")");
String methodName = member.getName();
if (decaF.matches(itdIsActually, world)) {
LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, fieldMunger);
- if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors))
+ if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors)) {
continue; // skip this one...
+ }
annotationHolder.addAnnotation(decaF.getAnnotation());
AsmRelationshipProvider.addDeclareAnnotationRelationship(world.getModelAsAsmManager(), decaF
.getSourceLocation(), itdIsActually.getSourceLocation());
modificationOccured = true;
} else {
- if (!decaF.isStarredAnnotationPattern())
+ if (!decaF.isStarredAnnotationPattern()) {
worthRetrying.add(decaF); // an annotation is specified
- // that might be put on by a
- // subsequent decaf
+ // that might be put on by a
+ // subsequent decaf
+ }
}
}
DeclareAnnotation decaF = (DeclareAnnotation) iter2.next();
if (decaF.matches(itdIsActually, world)) {
LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, fieldMunger);
- if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors))
+ if (doesAlreadyHaveAnnotation(annotationHolder, itdIsActually, decaF, reportedErrors)) {
continue; // skip this one...
+ }
annotationHolder.addAnnotation(decaF.getAnnotation());
AsmRelationshipProvider.addDeclareAnnotationRelationship(world.getModelAsAsmManager(), decaF
.getSourceLocation(), itdIsActually.getSourceLocation());
DeclareAnnotation decaMC = (DeclareAnnotation) iter2.next();
if (decaMC.matches(unMangledInterMethod, world)) {
LazyMethodGen annotationHolder = locateAnnotationHolderForFieldMunger(clazz, methodctorMunger);
- if (doesAlreadyHaveAnnotation(annotationHolder, unMangledInterMethod, decaMC, reportedErrors))
+ if (doesAlreadyHaveAnnotation(annotationHolder, unMangledInterMethod, decaMC, reportedErrors)) {
continue; // skip this one...
+ }
annotationHolder.addAnnotation(decaMC.getAnnotation());
unMangledInterMethod.addAnnotation(decaMC.getAnnotation());
AsmRelationshipProvider.addDeclareAnnotationRelationship(asmManager, decaMC.getSourceLocation(),
}
List<DeclareAnnotation> decaFs = getMatchingSubset(allDecafs, clazz.getType());
- if (decaFs.isEmpty())
+ if (decaFs.isEmpty()) {
return false; // nothing more to do
+ }
List<BcelField> fields = clazz.getFieldGens();
if (fields != null) {
Set<DeclareAnnotation> unusedDecafs = new HashSet<DeclareAnnotation>();
// against it
unusedDecafs.remove(decaF);
} else {
- if (!decaF.isStarredAnnotationPattern())
+ if (!decaF.isStarredAnnotationPattern()) {
worthRetrying.add(decaF); // an annotation is
- // specified that
- // might be put on
- // by a subsequent
- // decaf
+ // specified that
+ // might be put on
+ // by a subsequent
+ // decaf
+ }
}
}
boolean inlinedSomething = false;
for (Iterator i = methodGens.iterator(); i.hasNext();) {
LazyMethodGen mg = (LazyMethodGen) i.next();
- if (!mg.getName().equals("<init>"))
+ if (!mg.getName().equals("<init>")) {
continue;
+ }
InstructionHandle ih = findSuperOrThisCall(mg);
if (ih != null && isThisCall(ih)) {
LazyMethodGen donor = getCalledMethod(ih);
* some duplication that can be removed.
*/
public static void transformSynchronizedMethod(LazyMethodGen synchronizedMethod) {
- if (trace.isTraceEnabled())
+ if (trace.isTraceEnabled()) {
trace.enter("transformSynchronizedMethod", synchronizedMethod);
+ }
// System.err.println("DEBUG: Transforming synchronized method: "+
// synchronizedMethod.getName());
final InstructionFactory fact = synchronizedMethod.getEnclosingClass().getFactory();
// now move the targeters from the RET to the start of
// the monitorexit block
- InstructionTargeter[] targeters = element.getTargetersArray();
- if (targeters != null) {
- for (int i = 0; i < targeters.length; i++) {
-
- InstructionTargeter targeter = targeters[i];
- // what kinds are there?
- if (targeter instanceof LocalVariableTag) {
- // ignore
- } else if (targeter instanceof LineNumberTag) {
- // ignore
- // } else if (targeter instanceof
- // InstructionBranch &&
- // ((InstructionBranch)targeter).isGoto()) {
- // // move it...
- // targeter.updateTarget(element,
- // monitorExitBlockStart);
- } else if (targeter instanceof InstructionBranch) {
- // move it
- targeter.updateTarget(element, monitorExitBlockStart);
- } else {
- throw new BCException("Unexpected targeter encountered during transform: " + targeter);
- }
+ for (InstructionTargeter targeter : element.getTargetersCopy()) {
+ // what kinds are there?
+ if (targeter instanceof LocalVariableTag) {
+ // ignore
+ } else if (targeter instanceof LineNumberTag) {
+ // ignore
+ // } else if (targeter instanceof
+ // InstructionBranch &&
+ // ((InstructionBranch)targeter).isGoto()) {
+ // // move it...
+ // targeter.updateTarget(element,
+ // monitorExitBlockStart);
+ } else if (targeter instanceof InstructionBranch) {
+ // move it
+ targeter.updateTarget(element, monitorExitBlockStart);
+ } else {
+ throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
}
}
// now move the targeters from the RET to the start of
// the monitorexit block
- InstructionTargeter[] targeters = element.getTargetersArray();
- if (targeters != null) {
- for (int i = 0; i < targeters.length; i++) {
-
- InstructionTargeter targeter = targeters[i];
- // what kinds are there?
- if (targeter instanceof LocalVariableTag) {
- // ignore
- } else if (targeter instanceof LineNumberTag) {
- // ignore
- // } else if (targeter instanceof GOTO ||
- // targeter instanceof GOTO_W) {
- // // move it...
- // targeter.updateTarget(element,
- // monitorExitBlockStart);
- } else if (targeter instanceof InstructionBranch) {
- // move it
- targeter.updateTarget(element, monitorExitBlockStart);
- } else {
- throw new BCException("Unexpected targeter encountered during transform: " + targeter);
- }
+ for (InstructionTargeter targeter : element.getTargetersCopy()) {
+ // what kinds are there?
+ if (targeter instanceof LocalVariableTag) {
+ // ignore
+ } else if (targeter instanceof LineNumberTag) {
+ // ignore
+ // } else if (targeter instanceof GOTO ||
+ // targeter instanceof GOTO_W) {
+ // // move it...
+ // targeter.updateTarget(element,
+ // monitorExitBlockStart);
+ } else if (targeter instanceof InstructionBranch) {
+ // move it
+ targeter.updateTarget(element, monitorExitBlockStart);
+ } else {
+ throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
}
}
// now move the targeters from the RET to the start of the
// monitorexit block
- InstructionTargeter[] targeters = element.getTargetersArray();
- if (targeters != null) {
- for (int i = 0; i < targeters.length; i++) {
-
- InstructionTargeter targeter = targeters[i];
- // what kinds are there?
- if (targeter instanceof LocalVariableTag) {
- // ignore
- } else if (targeter instanceof LineNumberTag) {
- // ignore
- // } else if (targeter instanceof GOTO ||
- // targeter instanceof GOTO_W) {
- // // move it...
- // targeter.updateTarget(element,
- // monitorExitBlockStart);
- } else if (targeter instanceof InstructionBranch) {
- // move it
- targeter.updateTarget(element, monitorExitBlockStart);
- } else {
- throw new BCException("Unexpected targeter encountered during transform: " + targeter);
- }
+ for (InstructionTargeter targeter : element.getTargetersCopy()) {
+ // what kinds are there?
+ if (targeter instanceof LocalVariableTag) {
+ // ignore
+ } else if (targeter instanceof LineNumberTag) {
+ // ignore
+ // } else if (targeter instanceof GOTO ||
+ // targeter instanceof GOTO_W) {
+ // // move it...
+ // targeter.updateTarget(element,
+ // monitorExitBlockStart);
+ } else if (targeter instanceof InstructionBranch) {
+ // move it
+ targeter.updateTarget(element, monitorExitBlockStart);
+ } else {
+ throw new BCException("Unexpected targeter encountered during transform: " + targeter);
}
}
}
// a variable,
// going to add a new variable for the this var
- if (trace.isTraceEnabled())
+ if (trace.isTraceEnabled()) {
trace.exit("transformSynchronizedMethod");
+ }
}
/**
}
}
}
- if (!keepReturns)
+ if (!keepReturns) {
ret.append(footer);
+ }
return ret;
}
LazyMethodGen aa = (LazyMethodGen) a;
LazyMethodGen bb = (LazyMethodGen) b;
int i = aa.getName().compareTo(bb.getName());
- if (i != 0)
+ if (i != 0) {
return i;
+ }
return aa.getSignature().compareTo(bb.getSignature());
}
});
int depth = 1;
InstructionHandle start = mg.getBody().getStart();
while (true) {
- if (start == null)
+ if (start == null) {
return null;
+ }
Instruction inst = start.getInstruction();
if (inst.opcode == Constants.INVOKESPECIAL && ((InvokeInstruction) inst).getName(cpg).equals("<init>")) {
depth--;
- if (depth == 0)
+ if (depth == 0) {
return start;
+ }
} else if (inst.opcode == Constants.NEW) {
depth++;
}
InstructionHandle superOrThisCall = findSuperOrThisCall(mg);
// we don't walk bodies of things where it's a wrong constructor thingie
- if (superOrThisCall == null)
+ if (superOrThisCall == null) {
return false;
+ }
enclosingShadow = BcelShadow.makeConstructorExecution(world, mg, superOrThisCall);
if (mg.getEffectiveSignature() != null) {
match(mg, h, beforeSuperOrThisCall ? null : enclosingShadow, shadowAccumulator);
}
}
- if (canMatch(Shadow.ConstructorExecution))
+ if (canMatch(Shadow.ConstructorExecution)) {
match(enclosingShadow, shadowAccumulator);
+ }
}
// XXX we don't do pre-inits of interfaces
}
private boolean shouldWeaveBody(LazyMethodGen mg) {
- if (mg.isBridgeMethod())
+ if (mg.isBridgeMethod()) {
return false;
- if (mg.isAjSynthetic())
+ }
+ if (mg.isAjSynthetic()) {
return mg.getName().equals("<clinit>");
+ }
AjAttribute.EffectiveSignatureAttribute a = mg.getEffectiveSignature();
- if (a != null)
+ if (a != null) {
return a.isWeaveBody();
+ }
return true;
}
ConcreteTypeMunger cmunger = (ConcreteTypeMunger) i.next();
NewFieldTypeMunger munger = (NewFieldTypeMunger) cmunger.getMunger();
ResolvedMember initMethod = munger.getInitMethod(cmunger.getAspectType());
- if (!isStatic)
+ if (!isStatic) {
ret.append(InstructionConstants.ALOAD_0);
+ }
ret.append(Utility.createInvoke(fact, world, initMethod));
}
return ret;
// Exception handlers (pr230817)
if (canMatch(Shadow.ExceptionHandler) && !Range.isRangeHandle(ih)) {
- InstructionTargeter[] targeters = ih.getTargetersArray();
- if (targeters != null) {
- for (int j = 0; j < targeters.length; j++) {
- InstructionTargeter t = targeters[j];
- if (t instanceof ExceptionRange) {
- // assert t.getHandler() == ih
- ExceptionRange er = (ExceptionRange) t;
- if (er.getCatchType() == null)
- continue;
- if (isInitFailureHandler(ih))
- return;
-
- if (!ih.getInstruction().isStoreInstruction() && ih.getInstruction().getOpcode() != Constants.NOP) {
- // If using cobertura, the catch block stats with
- // INVOKESTATIC rather than ASTORE, in order that
- // the
- // ranges
- // for the methodcall and exceptionhandler shadows
- // that occur at this same
- // line, we need to modify the instruction list to
- // split them - adding a
- // NOP before the invokestatic that gets all the
- // targeters
- // that were aimed at the INVOKESTATIC
- mg.getBody().insert(ih, InstructionConstants.NOP);
- InstructionHandle newNOP = ih.getPrev();
- // what about a try..catch that starts at the start
- // of the exception handler? need to only include
- // certain targeters really.
- er.updateTarget(ih, newNOP, mg.getBody());
- for (int ii = 0; ii < targeters.length; ii++) {
- newNOP.addTargeter(targeters[ii]);
- }
- ih.removeAllTargeters();
- match(BcelShadow.makeExceptionHandler(world, er, mg, newNOP, enclosingShadow), shadowAccumulator);
- } else {
- match(BcelShadow.makeExceptionHandler(world, er, mg, ih, enclosingShadow), shadowAccumulator);
+ Set<InstructionTargeter> targeters = ih.getTargetersCopy();
+ for (InstructionTargeter t : targeters) {
+ if (t instanceof ExceptionRange) {
+ // assert t.getHandler() == ih
+ ExceptionRange er = (ExceptionRange) t;
+ if (er.getCatchType() == null) {
+ continue;
+ }
+ if (isInitFailureHandler(ih)) {
+ return;
+ }
+
+ if (!ih.getInstruction().isStoreInstruction() && ih.getInstruction().getOpcode() != Constants.NOP) {
+ // If using cobertura, the catch block stats with
+ // INVOKESTATIC rather than ASTORE, in order that
+ // the
+ // ranges
+ // for the methodcall and exceptionhandler shadows
+ // that occur at this same
+ // line, we need to modify the instruction list to
+ // split them - adding a
+ // NOP before the invokestatic that gets all the
+ // targeters
+ // that were aimed at the INVOKESTATIC
+ mg.getBody().insert(ih, InstructionConstants.NOP);
+ InstructionHandle newNOP = ih.getPrev();
+ // what about a try..catch that starts at the start
+ // of the exception handler? need to only include
+ // certain targeters really.
+ er.updateTarget(ih, newNOP, mg.getBody());
+ for (InstructionTargeter t2 : targeters) {
+ newNOP.addTargeter(t2);
}
+ ih.removeAllTargeters();
+ match(BcelShadow.makeExceptionHandler(world, er, mg, newNOP, enclosingShadow), shadowAccumulator);
+ } else {
+ match(BcelShadow.makeExceptionHandler(world, er, mg, ih, enclosingShadow), shadowAccumulator);
}
}
}
// it's
// not a join point according to 1.0.6 and 1.1.
} else {
- if (canMatch(Shadow.FieldSet))
+ if (canMatch(Shadow.FieldSet)) {
matchSetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
+ }
}
} else {
- if (canMatch(Shadow.FieldSet))
+ if (canMatch(Shadow.FieldSet)) {
matchSetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
+ }
}
} else {
- if (canMatch(Shadow.FieldGet))
+ if (canMatch(Shadow.FieldGet)) {
matchGetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
+ }
}
} else if (i instanceof InvokeInstruction) {
InvokeInstruction ii = (InvokeInstruction) i;
if (ii.getMethodName(clazz.getConstantPool()).equals("<init>")) {
- if (canMatch(Shadow.ConstructorCall))
+ if (canMatch(Shadow.ConstructorCall)) {
match(BcelShadow.makeConstructorCall(world, mg, ih, enclosingShadow), shadowAccumulator);
+ }
} else if (ii.opcode == Constants.INVOKESPECIAL) {
String onTypeName = ii.getClassName(cpg);
if (onTypeName.equals(mg.getEnclosingClass().getName())) {
InstructionHandle twoInstructionsAway = ih.getNext().getNext();
if (twoInstructionsAway.getInstruction().opcode == Constants.PUTSTATIC) {
String name = ((FieldInstruction) twoInstructionsAway.getInstruction()).getFieldName(cpg);
- if (name.equals(NameMangler.INITFAILURECAUSE_FIELD_NAME))
+ if (name.equals(NameMangler.INITFAILURECAUSE_FIELD_NAME)) {
return true;
+ }
}
return false;
}
Member field = BcelWorld.makeFieldJoinPointSignature(clazz, fi);
// synthetic fields are never join points
- if (field.getName().startsWith(NameMangler.PREFIX))
+ if (field.getName().startsWith(NameMangler.PREFIX)) {
return;
+ }
ResolvedMember resolvedField = field.resolve(world);
if (resolvedField == null) {
Member field = BcelWorld.makeFieldJoinPointSignature(clazz, fi);
// synthetic fields are never join points
- if (field.getName().startsWith(NameMangler.PREFIX))
+ if (field.getName().startsWith(NameMangler.PREFIX)) {
return;
+ }
ResolvedMember resolvedField = field.resolve(world);
if (resolvedField == null) {
ResolvedMember[] allMethods = type.getDeclaredMethods();
for (int i = 0; i < allMethods.length; i++) {
ResolvedMember member = allMethods[i];
- if (member.getName().equals(methodName))
+ if (member.getName().equals(methodName)) {
return member;
+ }
}
return null;
}
}
annotations = resolvedDooberry.getAnnotationTypes();
}
- if (annotations == null)
+ if (annotations == null) {
annotations = new ResolvedType[0];
+ }
mapToAnnotations.put(rm, annotations);
}
rm.setAnnotationTypes(annotations);
Member jpSig = world.makeJoinPointSignatureForMethodInvocation(clazz, invoke);
ResolvedMember declaredSig = jpSig.resolve(world);
// System.err.println(method + ", declaredSig: " +declaredSig);
- if (declaredSig == null)
+ if (declaredSig == null) {
return;
+ }
if (declaredSig.getKind() == Member.FIELD) {
Shadow.Kind kind;
kind = Shadow.FieldGet;
}
- if (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet))
+ if (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet)) {
match(BcelShadow.makeShadowForMethodCall(world, mg, ih, enclosingShadow, kind, declaredSig), shadowAccumulator);
+ }
} else {
AjAttribute.EffectiveSignatureAttribute effectiveSig = declaredSig.getEffectiveSignature();
- if (effectiveSig == null)
+ if (effectiveSig == null) {
return;
+ }
// System.err.println("call to inter-type member: " +
// effectiveSig);
- if (effectiveSig.isWeaveBody())
+ if (effectiveSig.isWeaveBody()) {
return;
+ }
ResolvedMember rm = effectiveSig.getEffectiveSignature();
fixParameterNamesForResolvedMember(rm, declaredSig);
fixAnnotationsForResolvedMember(rm, declaredSig); // abracadabra
- if (canMatch(effectiveSig.getShadowKind()))
+ if (canMatch(effectiveSig.getShadowKind())) {
match(BcelShadow.makeShadowForMethodCall(world, mg, ih, enclosingShadow, effectiveSig.getShadowKind(), rm),
shadowAccumulator);
+ }
}
} else {
- if (canMatch(Shadow.MethodCall))
+ if (canMatch(Shadow.MethodCall)) {
match(BcelShadow.makeMethodCall(world, mg, ih, enclosingShadow), shadowAccumulator);
+ }
}
}
CompilationAndWeavingContext.leavingPhase(mungerMatchToken);
}
- if (isMatched)
+ if (isMatched) {
shadowAccumulator.add(shadow);
+ }
CompilationAndWeavingContext.leavingPhase(shadowMatchToken);
return isMatched;
} else {
}
public Method getMethod() {
- if (savedMethod != null)
+ if (savedMethod != null) {
return savedMethod; // ??? this relies on gentle treatment of
- // constant pool
+ // constant pool
+ }
try {
MethodGen gen = pack();
// don't print empty ranges, that is, ranges who contain no
// actual instructions
for (InstructionHandle xx = r.getStart(); Range.isRangeHandle(xx); xx = xx.getNext()) {
- if (xx == r.getEnd())
+ if (xx == r.getEnd()) {
continue bodyPrint;
+ }
}
// doesn't handle nested: if (r.getStart().getNext() ==
if (r.getStart() == ih) {
printRangeString(r, depth++);
} else {
- if (r.getEnd() != ih)
+ if (r.getEnd() != ih) {
throw new RuntimeException("bad");
+ }
printRangeString(r, --depth);
}
} else {
InstructionTargeter t = (InstructionTargeter) tIter.next();
if (t instanceof LocalVariableTag) {
LocalVariableTag lvt = (LocalVariableTag) t;
- if (lvt.getSlot() == index)
+ if (lvt.getSlot() == index) {
return lvt;
+ }
}
}
return null;
}
public int getAccessFlagsWithoutSynchronized() {
- if (isSynchronized())
+ if (isSynchronized()) {
return modifiers - Modifier.SYNCHRONIZED;
+ }
return modifiers;
}
*/
InstructionHandle oldInstructionHandle = getBody().getStart();
InstructionHandle newInstructionHandle = fresh.getStart();
- LinkedList exceptionList = new LinkedList();
+ LinkedList<ExceptionRange> exceptionList = new LinkedList<ExceptionRange>();
- // map from localvariabletag to instruction handle
- Map localVariables = new HashMap();
+ Map<LocalVariableTag, LVPosition> localVariables = new HashMap<LocalVariableTag, LVPosition>();
int currLine = -1;
int lineNumberOffset = (fromFilename == null) ? 0 : getEnclosingClass().getSourceDebugExtensionOffset(fromFilename);
// now deal with line numbers
// and store up info for local variables
- Iterator tIter = oldInstructionHandle.getTargeters().iterator();
- while (tIter.hasNext()) {
- InstructionTargeter targeter = (InstructionTargeter) tIter.next();// targeters[k];
+ for (InstructionTargeter targeter : oldInstructionHandle.getTargeters()) {
if (targeter instanceof LineNumberTag) {
int line = ((LineNumberTag) targeter).getLineNumber();
if (line != currLine) {
}
} else if (targeter instanceof LocalVariableTag) {
LocalVariableTag lvt = (LocalVariableTag) targeter;
- LVPosition p = (LVPosition) localVariables.get(lvt);
+ LVPosition p = localVariables.get(lvt);
// If we don't know about it, create a new position and
// store
// If we do know about it - update its end position
int currLine = -1;
int lineNumberOffset = (fromFilename == null) ? 0 : getEnclosingClass().getSourceDebugExtensionOffset(fromFilename);
Map<LocalVariableTag, LVPosition> localVariables = new HashMap<LocalVariableTag, LVPosition>();
- LinkedList exceptionList = new LinkedList();
+ LinkedList<ExceptionRange> exceptionList = new LinkedList<ExceptionRange>();
Set<InstructionHandle> forDeletion = new HashSet<InstructionHandle>();
Set<BranchHandle> branchInstructions = new HashSet<BranchHandle>();
// OPTIMIZE sort out in here: getRange()/insertHandler() and type of
branchInstructions.add((BranchHandle) iHandle);
}
- InstructionTargeter[] targeters = iHandle.getTargetersArray();
- if (targeters != null) {
- for (int k = targeters.length - 1; k >= 0; k--) {
- InstructionTargeter targeter = targeters[k];
- if (targeter instanceof LineNumberTag) {
- int line = ((LineNumberTag) targeter).getLineNumber();
- if (line != currLine) {
- gen.addLineNumber(iHandle, line + lineNumberOffset);
- currLine = line;
- }
- } else if (targeter instanceof LocalVariableTag) {
- LocalVariableTag lvt = (LocalVariableTag) targeter;
- LVPosition p = localVariables.get(lvt);
- // If we don't know about it, create a new position
- // and store
- // If we do know about it - update its end position
- if (p == null) {
- LVPosition newp = new LVPosition();
- newp.start = newp.end = iHandle;
- localVariables.put(lvt, newp);
- } else {
- p.end = iHandle;
- }
+ for (InstructionTargeter targeter : iHandle.getTargetersCopy()) {
+ if (targeter instanceof LineNumberTag) {
+ int line = ((LineNumberTag) targeter).getLineNumber();
+ if (line != currLine) {
+ gen.addLineNumber(iHandle, line + lineNumberOffset);
+ currLine = line;
+ }
+ } else if (targeter instanceof LocalVariableTag) {
+ LocalVariableTag lvt = (LocalVariableTag) targeter;
+ LVPosition p = localVariables.get(lvt);
+ // If we don't know about it, create a new position
+ // and store
+ // If we do know about it - update its end position
+ if (p == null) {
+ LVPosition newp = new LVPosition();
+ newp.start = newp.end = iHandle;
+ localVariables.put(lvt, newp);
+ } else {
+ p.end = iHandle;
}
}
}
handleBranchInstruction(branchHandle, forDeletion);
}
// now add exception handlers
- for (Iterator iter = exceptionList.iterator(); iter.hasNext();) {
- ExceptionRange r = (ExceptionRange) iter.next();
- if (r.isEmpty())
+ for (ExceptionRange r : exceptionList) {
+ if (r.isEmpty()) {
continue;
+ }
gen.addExceptionHandler(jumpForward(r.getRealStart(), forDeletion), jumpForward(r.getRealEnd(), forDeletion),
jumpForward(r.getHandler(), forDeletion), (r.getCatchType() == null) ? null : (ObjectType) BcelWorld
.makeBcelType(r.getCatchType()));
}
- for (Iterator iterator = forDeletion.iterator(); iterator.hasNext();) {
+ for (InstructionHandle handle : forDeletion) {
try {
- theBody.delete((InstructionHandle) iterator.next());
+ theBody.delete(handle);
} catch (TargetLostException e) {
e.printStackTrace();
}
wasPackedOptimally = true;
}
- private void addLocalVariables(MethodGen gen, Map localVariables) {
+ private void addLocalVariables(MethodGen gen, Map<LocalVariableTag, LVPosition> localVariables) {
// now add local variables
gen.removeLocalVariables();
// bcel we should be able to do without it if we're paranoid enough
// through the rest of the compiler.
- Map duplicatedLocalMap = new HashMap();
- for (Iterator iter = localVariables.keySet().iterator(); iter.hasNext();) {
- LocalVariableTag tag = (LocalVariableTag) iter.next();
+ Map<InstructionHandle, Set<Integer>> duplicatedLocalMap = new HashMap<InstructionHandle, Set<Integer>>();
+ for (LocalVariableTag tag : localVariables.keySet()) {
// have we already added one with the same slot number and start
// location?
// if so, just continue.
- LVPosition lvpos = (LVPosition) localVariables.get(tag);
+ LVPosition lvpos = localVariables.get(tag);
InstructionHandle start = lvpos.start;
- Set slots = (Set) duplicatedLocalMap.get(start);
+ Set<Integer> slots = duplicatedLocalMap.get(start);
if (slots == null) {
- slots = new HashSet();
+ slots = new HashSet<Integer>();
duplicatedLocalMap.put(start, slots);
} else if (slots.contains(new Integer(tag.getSlot()))) {
// we already have a var starting at this tag with this slot
continue;
}
- slots.add(new Integer(tag.getSlot()));
+ slots.add(Integer.valueOf(tag.getSlot()));
Type t = tag.getRealType();
if (t == null) {
t = BcelWorld.makeBcelType(UnresolvedType.forSignature(tag.getType()));
}
}
- private void addExceptionHandlers(MethodGen gen, Map<InstructionHandle, InstructionHandle> map, LinkedList exnList) {
+ private void addExceptionHandlers(MethodGen gen, Map<InstructionHandle, InstructionHandle> map,
+ LinkedList<ExceptionRange> exnList) {
// now add exception handlers
- for (Iterator iter = exnList.iterator(); iter.hasNext();) {
- ExceptionRange r = (ExceptionRange) iter.next();
- if (r.isEmpty())
+ for (ExceptionRange r : exnList) {
+ if (r.isEmpty()) {
continue;
+ }
InstructionHandle rMappedStart = remap(r.getRealStart(), map);
InstructionHandle rMappedEnd = remap(r.getRealEnd(), map);
InstructionHandle rMappedHandler = remap(r.getHandler(), map);
}
}
- private void handleBranchInstruction(Map map, Instruction oldInstruction, Instruction newInstruction) {
+ private void handleBranchInstruction(Map<InstructionHandle, InstructionHandle> map, Instruction oldInstruction,
+ Instruction newInstruction) {
InstructionBranch oldBranchInstruction = (InstructionBranch) oldInstruction;
InstructionBranch newBranchInstruction = (InstructionBranch) newInstruction;
InstructionHandle oldTarget = oldBranchInstruction.getTarget(); // old
}
}
- private InstructionHandle jumpForward(InstructionHandle t, Set handlesForDeletion) {
-
+ private InstructionHandle jumpForward(InstructionHandle t, Set<InstructionHandle> handlesForDeletion) {
InstructionHandle target = t;
if (handlesForDeletion.contains(target)) {
do {
}
}
- private void handleRangeInstruction(InstructionHandle ih, LinkedList exnList) {
+ private void handleRangeInstruction(InstructionHandle ih, LinkedList<ExceptionRange> exnList) {
// we're a range instruction
Range r = Range.getRange(ih);
if (r instanceof ExceptionRange) {
// but I don't trust the only implementation, TreeSet, to do the right
// thing.
- /* private */static void insertHandler(ExceptionRange fresh, LinkedList l) {
+ /* private */static void insertHandler(ExceptionRange fresh, LinkedList<ExceptionRange> l) {
// Old implementation, simply: l.add(0,fresh);
- for (ListIterator iter = l.listIterator(); iter.hasNext();) {
- ExceptionRange r = (ExceptionRange) iter.next();
+ for (ListIterator<ExceptionRange> iter = l.listIterator(); iter.hasNext();) {
+ ExceptionRange r = iter.next();
// int freal = fresh.getRealStart().getPosition();
// int rreal = r.getRealStart().getPosition();
if (fresh.getPriority() >= r.getPriority()) {
*/
public void assertGoodBody() {
- if (true)
+ if (true) {
return; // only enable for debugging, consider using cheaper
+ }
// toString()
assertGoodBody(getBody(), toString()); // definingType.getNameAsIdentifier
// () + "." + getName());
if (true) {
return; // only to be enabled for debugging
}
- if (il == null)
+ if (il == null) {
return;
+ }
Set body = new HashSet();
Stack<Range> ranges = new Stack<Range>();
for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
if (r.getStart() == ih) {
ranges.push(r);
} else if (r.getEnd() == ih) {
- if (ranges.peek() != r)
+ if (ranges.peek() != r) {
throw new BCException("bad range inclusion in " + from);
+ }
ranges.pop();
}
}
}
private static void assertRangeHandle(InstructionHandle ih, String from) {
- if (!Range.isRangeHandle(ih))
+ if (!Range.isRangeHandle(ih)) {
throw new BCException("bad range handle " + ih + " in " + from);
+ }
}
private static void assertTargetedBy(InstructionHandle target, InstructionTargeter targeter, String from) {
Iterator tIter = target.getTargeters().iterator();
while (tIter.hasNext()) {
- if (((InstructionTargeter) tIter.next()) == targeter)
+ if (((InstructionTargeter) tIter.next()) == targeter) {
return;
+ }
}
throw new RuntimeException("bad targeting relationship in " + from);
}
private static void assertTargets(InstructionTargeter targeter, InstructionHandle target, String from) {
if (targeter instanceof Range) {
Range r = (Range) targeter;
- if (r.getStart() == target || r.getEnd() == target)
+ if (r.getStart() == target || r.getEnd() == target) {
return;
+ }
if (r instanceof ExceptionRange) {
- if (((ExceptionRange) r).getHandler() == target)
+ if (((ExceptionRange) r).getHandler() == target) {
return;
+ }
}
} else if (targeter instanceof InstructionBranch) {
InstructionBranch bi = (InstructionBranch) targeter;
- if (bi.getTarget() == target)
+ if (bi.getTarget() == target) {
return;
+ }
if (targeter instanceof InstructionSelect) {
InstructionSelect sel = (InstructionSelect) targeter;
InstructionHandle[] itargets = sel.getTargets();
for (int k = itargets.length - 1; k >= 0; k--) {
- if (itargets[k] == target)
+ if (itargets[k] == target) {
return;
+ }
}
}
} else if (targeter instanceof Tag) {
while (tIter.hasNext()) {
InstructionTargeter ts = (InstructionTargeter) tIter.next();
if (ts instanceof Range) {
- if (ret != null)
+ if (ret != null) {
throw new BCException("range handle with multiple ranges in " + from);
+ }
ret = (Range) ts;
}
}
- if (ret == null)
+ if (ret == null) {
throw new BCException("range handle with no range in " + from);
+ }
return ret;
}
// ----
boolean isAdviceMethod() {
- if (memberView == null)
+ if (memberView == null) {
return false;
+ }
return memberView.getAssociatedShadowMunger() != null;
}
boolean isAjSynthetic() {
- if (memberView == null)
+ if (memberView == null) {
return true;
+ }
return memberView.isAjSynthetic();
}
boolean isSynthetic() {
- if (memberView == null)
+ if (memberView == null) {
return false;
+ }
return memberView.isSynthetic();
}
public ISourceLocation getSourceLocation() {
- if (memberView != null)
+ if (memberView != null) {
return memberView.getSourceLocation();
+ }
return null;
}
public AjAttribute.EffectiveSignatureAttribute getEffectiveSignature() {
// if (memberView == null) return null;
- if (effectiveSignature != null)
+ if (effectiveSignature != null) {
return effectiveSignature;
+ }
return memberView.getEffectiveSignature();
}
}
public String getSignature() {
- if (memberView != null)
+ if (memberView != null) {
return memberView.getSignature();
+ }
return MemberImpl.typesToSignature(BcelWorld.fromBcel(getReturnType()), BcelWorld.fromBcel(getArgumentTypes()), false);
}
public String getParameterSignature() {
- if (memberView != null)
+ if (memberView != null) {
return memberView.getParameterSignature();
+ }
return MemberImpl.typesToSignature(BcelWorld.fromBcel(getArgumentTypes()));
}