use of org.eclipse.jdt.core.dom.CharacterLiteral in project che by eclipse.
the class ASTNodes method getEscapedCharacterLiteral.
/**
* Escapes a character value to a literal that can be used in Java source.
*
* @param ch
* the character value
* @return the escaped string
* @see org.eclipse.jdt.core.dom.CharacterLiteral#getEscapedValue()
*/
public static String getEscapedCharacterLiteral(char ch) {
CharacterLiteral characterLiteral = AST.newAST(ASTProvider.SHARED_AST_LEVEL).newCharacterLiteral();
characterLiteral.setCharValue(ch);
return characterLiteral.getEscapedValue();
}
use of org.eclipse.jdt.core.dom.CharacterLiteral in project eclipse-pmd by acanda.
the class AppendCharacterWithCharQuickFix method apply.
/**
* Replaces the string literal <code>"a"</code> in <code>buffer.append("a")</code> with the character literal
* <code>'a'</code>.
*/
@Override
protected boolean apply(final StringLiteral node) {
final CharacterLiteral character = node.getAST().newCharacterLiteral();
character.setEscapedValue(toCharValue(node.getEscapedValue()));
replace(node, character);
return true;
}
use of org.eclipse.jdt.core.dom.CharacterLiteral in project eclipse-pmd by acanda.
the class SimplifyStartsWithQuickFix method apply.
/**
* Rewrites <code>s.startsWith("a")</code> as <code>s.charAt(0) == 'a'</code>.
*/
@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;
}
use of org.eclipse.jdt.core.dom.CharacterLiteral in project whole by wholeplatform.
the class CompilationUnitBuilder method newLiteral.
public CharacterLiteral newLiteral(char value) {
CharacterLiteral str = ast.newCharacterLiteral();
str.setCharValue(value);
return str;
}
use of org.eclipse.jdt.core.dom.CharacterLiteral in project evosuite by EvoSuite.
the class TestExtractingVisitor method retrieveVariableReference.
/**
* <p>
* retrieveVariableReference
* </p>
*
* @param argument
* a {@link java.lang.Object} object.
* @param varType
* a {@link java.lang.Class} object.
* @return a {@link org.evosuite.testcase.VariableReference} object.
*/
protected VariableReference retrieveVariableReference(Object argument, Class<?> varType) {
if (argument instanceof ClassInstanceCreation) {
return retrieveVariableReference((ClassInstanceCreation) argument, varType);
}
if (argument instanceof VariableDeclarationFragment) {
return retrieveVariableReference((VariableDeclarationFragment) argument);
}
if (argument instanceof SimpleName) {
SimpleName simpleName = (SimpleName) argument;
lineNumber = testReader.getLineNumber(simpleName.getStartPosition());
return retrieveVariableReference(simpleName.resolveBinding(), varType);
}
if (argument instanceof IVariableBinding) {
return retrieveVariableReference((IVariableBinding) argument, varType);
}
if (argument instanceof PrefixExpression) {
return retrieveVariableReference((PrefixExpression) argument);
}
if (argument instanceof InfixExpression) {
return retrieveVariableReference((InfixExpression) argument, varType);
}
if (argument instanceof ExpressionStatement) {
ExpressionStatement exprStmt = (ExpressionStatement) argument;
Expression expression = exprStmt.getExpression();
return retrieveVariableReference(expression, varType);
}
if (argument instanceof NullLiteral) {
return retrieveVariableReference((NullLiteral) argument, varType);
}
if (argument instanceof StringLiteral) {
return retrieveVariableReference((StringLiteral) argument);
}
if (argument instanceof NumberLiteral) {
return retrieveVariableReference((NumberLiteral) argument);
}
if (argument instanceof CharacterLiteral) {
return retrieveVariableReference((CharacterLiteral) argument);
}
if (argument instanceof BooleanLiteral) {
return retrieveVariableReference((BooleanLiteral) argument);
}
if (argument instanceof ITypeBinding) {
if (varType != null) {
return new ValidVariableReference(testCase.getReference(), varType);
}
return new ValidVariableReference(testCase.getReference(), retrieveTypeClass(argument));
}
if (argument instanceof QualifiedName) {
return retrieveVariableReference((QualifiedName) argument);
}
if (argument instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) argument;
VariableReference result = retrieveResultReference(methodInvocation);
nestedCallResults.push(result);
return result;
}
if (argument instanceof ArrayCreation) {
return retrieveVariableReference((ArrayCreation) argument);
}
if (argument instanceof VariableDeclaration) {
return retrieveVariableReference((VariableDeclaration) argument);
}
if (argument instanceof ArrayAccess) {
// argument).getArray(), null);
return retrieveVariableReference((ArrayAccess) argument);
}
if (argument instanceof Assignment) {
return retrieveVariableReference(((Assignment) argument).getLeftHandSide(), null);
}
if (argument instanceof CastExpression) {
CastExpression castExpression = (CastExpression) argument;
VariableReference result = retrieveVariableReference(castExpression.getExpression(), null);
Class<?> castClass = retrieveTypeClass(castExpression.resolveTypeBinding());
assert castClass.isAssignableFrom(toClass(result.getType()));
result.setType(castClass);
return result;
}
throw new UnsupportedOperationException("Argument type " + argument.getClass() + " not implemented!");
}
Aggregations