List of usage examples for org.eclipse.jdt.internal.compiler.ast ArrayAllocationExpression ArrayAllocationExpression
ArrayAllocationExpression
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; }//w w w .j a v a 2 s .c o m return allocationExpression; }
From source file:lombok.eclipse.handlers.HandleSynchronized.java
License:Open Source License
public char[] createLockField(AnnotationValues<Synchronized> annotation, EclipseNode annotationNode, boolean isStatic, boolean reportErrors) { char[] lockName = annotation.getInstance().value().toCharArray(); Annotation source = (Annotation) annotationNode.get(); boolean autoMake = false; if (lockName.length == 0) { autoMake = true;/* w w w . ja v a2 s . c o m*/ lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME; } if (fieldExists(new String(lockName), annotationNode) == MemberExistsResult.NOT_EXISTS) { if (!autoMake) { if (reportErrors) annotationNode.addError(String.format("The field %s does not exist.", new String(lockName))); return null; } FieldDeclaration fieldDecl = new FieldDeclaration(lockName, 0, -1); setGeneratedBy(fieldDecl, source); fieldDecl.declarationSourceEnd = -1; fieldDecl.modifiers = (isStatic ? Modifier.STATIC : 0) | Modifier.FINAL | Modifier.PRIVATE; //We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable! ArrayAllocationExpression arrayAlloc = new ArrayAllocationExpression(); setGeneratedBy(arrayAlloc, source); arrayAlloc.dimensions = new Expression[] { makeIntLiteral("0".toCharArray(), source) }; arrayAlloc.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { 0, 0, 0 }); setGeneratedBy(arrayAlloc.type, source); fieldDecl.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { 0, 0, 0 }); setGeneratedBy(fieldDecl.type, source); fieldDecl.initialization = arrayAlloc; // TODO temporary workaround for issue 217. http://code.google.com/p/projectlombok/issues/detail?id=217 // injectFieldSuppressWarnings(annotationNode.up().up(), fieldDecl); injectField(annotationNode.up().up(), fieldDecl); } return lockName; }
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 w w . ja v a 2s .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
protected void consumeArrayCreationExpressionWithInitializer() { // ArrayCreationWithArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs ArrayInitializer // ArrayCreationWithArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs ArrayInitializer int length;//from ww w. j a va2 s . co m ArrayAllocationExpression arrayAllocation = new ArrayAllocationExpression(); this.expressionLengthPtr--; arrayAllocation.initializer = (ArrayInitializer) this.expressionStack[this.expressionPtr--]; arrayAllocation.type = getTypeReference(0); arrayAllocation.type.bits |= ASTNode.IgnoreRawTypeCheck; // no need to worry about raw type usage length = (this.expressionLengthStack[this.expressionLengthPtr--]); this.expressionPtr -= length; System.arraycopy(this.expressionStack, this.expressionPtr + 1, arrayAllocation.dimensions = new Expression[length], 0, length); arrayAllocation.sourceStart = this.intStack[this.intPtr--]; if (arrayAllocation.initializer == null) { arrayAllocation.sourceEnd = this.endStatementPosition; } else { arrayAllocation.sourceEnd = arrayAllocation.initializer.sourceEnd; } pushOnExpressionStack(arrayAllocation); }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeArrayCreationExpressionWithoutInitializer() { // ArrayCreationWithoutArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs // ArrayCreationWithoutArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs int length;/*from w w w . ja va2 s.com*/ ArrayAllocationExpression arrayAllocation = new ArrayAllocationExpression(); arrayAllocation.type = getTypeReference(0); arrayAllocation.type.bits |= ASTNode.IgnoreRawTypeCheck; // no need to worry about raw type usage length = (this.expressionLengthStack[this.expressionLengthPtr--]); this.expressionPtr -= length; System.arraycopy(this.expressionStack, this.expressionPtr + 1, arrayAllocation.dimensions = new Expression[length], 0, length); arrayAllocation.sourceStart = this.intStack[this.intPtr--]; if (arrayAllocation.initializer == null) { arrayAllocation.sourceEnd = this.endStatementPosition; } else { arrayAllocation.sourceEnd = arrayAllocation.initializer.sourceEnd; } pushOnExpressionStack(arrayAllocation); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.ArrayTranslations.java
License:Open Source License
/** * creates AST-Element/*w w w. j a v a2 s.c o m*/ * * if currentDimension == 1 -> result = new Base[role.length][][]; * if currentDimension == 2 -> result[i0] = new Base[role[i0].length][][]; * if currentDimension == arrayDimensions -> result[i0][i1][i2] = role[i0][i1][i2]._OT$Base; * @param currentDimension some dimensions must have special treatment * @param arrayDimensions maximum of dimensions of the array * @return the new created assignment */ private Assignment generateArrayInstantiation(int currentDimension, int arrayDimensions, AstGenerator gen) { SingleNameReference resultNameReference = new SingleNameReference(IOTConstants.OT_RESULT, 0); decapsulationOutput(resultNameReference); Expression lastArrayReference = resultNameReference; for (int idx = 0; idx < currentDimension; idx++) { SingleNameReference pos = new SingleNameReference(generateArrayIndexName(idx), 0); ArrayReference nextArray = new ArrayReference(lastArrayReference, pos); lastArrayReference = nextArray; } Expression lhsReference = lastArrayReference; lastArrayReference = decapsulationInput(gen.singleNameReference(ROLE_ARRAY_ARG)); for (int idx = 0; idx < currentDimension; idx++) { SingleNameReference pos = new SingleNameReference(generateArrayIndexName(idx), 0); ArrayReference nextArray = new ArrayReference(lastArrayReference, pos); lastArrayReference = nextArray; } Expression rhsReference = lastArrayReference; if (currentDimension == arrayDimensions) { return new Assignment(lhsReference, translation(rhsReference, this._providedType.leafComponentType(), this._requiredType.leafComponentType(), gen), 0); } else { //new Required[role[i0].length][][]; FieldReference lengthFieldReference = new FieldReference(IOTConstants.LENGTH, 0); lengthFieldReference.receiver = rhsReference; TypeReference reqTypeReference = gen.typeReference(this._requiredType.leafComponentType()); decapsulationOutput(reqTypeReference); ArrayAllocationExpression reqAllocationExpression = new ArrayAllocationExpression(); reqAllocationExpression.type = reqTypeReference; reqAllocationExpression.dimensions = new Expression[arrayDimensions - currentDimension]; reqAllocationExpression.dimensions[0] = lengthFieldReference; Assignment assignment = new Assignment(lhsReference, reqAllocationExpression, 0); return assignment; } }
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;// w w w.j a va 2 s . co 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.nabucco.framework.generator.compiler.transformation.java.service.NabuccoToJavaServiceJoinPointVisitor.java
License:Open Source License
@Override public void visit(MethodDeclaration nabuccoMethod, MdaModel<JavaModel> target) { try {/*from w ww. j av a2 s.co 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); }
From source file:org.nabucco.framework.mda.template.java.extract.statement.JavaAstStatementExtractorVisitor.java
License:Open Source License
@Override public boolean visit(ArrayAllocationExpression arrayAllocationExpression, BlockScope scope) { ArrayAllocationExpression arrayCopy = new ArrayAllocationExpression(); arrayCopy.dimensions = copy(arrayAllocationExpression.dimensions, scope); arrayCopy.initializer = copy(arrayAllocationExpression.initializer, scope); arrayCopy.type = copy(arrayAllocationExpression.type); this.statement = arrayCopy; return false; }