Example usage for org.eclipse.jdt.internal.compiler.ast MemberValuePair MemberValuePair

List of usage examples for org.eclipse.jdt.internal.compiler.ast MemberValuePair MemberValuePair

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast MemberValuePair MemberValuePair.

Prototype

public MemberValuePair(char[] token, int sourceStart, int sourceEnd, Expression value) 

Source Link

Usage

From source file:lombok.eclipse.handlers.ast.EclipseASTMaker.java

License:Open Source License

@Override
public ASTNode visitAnnotation(final lombok.ast.Annotation node, final Void p) {
    final Annotation ann;
    if (node.getValues().isEmpty()) {
        ann = new MarkerAnnotation(build(node.getType(), TypeReference.class), 0);
    } else if (node.getValues().containsKey("value") && node.getValues().size() == 1) {
        ann = new SingleMemberAnnotation(build(node.getType(), TypeReference.class), 0);
        ((SingleMemberAnnotation) ann).memberValue = build(node.getValues().get("value"));
    } else {// ww w  . j  a v  a 2 s .  co  m
        ann = new NormalAnnotation(build(node.getType(), TypeReference.class), 0);
        List<MemberValuePair> valuePairs = new ArrayList<MemberValuePair>();
        for (Entry<String, lombok.ast.Expression<?>> entry : node.getValues().entrySet()) {
            MemberValuePair valuePair = new MemberValuePair(entry.getKey().toCharArray(), 0, 0,
                    build(entry.getValue(), Expression.class));
            setGeneratedByAndCopyPos(valuePair, source, posHintOf(node));
            valuePairs.add(valuePair);
        }
        ((NormalAnnotation) ann).memberValuePairs = valuePairs.toArray(new MemberValuePair[0]);
    }
    setGeneratedByAndCopyPos(ann, source, posHintOf(node));
    return ann;
}

From source file:lombok.eclipse.handlers.EclipseHandlerUtil.java

License:Open Source License

public static Annotation[] addSuppressWarningsAll(EclipseNode node, ASTNode source,
        Annotation[] originalAnnotationArray) {
    Annotation[] anns = addAnnotation(source, originalAnnotationArray, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS,
            new StringLiteral(ALL, 0, 0, 0));

    if (Boolean.TRUE.equals(
            node.getAst().readConfiguration(ConfigurationKeys.ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS))) {
        MemberValuePair mvp = new MemberValuePair(JUSTIFICATION, 0, 0,
                new StringLiteral(GENERATED_CODE, 0, 0, 0));
        anns = addAnnotation(source, anns, EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS, mvp);
    }/*w w  w .  j  av  a 2s . c o m*/

    return anns;
}

From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitStructureRequestor.java

License:Open Source License

private Annotation convertToJDTAnnotation(
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation ajAnnotation) {
    Annotation jdtAnnotation = null;
    if (ajAnnotation != null) {
        if (ajAnnotation instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation) {
            jdtAnnotation = new MarkerAnnotation(convertToJDTTypeReference(ajAnnotation.type),
                    ajAnnotation.sourceStart);
        } else if (ajAnnotation instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.NormalAnnotation) {
            org.aspectj.org.eclipse.jdt.internal.compiler.ast.NormalAnnotation castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.NormalAnnotation) ajAnnotation;
            NormalAnnotation castedJDT = new NormalAnnotation(convertToJDTTypeReference(castedAJ.type),
                    castedAJ.sourceStart);
            if (castedAJ.memberValuePairs != null) {
                castedJDT.memberValuePairs = new MemberValuePair[castedAJ.memberValuePairs.length];
                for (int j = 0; j < castedAJ.memberValuePairs.length; j++) {
                    org.aspectj.org.eclipse.jdt.internal.compiler.ast.MemberValuePair ajMVP = castedAJ.memberValuePairs[j];
                    if (ajMVP != null) {
                        MemberValuePair jdtMVP = new MemberValuePair(ajMVP.name, ajMVP.sourceStart,
                                ajMVP.sourceEnd, convertToJDTExpression(ajMVP.value));
                        jdtMVP.bits = ajMVP.bits;
                        castedJDT.memberValuePairs[j] = jdtMVP;
                    }/*from   w ww. j  ava  2s  .c om*/
                }
            }
            jdtAnnotation = castedJDT;
        } else { // SingleMemberAnnotation
            org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation) ajAnnotation;
            SingleMemberAnnotation castedJDT = new SingleMemberAnnotation(
                    convertToJDTTypeReference(castedAJ.type), castedAJ.sourceStart);
            castedJDT.memberValue = convertToJDTExpression(castedAJ.memberValue);

            jdtAnnotation = castedJDT;
        }
        jdtAnnotation.sourceEnd = ajAnnotation.sourceEnd;
        jdtAnnotation.declarationSourceEnd = ajAnnotation.declarationSourceEnd;
        jdtAnnotation.implicitConversion = ajAnnotation.implicitConversion;
        jdtAnnotation.bits = ajAnnotation.bits;
        jdtAnnotation.statementEnd = ajAnnotation.statementEnd;
    }
    return jdtAnnotation;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeMemberValuePair() {
    // MemberValuePair ::= SimpleName '=' MemberValue
    char[] simpleName = this.identifierStack[this.identifierPtr];
    long position = this.identifierPositionStack[this.identifierPtr--];
    this.identifierLengthPtr--;
    int end = (int) position;
    int start = (int) (position >>> 32);
    Expression value = this.expressionStack[this.expressionPtr--];
    this.expressionLengthPtr--;
    MemberValuePair memberValuePair = new MemberValuePair(simpleName, start, end, value);
    pushOnAstStack(memberValuePair);//w  w  w  . j  a va 2  s .c o  m

    if (this.currentElement != null && this.currentElement instanceof RecoveredAnnotation) {
        RecoveredAnnotation recoveredAnnotation = (RecoveredAnnotation) this.currentElement;

        recoveredAnnotation.setKind(RecoveredAnnotation.NORMAL);
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator.java

License:Open Source License

public NormalAnnotation normalAnnotation(char[][] compoundName, char[][] names, Expression[] values) {
    assert names.length == values.length : "names and values must have same length"; //$NON-NLS-1$
    NormalAnnotation result = new NormalAnnotation(qualifiedTypeReference(compoundName), this.sourceStart);
    result.sourceEnd = this.sourceEnd;
    result.declarationSourceEnd = this.sourceEnd;
    MemberValuePair[] pairs = new MemberValuePair[names.length];
    for (int i = 0; i < names.length; i++) {
        pairs[i] = new MemberValuePair(names[i], this.sourceStart, this.sourceEnd, values[i]);
    }//w  w  w .j a  va2 s  . co  m
    result.memberValuePairs = pairs;
    return result;
}

From source file:org.nabucco.framework.mda.template.java.extract.membervaluepair.JavaAstMemberValuePairExtractorImpl.java

License:Open Source License

@Override
public List<MemberValuePair> extractMemberValuePairs(NormalAnnotation annotation, BlockScope scope)
        throws JavaTemplateException {

    if (annotation == null) {
        return Collections.<MemberValuePair>emptyList();
    }/* w  w w  .j a v a2  s.  com*/

    List<MemberValuePair> memberValuePairList = new ArrayList<MemberValuePair>();

    for (MemberValuePair memberValuePair : annotation.memberValuePairs) {

        // 'Expression' is a 'Statement' so the 'JavaAstStatementExtractor' can be applied.
        Expression expression = JavaAstExtractorFactory.getInstance().getStatementExtractor()
                .extractStatement(memberValuePair.value, scope);

        MemberValuePair memberValuePairCopy = new MemberValuePair(memberValuePair.name.clone(),
                memberValuePair.sourceStart, memberValuePair.sourceEnd, expression);

        memberValuePairList.add(memberValuePairCopy);
    }

    return memberValuePairList;
}