Aufräumen, neue BCEL-Version
This commit is contained in:
parent
eb0da3c36a
commit
81c8764fc6
@ -1,6 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class BooleanValue {
|
||||
Boolean c = true;
|
||||
Boolean b = c.booleanValue();
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class BooleanValueCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public BooleanValueCreator() {
|
||||
_cg = new ClassGen("bcelifier.BooleanValue", "java.lang.Object", "BooleanValue.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createFields();
|
||||
createMethod_0();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createFields() {
|
||||
FieldGen field;
|
||||
|
||||
field = new FieldGen(0, new ObjectType("java.lang.Boolean"), "c", _cp);
|
||||
_cg.addField(field.getField());
|
||||
|
||||
field = new FieldGen(0, new ObjectType("java.lang.Boolean"), "b", _cp);
|
||||
_cg.addField(field.getField());
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.BooleanValue", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(new PUSH(_cp, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new Type[] { Type.BOOLEAN }, Constants.INVOKESTATIC));
|
||||
il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "c", new ObjectType("java.lang.Boolean"), Constants.PUTFIELD));
|
||||
InstructionHandle ih_12 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "c", new ObjectType("java.lang.Boolean"), Constants.GETFIELD));
|
||||
il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
|
||||
il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new Type[] { Type.BOOLEAN }, Constants.INVOKESTATIC));
|
||||
il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "b", new ObjectType("java.lang.Boolean"), Constants.PUTFIELD));
|
||||
InstructionHandle ih_26 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.BooleanValueCreator creator = new bcelifier.BooleanValueCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.BooleanValue.class"));
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class FieldDeclaration {
|
||||
|
||||
Integer field = methode();
|
||||
|
||||
Integer methode()
|
||||
{
|
||||
return field;
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class FieldDeclarationCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public FieldDeclarationCreator() {
|
||||
_cg = new ClassGen("bcelifier.FieldDeclaration", "java.lang.Object", "FieldDeclaration.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createFields();
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createFields() {
|
||||
FieldGen field;
|
||||
|
||||
field = new FieldGen(0, new ObjectType("java.lang.Integer"), "field", _cp);
|
||||
_cg.addField(field.getField());
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.FieldDeclaration", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("bcelifier.FieldDeclaration", "methode", new ObjectType("java.lang.Integer"), Type.NO_ARGS, Constants.INVOKEVIRTUAL));
|
||||
il.append(_factory.createFieldAccess("bcelifier.FieldDeclaration", "field", new ObjectType("java.lang.Integer"), Constants.PUTFIELD));
|
||||
InstructionHandle ih_12 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, new ObjectType("java.lang.Integer"), Type.NO_ARGS, new String[] { }, "methode", "bcelifier.FieldDeclaration", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createFieldAccess("bcelifier.FieldDeclaration", "field", new ObjectType("java.lang.Integer"), Constants.GETFIELD));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.OBJECT));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.FieldDeclarationCreator creator = new bcelifier.FieldDeclarationCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.FieldDeclaration.class"));
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
class IfStatement{
|
||||
Integer methode(Boolean b){
|
||||
if(b){
|
||||
return 1;
|
||||
}else{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.bytecode.MethodGenerator;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
|
||||
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class IfStatementCreator {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGenerator _cg;
|
||||
|
||||
public IfStatementCreator() {
|
||||
|
||||
TypeinferenceResults typeinferenceResults = null;
|
||||
_cg = new ClassGenerator("bcelifier.IfStatement", new RefType("java.lang.Object", null, 0), "IfStatement.java", Const.ACC_SUPER, new String[] { }, typeinferenceResults);
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGenerator(0, Type.VOID, new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "<init>", "bcelifier.IfStatement", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGenerator(0, new ObjectType("java.lang.Integer"), new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "methode", "bcelifier.IfStatement", il, _cp);
|
||||
|
||||
il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", Type.BOOLEAN, Type.NO_ARGS, Const.INVOKEVIRTUAL));
|
||||
BranchInstruction ifeq_4 = InstructionFactory.createBranchInstruction(Const.IFEQ, null);
|
||||
il.append(ifeq_4);
|
||||
il.append(new PUSH(_cp, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC));
|
||||
il.append(InstructionFactory.createReturn(Type.OBJECT));
|
||||
InstructionHandle ih_12 = il.append(new PUSH(_cp, 2));
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC));
|
||||
il.append(InstructionFactory.createReturn(Type.OBJECT));
|
||||
ifeq_4.setTarget(ih_12);
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.IfStatementCreator creator = new bcelifier.IfStatementCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.IfStatement.class"));
|
||||
|
||||
System.out.println("bcelifier.IfStatement.class");
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class IntLiteral {
|
||||
Integer methode(){
|
||||
return 50000;
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class IntLiteralCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public IntLiteralCreator() {
|
||||
_cg = new ClassGen("bcelifier.IntLiteral", "java.lang.Object", "IntLiteral.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.IntLiteral", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, new ObjectType("java.lang.Integer"), Type.NO_ARGS, new String[] { }, "methode", "bcelifier.IntLiteral", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(new PUSH(_cp, 50000));
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Constants.INVOKESTATIC));
|
||||
InstructionHandle ih_5 = il.append(_factory.createReturn(Type.OBJECT));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.IntLiteralCreator creator = new bcelifier.IntLiteralCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.IntLiteral.class"));
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.OpenOption;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.commons.bcel6.classfile.ClassFormatException;
|
||||
import org.apache.commons.bcel6.classfile.ClassParser;
|
||||
import org.apache.commons.bcel6.classfile.JavaClass;
|
||||
import org.apache.commons.bcel6.util.BCELifier;
|
||||
|
||||
public class JavaToBCEL {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/BCEL/bcelifier/";
|
||||
|
||||
public static void main(String args[]){
|
||||
new JavaToBCEL();
|
||||
}
|
||||
|
||||
public JavaToBCEL(){
|
||||
try {
|
||||
//new BCELifier(new ClassParser(rootDirectory+"Lambda1.class").parse(), new FileOutputStream(new File(rootDirectory+"Lambda1Creator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"This.class").parse(), new FileOutputStream(new File(rootDirectory+"ThisCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"IntLiteral.class").parse(), new FileOutputStream(new File(rootDirectory+"IntLiteralCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"MethodCall.class").parse(), new FileOutputStream(new File(rootDirectory+"MethodCallCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"FieldDeclaration.class").parse(), new FileOutputStream(new File(rootDirectory+"FieldDeclarationCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"LocalVarAccess.class").parse(), new FileOutputStream(new File(rootDirectory+"LocalVarAccessCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"Wildcard.class").parse(), new FileOutputStream(new File(rootDirectory+"WildcardCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"BooleanValue.class").parse(), new FileOutputStream(new File(rootDirectory+"BooleanValueCreator.java"))).start();
|
||||
//new BCELifier(new ClassParser(rootDirectory+"NewClass.class").parse(), new FileOutputStream(new File(rootDirectory+"NewClassCreator.java"))).start();
|
||||
new BCELifier(new ClassParser(rootDirectory+"IfStatement.class").parse(), new FileOutputStream(new File(rootDirectory+"IfStatementCreator.java"))).start();
|
||||
} catch (ClassFormatException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
@ -1,8 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class Lambda1 {
|
||||
|
||||
Runnable methode(){
|
||||
return ()->System.out.println(this);
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class LocalVarAccess {
|
||||
Integer methode(Integer i){
|
||||
Integer var;
|
||||
var = 10 + i;
|
||||
return var;
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class LocalVarAccessCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public LocalVarAccessCreator() {
|
||||
_cg = new ClassGen("bcelifier.LocalVarAccess", "java.lang.Object", "LocalVarAccess.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.LocalVarAccess", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, new ObjectType("java.lang.Integer"), new Type[] { new ObjectType("java.lang.Integer") }, new String[] { "arg0" }, "methode", "bcelifier.LocalVarAccess", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(new PUSH(_cp, 10));
|
||||
il.append(_factory.createLoad(Type.OBJECT, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "intValue", Type.INT, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
|
||||
il.append(InstructionConstants.IADD);
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Constants.INVOKESTATIC));
|
||||
il.append(_factory.createStore(Type.OBJECT, 2));
|
||||
InstructionHandle ih_11 = il.append(_factory.createLoad(Type.OBJECT, 2));
|
||||
InstructionHandle ih_12 = il.append(_factory.createReturn(Type.OBJECT));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.LocalVarAccessCreator creator = new bcelifier.LocalVarAccessCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.LocalVarAccess.class"));
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,12 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class MethodCall {
|
||||
void methode(){
|
||||
}
|
||||
|
||||
void methode2(Runnable r){
|
||||
methode();
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class MethodCallCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public MethodCallCreator() {
|
||||
_cg = new ClassGen("bcelifier.MethodCall", "java.lang.Object", "MethodCall.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
createMethod_2();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.MethodCall", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, Type.VOID, Type.NO_ARGS, new String[] { }, "methode", "bcelifier.MethodCall", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_2() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, Type.VOID, new Type[] { new ObjectType("java.lang.Runnable") }, new String[] { "arg0" }, "methode2", "bcelifier.MethodCall", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("bcelifier.MethodCall", "methode", Type.VOID, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createLoad(Type.OBJECT, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Runnable", "run", Type.VOID, Type.NO_ARGS, Constants.INVOKEINTERFACE));
|
||||
InstructionHandle ih_10 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.MethodCallCreator creator = new bcelifier.MethodCallCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.MethodCall.class"));
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
|
||||
public class NewClass {
|
||||
public NewClass(Integer i){}
|
||||
void methode2(){
|
||||
new NewClass(1);
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class NewClassCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public NewClassCreator() {
|
||||
_cg = new ClassGen("bcelifier.NewClass", "java.lang.Object", "NewClass.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, new Type[] { new ObjectType("java.lang.Integer") }, new String[] { "arg0" }, "<init>", "bcelifier.NewClass", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, Type.VOID, Type.NO_ARGS, new String[] { }, "methode2", "bcelifier.NewClass", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createNew("bcelifier.NewClass"));
|
||||
il.append(InstructionConstants.DUP);
|
||||
il.append(new PUSH(_cp, 1));
|
||||
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Constants.INVOKESTATIC));
|
||||
il.append(_factory.createInvoke("bcelifier.NewClass", "<init>", Type.VOID, new Type[] { new ObjectType("java.lang.Integer") }, Constants.INVOKESPECIAL));
|
||||
il.append(InstructionConstants.POP);
|
||||
InstructionHandle ih_12 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.NewClassCreator creator = new bcelifier.NewClassCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.NewClass.class"));
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class Null {
|
||||
|
||||
Integer i = null;
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class NullCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public NullCreator() {
|
||||
_cg = new ClassGen("bcelifier.Null", "java.lang.Object", "Null.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createFields();
|
||||
createMethod_0();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createFields() {
|
||||
FieldGen field;
|
||||
|
||||
field = new FieldGen(0, new ObjectType("java.lang.Integer"), "i", _cp);
|
||||
_cg.addField(field.getField());
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.Null", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(InstructionConstants.ACONST_NULL);
|
||||
il.append(_factory.createFieldAccess("bcelifier.Null", "i", new ObjectType("java.lang.Integer"), Constants.PUTFIELD));
|
||||
InstructionHandle ih_9 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.NullCreator creator = new bcelifier.NullCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.Null.class"));
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,8 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class This {
|
||||
|
||||
This methode(){
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class ThisCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public ThisCreator() {
|
||||
_cg = new ClassGen("bcelifier.This", "java.lang.Object", "This.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createMethod_0();
|
||||
createMethod_1();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.This", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
private void createMethod_1() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(0, new ObjectType("bcelifier.This"), Type.NO_ARGS, new String[] { }, "methode", "bcelifier.This", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
InstructionHandle ih_1 = il.append(_factory.createReturn(Type.OBJECT));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.ThisCreator creator = new bcelifier.ThisCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.This.class"));
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
public class Wildcard<A> {
|
||||
Wildcard<? super String> a;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package bcelifier;
|
||||
|
||||
import org.apache.commons.bcel6.generic.*;
|
||||
import org.apache.commons.bcel6.classfile.*;
|
||||
import org.apache.commons.bcel6.*;
|
||||
import java.io.*;
|
||||
|
||||
public class WildcardCreator implements Constants {
|
||||
private InstructionFactory _factory;
|
||||
private ConstantPoolGen _cp;
|
||||
private ClassGen _cg;
|
||||
|
||||
public WildcardCreator() {
|
||||
_cg = new ClassGen("bcelifier.Wildcard", "java.lang.Object", "Wildcard.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
||||
|
||||
_cp = _cg.getConstantPool();
|
||||
_factory = new InstructionFactory(_cg, _cp);
|
||||
}
|
||||
|
||||
public void create(OutputStream out) throws IOException {
|
||||
createFields();
|
||||
createMethod_0();
|
||||
_cg.getJavaClass().dump(out);
|
||||
}
|
||||
|
||||
private void createFields() {
|
||||
FieldGen field;
|
||||
|
||||
field = new FieldGen(0, new ObjectType("bcelifier.Wildcard"), "a", _cp);
|
||||
_cg.addField(field.getField());
|
||||
}
|
||||
|
||||
private void createMethod_0() {
|
||||
InstructionList il = new InstructionList();
|
||||
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.Wildcard", il, _cp);
|
||||
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
||||
method.setMaxStack();
|
||||
method.setMaxLocals();
|
||||
_cg.addMethod(method.getMethod());
|
||||
il.dispose();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bcelifier.WildcardCreator creator = new bcelifier.WildcardCreator();
|
||||
creator.create(new FileOutputStream("bcelifier.Wildcard.class"));
|
||||
}
|
||||
}
|
Binary file not shown.
@ -87,6 +87,7 @@ public class MethodGenerator extends MethodGen{
|
||||
|
||||
method.addAttribute(factory.createSignatureAttribute(paramTypesSig+retTypeSig));
|
||||
|
||||
System.out.println(this.getInstructionList().size());
|
||||
StackMap stackMap = new StackMapTableGen(this, cp).getStackMap();
|
||||
if(stackMap != null)method.addCodeAttribute(stackMap);
|
||||
|
||||
|
@ -23,8 +23,8 @@ public class EinzelElement<A> implements KomplexeMenge<A>{
|
||||
Menge<A> i = new Menge<A>();
|
||||
i.add(item);
|
||||
ret.add(i);
|
||||
//return ret;
|
||||
throw new NotImplementedException();
|
||||
return ret;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,4 +1,5 @@
|
||||
class WhileTest{
|
||||
|
||||
void method(){
|
||||
Integer i;
|
||||
i = 1;
|
||||
|
@ -21,7 +21,6 @@ public class WhileTest extends SourceFileBytecodeTest{
|
||||
|
||||
Class cls = classLoader.loadClass(testName);
|
||||
|
||||
Object obj = cls.newInstance();
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user