List of usage examples for org.eclipse.jdt.core.dom IExtendedModifier isAnnotation
public boolean isAnnotation();
From source file:ch.acanda.eclipse.pmd.java.resolution.SuppressWarningsQuickFix.java
License:Open Source License
private Annotation findExistingSuppressWarningsAnnotation(final List<IExtendedModifier> modifiers) { for (final IExtendedModifier modifier : modifiers) { if (modifier.isAnnotation()) { final Annotation annotation = (Annotation) modifier; final Name typeName = annotation.getTypeName(); if (typeName.isSimpleName() && "SuppressWarnings".equals(typeName.getFullyQualifiedName()) || typeName.isQualifiedName() && "java.lang.SuppressWarnings".equals(typeName.getFullyQualifiedName())) { return annotation; }//from w w w . ja va2s .c o m } } return null; }
From source file:ch.acanda.eclipse.pmd.java.resolution.SuppressWarningsQuickFix.java
License:Open Source License
/** * @return The position after the last existing annotation. */// w ww.j ava2s . c om private int findPosition(final List<IExtendedModifier> modifiers) { int position = 0; int index = 0; for (final IExtendedModifier modifier : modifiers) { index++; if (modifier.isAnnotation()) { position = index; } } return position; }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java
License:Open Source License
/** * If no public type is found in a compilation unit it is returned the first one * //w w w .j a v a 2 s. co m * @param node {@link CompilationUnit} * @return <code>TypeDeclaration</code> object which defines the main class in a compilation unit * (this is the public class or interface which gives the name of the file). * * @flowerModelElementId _zVs8SpiOEd6aNMdNFvR5WQ */ @SuppressWarnings("unchecked") public static TypeDeclaration getMasterClass(CompilationUnit node) { Iterator<TypeDeclaration> it = node.types().iterator(); for (; it.hasNext();) { TypeDeclaration td = it.next(); for (Iterator<Modifier> it2 = td.modifiers().iterator(); it2.hasNext();) { IExtendedModifier iExtendedModifier = it2.next(); if (iExtendedModifier.isAnnotation()) continue; if (((Modifier) iExtendedModifier).isPublic()) return td; } } if (node.types().size() > 0) return (TypeDeclaration) node.types().get(0); throw new IllegalStateException( "A master class for " + node.getPackage() + ".[" + node.types() + "] could not been found"); }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java
License:Open Source License
/** * @flowerModelElementId _zVs8UZiOEd6aNMdNFvR5WQ */// w w w .j ava2 s. co m public static VisibilityKind convertJavaToModelVisibility(Object node) { List<IExtendedModifier> modifiers = getModifiers(node); for (IExtendedModifier iExtendedModifier : modifiers) { if (iExtendedModifier.isAnnotation()) continue; String modif = ((Modifier) iExtendedModifier).getKeyword().toString(); if ("public".equals(modif)) { return VisibilityKind.PUBLIC_LITERAL; } else if ("private".equals(modif)) { return VisibilityKind.PRIVATE_LITERAL; } else if ("protected".equals(modif)) { return VisibilityKind.PROTECTED_LITERAL; } } return VisibilityKind.PACKAGE_LITERAL; }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java
License:Open Source License
/** * Gets the feature value from Java Element for Model Element. * /*from www. jav a 2 s.c om*/ * @param node astElement for class or method declaration * @param modifier flag indicating the modifier for which to get the feature value * This should be one of the predefined flags: * <ul> * <li>{@link #MODIFIER_ABSTRACT}</li> * <li>{@link #MODIFIER_STATIC}</li> * </ul> * @return value for Model feature * * @author Luiza * @flowerModelElementId _zVs8VpiOEd6aNMdNFvR5WQ */ public static boolean getFeatureValueFromJavaModifier(Object node, String modifier) { List<IExtendedModifier> modifiers = getModifiers(node); for (IExtendedModifier iExtendedModifier : modifiers) { if (iExtendedModifier.isAnnotation()) continue; String modif = ((Modifier) iExtendedModifier).getKeyword().toString(); if (modifier.equals(modif)) return true; } return false; }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java
License:Open Source License
/** * Retrieves the annotations from the <code>astElement</code>'s modifiers * list./* ww w .j a v a 2 s .com*/ * * @param astElement * @return a list of {@link JavaAnnotationHolder} wrapping the * {@link Annotation annotations} * * @author Luiza */ public static List<JavaAnnotationHolder> getAnnotations(Object astElement) { List<JavaAnnotationHolder> annotations = new ArrayList<JavaAnnotationHolder>(); List<IExtendedModifier> modifiers = getModifiers(astElement); for (Iterator<IExtendedModifier> it = modifiers.iterator(); it.hasNext();) { IExtendedModifier iExtendedModifier = it.next(); if (iExtendedModifier.isAnnotation()) { annotations.add(new JavaAnnotationHolder((Annotation) iExtendedModifier)); } } return annotations; }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java
License:Open Source License
/** * Adds <code>newAnnotation</code> to the list of modifiers of * <code>toAstElement</code>. * The new Annotation will be placed on the first position in the modifiers list. * //from www . ja v a2 s . c o m * @param toAstElement * the {@link ASTNode parent ast element} to receive the * {@link Annotation} * @param newAnnotation * the new created {@link Annotation}. Note that it must be * unparented. Otherwise an exception will be generated. * * @author Luiza */ public static void addAnnotation(Object toAstElement, Annotation newAnnotation) { List<IExtendedModifier> modifiers = getModifiers(toAstElement); int lastAnnotationIndex = -1, index = 0; // find the last annotation position for (IExtendedModifier modifier : modifiers) { if (modifier.isAnnotation()) lastAnnotationIndex = index; index++; } index = lastAnnotationIndex + 1; if (index >= modifiers.size()) modifiers.add(newAnnotation); else modifiers.add(index, newAnnotation); }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java
License:Open Source License
/** * Moves <code>toMove</code> after <code>afterAnnotation</code> in the * modifiers list of the given <code>astElement</code>. * <p> // w w w. j ava 2s . c o m * Supposes that both {@link Annotation annotations} are contained in the * <code>astElement</code>'s list of modifiers. * * @author Luiza */ public static void moveAfterAnnotation(Object astElement, Annotation toMove, Annotation afterAnnotation) { List<IExtendedModifier> modifiers = getModifiers(astElement); modifiers.remove(toMove); int toIndex = 0; if (afterAnnotation == null) { // if toMove should be the first for (IExtendedModifier modifier : modifiers) if (modifier.isAnnotation()) break; // find the first element of its kind else toIndex++; } else { toIndex = modifiers.indexOf(afterAnnotation) + 1; } modifiers.add(toIndex, (IExtendedModifier) toMove); }
From source file:com.google.devtools.j2cpp.translate.GwtConverter.java
License:Open Source License
private boolean hasAnnotation(Class<?> annotation, List<IExtendedModifier> modifiers) { // Annotation bindings don't have the annotation's package. String annotationName = annotation.getSimpleName(); for (IExtendedModifier mod : modifiers) { if (mod.isAnnotation()) { Annotation annotationNode = (Annotation) mod; String modName = annotationNode.getTypeName().getFullyQualifiedName(); if (modName.equals(annotationName)) { if (annotationName.equals("GwtIncompatible") && annotationNode.isSingleMemberAnnotation()) { Expression value = ((SingleMemberAnnotation) annotationNode).getValue(); if (value instanceof StringLiteral) { if (compatibleAPIs.contains(((StringLiteral) value).getLiteralValue())) { // Pretend incompatible annotation isn't present, since what it's // flagging is J2ObjC-compatible. return false; }/*from ww w . j a va2s. com*/ } } return true; } } } return false; }
From source file:com.google.gdt.eclipse.appengine.rpc.markers.quickfixes.DeleteServiceMethodAnnotationProposal.java
License:Open Source License
@Override protected ASTRewrite getRewrite() throws CoreException { CompilationUnit targetAstRoot = ASTResolving.createQuickFixAST(getCompilationUnit(), null); createImportRewrite(targetAstRoot);/* w w w . ja v a2 s.c om*/ ASTRewrite rewrite = ASTRewrite.create(targetAstRoot.getAST()); // Find the method declaration in the AST we just generated (the one that // the AST rewriter is hooked up to). MethodDeclaration rewriterAstMethodDecl = JavaASTUtils.findMethodDeclaration(targetAstRoot, serviceMethod.resolveBinding().getKey()); if (rewriterAstMethodDecl == null) { return null; } ASTNode annotationNode = null; List<IExtendedModifier> modifiers = rewriterAstMethodDecl.modifiers(); for (IExtendedModifier modifier : modifiers) { if (modifier.isAnnotation()) { String name = ((Annotation) modifier).getTypeName().toString(); if (name.equals("ServiceMethod")) { //$NON-NLS-N$ annotationNode = (ASTNode) modifier; break; } } } if (annotationNode != null) { rewrite.remove(annotationNode, null); } return rewrite; }