}
/**
- * Compute maximum number of local variables.
+ * Compute maximum number of local variables based on the parameter count and bytecode usage of variables.
*/
public void setMaxLocals() {
+ setMaxLocals(false);
+ }
+
+ /**
+ * Compute maximum number of local variables.
+ *
+ * @param respectLocalVariableTable if true and the local variable table indicates more are in use
+ * than the code suggests, respect the higher value from the local variable table data.
+ */
+ public void setMaxLocals(boolean respectLocalVariableTable) {
if (il != null) {
int max = isStatic() ? 0 : 1;
}
}
}
-
- maxLocals = max;
+ if (!respectLocalVariableTable || max > maxLocals) {
+ maxLocals = max;
+ }
} else {
- maxLocals = 0;
+ if (!respectLocalVariableTable) {
+ maxLocals = 0;
+ }
}
}
import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IHierarchy;
import org.aspectj.asm.IProgramElement;
+import org.aspectj.asm.IRelationship;
import org.aspectj.asm.internal.Relationship;
import org.aspectj.testing.XMLBasedAjcTestCase;
"declare @method: int A.m() : @Fruit(\"orange\")");
assertTrue("Couldn't find 'declare @method' element in the tree", ipe != null);
- List l = asm.getRelationshipMap().get(ipe);
+ List<IRelationship> l = asm.getRelationshipMap().get(ipe);
assertTrue("Should have a relationship but does not ", l.size() > 0);
ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD,
"declare @field: int A.i : @Fruit(\"orange\")");
assertTrue("Couldn't find 'declare @type' element in the tree", ipe != null);
- List l = asm.getRelationshipMap().get(ipe);
+ List<IRelationship> l = asm.getRelationshipMap().get(ipe);
assertTrue("Should have a relationship but does not ", l.size() > 0);
ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD,
"declare @constructor: A.new(java.lang.String) : @Fruit(\"pear\")");
assertTrue("Couldn't find 'declare @constructor' element in the tree", ipe != null);
- List l = asm.getRelationshipMap().get(ipe);
+ List<IRelationship> l = asm.getRelationshipMap().get(ipe);
assertTrue("Should have a relationship but does not ", l.size() > 0);
ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR,
import org.aspectj.apache.bcel.util.SyntheticRepository;
import org.aspectj.testing.XMLBasedAjcTestCase;
import org.aspectj.tools.ajc.Ajc;
+import org.aspectj.weaver.ConcreteTypeMunger;
import org.aspectj.weaver.CrosscuttingMembers;
import org.aspectj.weaver.ReferenceType;
import org.aspectj.weaver.ResolvedMember;
.equals(sig));
}
- public List /* BcelTypeMunger */getTypeMunger(String classname) {
+ public List<ConcreteTypeMunger> getTypeMunger(String classname) {
ClassPath cp = new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path"));
recentWorld = new BcelWorld(cp.toString());
ReferenceType resolvedType = (ReferenceType) recentWorld.resolve(classname);
CrosscuttingMembers cmembers = resolvedType.collectCrosscuttingMembers(true);
- List tmungers = cmembers.getTypeMungers();
+ List<ConcreteTypeMunger> tmungers = cmembers.getTypeMungers();
return tmungers;
}
return null;
}
- public Hashtable getMeTheFields(String classname) {
+ public Hashtable<String,Field> getMeTheFields(String classname) {
JavaClass theClass = getClassFromDisk(ajc, classname);
- Hashtable retval = new Hashtable();
+ Hashtable<String,Field> retval = new Hashtable<>();
org.aspectj.apache.bcel.classfile.Field[] fs = theClass.getFields();
for (int i = 0; i < fs.length; i++) {
Field field = fs[i];
// Verifying what gets into a class targetted with a field ITD
public void testDesignF() {
runTest("generic itds - design F");
- Hashtable fields = getMeTheFields("C");
+ Hashtable<String,Field> fields = getMeTheFields("C");
// Declared in src as: List C.list1; and List<Z> C<Z>.list2;
Field list1 = (Field) fields.get("list1");// ajc$interField$$list1");
// Verifying what gets into a class when an interface it implements was targetted with a field ITD
public void testDesignG() {
runTest("generic itds - design G");
- Hashtable fields = getMeTheFields("C");
+ Hashtable<String,Field> fields = getMeTheFields("C");
// The ITDs are targetting an interface. That interface is generic and is parameterized with
// 'String' when implemented in the class C. This means the fields that make it into C should
* bridge methods have been created.
*/
public void checkMethodsExist(String classname,String[] methods) {
- Set methodsFound = new HashSet();
+ Set<String> methodsFound = new HashSet<>();
StringBuffer debugString = new StringBuffer();
try {
ClassLoader cl = new URLClassLoader(new URL[]{ajc.getSandboxDirectory().toURL()});
- Class clz = Class.forName(classname,false,cl);
+ Class<?> clz = Class.forName(classname,false,cl);
java.lang.reflect.Method[] ms = clz.getDeclaredMethods();
if (ms!=null) {
for (int i =0;i<ms.length;i++) {
}
StringBuffer unexpectedMethods = new StringBuffer();
if (!methodsFound.isEmpty()) {
- for (Iterator iter = methodsFound.iterator(); iter.hasNext();) {
- String element = (String) iter.next();
+ for (String element: methodsFound) {
unexpectedMethods.append("[").append(element).append("]");
}
fail("These methods weren't expected: "+unexpectedMethods);
return false;
}
try {
- final Class[] noparms = new Class[0];
+ final Class<?>[] noparms = new Class[0];
java.lang.reflect.Method isBridge
= java.lang.reflect.Method.class.getMethod("isBridge", noparms);
Boolean result = (Boolean) isBridge.invoke(m, new Object[0]);
public static void checkOneSignatureAttribute(Ajc ajc,String classname) {
JavaClass clazz = getClass(ajc,classname);
- Signature sigAttr = null;
Attribute[] attrs = clazz.getAttributes();
int signatureCount = 0;
StringBuffer sb = new StringBuffer();
sigAttr.getSignature().equals(sig));
}
- private static String stringify(Class[] clazzes) {
+ private static String stringify(Class<?>[] clazzes) {
if (clazzes==null) return "";
StringBuffer sb = new StringBuffer();
for (int i = 0; i < clazzes.length; i++) {
// }
/* For the specified class, check that each method has a stackmap attribute */
+ @SuppressWarnings("unused")
private void checkStackMapExistence(String classname, String toIgnore) throws ClassNotFoundException {
toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_";
JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
}
}
+ @SuppressWarnings("unused")
public void testMakeSJPOptimizationCollapsedSJPYes14() {
this.runTest("makeSJP optimization - Collapsed SJP - Yes 1.4");
try {
package org.aspectj.systemtest.ajc163;
import java.io.File;
-import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
if (whereToLook.getSourceLocation() != null && whereToLook.getSourceLocation().getLine() == line) {
return whereToLook;
}
- List kids = whereToLook.getChildren();
- for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
- IProgramElement object = (IProgramElement) iterator.next();
+ List<IProgramElement> kids = whereToLook.getChildren();
+ for (IProgramElement object: kids) {
if (object.getSourceLocation() != null && object.getSourceLocation().getLine() == line) {
return object;
}
import org.aspectj.apache.bcel.generic.InstructionFactory;
import org.aspectj.apache.bcel.generic.InstructionHandle;
import org.aspectj.apache.bcel.generic.InstructionList;
-import org.aspectj.apache.bcel.generic.InvokeDynamic;
import org.aspectj.apache.bcel.generic.LineNumberTag;
import org.aspectj.apache.bcel.generic.LocalVariableTag;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.WeaveMessage;
import org.aspectj.bridge.context.CompilationAndWeavingContext;
import org.aspectj.bridge.context.ContextToken;
-import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.AjcMemberMaker;
import org.aspectj.weaver.AnnotationAJ;
import org.aspectj.weaver.AnnotationOnTypeMunger;
} else {
packBody(gen);
}
- gen.setMaxLocals();
+
+ gen.setMaxLocals(true);
gen.setMaxStack();
} else {
gen.setInstructionList(null);
}
public void writeUnchangedBytes() throws IOException {
- writeWovenBytes(getBytes(), Collections.EMPTY_LIST);
+ writeWovenBytes(getBytes(), Collections.<ChildClass>emptyList());
}
- public void writeWovenBytes(byte[] bytes, List childClasses) throws IOException {
+ public void writeWovenBytes(byte[] bytes, List<ChildClass> childClasses) throws IOException {
writeChildClasses(childClasses);
// System.err.println("should write: " + getClassName());
package org.aspectj.weaver.bcel;
import java.lang.reflect.Modifier;
-import java.util.Objects;
-import java.util.function.Consumer;
import org.aspectj.weaver.Advice;
import org.aspectj.weaver.BcweaverTests;