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; 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; }
protected void consumeArrayCreationExpressionWithoutInitializer() { // ArrayCreationWithoutArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs // ArrayCreationWithoutArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs super.consumeArrayCreationExpressionWithoutInitializer(); ArrayAllocationExpression alloc = (ArrayAllocationExpression)this.expressionStack[this.expressionPtr]; if (alloc.type == this.assistNode){ if (!this.diet){ this.restartRecovery = true; // force to restart in recovery mode this.lastIgnoredToken = -1; } this.isOrphanCompletionNode = true; } }
protected void consumeArrayCreationExpressionWithInitializer() { // ArrayCreationWithArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs ArrayInitializer super.consumeArrayCreationExpressionWithInitializer(); ArrayAllocationExpression alloc = (ArrayAllocationExpression)this.expressionStack[this.expressionPtr]; if (alloc.type == this.assistNode){ if (!this.diet){ this.restartRecovery = true; // force to restart in recovery mode this.lastIgnoredToken = -1; } this.isOrphanCompletionNode = true; } }
protected void consumeArrayCreationExpressionWithInitializer() { // ArrayCreationWithArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs ArrayInitializer // ArrayCreationWithArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs ArrayInitializer int length; ArrayAllocationExpression arrayAllocation = new ArrayAllocationExpression(); this.expressionLengthPtr -- ; arrayAllocation.initializer = (ArrayInitializer) this.expressionStack[this.expressionPtr--]; length = (this.expressionLengthStack[this.expressionLengthPtr--]); this.expressionPtr -= length ; System.arraycopy( this.expressionStack, this.expressionPtr+1, arrayAllocation.dimensions = new Expression[length], 0, length); Annotation[][] annotationsOnDimensions = getAnnotationsOnDimensions(length); arrayAllocation.annotationsOnDimensions = annotationsOnDimensions; arrayAllocation.type = getTypeReference(0); arrayAllocation.type.bits |= ASTNode.IgnoreRawTypeCheck; // no need to worry about raw type usage if (annotationsOnDimensions != null) { arrayAllocation.bits |= ASTNode.HasTypeAnnotations; arrayAllocation.type.bits |= ASTNode.HasTypeAnnotations; } arrayAllocation.sourceStart = this.intStack[this.intPtr--]; if (arrayAllocation.initializer == null) { arrayAllocation.sourceEnd = this.endStatementPosition; } else { arrayAllocation.sourceEnd = arrayAllocation.initializer.sourceEnd ; } pushOnExpressionStack(arrayAllocation); }
protected void consumeArrayCreationExpressionWithoutInitializer() { // ArrayCreationWithoutArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs // ArrayCreationWithoutArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs int length; ArrayAllocationExpression arrayAllocation = new ArrayAllocationExpression(); length = (this.expressionLengthStack[this.expressionLengthPtr--]); this.expressionPtr -= length ; System.arraycopy( this.expressionStack, this.expressionPtr+1, arrayAllocation.dimensions = new Expression[length], 0, length); Annotation[][] annotationsOnDimensions = getAnnotationsOnDimensions(length); arrayAllocation.annotationsOnDimensions = annotationsOnDimensions; arrayAllocation.type = getTypeReference(0); arrayAllocation.type.bits |= ASTNode.IgnoreRawTypeCheck; // no need to worry about raw type usage if (annotationsOnDimensions != null) { arrayAllocation.bits |= ASTNode.HasTypeAnnotations; arrayAllocation.type.bits |= ASTNode.HasTypeAnnotations; } arrayAllocation.sourceStart = this.intStack[this.intPtr--]; if (arrayAllocation.initializer == null) { arrayAllocation.sourceEnd = this.endStatementPosition; } else { arrayAllocation.sourceEnd = arrayAllocation.initializer.sourceEnd ; } pushOnExpressionStack(arrayAllocation); }
public void cannotDefineDimensionsAndInitializer(ArrayAllocationExpression expresssion) { this.handle( IProblem.CannotDefineDimensionExpressionsWithInit, NoArgument, NoArgument, expresssion.sourceStart, expresssion.sourceEnd); }
public void incorrectLocationForNonEmptyDimension(ArrayAllocationExpression expression, int index) { this.handle( IProblem.IllegalDimension, NoArgument, NoArgument, expression.dimensions[index].sourceStart, expression.dimensions[index].sourceEnd); }
public void mustDefineDimensionsOrInitializer(ArrayAllocationExpression expression) { this.handle( IProblem.MustDefineEitherDimensionExpressionsOrInitializer, NoArgument, NoArgument, expression.sourceStart, expression.sourceEnd); }
public void multianewarray( TypeReference typeReference, TypeBinding typeBinding, int dimensions, ArrayAllocationExpression allocationExpression) { if (typeReference != null && (typeReference.bits & ASTNode.HasTypeAnnotations) != 0) { addAnnotationContext(typeReference, this.position, AnnotationTargetTypeConstants.NEW, allocationExpression); } super.multianewarray(typeReference, typeBinding, dimensions, allocationExpression); }
public void multianewarray( TypeReference typeReference, TypeBinding typeBinding, int dimensions, ArrayAllocationExpression allocationExpression) { this.countLabels = 0; this.stackDepth += (1 - dimensions); if (this.classFileOffset + 3 >= this.bCodeStream.length) { resizeByteArray(); } this.position += 2; this.bCodeStream[this.classFileOffset++] = Opcodes.OPC_multianewarray; writeUnsignedShort(this.constantPool.literalIndexForType(typeBinding)); this.bCodeStream[this.classFileOffset++] = (byte) dimensions; }
public void newArray(TypeReference typeReference, ArrayAllocationExpression allocationExpression, ArrayBinding arrayBinding) { TypeBinding component = arrayBinding.elementsType(); switch (component.id) { case TypeIds.T_int : newarray(ClassFileConstants.INT_ARRAY); break; case TypeIds.T_byte : newarray(ClassFileConstants.BYTE_ARRAY); break; case TypeIds.T_boolean : newarray(ClassFileConstants.BOOLEAN_ARRAY); break; case TypeIds.T_short : newarray(ClassFileConstants.SHORT_ARRAY); break; case TypeIds.T_char : newarray(ClassFileConstants.CHAR_ARRAY); break; case TypeIds.T_long : newarray(ClassFileConstants.LONG_ARRAY); break; case TypeIds.T_float : newarray(ClassFileConstants.FLOAT_ARRAY); break; case TypeIds.T_double : newarray(ClassFileConstants.DOUBLE_ARRAY); break; default : anewarray(component); } }
/** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ public boolean visit( ArrayAllocationExpression arrayAllocationExpression, BlockScope scope) { final int numberOfParens = (arrayAllocationExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; if (numberOfParens > 0) { manageOpeningParenthesizedExpression(arrayAllocationExpression, numberOfParens); } this.scribe.printNextToken(TerminalTokens.TokenNamenew); this.scribe.space(); arrayAllocationExpression.type.traverse(this, scope); final Expression[] dimensions = arrayAllocationExpression.dimensions; int dimensionsLength = dimensions.length; for (int i = 0; i < dimensionsLength; i++) { if (this.preferences.insert_space_before_opening_bracket_in_array_allocation_expression) { this.scribe.space(); } this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET, false); if (dimensions[i] != null) { if (this.preferences.insert_space_after_opening_bracket_in_array_allocation_expression) { this.scribe.space(); } dimensions[i].traverse(this, scope); this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET, this.preferences.insert_space_before_closing_bracket_in_array_allocation_expression); } else { this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET, this.preferences.insert_space_between_empty_brackets_in_array_allocation_expression); } } final ArrayInitializer initializer = arrayAllocationExpression.initializer; if (initializer != null) { initializer.traverse(this, scope); } if (numberOfParens > 0) { manageClosingParenthesizedExpression(arrayAllocationExpression, numberOfParens); } return false; }
@Override public void endVisit(ArrayAllocationExpression x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JArrayType type = (JArrayType) typeMap.get(x.resolvedType); if (x.initializer != null) { // handled by ArrayInitializer. } else { // Annoyingly, JDT only visits non-null dims, so we can't popList(). List<JExpression> dims = new ArrayList<JExpression>(); for (int i = x.dimensions.length - 1; i >= 0; --i) { JExpression dimension = pop(x.dimensions[i]); // can be null if index expression was empty if (dimension == null) { dimension = JAbsentArrayDimension.INSTANCE; } dims.add(dimension); } // Undo the stack reversal. Collections.reverse(dims); push(JNewArray.createDims(info, type, dims)); } } catch (Throwable e) { throw translateException(x, e); } }
private 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; 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; }
@Override public boolean visit(ArrayAllocationExpression node, BlockScope scope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); }
public boolean visit( ArrayAllocationExpression arrayAllocationExpression, BlockScope scope) { addRealFragment(arrayAllocationExpression); return false; }
/** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ public boolean visit( ArrayAllocationExpression arrayAllocationExpression, BlockScope scope) { final int numberOfParens = (arrayAllocationExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; if (numberOfParens > 0) { manageOpeningParenthesizedExpression(arrayAllocationExpression, numberOfParens); } this.scribe.printNextToken(TerminalTokens.TokenNamenew); this.scribe.space(); arrayAllocationExpression.type.traverse(this, scope); final Expression[] dimensions = arrayAllocationExpression.dimensions; int dimensionsLength = dimensions.length; for (int i = 0; i < dimensionsLength; i++) { if (arrayAllocationExpression.annotationsOnDimensions != null) { formatInlineAnnotations(arrayAllocationExpression.annotationsOnDimensions[i], true); } if (this.preferences.insert_space_before_opening_bracket_in_array_allocation_expression) { this.scribe.space(); } this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET, false); if (dimensions[i] != null) { if (this.preferences.insert_space_after_opening_bracket_in_array_allocation_expression) { this.scribe.space(); } dimensions[i].traverse(this, scope); this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET, this.preferences.insert_space_before_closing_bracket_in_array_allocation_expression); } else { this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET, this.preferences.insert_space_between_empty_brackets_in_array_allocation_expression); } } final ArrayInitializer initializer = arrayAllocationExpression.initializer; if (initializer != null) { initializer.traverse(this, scope); } if (numberOfParens > 0) { manageClosingParenthesizedExpression(arrayAllocationExpression, numberOfParens); } return false; }
private void addAnnotationContext(TypeReference typeReference, int info, int targetType, ArrayAllocationExpression allocationExpression) { allocationExpression.getAllAnnotationContexts(targetType, info, this.allTypeAnnotationContexts); }
public void newArray(TypeReference typeReference, ArrayAllocationExpression allocationExpression, ArrayBinding arrayBinding) { if (typeReference != null && (typeReference.bits & ASTNode.HasTypeAnnotations) != 0) { addAnnotationContext(typeReference, this.position, AnnotationTargetTypeConstants.NEW, allocationExpression); } super.newArray(typeReference, allocationExpression, arrayBinding); }
@Override public boolean visit(ArrayAllocationExpression node, BlockScope scope) { setGeneratedBy(node, source); applyOffsetExpression(node); return super.visit(node, scope); }