List of usage examples for org.eclipse.jdt.core.dom Annotation isSingleMemberAnnotation
public boolean isSingleMemberAnnotation()
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
private void reportProblem(Annotation annotation, String member, int valueIndex, Collection<DSAnnotationProblem> problems, String message, String... args) { if (errorLevel.isNone()) return;/* w ww.j a v a 2 s. c o m*/ Expression memberValue = annotation; if (annotation.isNormalAnnotation() && member != null) { NormalAnnotation na = (NormalAnnotation) annotation; for (Object value : na.values()) { MemberValuePair pair = (MemberValuePair) value; if (member.equals(pair.getName().getIdentifier())) { memberValue = pair.getValue(); break; } } } else if (annotation.isSingleMemberAnnotation()) { SingleMemberAnnotation sma = (SingleMemberAnnotation) annotation; memberValue = sma.getValue(); } int start = memberValue.getStartPosition(); int length = memberValue.getLength(); if (valueIndex >= 0 && memberValue instanceof ArrayInitializer) { ArrayInitializer ai = (ArrayInitializer) memberValue; if (valueIndex < ai.expressions().size()) { Expression element = (Expression) ai.expressions().get(valueIndex); start = element.getStartPosition(); length = element.getLength(); } } if (start >= 0) { DSAnnotationProblem problem = new DSAnnotationProblem(errorLevel.isError(), message, args); problem.setSourceStart(start); problem.setSourceEnd(start + length - 1); problems.add(problem); } }
From source file:ch.acanda.eclipse.pmd.java.resolution.SuppressWarningsQuickFix.java
License:Open Source License
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;//from w ww. j ava 2 s. c o m } 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; }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java
License:Open Source License
public static Object getLookupKeyForJavaAnnotation(Annotation annotation) { StringBuilder key = new StringBuilder(annotation.getTypeName().toString() + '('); if (annotation.isSingleMemberAnnotation()) { key.append(((SingleMemberAnnotation) annotation).getValue().toString() + ","); } else if (annotation.isNormalAnnotation()) { for (Object o : ((NormalAnnotation) annotation).values()) { MemberValuePair mvp = (MemberValuePair) o; key.append(mvp.getName().toString() + "=" + mvp.getValue().toString() + ","); }/*from ww w. j a v a2s . co m*/ } key.append(')'); return key.toString(); }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReverseJavaAnnotation.java
License:Open Source License
@Override protected Object getFeatureValueFromAST(EStructuralFeature feature, JavaAnnotationHolder astElement) { Annotation annotation = astElement.getAnnotation(); if (astElement == null) throw new IllegalArgumentException("astElement is null"); switch (feature.getFeatureID()) { case EcorePackage.EANNOTATION__SOURCE: return annotation.getTypeName().toString(); case EcorePackage.EANNOTATION__DETAILS: if (annotation.isNormalAnnotation()) { return ((NormalAnnotation) annotation).values(); } else if (annotation.isSingleMemberAnnotation()) { return ((SingleMemberAnnotation) annotation).getValue(); } else/*from ww w. ja v a 2s . c om*/ return null; default: throw new IllegalArgumentException("Cannot get value for feature in ReverseJavaAnnotation:" + feature); } }
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 w w w. ja va 2s. c o m } } return true; } } } return false; }
From source file:com.halware.nakedide.eclipse.ext.annot.ast.SingleValueAnnotationEvaluatorAndModifier.java
License:Open Source License
public void modify(Object object, Object value) { if (!(object instanceof AbstractNode)) { return;/*from ww w . j a v a2 s . c o m*/ } AbstractNode node = (AbstractNode) object; Annotation annotation = annotation(node); if (annotation != null && !(annotation.isSingleMemberAnnotation() || annotation.isMarkerAnnotation())) { return; } try { if (value == null || isEmptyString(value)) { if (annotation != null) { removeAnnotation(node); } } else { if (annotation == null) { addSingleMemberAnnotation(node, value); } else { updateSingleMemberAnnotation(node, value); } } } catch (JavaModelException e) { getLOGGER().error(e); } catch (MalformedTreeException e) { getLOGGER().error(e); } catch (BadLocationException e) { getLOGGER().error(e); } catch (CoreException e) { getLOGGER().error(e); } }
From source file:com.halware.nakedide.eclipse.ext.annot.utils.dali.ASTTools.java
License:Open Source License
public static boolean containsAnnotationElement(BodyDeclaration bodyDeclaration, String annotationName, String elementName) {/*from w w w . j ava 2s . c o m*/ Annotation annotation = annotation(bodyDeclaration, annotationName); if (elementName.equals("value") && annotation.isSingleMemberAnnotation()) { return ((SingleMemberAnnotation) annotation).getValue() != null; } return memberValuePair(annotation, elementName) != null; }
From source file:com.halware.nakedide.eclipse.ext.annot.utils.dali.ASTTools.java
License:Open Source License
public static Expression member(Annotation annotation, String memberName) { if (memberName.equals("value") && annotation.isSingleMemberAnnotation()) { return ((SingleMemberAnnotation) annotation).getValue(); }//w w w. j av a 2s.co m MemberValuePair valuePair = memberValuePair(annotation, memberName); return (valuePair == null) ? null : valuePair.getValue(); }
From source file:com.wuetherich.osgi.ds.annotations.internal.builder.DsAnnotationAstVisitor.java
License:Open Source License
/** * <p>// w w w.j a v a2 s . com * </p> * * @param node */ private void handleDsAnnotation(Annotation node) { try { // if (_currentTypeDeclaration != null) { // if (node.resolveTypeBinding().getQualifiedName().equals(Component.class.getName())) { // _descriptions.put(_currentTypeDeclaration, new AstBasedComponentDescription(_currentTypeDeclaration)); getCurrentComponentDescription().setComponentDefaults(); // if (node.isNormalAnnotation()) { handleNormalComponentAnnotation((NormalAnnotation) node); } else if (node.isSingleMemberAnnotation()) { // } else if (node.isMarkerAnnotation()) { // } } if (_currentMethodDeclaration != null) { // if (node.resolveTypeBinding().getQualifiedName().equals(Activate.class.getName())) { getCurrentComponentDescription() .setActivateMethod(_currentMethodDeclaration.getName().getFullyQualifiedName()); } // else if (node.resolveTypeBinding().getQualifiedName().equals(Deactivate.class.getName())) { getCurrentComponentDescription() .setDeactivateMethod(_currentMethodDeclaration.getName().getFullyQualifiedName()); } // else if (node.resolveTypeBinding().getQualifiedName().equals(Modified.class.getName())) { getCurrentComponentDescription() .setModifiedMethod(_currentMethodDeclaration.getName().getFullyQualifiedName()); } // else if (node.resolveTypeBinding().getQualifiedName().equals(Reference.class.getName())) { // if (node.isNormalAnnotation()) { handleNormalReferenceAnnotation((NormalAnnotation) node); } else if (node.isSingleMemberAnnotation()) { // } else if (node.isMarkerAnnotation()) { // String service = _currentMethodDeclaration.resolveBinding().getParameterTypes()[0] .getBinaryName(); String bind = _currentMethodDeclaration.getName().getFullyQualifiedName(); // getCurrentComponentDescription().addReference(service, bind, null, null, null, null, null); } } } } } catch (Exception e) { ASTNode astNode = node; // if (e instanceof DsAnnotationException) { // DsAnnotationException annotationException = (DsAnnotationException) e; // if (annotationException.hasAnnotationField()) { astNode = node; if (node instanceof NormalAnnotation) { for (Object object : ((NormalAnnotation) node).values()) { // MemberValuePair pair = (MemberValuePair) object; String valueName = pair.getName().toString(); // if (valueName.equals(annotationException.getAnnotationField())) { astNode = pair; break; } } } } } // if (getCurrentComponentDescription() != null) { getCurrentComponentDescription().getProblems() .add(new DsAnnotationProblem( e.getMessage() != null ? e.getMessage() : "Unknown error in annotation", astNode.getStartPosition(), astNode.getStartPosition() + astNode.getLength())); } } }
From source file:edu.cmu.cs.crystal.annotations.AnnotationFinder.java
License:Open Source License
/** * Get multiple annotations out of an annotation array. * This presumes that baseAnno was marked as a multi. If so, it is * expected to be either a singleMemberAnno, or a normal anno with an * "annos" identifier.//from w w w.j av a2 s. com * * @param baseAnno The multi annotation * @return The CrystalAnnotations found inside of it * @throws CrystalRuntimeException if anything went wrong during parsing. This means * that the annotation was not actually a multi annotation and should not * be marked as such. */ private List<? extends ICrystalAnnotation> getMulti(Annotation baseAnno) { CrystalRuntimeException err = new CrystalRuntimeException( "Hey! " + "If you have a multi annotation, it better have an array of Annotations!" + " Found " + baseAnno.toString() + " without an array."); List<Expression> realAnnos = null; List<ICrystalAnnotation> crystalAnnos = new ArrayList<ICrystalAnnotation>(); if (baseAnno.isSingleMemberAnnotation()) { SingleMemberAnnotation anno = (SingleMemberAnnotation) baseAnno; if (!(anno.getValue() instanceof ArrayInitializer)) { realAnnos = Collections.singletonList(anno.getValue()); } else { realAnnos = ((ArrayInitializer) anno.getValue()).expressions(); } } else if (baseAnno.isNormalAnnotation()) { NormalAnnotation anno = (NormalAnnotation) baseAnno; for (MemberValuePair pair : (List<MemberValuePair>) anno.values()) { if (pair.getName().getIdentifier().equals("annos") && pair.getValue() instanceof ArrayInitializer) { realAnnos = ((ArrayInitializer) pair.getValue()).expressions(); break; } } if (realAnnos == null) throw err; } else throw err; //ok, now we have the array of annotations for (Expression exp : realAnnos) { if (!(exp instanceof Annotation)) throw err; IAnnotationBinding binding = ((Annotation) exp).resolveAnnotationBinding(); crystalAnnos.add(db.createAnnotation(binding)); } return crystalAnnos; }