use of org.eclipse.jdt.core.dom.QualifiedName in project AutoRefactor by JnRouvignac.
the class ObsoleteLambdaExpressionRatherThanComparatorCleanUp method isRefactorComparisonToRefactor.
private boolean isRefactorComparisonToRefactor(final AtomicReference<Expression> criteria, final AtomicBoolean isForward, final SimpleName name1, final SimpleName name2, final Expression expr1, final Expression expr2) {
MethodInvocation method1 = ASTNodes.as(expr1, MethodInvocation.class);
MethodInvocation method2 = ASTNodes.as(expr2, MethodInvocation.class);
QualifiedName field1 = ASTNodes.as(expr1, QualifiedName.class);
QualifiedName field2 = ASTNodes.as(expr2, QualifiedName.class);
if (method1 != null && Utils.isEmpty(method1.arguments()) && method2 != null && Utils.isEmpty(method2.arguments())) {
String methodName1 = method1.getName().getIdentifier();
String methodName2 = method2.getName().getIdentifier();
SimpleName objectExpr1 = ASTNodes.as(method1.getExpression(), SimpleName.class);
SimpleName objectExpr2 = ASTNodes.as(method2.getExpression(), SimpleName.class);
if (Utils.equalNotNull(methodName1, methodName2) && objectExpr1 != null && objectExpr2 != null) {
if (ASTNodes.isSameVariable(objectExpr1, name1) && ASTNodes.isSameVariable(objectExpr2, name2)) {
criteria.set(method1);
return true;
}
if (ASTNodes.isSameVariable(objectExpr1, name2) && ASTNodes.isSameVariable(objectExpr2, name1)) {
criteria.set(method1);
isForward.lazySet(!isForward.get());
return true;
}
}
} else if (field1 != null && field2 != null) {
SimpleName fieldName1 = field1.getName();
SimpleName fieldName2 = field2.getName();
SimpleName objectExpr1 = ASTNodes.as(field1.getQualifier(), SimpleName.class);
SimpleName objectExpr2 = ASTNodes.as(field2.getQualifier(), SimpleName.class);
if (ASTNodes.isSameVariable(fieldName1, fieldName2) && objectExpr1 != null && objectExpr2 != null) {
if (ASTNodes.isSameVariable(objectExpr1, name1) && ASTNodes.isSameVariable(objectExpr2, name2)) {
criteria.set(field1);
return true;
}
if (ASTNodes.isSameVariable(objectExpr1, name2) && ASTNodes.isSameVariable(objectExpr2, name1)) {
criteria.set(field1);
isForward.lazySet(!isForward.get());
return true;
}
}
}
return false;
}
use of org.eclipse.jdt.core.dom.QualifiedName in project AutoRefactor by JnRouvignac.
the class NamedMethodRatherThanLogLevelParameterCleanUp method visit.
@Override
public boolean visit(final MethodInvocation visited) {
if (ASTNodes.usesGivenSignature(visited, Logger.class.getCanonicalName(), "log", Level.class.getCanonicalName(), String.class.getCanonicalName())) {
// $NON-NLS-1$
List<Expression> args = visited.arguments();
if (args != null && args.size() == 2) {
QualifiedName levelType = ASTNodes.as(args.get(0), QualifiedName.class);
if (levelType != null) {
String methodName;
if (ASTNodes.isField(levelType, Level.class.getCanonicalName(), "SEVERE")) {
// $NON-NLS-1$
// $NON-NLS-1$
methodName = "severe";
} else if (ASTNodes.isField(levelType, Level.class.getCanonicalName(), "WARNING")) {
// $NON-NLS-1$
// $NON-NLS-1$
methodName = "warning";
} else if (ASTNodes.isField(levelType, Level.class.getCanonicalName(), "INFO")) {
// $NON-NLS-1$
// $NON-NLS-1$
methodName = "info";
} else if (ASTNodes.isField(levelType, Level.class.getCanonicalName(), "FINE")) {
// $NON-NLS-1$
// $NON-NLS-1$
methodName = "fine";
} else if (ASTNodes.isField(levelType, Level.class.getCanonicalName(), "FINER")) {
// $NON-NLS-1$
// $NON-NLS-1$
methodName = "finer";
} else if (ASTNodes.isField(levelType, Level.class.getCanonicalName(), "FINEST")) {
// $NON-NLS-1$
// $NON-NLS-1$
methodName = "finest";
} else {
return true;
}
replaceLevelByMethodName(visited, methodName);
return false;
}
}
}
return true;
}
use of org.eclipse.jdt.core.dom.QualifiedName in project AutoRefactor by JnRouvignac.
the class RemoveUnneededThisExpressionCleanUp method thisExpressionRefersToEnclosingType.
private static boolean thisExpressionRefersToEnclosingType(final Name thisQualifierName, final ASTNode node) {
if (thisQualifierName == null) {
return true;
}
ASTNode enclosingType = ASTNodes.getEnclosingType(node);
if (enclosingType instanceof AnonymousClassDeclaration) {
return false;
}
AbstractTypeDeclaration ancestor = (AbstractTypeDeclaration) enclosingType;
if (thisQualifierName instanceof SimpleName) {
return ASTNodes.isEqual((SimpleName) thisQualifierName, ancestor.getName());
}
if (thisQualifierName instanceof QualifiedName) {
QualifiedName qualifiedName = (QualifiedName) thisQualifierName;
return ASTNodes.isEqual(qualifiedName.getName(), ancestor.getName()) && thisExpressionRefersToEnclosingType(qualifiedName.getQualifier(), ancestor);
}
throw new NotImplementedException(thisQualifierName);
}
use of org.eclipse.jdt.core.dom.QualifiedName in project AutoRefactor by JnRouvignac.
the class AbstractPrimitiveRatherThanWrapperCleanUp method isNotNull.
private boolean isNotNull(final Expression expression) {
if (expression instanceof ParenthesizedExpression) {
ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression;
return isNotNull(parenthesizedExpression.getExpression());
}
if (expression instanceof ConditionalExpression) {
ConditionalExpression prefixExpression = (ConditionalExpression) expression;
return isNotNull(prefixExpression.getThenExpression()) && isNotNull(prefixExpression.getElseExpression());
}
if (getLiteralClass().equals(expression.getClass())) {
return true;
}
if (expression instanceof QualifiedName) {
QualifiedName qualifiedName = (QualifiedName) expression;
return ASTNodes.hasType(qualifiedName.getQualifier(), getWrapperFullyQualifiedName()) && (ASTNodes.isField(qualifiedName, getWrapperFullyQualifiedName(), getSafeInConstants()) || ASTNodes.isField(qualifiedName, getPrimitiveTypeName(), getSafeInConstants()));
}
if (expression instanceof InfixExpression) {
InfixExpression infixExpression = (InfixExpression) expression;
return getInfixInSafeOperators().contains(infixExpression.getOperator());
}
if (expression instanceof PrefixExpression) {
PrefixExpression prefixExpression = (PrefixExpression) expression;
return getPrefixInSafeOperators().contains(prefixExpression.getOperator());
}
if (expression instanceof PostfixExpression) {
PostfixExpression postfixExpression = (PostfixExpression) expression;
return getPostfixInSafeOperators().contains(postfixExpression.getOperator());
}
if (expression instanceof CastExpression) {
CastExpression castExpression = (CastExpression) expression;
return ASTNodes.hasType(castExpression.getType().resolveBinding(), getPrimitiveTypeName()) || ASTNodes.hasType(castExpression.getType().resolveBinding(), getWrapperFullyQualifiedName()) && isNotNull(castExpression.getExpression());
}
if (expression instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) expression;
return // $NON-NLS-1$
ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", getPrimitiveTypeName()) || getParsingMethodName(getWrapperFullyQualifiedName()) != null && (// $NON-NLS-1$
ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", String.class.getCanonicalName()) || // $NON-NLS-1$
ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", String.class.getCanonicalName(), int.class.getSimpleName()));
}
if (expression instanceof ClassInstanceCreation) {
ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
List<Expression> classInstanceCreationArguments = classInstanceCreation.arguments();
if (classInstanceCreationArguments.size() == 1) {
Expression arg0 = classInstanceCreationArguments.get(0);
return ASTNodes.hasType(arg0, String.class.getCanonicalName());
}
}
return false;
}
use of org.eclipse.jdt.core.dom.QualifiedName in project sts4 by spring-projects.
the class WebfluxMethodFinder method visit.
@Override
public boolean visit(MethodInvocation node) {
boolean visitChildren = true;
if (node != this.root) {
IMethodBinding methodBinding = node.resolveMethodBinding();
try {
if (WebfluxUtils.REQUEST_PREDICATES_TYPE.equals(methodBinding.getDeclaringClass().getBinaryName())) {
String name = methodBinding.getName();
if (name != null && WebfluxUtils.REQUEST_PREDICATE_HTTPMETHOD_METHODS.contains(name)) {
Range range = doc.toRange(node.getStartPosition(), node.getLength());
methods.add(new WebfluxRouteElement(name, range));
} else if (name != null && WebfluxUtils.REQUEST_PREDICATE_METHOD_METHOD.equals(name)) {
QualifiedName qualifiedName = WebfluxUtils.extractQualifiedNameArgument(node);
if (qualifiedName.getName() != null) {
Range range = doc.toRange(qualifiedName.getStartPosition(), qualifiedName.getLength());
methods.add(new WebfluxRouteElement(qualifiedName.getName().toString(), range));
}
}
}
} catch (BadLocationException e) {
// ignore
}
if (WebfluxUtils.isRouteMethodInvocation(methodBinding)) {
visitChildren = false;
}
}
return visitChildren;
}
Aggregations