use of org.eclipse.jdt.core.dom.NumberLiteral in project AutoRefactor by JnRouvignac.
the class BigNumberCleanUp method visit.
@Override
public boolean visit(final MethodInvocation visited) {
if (visited.getExpression() == null) {
return true;
}
if (getJavaMinorVersion() >= 5 && (ASTNodes.usesGivenSignature(visited, BigInteger.class.getCanonicalName(), "valueOf", // $NON-NLS-1$
long.class.getSimpleName()) || // $NON-NLS-1$
ASTNodes.usesGivenSignature(// $NON-NLS-1$
visited, // $NON-NLS-1$
BigDecimal.class.getCanonicalName(), // $NON-NLS-1$
"valueOf", long.class.getSimpleName()) || // $NON-NLS-1$
ASTNodes.usesGivenSignature(// $NON-NLS-1$
visited, // $NON-NLS-1$
BigDecimal.class.getCanonicalName(), // $NON-NLS-1$
"valueOf", double.class.getSimpleName()))) {
ITypeBinding typeBinding = visited.getExpression().resolveTypeBinding();
Expression arg0 = (Expression) visited.arguments().get(0);
if (arg0 instanceof NumberLiteral) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String token = ((NumberLiteral) arg0).getToken().replaceFirst("[lLfFdD]$", "").replace("_", "");
if (token.contains(".") && ASTNodes.hasType(typeBinding, BigDecimal.class.getCanonicalName())) {
// $NON-NLS-1$
TextEditGroup group = new TextEditGroup(MultiFixMessages.BigNumberCleanUp_description);
ASTRewrite rewrite = cuRewrite.getASTRewrite();
rewrite.replace(visited, getClassInstanceCreatorNode(visited.getExpression(), token), group);
} else if (JavaConstants.ZERO_LONG_LITERAL_RE.matcher(token).matches()) {
// $NON-NLS-1$
replaceWithQualifiedName(visited, typeBinding, "ZERO");
} else if (JavaConstants.ONE_LONG_LITERAL_RE.matcher(token).matches()) {
// $NON-NLS-1$
replaceWithQualifiedName(visited, typeBinding, "ONE");
} else if (JavaConstants.TEN_LONG_LITERAL_RE.matcher(token).matches()) {
// $NON-NLS-1$
replaceWithQualifiedName(visited, typeBinding, "TEN");
} else {
return true;
}
return false;
}
}
return true;
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project AutoRefactor by JnRouvignac.
the class ObsoleteUppercaseNumberSuffixRatherThanLowercaseCleanUp method useUppercase.
private void useUppercase(final NumberLiteral node, final String token) {
ASTRewrite rewrite = cuRewrite.getASTRewrite();
ASTNodeFactory ast = cuRewrite.getASTBuilder();
TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteUppercaseNumberSuffixRatherThanLowercaseCleanUp_description);
String newToken = token.substring(0, token.length() - 1) + token.substring(token.length() - 1).toUpperCase();
NumberLiteral replacement = ast.newNumberLiteral(newToken);
ASTNodes.replaceButKeepComment(rewrite, node, replacement, group);
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final ArrayAccess node) {
Expression _index = node.getIndex();
if ((_index instanceof NumberLiteral)) {
node.getArray().accept(this);
this.appendToBuffer(".get(");
node.getIndex().accept(this);
this.appendToBuffer(")");
} else {
final String arrayname = this.computeArrayName(node);
StringConcatenation _builder = new StringConcatenation();
_builder.append("{val _rdIndx_");
_builder.append(arrayname);
_builder.append("=");
this.appendToBuffer(_builder.toString());
node.getIndex().accept(this);
this.appendSpaceToBuffer();
node.getArray().accept(this);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append(".get(_rdIndx_");
_builder_1.append(arrayname);
_builder_1.append(")}");
this.appendToBuffer(_builder_1.toString());
}
return false;
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project evosuite by EvoSuite.
the class TestExtractingVisitor method retrieveTypeClass.
/**
* <p>
* retrieveTypeClass
* </p>
*
* @param argument
* a {@link java.lang.Object} object.
* @return a {@link java.lang.Class} object.
*/
protected Class<?> retrieveTypeClass(Object argument) {
assert argument != null;
if (argument instanceof SimpleType) {
SimpleType simpleType = (SimpleType) argument;
return retrieveTypeClass(simpleType);
}
if (argument instanceof ITypeBinding) {
ITypeBinding binding = (ITypeBinding) argument;
return retrieveTypeClass(binding);
}
if (argument instanceof IVariableBinding) {
IVariableBinding variableBinding = (IVariableBinding) argument;
return retrieveTypeClass(variableBinding.getType());
}
if (argument instanceof SimpleName) {
SimpleName simpleName = (SimpleName) argument;
return retrieveTypeClass(simpleName.resolveBinding());
}
if (argument instanceof StringLiteral) {
return String.class;
}
if (argument instanceof NumberLiteral) {
return retrieveTypeClass((NumberLiteral) argument);
}
if (argument instanceof PrimitiveType) {
PrimitiveType primitiveType = (PrimitiveType) argument;
String typeCode = primitiveType.getPrimitiveTypeCode().toString();
Class<?> result = PRIMITIVE_TYPECODE_MAPPING.get(typeCode);
assert result != null : "Could not resolve typecode " + typeCode + ".";
return result;
}
if (argument instanceof ArrayType) {
ArrayType arrayType = (ArrayType) argument;
return retrieveTypeClass(arrayType);
}
if (argument instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) argument;
return retrieveTypeClass(parameterizedType.getType());
}
if (argument instanceof VariableDeclarationFragment) {
VariableDeclarationFragment varDeclFrgmnt = (VariableDeclarationFragment) argument;
return retrieveTypeClass(varDeclFrgmnt.resolveBinding());
}
if (argument instanceof InfixExpression) {
InfixExpression infixExpr = (InfixExpression) argument;
ITypeBinding refTypeBinding = infixExpr.resolveTypeBinding();
if (refTypeBinding != null) {
return retrieveTypeClass(refTypeBinding);
} else {
throw new RuntimeException("Could not determine type class of infix expression '" + infixExpr + "'.");
}
}
if (argument instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) argument;
ITypeBinding typeBinding = methodInvocation.resolveTypeBinding();
if (typeBinding != null) {
return retrieveTypeClass(typeBinding);
}
Expression typeExpression = methodInvocation.getExpression();
if (typeExpression instanceof MethodInvocation) {
MethodInvocation parentMethodInvocation = (MethodInvocation) typeExpression;
IMethodBinding parentMethodBinding = parentMethodInvocation.resolveMethodBinding();
return retrieveTypeClass(parentMethodBinding.getDeclaringClass());
} else {
return retrieveTypeClass(typeExpression);
}
}
if (argument instanceof ArrayAccess) {
ArrayAccess arrayAccess = (ArrayAccess) argument;
return retrieveTypeClass(arrayAccess.getArray());
}
if (argument instanceof Class<?>) {
return (Class<?>) argument;
}
if (argument instanceof ClassInstanceCreation) {
return retrieveTypeClass(((ClassInstanceCreation) argument).resolveTypeBinding());
}
if (argument instanceof BooleanLiteral) {
return Boolean.TYPE;
}
throw new UnsupportedOperationException("Retrieval of type " + argument.getClass() + " not implemented yet!");
}
use of org.eclipse.jdt.core.dom.NumberLiteral in project evosuite by EvoSuite.
the class TestExtractingVisitor method retrieveVariableReference.
private VariableReference retrieveVariableReference(PrefixExpression prefixExpr, Class<?> numberClass) {
if (prefixExpr.getOperator() == org.eclipse.jdt.core.dom.PrefixExpression.Operator.MINUS) {
NumberLiteral numberLiteral = (NumberLiteral) prefixExpr.getOperand();
Number value = (Number) numberLiteral.resolveConstantExpressionValue();
value = negate(value);
PrimitiveStatement<?> numberAssignment = createPrimitiveStatement(numberClass, value);
testCase.addStatement(numberAssignment);
return numberAssignment.getReturnValue();
}
throw new UnsupportedOperationException("Prefix " + prefixExpr + " not implemented!");
}
Aggregations