List of usage examples for org.eclipse.jdt.core.dom CharacterLiteral setEscapedValue
public void setEscapedValue(String value)
From source file:ch.acanda.eclipse.pmd.java.resolution.optimization.SimplifyStartsWithQuickFix.java
License:Open Source License
/** * Rewrites <code>s.startsWith("a")</code> as <code>s.charAt(0) == 'a'</code>. *///from w ww.j a v a 2 s . com @Override @SuppressWarnings("unchecked") protected boolean apply(final MethodInvocation node) { final AST ast = node.getAST(); final MethodInvocation charAt = ast.newMethodInvocation(); charAt.setExpression(copy(node.getExpression())); charAt.setName(ast.newSimpleName("charAt")); charAt.arguments().add(ast.newNumberLiteral("0")); final CharacterLiteral character = ast.newCharacterLiteral(); final StringLiteral s = (StringLiteral) node.arguments().get(0); character.setEscapedValue(s.getEscapedValue().replace('"', '\'')); final InfixExpression eq = ast.newInfixExpression(); eq.setOperator(Operator.EQUALS); eq.setLeftOperand(charAt); eq.setRightOperand(character); replace(node, eq); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.stringandstringbuffer.AppendCharacterWithCharQuickFix.java
License:Open Source License
/** * Replaces the string literal <code>"a"</code> in <code>buffer.append("a")</code> with the character literal * <code>'a'</code>.// w ww. j av a 2 s.c o m */ @Override protected boolean apply(final StringLiteral node) { final CharacterLiteral character = node.getAST().newCharacterLiteral(); character.setEscapedValue(toCharValue(node.getEscapedValue())); replace(node, character); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.stringandstringbuffer.UseIndexOfCharQuickFix.java
License:Open Source License
/** * Replaces the string literal <code>"a"</code> in <code>s.indexOf("a")</code> with the character literal * <code>'a'</code>.//from ww w .ja va 2s . c o m */ @Override protected boolean apply(final MethodInvocation node) { @SuppressWarnings("unchecked") final List<Expression> arguments = node.arguments(); if (arguments.size() == 1 && arguments.get(0) instanceof StringLiteral) { final CharacterLiteral character = node.getAST().newCharacterLiteral(); final StringLiteral string = (StringLiteral) arguments.get(0); character.setEscapedValue(toCharValue(string.getEscapedValue())); replace(string, character); return true; } return false; }
From source file:java5totext.input.JDTVisitor.java
License:Open Source License
@Override public void endVisit(org.eclipse.jdt.core.dom.CharacterLiteral node) { CharacterLiteral element = (CharacterLiteral) this.binding.get(node); this.initializeNode(element, node); 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.CharacterLiteral node) { CharacterLiteral element = (CharacterLiteral) this.binding.get(node); initializeNode(element, node);/*w w w. j a va 2 s. com*/ element.setEscapedValue(node.getEscapedValue()); }