use of org.eclipse.jdt.core.dom.MemberValuePair in project AutoRefactor by JnRouvignac.
the class AnnotationRefactoring method visit.
@Override
public boolean visit(NormalAnnotation node) {
final Refactorings r = this.ctx.getRefactorings();
final ASTBuilder b = this.ctx.getASTBuilder();
final List<MemberValuePair> values = values(node);
if (values.isEmpty()) {
r.replace(node, b.markerAnnotation(b.move(node.getTypeName())));
return DO_NOT_VISIT_SUBTREE;
} else if (values.size() == 1) {
MemberValuePair pair = values.get(0);
if ("value".equals(pair.getName().getIdentifier())) {
r.replace(node, b.singleValueAnnotation(b.move(node.getTypeName()), b.move(pair.getValue())));
return DO_NOT_VISIT_SUBTREE;
}
}
boolean result = VISIT_SUBTREE;
Map<String, IMethodBinding> elements = toElementsMap(node.resolveAnnotationBinding());
for (MemberValuePair pair : values) {
IMethodBinding elementBinding = elements.get(pair.getName().getIdentifier());
if (equal(elementBinding.getReturnType(), pair.getValue(), elementBinding.getDefaultValue())) {
r.remove(pair);
result = DO_NOT_VISIT_SUBTREE;
} else if (pair.getValue().getNodeType() == ARRAY_INITIALIZER) {
ArrayInitializer arrayInit = (ArrayInitializer) pair.getValue();
List<Expression> exprs = expressions(arrayInit);
if (exprs.size() == 1) {
r.replace(arrayInit, b.move(exprs.get(0)));
result = DO_NOT_VISIT_SUBTREE;
}
}
}
return result;
}
Aggregations