List of usage examples for org.eclipse.jdt.core.dom StringLiteral setEscapedValue
public void setEscapedValue(String token)
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()); }