Example usage for org.eclipse.jdt.core.dom Annotation isMarkerAnnotation

List of usage examples for org.eclipse.jdt.core.dom Annotation isMarkerAnnotation

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Annotation isMarkerAnnotation.

Prototype

public boolean isMarkerAnnotation() 

Source Link

Document

Returns whether this is a marker annotation ( MarkerAnnotation ).

Usage

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  2s. com*/

    } 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.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 w w w  .  jav a 2  s . com*/
    }
    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.wuetherich.osgi.ds.annotations.internal.builder.DsAnnotationAstVisitor.java

License:Open Source License

/**
 * <p>// w w  w  . j a v  a 2  s. c o  m
 * </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:net.atos.optimus.m2t.merger.java.core.DefaultMergingStrategy.java

License:Open Source License

/**
 * Annotation attributes handlings for annotation's type located in the
 * generated annotation property file.//from ww w. j  a va 2  s .c o  m
 * 
 * @param annotationInTheExistingFragment
 * @param existingAnnotation
 * @param lw
 * @param generatedAnnotations
 * @param annoName
 */
private void mergeAnnotationAttributes(Annotation annotationInTheExistingFragment,
        Annotation annotationInTheGeneratedFragment, ListRewrite lw) {

    if (annotationInTheExistingFragment.isMarkerAnnotation()) {
        /*
         * The annotation used inside the existing fragment is a marker
         * annotation (annotation without attribute)
         */
        if (!annotationInTheGeneratedFragment.isMarkerAnnotation()) {
            /*
             * The annotation used inside the generated fragment contains
             * one or many attributes. The annotation used inside the
             * generated fragment must be used in the result
             */
            lw.replace(annotationInTheExistingFragment, annotationInTheGeneratedFragment, null);
        }
    } else {
        if (annotationInTheExistingFragment.isSingleMemberAnnotation()) {
            /*
             * The annotation used inside the existing fragment is a single
             * member annotation (annotation without only one attribute)
             */
            if (annotationInTheGeneratedFragment.isSingleMemberAnnotation()) {
                /*
                 * The annotation used inside the generated fragment
                 * contains one value. Existing value must be replaced by
                 * generated value.
                 */

                this.astr.replace(annotationInTheExistingFragment, annotationInTheGeneratedFragment, null);
            } else {
                if (annotationInTheGeneratedFragment.isNormalAnnotation()) {
                    /*
                     * The annotation used inside the generated fragment
                     * contains several attributes. Existing value must be
                     * replaced by generated value.
                     */
                    lw.replace(annotationInTheExistingFragment, annotationInTheGeneratedFragment, null);
                }
            }
        } else {
            /*
             * The annotation used inside the existing fragment is a normal
             * annotation (annotation with several attributes)
             */
            if (annotationInTheGeneratedFragment.isSingleMemberAnnotation()) {
                /*
                 * What should be done in that case ? The existing
                 * annotation has been probably enhance => Let the existing
                 * content as before.
                 */
            } else {
                if (annotationInTheGeneratedFragment.isNormalAnnotation()) {
                    /*
                     * The annotation used inside the generated fragment
                     * contains several attributes. Existing and generated
                     * annotations must be merged.
                     */
                    this.mergeAnnotationAttribute((NormalAnnotation) annotationInTheExistingFragment,
                            (NormalAnnotation) annotationInTheGeneratedFragment);
                }
            }
        }
    }
}

From source file:org.codemucker.jmutate.ast.JAstFlattener.java

License:Open Source License

/**
 * Delegate to the relevant visit(<concrete-annotation-type>) method
 * /*from   w w w . j  av  a2 s  .  c  o  m*/
 * @param node
 * @return
 */
public boolean visit(Annotation node) {
    if (node.isMarkerAnnotation()) {
        return visit((MarkerAnnotation) node);
    } else if (node.isSingleMemberAnnotation()) {
        return visit((SingleMemberAnnotation) node);
    } else if (node.isNormalAnnotation()) {
        return visit((NormalAnnotation) node);
    }
    return false;
}

From source file:org.eclipse.jpt.common.core.internal.utility.jdt.AbstractNestedDeclarationAnnotationAdapter.java

License:Open Source License

@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 {//from   www .  j  av  a  2  s.c  om
        throw new IllegalStateException("unknown annotation type: " + outer); //$NON-NLS-1$
    }
}

From source file:org.eclipse.jpt.common.core.internal.utility.jdt.AbstractNestedDeclarationAnnotationAdapter.java

License:Open Source License

/**
 * Remove the <em>first</em> annotation element with the specified name
 * from the specified annotation, converting the annotation as appropriate.
 *///  w  w w.  jav a  2s .c  om
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); //$NON-NLS-1$
    }
}

From source file:org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter.java

License:Open Source License

public void removeAnnotation(ModifiedDeclaration declaration) {
    if (this.getIndex() == 0) {
        // check for the stand-alone annotation
        if (this.standAloneAnnotationIsPresent(declaration)) {
            this.removeStandAloneAnnotation(declaration);
            return;
        }/*from   w  ww .j ava 2  s.c o  m*/
    }
    this.removeNestedAnnotation(declaration);
    if (this.nestedElementCanBeConvertedToStandAlone(declaration)) {
        this.convertLastElementAnnotationToStandAloneAnnotation(declaration);
    }
    Annotation containerAnnotation = this.getContainerAnnotation(declaration);
    if (containerAnnotation != null && containerAnnotation.isMarkerAnnotation()) {
        removeContainerAnnotation(declaration);
    }
}

From source file:org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter.java

License:Open Source License

/**
 * move the specified, non-null, stand-alone annotation to
 * the container annotation at index=0// w  w  w .ja  v  a  2s  .  c o  m
 */
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); //$NON-NLS-1$
    }
    this.removeStandAloneAnnotation(declaration);
}

From source file:org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter.java

License:Open Source License

/**
 * return whether the "nested" annotation container has been reduced to
 * a single element (and the array initializer is converted to just
 * the single remaining element) and can be further converted to the
 * "stand-alone" annotation:/* www .  j a  va2  s. c om*/
 * <pre>
 *     &#64;Outer(foo={&#64;Inner("zero"), &#64;Inner("one")}) =>
 *     &#64;Outer(foo=&#64;Inner("zero")) =>
 *     &#64;Inner("zero")
 * </pre>
 */
private boolean nestedElementCanBeConvertedToStandAlone(ModifiedDeclaration declaration) {
    Annotation containerAnnotation = this.getContainerAnnotation(declaration);
    if (containerAnnotation == null) {
        return false;
    }
    if (containerAnnotation.isMarkerAnnotation()) {
        return false;
    }
    if (containerAnnotation.isSingleMemberAnnotation()) {
        if (this.getElementName().equals(VALUE)) {
            return (((SingleMemberAnnotation) containerAnnotation).getValue()
                    .getNodeType() != ASTNode.ARRAY_INITIALIZER)
                    && (this.zeroNestedAnnotationAdapter.getAnnotation(declaration) != null);
        }
        return false;
    }
    if (containerAnnotation.isNormalAnnotation()) {
        NormalAnnotation na = (NormalAnnotation) containerAnnotation;
        if (na.values().size() == 0) {
            return false; // there are no elements present
        }
        if (na.values().size() != 1) {
            return false; // there are other elements present - leave them all alone
        }
        MemberValuePair pair = (MemberValuePair) na.values().get(0);
        if (this.getElementName().equals(pair.getName().getFullyQualifiedName())) {
            return (pair.getValue().getNodeType() != ASTNode.ARRAY_INITIALIZER)
                    && (this.zeroNestedAnnotationAdapter.getAnnotation(declaration) != null);
        }
        return false;
    }
    throw new IllegalStateException("unknown annotation type: " + containerAnnotation); //$NON-NLS-1$
}