use of org.eclipse.jdt.core.dom.NormalAnnotation in project eclipse-pmd by acanda.
the class SuppressWarningsQuickFix method createReplacementSuppressWarningsAnnotation.
private Annotation createReplacementSuppressWarningsAnnotation(final Annotation existingAnnotation, final AST ast) {
final Annotation replacement;
if (existingAnnotation == null || existingAnnotation.isMarkerAnnotation()) {
final SingleMemberAnnotation annotation = createAnnotation(ast, SingleMemberAnnotation.class);
annotation.setValue(createPMDLiteralValue(ast));
replacement = annotation;
} else if (existingAnnotation.isSingleMemberAnnotation()) {
final SingleMemberAnnotation existingSingleMemberAnnotation = (SingleMemberAnnotation) existingAnnotation;
final SingleMemberAnnotation annotation = createAnnotation(ast, SingleMemberAnnotation.class);
annotation.setValue(createArrayInitializer(existingSingleMemberAnnotation.getValue()));
replacement = annotation;
} else if (existingAnnotation.isNormalAnnotation()) {
final NormalAnnotation existingNormalAnnotation = (NormalAnnotation) existingAnnotation;
final NormalAnnotation annotation = createAnnotation(ast, NormalAnnotation.class);
createAnnotationValues(existingNormalAnnotation, annotation);
replacement = annotation;
} else {
replacement = existingAnnotation;
}
return replacement;
}
use of org.eclipse.jdt.core.dom.NormalAnnotation in project sts4 by spring-projects.
the class RequestMappingSymbolProvider method getContentTypes.
private String[] getContentTypes(Annotation node) {
if (node.isNormalAnnotation()) {
NormalAnnotation normNode = (NormalAnnotation) node;
List<?> values = normNode.values();
for (Iterator<?> iterator = values.iterator(); iterator.hasNext(); ) {
Object object = iterator.next();
if (object instanceof MemberValuePair) {
MemberValuePair pair = (MemberValuePair) object;
String valueName = pair.getName().getIdentifier();
if (valueName != null && valueName.equals("produces")) {
Expression expression = pair.getValue();
return ASTUtils.getExpressionValueAsArray(expression);
}
}
}
}
return new String[0];
}
use of org.eclipse.jdt.core.dom.NormalAnnotation in project sts4 by spring-projects.
the class RequestMappingSymbolProvider method getAcceptTypes.
private String[] getAcceptTypes(Annotation node) {
if (node.isNormalAnnotation()) {
NormalAnnotation normNode = (NormalAnnotation) node;
List<?> values = normNode.values();
for (Iterator<?> iterator = values.iterator(); iterator.hasNext(); ) {
Object object = iterator.next();
if (object instanceof MemberValuePair) {
MemberValuePair pair = (MemberValuePair) object;
String valueName = pair.getName().getIdentifier();
if (valueName != null && valueName.equals("consumes")) {
Expression expression = pair.getValue();
return ASTUtils.getExpressionValueAsArray(expression);
}
}
}
}
return new String[0];
}
use of org.eclipse.jdt.core.dom.NormalAnnotation in project sts4 by spring-projects.
the class RequestMappingSymbolProvider method getMethod.
private String[] getMethod(Annotation node) {
String[] methods = null;
if (node.isNormalAnnotation()) {
NormalAnnotation normNode = (NormalAnnotation) node;
List<?> values = normNode.values();
for (Iterator<?> iterator = values.iterator(); iterator.hasNext(); ) {
Object object = iterator.next();
if (object instanceof MemberValuePair) {
MemberValuePair pair = (MemberValuePair) object;
String valueName = pair.getName().getIdentifier();
if (valueName != null && valueName.equals("method")) {
Expression expression = pair.getValue();
methods = ASTUtils.getExpressionValueAsArray(expression);
break;
}
}
}
} else if (node instanceof SingleMemberAnnotation) {
methods = getRequestMethod((SingleMemberAnnotation) node);
}
if (methods == null && node.getParent() instanceof MethodDeclaration) {
Annotation parentAnnotation = getParentAnnotation(node);
if (parentAnnotation != null) {
methods = getMethod(parentAnnotation);
}
}
return methods;
}
use of org.eclipse.jdt.core.dom.NormalAnnotation in project sts4 by spring-projects.
the class RequestMappingSymbolProvider method getPath.
private String[] getPath(Annotation node) {
if (node.isNormalAnnotation()) {
NormalAnnotation normNode = (NormalAnnotation) node;
List<?> values = normNode.values();
for (Iterator<?> iterator = values.iterator(); iterator.hasNext(); ) {
Object object = iterator.next();
if (object instanceof MemberValuePair) {
MemberValuePair pair = (MemberValuePair) object;
String valueName = pair.getName().getIdentifier();
if (valueName != null && (valueName.equals("value") || valueName.equals("path"))) {
Expression expression = pair.getValue();
return ASTUtils.getExpressionValueAsArray(expression);
}
}
}
} else if (node.isSingleMemberAnnotation()) {
SingleMemberAnnotation singleNode = (SingleMemberAnnotation) node;
Expression expression = singleNode.getValue();
return ASTUtils.getExpressionValueAsArray(expression);
}
return new String[] { "" };
}
Aggregations