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

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

Introduction

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

Prototype

public final AST getAST() 

Source Link

Document

Returns this node's AST.

Usage

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 w  w . j  av a  2s .  co  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:com.google.currysrc.processors.ModifyStringLiterals.java

License:Apache License

@Override
public void process(Context context, CompilationUnit cu) {
    final ASTRewrite rewrite = context.rewrite();
    ASTVisitor visitor = new ASTVisitor(false /* visitDocTags */) {
        @Override//from  w w  w  .jav a 2 s.  com
        public boolean visit(StringLiteral node) {
            String literalValue = node.getLiteralValue();
            // TODO Replace with Pattern
            if (literalValue.contains(oldString)) {
                String newLiteralValue = literalValue.replace(oldString, newString);
                StringLiteral newLiteral = node.getAST().newStringLiteral();
                newLiteral.setLiteralValue(newLiteralValue);
                rewrite.replace(node, newLiteral, null /* editGorup */);
            }
            return false;
        }
    };
    cu.accept(visitor);
}

From source file:org.springframework.ide.vscode.boot.java.utils.ASTUtils.java

License:Open Source License

public static String getLiteralValue(StringLiteral node) {
    synchronized (node.getAST()) {
        return node.getLiteralValue();
    }//from   w  w w. ja  va2  s.  c  o  m
}