Example usage for com.google.gwt.dev.jjs.ast JStringLiteral getValue

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

Introduction

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

Prototype

public String getValue() 

Source Link

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 + "\".");
    }//from  w ww.j  a  va  2  s. 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);
}