Search in sources :

Example 1 with NewInstance

use of org.candle.decompiler.intermediate.expression.NewInstance in project candle-decompiler by bradsdavis.

the class MethodIntermediateVisitor method visitNEW.

// New object instances.
public void visitNEW(NEW instruction) {
    ObjectType type = instruction.getLoadClassType(this.context.getMethodGen().getConstantPool());
    Type t = instruction.getType(this.context.getMethodGen().getConstantPool());
    LOG.debug("New object: " + t + ", " + type);
    NewInstance instance = new NewInstance(context.getCurrentInstruction(), type);
    context.getExpressions().push(instance);
}
Also used : OperationType(org.candle.decompiler.intermediate.expression.OperationType) ArithmeticType(org.candle.decompiler.intermediate.expression.ArithmeticType) NewInstance(org.candle.decompiler.intermediate.expression.NewInstance)

Example 2 with NewInstance

use of org.candle.decompiler.intermediate.expression.NewInstance in project candle-decompiler by bradsdavis.

the class MethodIntermediateVisitor method visitINVOKESPECIAL.

public void visitINVOKESPECIAL(INVOKESPECIAL instruction) {
    LOG.debug("Invoking special.");
    Type[] types = instruction.getArgumentTypes(context.getMethodGen().getConstantPool());
    final List<Expression> parameters = new ArrayList<Expression>(types.length);
    for (int i = 0, j = types.length; i < j; i++) {
        Expression param = context.getExpressions().pop();
        LOG.debug("Parameter: " + param);
        parameters.add(param);
    }
    // now, get the target that we are calling the method on.
    Expression target = context.getExpressions().pop();
    // collect the method name we are calling.
    String methodName = instruction.getMethodName(context.getMethodGen().getConstantPool());
    MethodInvocation methodInvocation = null;
    // create the expression..
    if (StringUtils.equals(Constants.CONSTRUCTOR_NAME, methodName)) {
        LOG.debug(target.getClass());
        // TODO: Figure out why the dup / new causes issues.
        if (target instanceof NewInstance) {
            // get rid of this.
            context.getExpressions().pop();
        }
        methodInvocation = new ConstructorInvocation(context.getCurrentInstruction(), target, methodName, parameters);
    } else {
        methodInvocation = new MethodInvocation(context.getCurrentInstruction(), target, methodName, parameters);
    }
    LOG.debug("Pushing: " + methodInvocation);
    context.getExpressions().push(methodInvocation);
}
Also used : OperationType(org.candle.decompiler.intermediate.expression.OperationType) ArithmeticType(org.candle.decompiler.intermediate.expression.ArithmeticType) ConstructorInvocation(org.candle.decompiler.intermediate.expression.ConstructorInvocation) TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) ArrayList(java.util.ArrayList) MethodInvocation(org.candle.decompiler.intermediate.expression.MethodInvocation) NewInstance(org.candle.decompiler.intermediate.expression.NewInstance)

Example 3 with NewInstance

use of org.candle.decompiler.intermediate.expression.NewInstance in project candle-decompiler by bradsdavis.

the class ExpressionEnhancer method visitStatementIntermediate.

@Override
public void visitStatementIntermediate(StatementIntermediate line) {
    Expression exp = line.getExpression();
    // ok, now we can visit the expression...
    exp.visit(new ASTListener() {

        @Override
        public void accept(Expression e) {
            if (e instanceof NewInstance) {
                if (((NewInstance) e).getType() instanceof ObjectType) {
                    ObjectType obj = (ObjectType) ((NewInstance) e).getType();
                    if (StringUtils.equals("java.lang.StringBuilder", obj.getClassName())) {
                        System.out.println(obj.getClassName());
                    }
                }
            }
        }
    });
}
Also used : ObjectType(org.apache.bcel.generic.ObjectType) Expression(org.candle.decompiler.intermediate.expression.Expression) ASTListener(org.candle.decompiler.intermediate.expression.ASTListener) NewInstance(org.candle.decompiler.intermediate.expression.NewInstance)

Aggregations

NewInstance (org.candle.decompiler.intermediate.expression.NewInstance)3 ArithmeticType (org.candle.decompiler.intermediate.expression.ArithmeticType)2 Expression (org.candle.decompiler.intermediate.expression.Expression)2 OperationType (org.candle.decompiler.intermediate.expression.OperationType)2 ArrayList (java.util.ArrayList)1 ObjectType (org.apache.bcel.generic.ObjectType)1 ASTListener (org.candle.decompiler.intermediate.expression.ASTListener)1 ConstructorInvocation (org.candle.decompiler.intermediate.expression.ConstructorInvocation)1 MethodInvocation (org.candle.decompiler.intermediate.expression.MethodInvocation)1 TypedExpression (org.candle.decompiler.intermediate.expression.TypedExpression)1