Commit 2e2e1adf authored by pcregut's avatar pcregut

Put Version tags in all the constructors as in ASM. Not sure it is worth the...

Put Version tags in all the constructors as in ASM. Not sure it is worth the pain. Future testing nightmare ahead !
parent 1a0896e6
......@@ -51,6 +51,11 @@ package org.ow2.asmdex;
*/
public abstract class AnnotationVisitor {
/**
* The ASM API version implemented by this visitor.
*/
final protected int api;
/**
* The annotation visitor to which this visitor must delegate method calls.
* May be null.
......@@ -61,7 +66,9 @@ public abstract class AnnotationVisitor {
* Constructs a new {@link AnnotationVisitor}.
*
*/
public AnnotationVisitor() { }
public AnnotationVisitor(final int api) {
this.api = api;
}
/**
* Constructs a new {@link AnnotationVisitor}.
......@@ -69,7 +76,8 @@ public abstract class AnnotationVisitor {
* @param av the annotation visitor to which this visitor must delegate
* method calls. May be null.
*/
public AnnotationVisitor(final AnnotationVisitor av) {
public AnnotationVisitor(final int api, final AnnotationVisitor av) {
this.api = api;
this.av = av;
}
/**
......
......@@ -112,6 +112,7 @@ public class AnnotationWriter extends AnnotationVisitor {
* @param annotationItem the Annotation Item to visit.
*/
public AnnotationWriter(ConstantPool constantPool, AnnotationItem annotationItem) {
super(Opcodes.ASM4);
this.constantPool = constantPool;
this.annotationItem = annotationItem;
}
......
......@@ -181,6 +181,7 @@ public class ApplicationReader {
*/
private static enum VisitorType { classVisitor, methodVisitor, fieldVisitor };
protected int api;
// ------------------------------------------------------------------------
// Constructors
......@@ -190,8 +191,8 @@ public class ApplicationReader {
* Constructs a new {@link ApplicationReader} object.
* @param byteCode the bytecode of the application to be read.
*/
public ApplicationReader(final byte[] byteCode) {
this(byteCode, 0, byteCode.length);
public ApplicationReader(final int api, final byte[] byteCode) {
this(api, byteCode, 0, byteCode.length);
}
/**
......@@ -200,7 +201,7 @@ public class ApplicationReader {
* @param startOffset the start offset of the application data.
* @param length the length of the application data.
*/
public ApplicationReader(final byte[] byteCode, final int startOffset, final int length) {
public ApplicationReader(final int api, final byte[] byteCode, final int startOffset, final int length) {
// Uses the byteCode array as-is for parsing the header, unless an
// offset and different length were requested, in which case we
......@@ -227,8 +228,8 @@ public class ApplicationReader {
* @param inputStream an input stream from which to read the application.
* @throws IOException if a problem occurs during reading.
*/
public ApplicationReader(final InputStream inputStream ) throws IOException {
this(readApplication(inputStream));
public ApplicationReader(final int api, final InputStream inputStream ) throws IOException {
this(api, readApplication(inputStream));
}
/**
......@@ -236,9 +237,9 @@ public class ApplicationReader {
* @param fileName name and path of the application (DEX) to be read.
* @throws IOException if an exception occurs during reading.
*/
public ApplicationReader(final String fileName) throws IOException {
public ApplicationReader(int api, final String fileName) throws IOException {
// Opens as an InputStream the file whose name is given.
this(readApplication(new FileInputStream(new File(fileName))));
this(api, readApplication(new FileInputStream(new File(fileName))));
}
/**
......@@ -246,8 +247,8 @@ public class ApplicationReader {
* @param file the dex file to be read.
* @throws IOException if an exception occurs during reading.
*/
public ApplicationReader(final File file) throws IOException {
this(readApplication(new FileInputStream(file)));
public ApplicationReader(int api, final File file) throws IOException {
this(api, readApplication(new FileInputStream(file)));
}
......@@ -1247,7 +1248,7 @@ public class ApplicationReader {
ISpecificAnnotationParser specificAnnotationParser =
new ExceptionSpecificAnnotationParser(Constants.EXCEPTION_ANNOTATION_INTERNAL_NAME);
boolean foundAnnotation = parseSpecificAnnotations(new ExceptionAnnotationVisitor(), specificAnnotationParser);
boolean foundAnnotation = parseSpecificAnnotations(new ExceptionAnnotationVisitor(api), specificAnnotationParser);
return foundAnnotation ?
((ExceptionSpecificAnnotationParser)specificAnnotationParser).getExceptions()
......@@ -1264,7 +1265,7 @@ public class ApplicationReader {
ISpecificAnnotationParser specificAnnotationParser =
new DefaultAnnotationSpecificAnnotationParser(Constants.ANNOTATION_DEFAULT_INTERNAL_NAME);
boolean foundAnnotation = parseSpecificAnnotations(new DefaultAnnotationVisitor(), specificAnnotationParser);
boolean foundAnnotation = parseSpecificAnnotations(new DefaultAnnotationVisitor(api), specificAnnotationParser);
if (foundAnnotation) {
// We found a Default Annotation. However, this method was called as we were
// visiting a Class. But ASM calls the visitDefaultAnnotation for each Method
......@@ -1294,7 +1295,7 @@ public class ApplicationReader {
ISpecificAnnotationParser specificAnnotationParser =
new SignatureSpecificAnnotationParser(Constants.SIGNATURE_ANNOTATION_INTERNAL_NAME);
boolean foundAnnotation = parseSpecificAnnotations(new SignatureAnnotationVisitor(), specificAnnotationParser);
boolean foundAnnotation = parseSpecificAnnotations(new SignatureAnnotationVisitor(api), specificAnnotationParser);
if (foundAnnotation) {
result = ((SignatureSpecificAnnotationParser)specificAnnotationParser).getSignature();
}
......@@ -1313,7 +1314,7 @@ public class ApplicationReader {
ISpecificAnnotationParser specificAnnotationParser =
new MemberClassesSpecificAnnotationParser(Constants.MEMBER_CLASSES_ANNOTATION_INTERNAL_NAME);
boolean foundAnnotation = parseSpecificAnnotations(new MemberClassesAnnotationVisitor(), specificAnnotationParser);
boolean foundAnnotation = parseSpecificAnnotations(new MemberClassesAnnotationVisitor(api), specificAnnotationParser);
if (foundAnnotation) {
MemberClassesSpecificAnnotationParser parser = (MemberClassesSpecificAnnotationParser)specificAnnotationParser;
......@@ -1361,8 +1362,8 @@ public class ApplicationReader {
ISpecificAnnotationParser enclosingClassSpecificAnnotationParser =
new EnclosingClassSpecificAnnotationParser(Constants.ENCLOSING_CLASS_ANNOTATION_INTERNAL_NAME);
boolean foundFirstAnnotation = parseSpecificAnnotations(new InnerClassAnnotationVisitor(), innerClassSpecificAnnotationParser);
boolean foundSecondAnnotation = parseSpecificAnnotations(new EnclosingClassAnnotationVisitor(), enclosingClassSpecificAnnotationParser);
boolean foundFirstAnnotation = parseSpecificAnnotations(new InnerClassAnnotationVisitor(api), innerClassSpecificAnnotationParser);
boolean foundSecondAnnotation = parseSpecificAnnotations(new EnclosingClassAnnotationVisitor(api), enclosingClassSpecificAnnotationParser);
if (foundFirstAnnotation && foundSecondAnnotation) {
InnerClassSpecificAnnotationParser innerParser = (InnerClassSpecificAnnotationParser)innerClassSpecificAnnotationParser;
......@@ -1404,8 +1405,8 @@ public class ApplicationReader {
ISpecificAnnotationParser innerClassSpecificAnnotationParser =
new InnerClassSpecificAnnotationParser(Constants.INNER_CLASS_ANNOTATION_INTERNAL_NAME);
boolean foundFirstAnnotation = parseSpecificAnnotations(new EnclosingMethodAnnotationVisitor(), enclosingMethodSpecificAnnotationParser);
boolean foundSecondAnnotation = parseSpecificAnnotations(new InnerClassAnnotationVisitor(), innerClassSpecificAnnotationParser);
boolean foundFirstAnnotation = parseSpecificAnnotations(new EnclosingMethodAnnotationVisitor(api), enclosingMethodSpecificAnnotationParser);
boolean foundSecondAnnotation = parseSpecificAnnotations(new InnerClassAnnotationVisitor(api), innerClassSpecificAnnotationParser);
if (foundFirstAnnotation && foundSecondAnnotation) {
int methodId = ((EnclosingMethodSpecificAnnotationParser)enclosingMethodSpecificAnnotationParser).getClassId();
......
......@@ -46,12 +46,17 @@ public abstract class ApplicationVisitor {
* May be null.
*/
protected ApplicationVisitor av;
/**
* The ASM API version implemented by this visitor.
*/
final protected int api;
/**
* Constructs a new {@link ApplicationVisitor}.
*
*/
public ApplicationVisitor() { }
public ApplicationVisitor(final int api) { this.api = api; }
/**
* Constructs a new {@link ApplicationVisitor}.
......@@ -59,7 +64,8 @@ public abstract class ApplicationVisitor {
* @param av the application visitor to which this visitor must delegate
* method calls. May be null.
*/
public ApplicationVisitor(final ApplicationVisitor av) {
public ApplicationVisitor(final int api, final ApplicationVisitor av) {
this.api = api;
this.av = av;
}
......
......@@ -198,6 +198,7 @@ public class ApplicationWriter extends ApplicationVisitor {
* Constructs an new {@link ClassWriter}.
*/
public ApplicationWriter() {
super(Opcodes.ASM4);
}
/**
......@@ -222,6 +223,7 @@ public class ApplicationWriter extends ApplicationVisitor {
* bytecode where applicable.
*/
public ApplicationWriter(final ApplicationReader applicationReader) {
super(Opcodes.ASM4);
applicationReader.copyPool(this);
this.applicationReader = applicationReader;
}
......
......@@ -62,11 +62,16 @@ public abstract class ClassVisitor {
* be null.
*/
protected ClassVisitor cv;
/**
* The ASM API version implemented by this visitor.
*/
final protected int api;
/**
* Constructs a new {@link ClassVisitor}.
*/
public ClassVisitor() { }
public ClassVisitor(final int api) { this.api = api; }
/**
* Constructs a new {@link ClassVisitor}.
......@@ -74,7 +79,8 @@ public abstract class ClassVisitor {
* @param cv the class visitor to which this visitor must delegate method
* calls. May be null.
*/
public ClassVisitor(final ClassVisitor cv) {
public ClassVisitor(final int api, final ClassVisitor cv) {
this.api = api;
this.cv = cv;
}
......
......@@ -87,6 +87,7 @@ public class ClassWriter extends ClassVisitor {
*/
public ClassWriter(ApplicationWriter applicationWriter, ConstantPool constantPool, int access,
String name, String[] signature, String superName, String[] interfaces) {
super(Opcodes.ASM4);
this.applicationWriter = applicationWriter;
this.constantPool = constantPool;
classDefinitionItem = constantPool.addClassToConstantPool(name, superName, access,
......
......@@ -52,11 +52,18 @@ public abstract class FieldVisitor {
*/
protected FieldVisitor fv;
/**
* The ASM API version implemented by this visitor.
*/
final protected int api;
/**
* Constructs a new {@link FieldVisitor}.
*
*/
public FieldVisitor() { }
public FieldVisitor(final int api) {
this.api = api;
}
/**
* Constructs a new {@link FieldVisitor}.
......@@ -64,7 +71,8 @@ public abstract class FieldVisitor {
* @param fv the field visitor to which this visitor must delegate method
* calls. May be null.
*/
public FieldVisitor(final FieldVisitor fv) {
public FieldVisitor(final int api, final FieldVisitor fv) {
this.api = api;
this.fv = fv;
}
......
......@@ -60,7 +60,7 @@ public class FieldWriter extends FieldVisitor {
*/
public FieldWriter(ConstantPool constantPool, String classOwningName, int access,
String name, String desc, String[] signature, Object value) {
super(Opcodes.ASM4);
this.constantPool = constantPool;
// Registers the Field in the Field constant pool.
......
......@@ -87,10 +87,16 @@ public abstract class MethodVisitor {
*/
protected MethodVisitor mv;
/**
* The ASM API version implemented by this visitor.
*/
final protected int api;
/**
* Constructs a new {@link MethodVisitor}.
*/
public MethodVisitor() {
public MethodVisitor(final int api) {
this.api = api;
}
/**
......@@ -99,7 +105,8 @@ public abstract class MethodVisitor {
* @param mv the method visitor to which this visitor must delegate method
* calls. May be null.
*/
public MethodVisitor(final MethodVisitor mv) {
public MethodVisitor(final int api, final MethodVisitor mv) {
this.api = api;
this.mv = mv;
}
......
......@@ -146,7 +146,7 @@ public class MethodWriter extends MethodVisitor {
*/
public MethodWriter(ClassWriter classWriter, int access, String name,
String desc, String[] signature, String[] exceptions) {
super(Opcodes.ASM4);
this.classWriter = classWriter;
constantPool = classWriter.getConstantPool();
......
......@@ -38,6 +38,8 @@ package org.ow2.asmdex;
*/
public interface Opcodes {
public static final int ASM4 = 0x40000;
/**
* Spurious accessor used by the writer when it an instruction refers to a
* class, Method or a Field not parsed yet.
......
......@@ -43,6 +43,14 @@ import org.ow2.asmdex.AnnotationVisitor;
*/
public class DefaultAnnotationVisitor extends AnnotationVisitor {
/**
* Constructor.
* @param api the API level
*/
public DefaultAnnotationVisitor(int api) {
super(api);
}
private List<DefaultAnnotationInformation> infos = new ArrayList<DefaultAnnotationInformation>();
/**
......
......@@ -42,6 +42,14 @@ public class EnclosingClassAnnotationVisitor extends AnnotationVisitor {
private String className;
/**
* Constructor.
* @param api the API level
*/
public EnclosingClassAnnotationVisitor(int api) {
super(api);
}
/**
* Get the class name
* @return complete name
......
......@@ -41,6 +41,15 @@ import org.ow2.asmdex.AnnotationVisitor;
public class EnclosingMethodAnnotationVisitor extends AnnotationVisitor {
int methodId;
/**
* Constructor.
* @param api the API level
*/
public EnclosingMethodAnnotationVisitor(int api) {
super(api);
}
/**
* Get the class index in the class pool
* @return class index
......
......@@ -45,6 +45,14 @@ import org.ow2.asmdex.AnnotationVisitor;
*/
public class ExceptionAnnotationVisitor extends AnnotationVisitor {
/**
* Constructor.
* @param api the API level
*/
public ExceptionAnnotationVisitor(int api) {
super(api);
}
private List<String> classNames = new ArrayList<String>();
/**
* Get the class names of exceptions.
......
......@@ -43,6 +43,15 @@ public class InnerClassAnnotationVisitor extends AnnotationVisitor {
private int access;
private String simpleName;
/**
* Constructor.
* @param api the API level
*/
public InnerClassAnnotationVisitor(int api) {
super(api);
}
/**
* Get the access flags as a bitset
* @return integer coding the bitset
......
......@@ -44,6 +44,15 @@ import org.ow2.asmdex.AnnotationVisitor;
public class MemberClassesAnnotationVisitor extends AnnotationVisitor {
private List<String> innerClasses = new ArrayList<String>();
/**
* Constructor.
* @param api the API level
*/
public MemberClassesAnnotationVisitor(int api) {
super(api);
}
/**
* List of inner classes.
* @return list of names
......
......@@ -44,6 +44,15 @@ import org.ow2.asmdex.AnnotationVisitor;
public class SignatureAnnotationVisitor extends AnnotationVisitor {
private List<String> signature = new ArrayList<String>();
/**
* Constructor.
* @param api the API level
*/
public SignatureAnnotationVisitor(int api) {
super(api);
}
/**
* signature.
* @return list of string coding the signature
......
......@@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.util.List;
import org.ow2.asmdex.AnnotationVisitor;
import org.ow2.asmdex.Opcodes;
/**
* A node that represents an annotation.
......@@ -80,21 +81,42 @@ public class AnnotationNode extends AnnotationVisitor {
/**
* Constructs a new {@link AnnotationNode}.
*
* @param api the API level
* @param desc the class descriptor of the annotation class.
*/
public AnnotationNode(final String desc) {
public AnnotationNode(int api, final String desc) {
super(api);
this.desc = desc;
}
/**
* Constructs a new {@link AnnotationNode}.
*
* @param desc the class descriptor of the annotation class.
*/
public AnnotationNode(final String desc) {
this(Opcodes.ASM4, desc);
}
/**
* Constructs a new {@link AnnotationNode} to visit an array value.
*
* @param api the API level
* @param values where the visited values must be stored.
*/
public AnnotationNode(final List<Object> values) {
public AnnotationNode(int api, final List<Object> values) {
super(api);
this.values = values;
}
/**
* Constructs a new {@link AnnotationNode} to visit an array value.
*
* @param values where the visited values must be stored.
*/
public AnnotationNode(final List<Object> values) {
this(Opcodes.ASM4,values);
}
// ------------------------------------------------------------------------
// Visitor Methods.
......
......@@ -60,6 +60,13 @@ public class ApplicationNode extends ApplicationVisitor {
*/
public List<AnnotationNode> invisibleAnnotations;
/**
* Constructs a new {@link ApplicationNode}.
* @param api the API level
*/
public ApplicationNode(int api) {
super(api);
}
// ------------------------------------------------------
// Visitor Methods.
// ------------------------------------------------------
......
......@@ -39,6 +39,7 @@ import org.ow2.asmdex.AnnotationVisitor;
import org.ow2.asmdex.ClassVisitor;
import org.ow2.asmdex.FieldVisitor;
import org.ow2.asmdex.MethodVisitor;
import org.ow2.asmdex.Opcodes;
/**
* A node that represents a class.
......@@ -126,13 +127,15 @@ public class ClassNode extends ClassVisitor {
/**
* Constructs a new {@link ClassNode}.
*/
public ClassNode() {
public ClassNode(int api) {
super(api);
}
/**
* Constructs a new {@link ClassNode}.
*/
public ClassNode(int access, String name, String[] signature, String superName, String[] interfaces) {
public ClassNode(int api, int access, String name, String[] signature, String superName, String[] interfaces) {
super(api);
this.access = access;
this.name = name;
if (signature != null) {
......@@ -143,7 +146,13 @@ public class ClassNode extends ClassVisitor {
this.interfaces = Arrays.asList(interfaces);
}
}
/**
* Constructs a new {@link ClassNode}.
*/
public ClassNode(int access, String name, String[] signature, String superName, String[] interfaces) {
this(Opcodes.ASM4, access, name, signature, superName, interfaces);
}
// ------------------------------------------------------
// Visitor Methods.
......@@ -174,7 +183,7 @@ public class ClassNode extends ClassVisitor {
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
String[] signature, String[] exceptions) {
MethodNode n = new MethodNode(access, name, desc, signature, exceptions);
MethodNode n = new MethodNode(api, access, name, desc, signature, exceptions);
methods.add(n);
return n;
}
......
......@@ -37,6 +37,7 @@ import java.util.List;
import org.ow2.asmdex.AnnotationVisitor;
import org.ow2.asmdex.ClassVisitor;
import org.ow2.asmdex.FieldVisitor;
import org.ow2.asmdex.Opcodes;
/**
* A node that represents a field.
......@@ -87,6 +88,7 @@ public class FieldNode extends FieldVisitor {
/**
* Constructs a new {@link FieldNode}.
*
* @param api the API level
* @param access the field's access flags (see
* {@link org.ow2.asmdex.Opcodes}). This parameter also indicates
* if the field is synthetic.
......@@ -99,12 +101,14 @@ public class FieldNode extends FieldVisitor {
* {@link Double} or a {@link String}.
*/
public FieldNode(
final int api,
final int access,
final String name,
final String desc,
final String[] signature,
final Object value)
{
super(api);
this.access = access;
this.name = name;
this.desc = desc;
......@@ -112,6 +116,29 @@ public class FieldNode extends FieldVisitor {
this.value = value;
}
/**
* Constructs a new {@link FieldNode}.
*
* @param access the field's access flags (see
* {@link org.ow2.asmdex.Opcodes}). This parameter also indicates
* if the field is synthetic.
* @param name the field's name.
* @param desc the field's descriptor .
* @param signature the field's signature.
* @param value the field's initial value. This parameter, which may be
* <tt>null</tt> if the field does not have an initial value, must
* be an {@link Integer}, a {@link Float}, a {@link Long}, a
* {@link Double} or a {@link String}.
*/
public FieldNode(
final int access,
final String name,
final String desc,
final String[] signature,
final Object value)
{
this(Opcodes.ASM4, access,name, desc, signature, value);
}
// ------------------------------------------------------------------------
// Accept method
......
This diff is collapsed.
......@@ -51,9 +51,11 @@ public class AsmDexifierAnnotationVisitor extends AnnotationVisitor {
/**
* Constructs a new {@link AsmDexifierAnnotationVisitor}.
*
* @param api API level
* @param id identifier of the annotation visitor variable in the produced code.
*/
public AsmDexifierAnnotationVisitor(final int id, final int nbTabulations) {
public AsmDexifierAnnotationVisitor(final int api, final int id, final int nbTabulations) {
super(api);
this.id = id;
pr = new AsmDexPrinter();
pr.currentTabulation = nbTabulations;
......@@ -94,7 +96,7 @@ public class AsmDexifierAnnotationVisitor extends AnnotationVisitor {
pr.addEOL();
pr.closeText();
AsmDexifierAnnotationVisitor av = new AsmDexifierAnnotationVisitor(id + 1, pr.currentTabulation + 1);
AsmDexifierAnnotationVisitor av = new AsmDexifierAnnotationVisitor(api, id + 1, pr.currentTabulation + 1);
pr.addTextToList(av.getTextComponent());
pr.addTabulation();
......@@ -125,7 +127,7 @@ public class AsmDexifierAnnotationVisitor extends AnnotationVisitor {
pr.addEOL();
pr.closeText();
AsmDexifierAnnotationVisitor av = new AsmDexifierAnnotationVisitor(id + 1, pr.currentTabulation + 1);
AsmDexifierAnnotationVisitor av = new AsmDexifierAnnotationVisitor(api, id + 1, pr.currentTabulation + 1);
pr.addTextToList(av.getTextComponent());
pr.addTabulation();
......
......@@ -39,6 +39,7 @@ import java.util.ArrayList;
import org.ow2.asmdex.ApplicationReader;
import org.ow2.asmdex.ApplicationVisitor;
import org.ow2.asmdex.ClassVisitor;
import org.ow2.asmdex.Opcodes;
/**
* An {@link ApplicationVisitor} that prints the AsmDex code that generates the Application
......@@ -123,9 +124,11 @@ public class AsmDexifierApplicationVisitor extends ApplicationVisitor {
/**
* Constructs a new {@link AsmDexifierApplicationVisitor} object.
*
* @param api API level
* @param pw the print writer to be used to print the class.
*/
public AsmDexifierApplicationVisitor(final PrintWriter pw) {
public AsmDexifierApplicationVisitor(int api, final PrintWriter pw) {
super(api);
this.pw = pw;
pr = new AsmDexPrinter();
dumpMethods = new ArrayList<String>();
......@@ -135,14 +138,15 @@ public class AsmDexifierApplicationVisitor extends ApplicationVisitor {
/**
* Constructs a new {@link AsmDexifierApplicationVisitor} object.
*
* @param api API level
* @param pw the print writer to be used to print the class.
* @param packageName name of the package, or Null if none should be written.
* @param filenameOutput possible path and filename of the file where to save the output.
* If not Null, a Main method will be created.
*/
public AsmDexifierApplicationVisitor(final PrintWriter pw, final String packageName,
public AsmDexifierApplicationVisitor(int api, final PrintWriter pw, final String packageName,
final String filenameOutput) {
this(pw);
this(api, pw);
this.packageName = packageName;
this.filenameOutput = filenameOutput;
}
......@@ -212,8 +216,8 @@ public class AsmDexifierApplicationVisitor extends ApplicationVisitor {
}
}