Example usage for org.eclipse.jdt.core.dom StringLiteral setEscapedValue

List of usage examples for org.eclipse.jdt.core.dom StringLiteral setEscapedValue

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom StringLiteral setEscapedValue.

Prototype

public void setEscapedValue(String token) 

Source Link

Document

Sets the string value of this literal node to the given string literal token.

Usage

From source file:ch.acanda.eclipse.pmd.java.resolution.optimization.AddEmptyStringQuickFix.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
protected boolean apply(final InfixExpression node) {
    final Expression rightOperand = node.getRightOperand();

    // "" + "abc" -> "abc"
    // "" + x.toString() -> x.toString()
    if (isString(rightOperand)) {
        return replace(node, copy(rightOperand));
    }/*w  ww .ja  v a 2s .  co  m*/

    // "" + 'a' -> "a"
    if (isCharacterLiteral(rightOperand)) {
        final AST ast = node.getAST();
        final StringLiteral stringLiteral = ast.newStringLiteral();
        final String escapedCharacter = ((CharacterLiteral) rightOperand).getEscapedValue();
        stringLiteral.setEscapedValue(convertToEscapedString(escapedCharacter));
        return replace(node, stringLiteral);
    }

    // "" + x -> String.valueOf(x)
    final AST ast = node.getAST();
    final MethodInvocation toString = ast.newMethodInvocation();
    toString.setExpression(ast.newSimpleName("String"));
    toString.setName(ast.newSimpleName("valueOf"));
    toString.arguments().add(copy(rightOperand));
    return replace(node, toString);
}

From source file:java5totext.input.JDTVisitor.java

License:Open Source License

@Override
public void endVisit(org.eclipse.jdt.core.dom.StringLiteral node) {
    StringLiteral element = (StringLiteral) this.binding.get(node);
    this.initializeNode(element, node);
    element.setValue(node.getLiteralValue());
    element.setEscapedValue(node.getEscapedValue());
}

From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java

License:Open Source License

@Override
public void endVisit(final org.eclipse.jdt.core.dom.StringLiteral node) {
    StringLiteral element = (StringLiteral) this.binding.get(node);
    initializeNode(element, node);//from   ww  w . j a v a2  s .c  om

    element.setEscapedValue(node.getEscapedValue());
}