Example usage for com.google.gwt.dev.jjs.ast JMethodCall JMethodCall

List of usage examples for com.google.gwt.dev.jjs.ast JMethodCall JMethodCall

Introduction

In this page you can find the example usage for com.google.gwt.dev.jjs.ast JMethodCall JMethodCall.

Prototype

public JMethodCall(SourceInfo info, JExpression instance, JMethod method, JType overrideReturnType) 

Source Link

Document

Create a method call whose type is overridden to the specified type, ignoring the return type of the target method.

Usage

From source file:rocket.logging.compiler.LoggingLevelByNameAssigner.java

License:Apache License

@Override
protected void adjustMethod(final JMethodCall methodCall, final Context context) {
    final JStringLiteral stringLiteral = (JStringLiteral) methodCall.getArgs().get(0);
    final String name = stringLiteral.getValue();

    final JClassType logger = this.getLevelLogger(name);
    if (null == logger) {
        throw new IllegalStateException("Unable to fetch logger for \"" + name + "\".");
    }/*w ww  .  j a v a  2s .  c om*/

    final JMethod loggerConstructor = this.findLevelLoggerConstructorMethod(logger);
    if (null == loggerConstructor) {
        throw new IllegalStateException("Unable to find constructor for type: " + logger);
    }

    // replace LoggerFactory.getLogger(String) with new XXXLevelLogger( new
    // WrappedLogger );
    final JClassType targetLogger = this.getTargetLogger(name);
    if (null == logger) {
        throw new IllegalStateException("Unable to fetch logger for \"" + name + "\".");
    }

    final JMethod targetLoggerConstructor = this.findTargetLoggerConstructorMethod(targetLogger);
    if (null == targetLoggerConstructor) {
        throw new IllegalStateException("Unable to find constructor for type: " + targetLogger);
    }

    // havent built new wrapped expression!
    final JProgram program = this.getProgram();

    final JNewInstance newTargetInstance = new JNewInstance(program, methodCall.getSourceInfo(), targetLogger);
    final JMethodCall callNewTargetInstance = new JMethodCall(program, methodCall.getSourceInfo(),
            newTargetInstance, targetLoggerConstructor);
    callNewTargetInstance.getArgs().add(program.getLiteralString(name));

    // inserts a new xxxLevelLogger( Logger )
    final JNewInstance newLevelLoggerInstance = new JNewInstance(program, methodCall.getSourceInfo(), logger);
    JMethodCall call = new JMethodCall(program, methodCall.getSourceInfo(), newLevelLoggerInstance,
            loggerConstructor);
    call.getArgs().add(callNewTargetInstance);

    context.replaceMe(call);
}

From source file:rocket.logging.compiler.NoneLoggingFactoryGetLoggerOptimiser.java

License:Apache License

@Override
protected void adjustMethod(final JMethodCall methodCall, final Context context) {
    final JClassType logger = this.getNoneLevelLogger();
    final JMethod loggerConstructor = this.findLevelLoggerConstructorMethod(logger);
    log("loggerConstructor -> " + loggerConstructor);

    // inserts a new xxxLevelLogger( Logger )
    final JProgram program = this.getProgram();
    final JNewInstance noneLevelLogger = new JNewInstance(program, methodCall.getSourceInfo(), logger);
    JMethodCall call = new JMethodCall(program, methodCall.getSourceInfo(), noneLevelLogger, loggerConstructor);

    context.replaceMe(call);//from  w w w .  j  av a  2  s  .  c  o m
}