Example usage for org.eclipse.jdt.core.dom NormalAnnotation values

List of usage examples for org.eclipse.jdt.core.dom NormalAnnotation values

Introduction

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

Prototype

ASTNode.NodeList values

To view the source code for org.eclipse.jdt.core.dom NormalAnnotation values.

Click Source Link

Document

The list of member value pairs (element type: MemberValuePair ).

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(NormalAnnotation node) {
    this.fBuffer.append("@");//$NON-NLS-1$
    node.getTypeName().accept(this);
    this.fBuffer.append("(");//$NON-NLS-1$
    for (Iterator<MemberValuePair> it = node.values().iterator(); it.hasNext();) {
        MemberValuePair p = it.next();//  w  ww .j  a v  a  2s .  c o  m
        p.accept(this);
        if (it.hasNext()) {
            this.fBuffer.append(",");//$NON-NLS-1$
        }
    }
    this.fBuffer.append(")");//$NON-NLS-1$
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(NormalAnnotation node) {
    boa.types.Ast.Modifier.Builder b = getAnnotationBuilder(node);
    for (Object v : node.values()) {
        MemberValuePair pair = (MemberValuePair) v;
        pair.getValue().accept(this);
        if (expressions.empty()) {
            boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder();
            //         eb.setPosition(pos.build()); // FIXME
            eb.setKind(boa.types.Ast.Expression.ExpressionKind.ANNOTATION);
            eb.setAnnotation(modifiers.pop());
            b.addAnnotationMembers(pair.getName().getFullyQualifiedName());
            b.addAnnotationValues(eb.build());
        } else {//w  w  w  .j a va2s . c  o m
            b.addAnnotationMembers(pair.getName().getFullyQualifiedName());
            b.addAnnotationValues(expressions.pop());
        }
    }
    modifiers.push(b.build());
    return false;
}

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;/*from  w  ww  . j a va  2s .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

/**
 * Creates the member value pairs of the annotation.
 *//*www.  ja v a 2  s. com*/
@SuppressWarnings("unchecked")
private void createAnnotationValues(final NormalAnnotation existingAnnotation,
        final NormalAnnotation annotation) {
    final AST ast = annotation.getAST();
    final List<MemberValuePair> values = annotation.values();
    final List<MemberValuePair> existingValues = existingAnnotation.values();
    for (final MemberValuePair existingPair : existingValues) {
        if ("value".equals(existingPair.getName().getFullyQualifiedName())) {
            final MemberValuePair pair = (MemberValuePair) ast.createInstance(MemberValuePair.class);
            pair.setName(ASTUtil.copy(existingPair.getName()));
            pair.setValue(createArrayInitializer(existingPair.getValue()));
            values.add(pair);
        } else {
            values.add(ASTUtil.copy(existingPair));
        }
    }
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(NormalAnnotation node) {
    this.buffer.append("@");//$NON-NLS-1$
    node.getTypeName().accept(this);
    this.buffer.append("(");//$NON-NLS-1$
    for (Iterator it = node.values().iterator(); it.hasNext();) {
        MemberValuePair p = (MemberValuePair) it.next();
        p.accept(this);
        if (it.hasNext()) {
            this.buffer.append(",");//$NON-NLS-1$
        }// ww w  .ja v  a 2 s .  c o  m
    }
    this.buffer.append(")");//$NON-NLS-1$
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java

License:Open Source License

@Override
public boolean visit(NormalAnnotation node) {
    handleArguments(node.values(), this.options.alignment_for_arguments_in_annotation);
    return true;//from  ww  w.j  av  a2  s .  c o  m
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(NormalAnnotation node) {
    handleAnnotation(node, true);//from  w  w  w .j  a va2s  .c  o m
    handleCommas(node.values(), this.options.insert_space_before_comma_in_annotation,
            this.options.insert_space_after_comma_in_annotation);
    return true;
}

From source file:com.google.gdt.eclipse.core.JavaASTUtils.java

License:Open Source License

/**
 * Returns an annotation's value. If the annotation not a single-member
 * annotation, this is the value corresponding to the key named "value".
 *///from   w ww.  ja  v  a 2  s.c  o m
@SuppressWarnings("unchecked")
public static Expression getAnnotationValue(Annotation annotation) {
    if (annotation instanceof SingleMemberAnnotation) {
        return ((SingleMemberAnnotation) annotation).getValue();
    } else if (annotation instanceof NormalAnnotation) {
        NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
        for (MemberValuePair pair : (List<MemberValuePair>) normalAnnotation.values()) {
            if (pair.getName().getIdentifier().equals("value")) {
                return pair.getValue();
            }
        }
    }
    return null;
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link NormalAnnotation}s. */
@Override/*from w  w  w  .j  a v  a  2  s.c om*/
public boolean visit(NormalAnnotation node) {
    sync(node);
    builder.open(ZERO);
    token("@");
    node.getTypeName().accept(this);
    builder.open(plusTwo, MAX_LINES_FOR_ANNOTATION_ELEMENT_VALUE_PAIRS);
    token("(");
    builder.breakOp();
    boolean first = true;

    // Format the member value pairs one-per-line if any of them are
    // initialized with arrays.
    boolean hasArrayInitializer = false;
    for (MemberValuePair value : (List<MemberValuePair>) node.values()) {
        if (value.getValue().getNodeType() == ASTNode.ARRAY_INITIALIZER) {
            hasArrayInitializer = true;
            break;
        }
    }

    for (MemberValuePair value : (List<MemberValuePair>) node.values()) {
        if (!first) {
            token(",");
            if (hasArrayInitializer) {
                builder.forcedBreak();
            } else {
                builder.breakOp(" ");
            }
        }
        value.accept(this);
        first = false;
    }
    builder.breakOp(FillMode.UNIFIED, "", minusTwo, Optional.<BreakTag>absent());
    token(")");
    builder.close();
    builder.close();
    return false;
}

From source file:com.halware.nakedide.eclipse.ext.annot.utils.dali.ASTTools.java

License:Open Source License

public static MemberValuePair memberValuePair(NormalAnnotation annotation, String elementName) {
    for (Iterator stream = annotation.values().iterator(); stream.hasNext();) {
        MemberValuePair valuePair = (MemberValuePair) stream.next();
        if (valuePair.getName().getFullyQualifiedName().equals(elementName)) {
            return valuePair;
        }//ww w. j a  v  a  2 s  .  c o  m
    }
    return null;
}