javassist.expr.NewExpr Java Examples

The following examples show how to use javassist.expr.NewExpr. 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: SourceTargetTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
protected String replaceInstrument(
        NewExpr expr,
        String statement)
        throws CannotCompileException {
    String replacement = getReplaceStatement(expr, statement);
    try {
        String s = replacement.replaceAll("\n", "");
        expr.replace(s);
    } catch (CannotCompileException e) {
        Logger.error("Replace new expr instrument error with statement: "
                + statement + "\n", e);
        throw e;
    }
    return replacement;
}
 
Example #6
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 #7
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;
}
 
Example #8
Source File: ExprExecTransformer.java    From DroidAssist with Apache License 2.0 5 votes vote down vote up
protected boolean execute(
        CtClass inputClass,
        String inputClassName,
        NewExpr newExpr)
        throws CannotCompileException, NotFoundException {
    return false;
}
 
Example #9
Source File: CampfireThirstPatch.java    From jorbs-spire-mod with MIT License 5 votes vote down vote up
public static ExprEditor Instrument() {
   return new ExprEditor() {
       public void edit(NewExpr e) throws CannotCompileException {
           // Completely replace the rest option with thirst for Cull
           if(e.getClassName().equals("com.megacrit.cardcrawl.ui.campfire.RestOption")) {
                e.replace(String.format(
                        "{$_ = %1$s.getCullCampfireOption($proceed($$));}",
                        CampfireThirstPatch.class.getName()));
           }
       }
   };
}
 
Example #10
Source File: MatchFinderExprEditor.java    From ModTheSpire with MIT License 4 votes vote down vote up
@Override
public void edit(NewExpr expr) {
    doMatch(Expectation.NEW_EXPRESSION, expr);
}
 
Example #11
Source File: Matcher.java    From ModTheSpire with MIT License 4 votes vote down vote up
public boolean match(Expr toMatch) {
    NewExpr expr = (NewExpr) toMatch;

    return expr.getClassName().equals(className);
}