Example usage for org.eclipse.jdt.core.dom MemberValuePair getName

List of usage examples for org.eclipse.jdt.core.dom MemberValuePair getName

Introduction

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

Prototype

public SimpleName getName() 

Source Link

Document

Returns the member name.

Usage

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

License:Open Source License

@Override
public boolean visit(MemberValuePair node) {
    node.getName().accept(this);
    this.fBuffer.append("=");//$NON-NLS-1$
    node.getValue().accept(this);
    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 av a2 s . com
            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;//ww w  .  ja  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

/**
 * Creates the member value pairs of the annotation.
 *///from w w  w.ja  va  2s  .c  o  m
@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(MemberValuePair node) {
    node.getName().accept(this);
    this.buffer.append("=");//$NON-NLS-1$
    node.getValue().accept(this);
    return false;
}

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() + ",");
        }/* w w w.ja  va 2  s  .  com*/
    }
    key.append(')');
    return key.toString();
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReverseJavaAnnotation.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
protected void setFeatureValue(EStructuralFeature feature, SyncAnnotation modelElement, Object value) {
    if (EcorePackage.eINSTANCE.getEAnnotation_Details().equals(feature)) {
        modelElement.getDetails().clear();

        if (value instanceof List) {
            List annotationValues = (List) value;

            for (int i = 0; i < annotationValues.size(); i++) {
                MemberValuePair mvp = (MemberValuePair) annotationValues.get(i);
                EStringToStringMapEntryImpl entry = (EStringToStringMapEntryImpl) EcoreFactory.eINSTANCE
                        .create(EcorePackage.eINSTANCE.getEStringToStringMapEntry());
                entry.setKey(mvp.getName().toString());
                entry.setValue(mvp.getValue().toString());
                // add Entry instead of put(key,value) to preserve the parameter order
                modelElement.getDetails().add(entry);
            }//  w  ww . j a va  2  s  .co  m
        } else if (value instanceof Expression) {
            EStringToStringMapEntryImpl entry = (EStringToStringMapEntryImpl) EcoreFactory.eINSTANCE
                    .create(EcorePackage.eINSTANCE.getEStringToStringMapEntry());
            entry.setKey("");
            entry.setValue(((Expression) value).toString());
            modelElement.getDetails().add(entry);
        }

    } else {
        super.setFeatureValue(feature, modelElement, value);
    }
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReverseJavaAnnotation.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
protected boolean safeEquals(Object o1, Object o2) {

    if (o1 == null && o2 == null)
        return true;

    // for annotation details
    if (o1 instanceof EMap) {
        if (o2 == null) { // could receive null for MarkerAnnotation
            if (((EMap) o1).isEmpty())
                return true;
            else/* w ww . j a va 2 s . co  m*/
                return false;
        } else if (o2 instanceof List) { // list of MemberValuePair for NormalAnnotation
            List annotationValues = (List) o2;
            EMap syncAnnotationDetails = (EMap) o1;
            if (syncAnnotationDetails.size() == annotationValues.size()) {
                for (Object o : annotationValues) {
                    MemberValuePair mvp = (MemberValuePair) o;
                    if (!super.safeEquals(syncAnnotationDetails.get(mvp.getName().toString()),
                            mvp.getValue().toString()))
                        return false;
                }
                return true;
            } else
                return false;
        } else if (o2 instanceof Expression) { // or Expression for SingleMemberAnnotation
            if (((EMap) o1).size() != 1)
                return false;
            else
                return super.safeEquals(((EMap) o1).get(""), o2.toString());
        }
        return false;

    } else
        return super.safeEquals(o1, o2);
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(MemberValuePair node) {
    node.getName().accept(this);
    sb.print('=');
    node.getValue().accept(this);
    return false;
}

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 w  w  .j a v a 2  s  .c om*/
@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;
}