org.eclipse.jdt.core.dom.SingleMemberAnnotation smAnn = (org.eclipse.jdt.core.dom.SingleMemberAnnotation) annotation; values.add(smAnn.getValue().toString()); } else if (annotation.isNormalAnnotation()) { org.eclipse.jdt.core.dom.NormalAnnotation normalAnn = (org.eclipse.jdt.core.dom.NormalAnnotation) annotation; for (Object value : normalAnn.values()) values.add(value.toString());
@Override public boolean isNormal() { return annotation.isNormalAnnotation(); }
@Override public boolean isNormal() { return annotation.isNormalAnnotation(); }
/** * Return the value of the *first* annotation element * with the adapter's element name. * Return null if the annotation has no such element. * (An element name of "value" will return the value of a single * member annotation.) */ protected Expression elementValue(Annotation annotation) { if (annotation.isNormalAnnotation()) { return this.elementValue((NormalAnnotation) annotation); } if (annotation.isSingleMemberAnnotation()) { return this.elementValue((SingleMemberAnnotation) annotation); } return null; }
/** * Remove the *first* annotation element with the specified name * from the specified annotation, converting the annotation as appropriate. */ protected void removeElementAndNormalize(ModifiedDeclaration declaration, Annotation outer) { if (outer.isNormalAnnotation()) { this.removeElementAndNormalize(declaration, (NormalAnnotation) outer); } else if (outer.isSingleMemberAnnotation()) { this.removeElementAndNormalize(declaration, (SingleMemberAnnotation) outer); } else if (outer.isMarkerAnnotation()) { this.removeElementAndNormalize(declaration, (MarkerAnnotation) outer); } else { throw new IllegalArgumentException("unknown annotation type: " + outer); } }
protected void removeElement(Annotation annotation, ModifiedDeclaration declaration) { if (annotation == null) { this.removeElementNoAnnotation(declaration); } else if (annotation.isMarkerAnnotation()) { this.removeElementMarkerAnnotation((MarkerAnnotation) annotation, declaration); } else if (annotation.isSingleMemberAnnotation()) { this.removeElementSingleMemberAnnotation((SingleMemberAnnotation) annotation, declaration); } else if (annotation.isNormalAnnotation()) { this.removeElementNormalAnnotation((NormalAnnotation) annotation, declaration); } else { throw new IllegalArgumentException("unknown annotation type: " + annotation); } }
/** * When there is only a single element in an array initializer, convert the * expression to be just the single element; e.g. * <pre> * @Foo(xxx={"abc"}) => @Foo(xxx="abc") * or * @Foo({"abc"}) => @Foo("abc") * </pre> */ private void convertArrayToLastRemainingExpression(Annotation outer, Expression lastValue) { lastValue = (Expression) ASTNode.copySubtree(lastValue.getAST(), lastValue); if (outer.isNormalAnnotation()) { this.memberValuePair((NormalAnnotation) outer).setValue(lastValue); } else if (outer.isSingleMemberAnnotation()) { ((SingleMemberAnnotation) outer).setValue(lastValue); } else { throw new IllegalArgumentException("unexpected annotation type: " + outer); } }
/** * Return the expression value of the *first* annotation element * with the adapter's element name. * Return null if the annotation has no such element. * (An element name of "value" will return the value of a single * member annotation.) */ protected E expression(Annotation annotation) { if (annotation == null) { return this.expressionNoAnnotation(); } if (annotation.isMarkerAnnotation()) { return this.expressionMarkerAnnotation((MarkerAnnotation) annotation); } if (annotation.isSingleMemberAnnotation()) { return this.expressionSingleMemberAnnotation((SingleMemberAnnotation) annotation); } if (annotation.isNormalAnnotation()) { return this.expressionNormalAnnotation((NormalAnnotation) annotation); } throw new IllegalArgumentException("unknown annotation type: " + annotation); }
@Override protected void addAnnotation(ModifiedDeclaration declaration, Annotation inner) { Annotation outer = this.outerAnnotationAdapter.getAnnotation(declaration); if (outer == null) { this.buildNewOuterAnnotation(declaration, inner); } else if (outer.isMarkerAnnotation()) { this.modifyAnnotation(declaration, (MarkerAnnotation) outer, inner); } else if (outer.isSingleMemberAnnotation()) { this.modifyAnnotation(declaration, (SingleMemberAnnotation) outer, inner); } else if (outer.isNormalAnnotation()) { this.modifyAnnotation(declaration, (NormalAnnotation) outer, inner); } else { throw new IllegalStateException("unknown annotation type: " + outer); } }
public AnnotationSource<O> removeValue(final String name) if (annotation.isNormalAnnotation())
public AnnotationSource<O> removeValue(final String name) if (annotation.isNormalAnnotation())
/** * set non-null, non-empty value */ protected void setValue(Expression value, Annotation annotation, ModifiedDeclaration declaration) { if (value == null) { this.removeElement(annotation, declaration); } else if (annotation == null) { this.setValueNoAnnotation(value, declaration); } else if (annotation.isMarkerAnnotation()) { this.setValueMarkerAnnotation(value, (MarkerAnnotation) annotation, declaration); } else if (annotation.isSingleMemberAnnotation()) { this.setValueSingleMemberAnnotation(value, (SingleMemberAnnotation) annotation, declaration); } else if (annotation.isNormalAnnotation()) { this.setValueNormalAnnotation(value, (NormalAnnotation) annotation, declaration); } else { throw new IllegalArgumentException("unknown annotation type: " + annotation); } }
ClassFileSequencerLexicon.AnnotationType.MARKER.toString()); LOGGER.debug("Marker annotation {0} created", name); } else if (annotation.isNormalAnnotation()) { annotationNode.setProperty(ClassFileSequencerLexicon.ANNOTATION_TYPE, ClassFileSequencerLexicon.AnnotationType.NORMAL.toString());
ClassFileSequencerLexicon.AnnotationType.MARKER.toString()); LOGGER.debug("Marker annotation {0} created", name); } else if (annotation.isNormalAnnotation()) { annotationNode.setProperty(ClassFileSequencerLexicon.ANNOTATION_TYPE, ClassFileSequencerLexicon.AnnotationType.NORMAL.toString());
if (containerAnnotation.isNormalAnnotation()) { NormalAnnotation na = (NormalAnnotation) containerAnnotation; if (na.values().size() == 0) {
/** * move the annotation in the container annotation at index=0 * to the stand-alone annotation */ private void convertLastElementAnnotationToStandAloneAnnotation(ModifiedDeclaration declaration) { Annotation last = this.zeroNestedAnnotationAdapter.getAnnotation(declaration); if (last == null) { throw new IllegalStateException("the last nested annotation is missing"); } else if (last.isMarkerAnnotation()) { this.newStandAloneMarkerAnnotation(declaration); } else if (last.isSingleMemberAnnotation()) { Expression vv = ((SingleMemberAnnotation) last).getValue(); vv = (Expression) ASTNode.copySubtree(vv.getAST(), vv); this.newStandAloneSingleMemberAnnotation(declaration).setValue(vv); } else if (last.isNormalAnnotation()) { NormalAnnotation newNA = this.newStandAloneNormalAnnotation(declaration); List<MemberValuePair> values = this.values(newNA); for (MemberValuePair pair : this.values((NormalAnnotation) last)) { values.add((MemberValuePair) ASTNode.copySubtree(pair.getAST(), pair)); } } else { throw new IllegalStateException("unknown annotation type: " + last); } this.zeroNestedAnnotationAdapter.removeAnnotation(declaration); }
/** * move the specified, non-null, stand-alone annotation to * the container annotation at index=0 */ private void moveStandAloneAnnotationToContainerAnnotation(Annotation standAloneAnnotation, ModifiedDeclaration declaration) { if (standAloneAnnotation.isMarkerAnnotation()) { this.zeroNestedAnnotationAdapter.newMarkerAnnotation(declaration); } else if (standAloneAnnotation.isSingleMemberAnnotation()) { Expression vv = ((SingleMemberAnnotation) standAloneAnnotation).getValue(); vv = (Expression) ASTNode.copySubtree(vv.getAST(), vv); this.zeroNestedAnnotationAdapter.newSingleMemberAnnotation(declaration).setValue(vv); } else if (standAloneAnnotation.isNormalAnnotation()) { NormalAnnotation newNA = this.zeroNestedAnnotationAdapter.newNormalAnnotation(declaration); List<MemberValuePair> values = this.values(newNA); for (MemberValuePair pair : this.values((NormalAnnotation) standAloneAnnotation)) { values.add((MemberValuePair) ASTNode.copySubtree(pair.getAST(), pair)); } } else { throw new IllegalStateException("unknown annotation type: " + standAloneAnnotation); } this.removeStandAloneAnnotation(declaration); }