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

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

Introduction

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

Prototype

public ArrayInitializer() 

Source Link

Document

ArrayInitializer constructor comment.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.compiler.parser.SourceTypeConverter.java

License:Open Source License

private FieldDeclaration convert(SourceField fieldHandle, TypeDeclaration type,
        CompilationResult compilationResult) throws JavaModelException {

    SourceFieldElementInfo fieldInfo = (SourceFieldElementInfo) fieldHandle.getElementInfo();
    FieldDeclaration field = new FieldDeclaration();

    int start = fieldInfo.getNameSourceStart();
    int end = fieldInfo.getNameSourceEnd();

    field.name = fieldHandle.getElementName().toCharArray();
    field.sourceStart = start;//from ww w.  j a  va 2  s. c om
    field.sourceEnd = end;
    field.declarationSourceStart = fieldInfo.getDeclarationSourceStart();
    field.declarationSourceEnd = fieldInfo.getDeclarationSourceEnd();
    int modifiers = fieldInfo.getModifiers();
    boolean isEnumConstant = (modifiers & ClassFileConstants.AccEnum) != 0;
    if (isEnumConstant) {
        field.modifiers = modifiers & ~ClassFileConstants.AccEnum; // clear AccEnum bit onto AST (binding will add it)
    } else {
        field.modifiers = modifiers;
        field.type = createTypeReference(fieldInfo.getTypeName(), start, end);
    }

    // convert 1.5 specific constructs only if compliance is 1.5 or above
    if (this.has1_5Compliance) {
        /* convert annotations */
        field.annotations = convertAnnotations(fieldHandle);
    }

    /* conversion of field constant */
    if ((this.flags & FIELD_INITIALIZATION) != 0) {
        char[] initializationSource = fieldInfo.getInitializationSource();
        if (initializationSource != null) {
            if (this.parser == null) {
                this.parser = new Parser(this.problemReporter, true);
            }
            this.parser.parse(field, type, this.unit, initializationSource);
        }
    }

    /* conversion of local and anonymous types */
    if ((this.flags & LOCAL_TYPE) != 0) {
        IJavaElement[] children = fieldInfo.getChildren();
        int childrenLength = children.length;
        if (childrenLength == 1) {
            field.initialization = convert(children[0], isEnumConstant ? field : null, compilationResult);
        } else if (childrenLength > 1) {
            ArrayInitializer initializer = new ArrayInitializer();
            field.initialization = initializer;
            Expression[] expressions = new Expression[childrenLength];
            initializer.expressions = expressions;
            for (int i = 0; i < childrenLength; i++) {
                expressions[i] = convert(children[i], isEnumConstant ? field : null, compilationResult);
            }
        }
    }
    return field;
}

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

License:Open Source License

@Override
public ASTNode visitNewArray(final lombok.ast.NewArray node, final Void p) {
    ArrayAllocationExpression allocationExpression = new ArrayAllocationExpression();
    setGeneratedByAndCopyPos(allocationExpression, source, posHintOf(node));
    allocationExpression.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    allocationExpression.type = build(node.getType());
    final List<Expression> dims = new ArrayList<Expression>();
    dims.addAll(build(node.getDimensionExpressions(), Expression.class));
    allocationExpression.dimensions = toArray(dims, new Expression[0]);
    final List<Expression> initializerExpressions = build(node.getInitializerExpressions(), Expression.class);
    if (!initializerExpressions.isEmpty()) {
        ArrayInitializer initializer = new ArrayInitializer();
        setGeneratedByAndCopyPos(initializer, source, posHintOf(node));
        initializer.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
        initializer.expressions = initializerExpressions.isEmpty() ? null
                : toArray(initializerExpressions, new Expression[0]);
        allocationExpression.initializer = initializer;
    }//from  w w  w .j a  v  a2  s .  co  m
    return allocationExpression;
}

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

License:Open Source License

public static Annotation[] createConstructorProperties(ASTNode source, Collection<EclipseNode> fields) {
    if (fields.isEmpty())
        return null;

    int pS = source.sourceStart, pE = source.sourceEnd;
    long p = (long) pS << 32 | pE;
    long[] poss = new long[3];
    Arrays.fill(poss, p);/*from  www  .  j a  v a2 s. c  om*/
    QualifiedTypeReference constructorPropertiesType = new QualifiedTypeReference(
            JAVA_BEANS_CONSTRUCTORPROPERTIES, poss);
    setGeneratedBy(constructorPropertiesType, source);
    SingleMemberAnnotation ann = new SingleMemberAnnotation(constructorPropertiesType, pS);
    ann.declarationSourceEnd = pE;

    ArrayInitializer fieldNames = new ArrayInitializer();
    fieldNames.sourceStart = pS;
    fieldNames.sourceEnd = pE;
    fieldNames.expressions = new Expression[fields.size()];

    int ctr = 0;
    for (EclipseNode field : fields) {
        char[] fieldName = removePrefixFromField(field);
        fieldNames.expressions[ctr] = new StringLiteral(fieldName, pS, pE, 0);
        setGeneratedBy(fieldNames.expressions[ctr], source);
        ctr++;
    }

    ann.memberValue = fieldNames;
    setGeneratedBy(ann, source);
    setGeneratedBy(ann.memberValue, source);
    return new Annotation[] { ann };
}

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.java

License:Open Source License

/**
 * Convert groovy annotations into JDT annotations
 * /*from ww  w . ja  va2s .c  o m*/
 * @return an array of annotations or null if there are none
 */
private Annotation[] transformAnnotations(List<AnnotationNode> groovyAnnotations) {
    // FIXASC positions are crap
    if (groovyAnnotations != null && groovyAnnotations.size() > 0) {
        List<Annotation> annotations = new ArrayList<Annotation>();
        for (AnnotationNode annotationNode : groovyAnnotations) {
            ClassNode annoType = annotationNode.getClassNode();
            Map<String, Expression> memberValuePairs = annotationNode.getMembers();
            // FIXASC (M3) do more than pure marker annotations and do annotation values

            if (memberValuePairs == null || memberValuePairs.size() == 0) {
                // Marker annotation:
                TypeReference annotationReference = createTypeReferenceForClassNode(annoType);
                annotationReference.sourceStart = annotationNode.getStart();
                annotationReference.sourceEnd = annotationNode.getEnd();

                MarkerAnnotation annotation = new MarkerAnnotation(annotationReference,
                        annotationNode.getStart());
                annotation.declarationSourceEnd = annotation.sourceEnd;
                annotations.add(annotation);
            } else {

                if (memberValuePairs.size() == 1 && memberValuePairs.containsKey("value")) {
                    // Single member annotation

                    // Code written to only manage a single class literal value annotation - so that @RunWith works
                    Expression value = memberValuePairs.get("value");
                    if (value instanceof PropertyExpression) {
                        String pExpression = ((PropertyExpression) value).getPropertyAsString();
                        if (pExpression.equals("class")) {
                            TypeReference annotationReference = createTypeReferenceForClassNode(annoType);
                            annotationReference.sourceStart = annotationNode.getStart();
                            annotationReference.sourceEnd = annotationNode.getEnd();
                            SingleMemberAnnotation annotation = new SingleMemberAnnotation(annotationReference,
                                    annotationNode.getStart());
                            annotation.memberValue = new ClassLiteralAccess(value.getEnd(),
                                    classLiteralToTypeReference((PropertyExpression) value));
                            annotation.declarationSourceEnd = annotation.sourceStart
                                    + annoType.getNameWithoutPackage().length();
                            annotations.add(annotation);
                        }
                    } else if (value instanceof VariableExpression && annoType.getName().endsWith("RunWith")) {
                        // FIXASC special case for 'RunWith(Foo)' where for some reason groovy doesn't mind the missing
                        // '.class'
                        // FIXASC test this
                        TypeReference annotationReference = createTypeReferenceForClassNode(annoType);
                        annotationReference.sourceStart = annotationNode.getStart();
                        annotationReference.sourceEnd = annotationNode.getEnd();
                        SingleMemberAnnotation annotation = new SingleMemberAnnotation(annotationReference,
                                annotationNode.getStart());
                        String v = ((VariableExpression) value).getName();
                        TypeReference ref = null;
                        int start = annotationReference.sourceStart;
                        int end = annotationReference.sourceEnd;
                        if (v.indexOf(".") == -1) {
                            ref = new SingleTypeReference(v.toCharArray(), toPos(start, end - 1));
                        } else {
                            char[][] splits = CharOperation.splitOn('.', v.toCharArray());
                            ref = new QualifiedTypeReference(splits, positionsFor(splits, start, end - 2));
                        }
                        annotation.memberValue = new ClassLiteralAccess(value.getEnd(), ref);
                        annotation.declarationSourceEnd = annotation.sourceStart
                                + annoType.getNameWithoutPackage().length();
                        annotations.add(annotation);
                        // FIXASC underlining for SuppressWarnings doesn't seem right when included in messages
                    } else if (annoType.getName().equals("SuppressWarnings")
                            && (value instanceof ConstantExpression || value instanceof ListExpression)) {
                        if (value instanceof ListExpression) {
                            ListExpression listExpression = (ListExpression) value;
                            // FIXASC tidy up all this junk (err, i mean 'refactor') once we have confidence in test
                            // coverage
                            List<Expression> listOfExpressions = listExpression.getExpressions();
                            TypeReference annotationReference = createTypeReferenceForClassNode(annoType);
                            annotationReference.sourceStart = annotationNode.getStart();
                            annotationReference.sourceEnd = annotationNode.getEnd() - 1;
                            SingleMemberAnnotation annotation = new SingleMemberAnnotation(annotationReference,
                                    annotationNode.getStart());

                            ArrayInitializer arrayInitializer = new ArrayInitializer();
                            arrayInitializer.expressions = new org.eclipse.jdt.internal.compiler.ast.Expression[listOfExpressions
                                    .size()];
                            for (int c = 0; c < listOfExpressions.size(); c++) {
                                ConstantExpression cExpression = (ConstantExpression) listOfExpressions.get(c);
                                String v = (String) cExpression.getValue();
                                TypeReference ref = null;
                                int start = cExpression.getStart();
                                int end = cExpression.getEnd() - 1;
                                if (v.indexOf(".") == -1) {
                                    ref = new SingleTypeReference(v.toCharArray(), toPos(start, end - 1));
                                    annotation.declarationSourceEnd = annotation.sourceStart
                                            + annoType.getNameWithoutPackage().length() - 1;
                                } else {
                                    char[][] splits = CharOperation.splitOn('.', v.toCharArray());
                                    ref = new QualifiedTypeReference(splits,
                                            positionsFor(splits, start, end - 2));
                                    annotation.declarationSourceEnd = annotation.sourceStart
                                            + annoType.getName().length() - 1;
                                }
                                arrayInitializer.expressions[c] = new StringLiteral(v.toCharArray(), start, end,
                                        -1);
                            }
                            annotation.memberValue = arrayInitializer;
                            annotations.add(annotation);
                        } else {
                            ConstantExpression constantExpression = (ConstantExpression) value;
                            if (value.getType().getName().equals("java.lang.String")) {
                                // single value, eg. @SuppressWarnings("unchecked")
                                // FIXASC tidy up all this junk (err, i mean 'refactor') once we have confidence in test
                                // coverage
                                // FIXASC test positional info for conjured up anno refs
                                TypeReference annotationReference = createTypeReferenceForClassNode(annoType);
                                annotationReference.sourceStart = annotationNode.getStart();
                                annotationReference.sourceEnd = annotationNode.getEnd() - 1;
                                SingleMemberAnnotation annotation = new SingleMemberAnnotation(
                                        annotationReference, annotationNode.getStart());
                                String v = (String) constantExpression.getValue();
                                TypeReference ref = null;
                                int start = constantExpression.getStart();
                                int end = constantExpression.getEnd() - 1;
                                if (v.indexOf(".") == -1) {
                                    ref = new SingleTypeReference(v.toCharArray(), toPos(start, end - 1));
                                    annotation.declarationSourceEnd = annotation.sourceStart
                                            + annoType.getNameWithoutPackage().length() - 1;
                                } else {
                                    char[][] splits = CharOperation.splitOn('.', v.toCharArray());
                                    ref = new QualifiedTypeReference(splits,
                                            positionsFor(splits, start, end - 2));
                                    annotation.declarationSourceEnd = annotation.sourceStart
                                            + annoType.getName().length() - 1;
                                }
                                annotation.memberValue = new StringLiteral(v.toCharArray(), start, end, -1);
                                annotations.add(annotation);
                            }
                        }
                    }
                } else if (annoType.getNameWithoutPackage().equals("Test")) {
                    // normal annotation (with at least one member value pair)
                    // GRECLIPSE-569
                    // treat as a marker annotation
                    // this is specifically written so that annotations like @Test(expected = FooException) can be found
                    TypeReference annotationReference = createTypeReferenceForClassNode(annoType);
                    annotationReference.sourceStart = annotationNode.getStart();
                    annotationReference.sourceEnd = annotationNode.getEnd();

                    MarkerAnnotation annotation = new MarkerAnnotation(annotationReference,
                            annotationNode.getStart());
                    annotation.declarationSourceEnd = annotation.sourceEnd;
                    annotations.add(annotation);
                }
            }
        }
        if (annotations.size() > 0) {
            return annotations.toArray(new Annotation[annotations.size()]);
        }
    }
    return null;
}

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

License:Open Source License

/**
 * Only handle certain kinds of expressions
 * all others will be returned as null//from   w  ww. ja  v a2 s  . c  om
 * 
 * String constants
 * int constants
 * arrays
 * ClassRefs
 * Enum ref
 * Annotation ref
 * 
 * @param ajExpr
 * @return jdtExpr
 */
private Expression convertToJDTExpression(org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression ajExpr) {
    if (ajExpr == null) {
        return null;
    }
    Expression jdtExpr = null;
    if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation) ajExpr;
        StringLiteralConcatenation castedJDT = new StringLiteralConcatenation(
                (StringLiteral) convertToJDTExpression(castedAJ.literals[0]),
                (StringLiteral) convertToJDTExpression(castedAJ.literals[1]));
        for (int i = 2; i < castedAJ.literals.length; i++) {
            // may not be able to handle non-string constants here
            castedJDT.extendsWith((StringLiteral) convertToJDTExpression(castedAJ.literals[i]));
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.CharLiteral) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.CharLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.CharLiteral) ajExpr;
        CharLiteral castedJDT = new CharLiteral(castedAJ.source(), castedAJ.sourceStart, castedAJ.sourceEnd);
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.DoubleLiteral) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.DoubleLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.DoubleLiteral) ajExpr;
        DoubleLiteral castedJDT = new DoubleLiteral(castedAJ.source(), castedAJ.sourceStart,
                castedAJ.sourceEnd);
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.FloatLiteral) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.FloatLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.FloatLiteral) ajExpr;
        FloatLiteral castedJDT = new FloatLiteral(castedAJ.source(), castedAJ.sourceStart, castedAJ.sourceEnd);
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue) {
        // ECLIPSE 3.7.1 --- must use reflection since constructors have changed
        // ORIG
        //            IntLiteralMinValue castedJDT = new IntLiteralMinValue();
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue) ajExpr;
        IntLiteral castedJDT = null;
        try {
            castedJDT = CompilerASTNodeCompatibilityWrapper.createJDTIntLiteralMinValue(castedAJ);
        } catch (Exception e) {
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteral) {
        // ECLIPSE 3.7.1 --- must use reflection since constructors have changed
        // ORIG
        //            IntLiteralMinValue castedJDT = new IntLiteralMinValue();
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.IntLiteral) ajExpr;
        IntLiteral castedJDT = null;
        try {
            castedJDT = CompilerASTNodeCompatibilityWrapper.createJDTIntLiteral(castedAJ);
        } catch (Exception e) {
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.FalseLiteral) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.FalseLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.FalseLiteral) ajExpr;
        FalseLiteral castedJDT = null;
        try {
            castedJDT = CompilerASTNodeCompatibilityWrapper.createJDTFalseLiteral(castedAJ);
        } catch (Exception e) {
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.NullLiteral) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.NullLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.NullLiteral) ajExpr;
        NullLiteral castedJDT = null;
        try {
            castedJDT = CompilerASTNodeCompatibilityWrapper.createJDTNullLiteral(castedAJ);
        } catch (Exception e) {
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TrueLiteral) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.TrueLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TrueLiteral) ajExpr;
        TrueLiteral castedJDT = null;
        try {
            castedJDT = CompilerASTNodeCompatibilityWrapper.createJDTTrueLiteral(castedAJ);
        } catch (Exception e) {
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteralMinValue) {
        // ECLIPSE 3.7.1 --- must use reflection since constructors have changed
        // ORIG
        //            IntLiteralMinValue castedJDT = new IntLiteralMinValue();
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteralMinValue castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteralMinValue) ajExpr;
        LongLiteral castedJDT = null;
        try {
            castedJDT = CompilerASTNodeCompatibilityWrapper.createJDTLongLiteralMinValue(castedAJ);
        } catch (Exception e) {
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteral) {
        // ECLIPSE 3.7.1 --- must use reflection since constructors have changed
        // ORIG
        //            IntLiteralMinValue castedJDT = new IntLiteralMinValue();
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.LongLiteral) ajExpr;
        LongLiteral castedJDT = null;
        try {
            castedJDT = CompilerASTNodeCompatibilityWrapper.createJDTLongLiteral(castedAJ);
        } catch (Exception e) {
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral) {
        // note that here we capture both StringLiteral and ExtendedStringLiteral
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral) ajExpr;
        // can we get away with no line number?
        StringLiteral castedJDT = new StringLiteral(castedAJ.source(), castedAJ.sourceStart, castedAJ.sourceEnd,
                0);
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayInitializer) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayInitializer castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayInitializer) ajExpr;
        ArrayInitializer castedJDT = new ArrayInitializer();
        if (castedAJ.expressions != null) {
            castedJDT.expressions = new Expression[castedAJ.expressions.length];
            for (int i = 0; i < castedJDT.expressions.length; i++) {
                castedJDT.expressions[i] = convertToJDTExpression(castedAJ.expressions[i]);
            }
        }
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression) ajExpr;
        ArrayAllocationExpression castedJDT = new ArrayAllocationExpression();
        castedJDT.type = convertToJDTTypeReference(castedAJ.type);
        if (castedAJ.dimensions != null) {
            castedJDT.dimensions = new Expression[castedAJ.dimensions.length];
            for (int i = 0; i < castedJDT.dimensions.length; i++) {
                castedJDT.dimensions[i] = convertToJDTExpression(castedAJ.dimensions[i]);
            }
        }
        castedJDT.initializer = (ArrayInitializer) convertToJDTExpression(castedAJ.initializer);
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldReference) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.FieldReference) ajExpr;
        FieldReference castedJDT = new FieldReference(castedAJ.token,
                toPos(castedAJ.sourceStart, castedAJ.sourceEnd));
        castedJDT.nameSourcePosition = castedAJ.nameSourcePosition;
        castedJDT.receiver = convertToJDTExpression(castedAJ.receiver);
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayReference) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayReference) ajExpr;
        ArrayReference castedJDT = new ArrayReference(convertToJDTExpression(castedAJ.receiver),
                convertToJDTExpression(castedAJ.position));
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference) ajExpr;
        QualifiedNameReference castedJDT = new QualifiedNameReference(castedAJ.tokens, castedAJ.sourcePositions,
                castedAJ.sourceStart, castedAJ.sourceEnd);
        castedJDT.indexOfFirstFieldBinding = castedAJ.indexOfFirstFieldBinding;
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleNameReference) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleNameReference castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleNameReference) ajExpr;
        SingleNameReference castedJDT = new SingleNameReference(castedAJ.token,
                toPos(castedAJ.sourceStart, castedAJ.sourceEnd));
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) {
        jdtExpr = convertToJDTTypeReference(
                (org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference) ajExpr);
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess) {
        org.aspectj.org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess castedAJ = (org.aspectj.org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess) ajExpr;
        ClassLiteralAccess castedJDT = new ClassLiteralAccess(castedAJ.sourceEnd,
                convertToJDTTypeReference(castedAJ.type));
        jdtExpr = castedJDT;
    } else if (ajExpr instanceof org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation) {
        jdtExpr = convertToJDTAnnotation((org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation) ajExpr);
    }

    if (jdtExpr != null) {
        // now fill in other fields
        jdtExpr.bits = ajExpr.bits;
        jdtExpr.implicitConversion = ajExpr.implicitConversion;
        jdtExpr.sourceStart = ajExpr.sourceStart;
        jdtExpr.sourceEnd = ajExpr.sourceEnd;
        jdtExpr.statementEnd = ajExpr.statementEnd;
    }
    return jdtExpr;
}

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

License:Open Source License

public void arrayInitializer(int length) {
    //length is the size of the array Initializer
    //expressionPtr points on the last elt of the arrayInitializer,
    // in other words, it has not been decremented yet.

    ArrayInitializer ai = new ArrayInitializer();
    if (length != 0) {
        this.expressionPtr -= length;
        System.arraycopy(this.expressionStack, this.expressionPtr + 1, ai.expressions = new Expression[length],
                0, length);//from www.  j  a  v  a  2  s. c  o  m
    }
    pushOnExpressionStack(ai);
    //positionning
    ai.sourceEnd = this.endStatementPosition;
    ai.sourceStart = this.intStack[this.intPtr--];
}

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

License:Open Source License

private static Expression annotationValues(Object elementValue, AstGenerator gen, ProblemReporter pr) {
    if (elementValue instanceof Object[]) {
        Object[] valuesArray = (Object[]) elementValue;
        ArrayInitializer arrayInit = new ArrayInitializer();
        arrayInit.expressions = new Expression[valuesArray.length];
        for (int k = 0; k < valuesArray.length; k++) {
            arrayInit.expressions[k] = annotationValue(valuesArray[k], gen, pr);
            if (arrayInit.expressions[k] == null)
                return null; // error detected.
        }/*from ww  w . j av a2s . c om*/
        return arrayInit;
    } else {
        return annotationValue(elementValue, gen, pr);
    }
}

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

License:Open Source License

public ArrayAllocationExpression arrayAllocation(TypeReference typeRef, int dims, Expression[] arguments) {
    ArrayAllocationExpression allocation = new ArrayAllocationExpression();
    allocation.type = typeRef;//from  www.  jav  a 2  s .c  o  m
    if (arguments == null) {
        allocation.dimensions = new Expression[] { intLiteral(dims) };
    } else {
        allocation.dimensions = new Expression[dims];
        allocation.initializer = new ArrayInitializer();
        allocation.initializer.expressions = arguments;
    }
    return setPos(allocation);
}

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

License:Open Source License

public SingleMemberAnnotation singleStringsMemberAnnotation(char[][] compoundName, char[][] memberValues) {
    SingleMemberAnnotation result = new SingleMemberAnnotation(qualifiedTypeReference(compoundName),
            this.sourceStart);
    result.sourceEnd = this.sourceEnd;
    result.declarationSourceEnd = this.sourceEnd;
    ArrayInitializer arrayInitializer = new ArrayInitializer();
    arrayInitializer.expressions = new Expression[memberValues.length];
    for (int i = 0; i < memberValues.length; i++)
        arrayInitializer.expressions[i] = stringLiteral(memberValues[i]);
    result.memberValue = arrayInitializer;
    return result;
}

From source file:org.nabucco.framework.generator.compiler.transformation.java.service.NabuccoToJavaServiceJoinPointVisitor.java

License:Open Source License

@Override
public void visit(MethodDeclaration nabuccoMethod, MdaModel<JavaModel> target) {

    try {//from   ww w.j a v  a2  s  .c o m
        String name = nabuccoMethod.nodeToken1.tokenImage;

        List<NabuccoAnnotation> annotationList = NabuccoAnnotationMapper.getInstance()
                .mapToAnnotationList(nabuccoMethod.annotationDeclaration, NabuccoAnnotationType.JOIN_POINT);

        JavaAstModelProducer producer = JavaAstModelProducer.getInstance();

        Literal nameLiteral = producer.createLiteral(name, LiteralType.STRING_LITERAL);

        List<Expression> joinPoints = new ArrayList<Expression>();

        for (NabuccoAnnotation annotation : annotationList) {
            joinPoints.add(producer.createLiteral(annotation.getValue(), LiteralType.STRING_LITERAL));
        }

        Expression array;

        if (!joinPoints.isEmpty()) {
            ArrayAllocationExpression arrayAllocation = new ArrayAllocationExpression();
            arrayAllocation.type = producer.createTypeReference("String", false);
            arrayAllocation.dimensions = new Expression[1];
            arrayAllocation.initializer = new ArrayInitializer();
            arrayAllocation.initializer.expressions = joinPoints.toArray(new Expression[joinPoints.size()]);
            array = arrayAllocation;
        } else {
            array = producer.createSingleNameReference(NO_ASPECTS);
        }

        MessageSend statement = producer.createMessageSend("put", this.aspectConstant,
                Arrays.asList(nameLiteral, array));

        this.aspectStatements.statements = Arrays.copyOf(this.aspectStatements.statements,
                this.aspectStatements.statements.length + 1);
        this.aspectStatements.statements[this.aspectStatements.statements.length - 1] = statement;

    } catch (JavaModelException jme) {
        throw new NabuccoVisitorException("Error creating service operation aspect.");
    }

    super.visit(nabuccoMethod, target);
}