use of org.eclipse.jdt.core.dom.Annotation in project che by eclipse.
the class ModifierRewrite method copyAllAnnotations.
public void copyAllAnnotations(ASTNode otherDecl, TextEditGroup editGroup) {
ListRewrite modifierList = evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl);
List<IExtendedModifier> originalList = modifierList.getOriginalList();
for (Iterator<IExtendedModifier> iterator = originalList.iterator(); iterator.hasNext(); ) {
IExtendedModifier modifier = iterator.next();
if (modifier.isAnnotation()) {
fModifierRewrite.insertLast(fModifierRewrite.getASTRewrite().createCopyTarget((Annotation) modifier), editGroup);
}
}
}
use of org.eclipse.jdt.core.dom.Annotation in project che by eclipse.
the class UnresolvedElementsSubProcessor method getAnnotationMemberProposals.
public static void getAnnotationMemberProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException {
CompilationUnit astRoot = context.getASTRoot();
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(astRoot);
Annotation annotation;
String memberName;
if (selectedNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) {
if (selectedNode.getParent().getLocationInParent() != NormalAnnotation.VALUES_PROPERTY) {
return;
}
annotation = (Annotation) selectedNode.getParent().getParent();
memberName = ((SimpleName) selectedNode).getIdentifier();
} else if (selectedNode.getLocationInParent() == SingleMemberAnnotation.VALUE_PROPERTY) {
annotation = (Annotation) selectedNode.getParent();
//$NON-NLS-1$
memberName = "value";
} else {
return;
}
ITypeBinding annotBinding = annotation.resolveTypeBinding();
if (annotBinding == null) {
return;
}
if (annotation instanceof NormalAnnotation) {
// similar names
IMethodBinding[] otherMembers = annotBinding.getDeclaredMethods();
for (int i = 0; i < otherMembers.length; i++) {
IMethodBinding binding = otherMembers[i];
String curr = binding.getName();
int relevance = NameMatcher.isSimilarName(memberName, curr) ? IProposalRelevance.CHANGE_TO_ATTRIBUTE_SIMILAR_NAME : IProposalRelevance.CHANGE_TO_ATTRIBUTE;
String label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_UnresolvedElementsSubProcessor_changetoattribute_description, BasicElementLabels.getJavaElementName(curr));
proposals.add(new RenameNodeCorrectionProposal(label, cu, problem.getOffset(), problem.getLength(), curr, relevance));
}
}
if (annotBinding.isFromSource()) {
ICompilationUnit targetCU = ASTResolving.findCompilationUnitForBinding(cu, astRoot, annotBinding);
if (targetCU != null) {
String label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_UnresolvedElementsSubProcessor_createattribute_description, BasicElementLabels.getJavaElementName(memberName));
Image image = JavaPluginImages.get(JavaPluginImages.IMG_MISC_PUBLIC);
proposals.add(new NewAnnotationMemberProposal(label, targetCU, selectedNode, annotBinding, IProposalRelevance.CREATE_ATTRIBUTE, image));
}
}
}
use of org.eclipse.jdt.core.dom.Annotation in project che by eclipse.
the class ModifierCorrectionSubProcessor method findAnnotation.
private static Annotation findAnnotation(String qualifiedTypeName, List<IExtendedModifier> modifiers) {
for (int i = 0; i < modifiers.size(); i++) {
IExtendedModifier curr = modifiers.get(i);
if (curr instanceof Annotation) {
Annotation annot = (Annotation) curr;
ITypeBinding binding = annot.getTypeName().resolveTypeBinding();
if (binding != null && qualifiedTypeName.equals(binding.getQualifiedName())) {
return annot;
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.Annotation in project che by eclipse.
the class ModifierCorrectionSubProcessor method addOverridingDeprecatedMethodProposal.
public static void addOverridingDeprecatedMethodProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ICompilationUnit cu = context.getCompilationUnit();
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (!(selectedNode instanceof MethodDeclaration)) {
return;
}
boolean is50OrHigher = JavaModelUtil.is50OrHigher(cu.getJavaProject());
MethodDeclaration methodDecl = (MethodDeclaration) selectedNode;
AST ast = methodDecl.getAST();
ASTRewrite rewrite = ASTRewrite.create(ast);
if (is50OrHigher) {
Annotation annot = ast.newMarkerAnnotation();
//$NON-NLS-1$
annot.setTypeName(ast.newName("Deprecated"));
rewrite.getListRewrite(methodDecl, methodDecl.getModifiersProperty()).insertFirst(annot, null);
}
Javadoc javadoc = methodDecl.getJavadoc();
if (javadoc != null || !is50OrHigher) {
if (!is50OrHigher) {
javadoc = ast.newJavadoc();
rewrite.set(methodDecl, MethodDeclaration.JAVADOC_PROPERTY, javadoc, null);
}
TagElement newTag = ast.newTagElement();
newTag.setTagName(TagElement.TAG_DEPRECATED);
JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
}
String label = CorrectionMessages.ModifierCorrectionSubProcessor_overrides_deprecated_description;
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.OVERRIDES_DEPRECATED, image);
proposals.add(proposal);
}
use of org.eclipse.jdt.core.dom.Annotation in project che by eclipse.
the class NullAnnotationsRewriteOperations method hasNullAnnotation.
private static boolean hasNullAnnotation(MethodDeclaration decl) {
List<IExtendedModifier> modifiers = decl.modifiers();
String nonnull = NullAnnotationsFix.getNonNullAnnotationName(decl.resolveBinding().getJavaElement(), false);
String nullable = NullAnnotationsFix.getNullableAnnotationName(decl.resolveBinding().getJavaElement(), false);
for (Object mod : modifiers) {
if (mod instanceof Annotation) {
Name annotationName = ((Annotation) mod).getTypeName();
String fullyQualifiedName = annotationName.getFullyQualifiedName();
if (annotationName.isSimpleName() ? nonnull.endsWith(fullyQualifiedName) : fullyQualifiedName.equals(nonnull))
return true;
if (annotationName.isSimpleName() ? nullable.endsWith(fullyQualifiedName) : fullyQualifiedName.equals(nullable))
return true;
}
}
return false;
}
Aggregations