Java Code Examples for javassist.expr.NewExpr#getClassName()

The following examples show how to use javassist.expr.NewExpr#getClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstructorCallTimingTransformer.java    From DroidAssist with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        NewExpr expr)
        throws CannotCompileException, NotFoundException {

    String insnClassName = expr.getClassName();
    String insnSignature = expr.getSignature();

    if (!isMatchConstructorSource(insnClassName, insnSignature)) {
        return false;
    }

    String statement = getDefaultTimingStatement(false, getTarget());
    String replacement = replaceInstrument(expr, statement);

    Logger.warning(getPrettyName() + " by: " + replacement
            + " at " + inputClassName + ".java" + ":" + expr.getLineNumber());
    return true;
}
 
Example 2
Source File: ConstructorCallAroundTransformer.java    From DroidAssist with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        NewExpr expr)
        throws CannotCompileException, NotFoundException {

    String insnClassName = expr.getClassName();
    String insnSignature = expr.getSignature();

    if (!isMatchConstructorSource(insnClassName, insnSignature)) {
        return false;
    }

    String before = getTargetBefore();
    String after = getTargetAfter();
    // "$_=$proceed($$);" represents the original method body
    String statement = "{" + before + "$_=$proceed($$);" + after + "}";
    String replacement = replaceInstrument(expr, statement);

    Logger.warning(getPrettyName() + " by: " + replacement
            + " at " + inputClassName + ".java" + ":" + expr.getLineNumber());
    return true;
}
 
Example 3
Source File: ConstructorCallTryCatchTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        NewExpr expr)
        throws CannotCompileException, NotFoundException {

    if (isMatchSourceClassName(inputClassName)) {
        return false;
    }

    String insnClassName = expr.getClassName();
    String insnSignature = expr.getSignature();

    if (!isMatchConstructorSource(insnClassName, insnSignature)) {
        return false;
    }

    String proceed = "$_=$proceed($$);";

    String statement = "try{" + proceed + "} catch (" + getException() + " e) {"
            + getTarget().replace("$e", "e") + "}";

    String replacement = replaceInstrument(expr, statement);

    Logger.warning(getPrettyName() + " by: " + replacement
            + " at " + inputClassName + ".java" + ":" + expr.getLineNumber());
    return true;
}
 
Example 4
Source File: SourceTargetTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
protected String getReplaceStatement(NewExpr expr, String statement) {
    int line = expr.getLineNumber();
    String name = "<init>";
    String className = expr.getClassName();
    String fileName = expr.getFileName();
    return getReplaceStatement(statement, line, name, className, fileName);
}
 
Example 5
Source File: ConstructorCallInsertTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        NewExpr newExpr)
        throws CannotCompileException, NotFoundException {

    String insnClassName = newExpr.getClassName();
    String insnSignature = newExpr.getSignature();

    if (!isMatchConstructorSource(insnClassName, insnSignature)) {
        return false;
    }
    String target = getTarget();

    if (!target.endsWith(";")) {
        target = target + ";";
    }
    String before = isAsBefore() ? target : "";
    String after = isAsAfter() ? target : "";
    String statement = "{" + before + "$_=$proceed($$);" + after + "}";
    String replacement = replaceInstrument(newExpr, statement);

    if (isAsBefore()) {
        Logger.warning(getPrettyName() + " by before: " + replacement
                + " at " + inputClassName + ".java" + ":" + newExpr.getLineNumber());
    }

    if (isAsAfter()) {
        Logger.warning(getPrettyName() + " by after: " + replacement
                + " at " + inputClassName + ".java" + ":" + newExpr.getLineNumber());
    }
    return true;
}
 
Example 6
Source File: ConstructorCallReplaceTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        NewExpr newExpr)
        throws CannotCompileException, NotFoundException {

    String insnClassName = newExpr.getClassName();
    String insnSignature = newExpr.getSignature();

    if (!isMatchConstructorSource(insnClassName, insnSignature)) {
        return false;
    }

    String target = getTarget();

    if (!target.startsWith("$_=") || !target.startsWith("$_ =")) {
        if (target.startsWith("{")) {
            target = "{" + "$_=" + target.substring(1);
        } else {
            target = "$_=" + target;
        }
    }

    String replacement = replaceInstrument(newExpr, target);

    Logger.warning(getPrettyName() + "by: " + replacement
            + " at " + inputClassName + ".java" + ":" + newExpr.getLineNumber());
    return true;
}