Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java')
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java
index 6aaaa5c25..a922effd6 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java
@@ -48,6 +48,8 @@ public class ArrayAllocationExpression extends Expression {
public Annotation [][] annotationsOnDimensions; // jsr308 style annotations.
public ArrayInitializer initializer;
+ private TypeBinding expectedType;
+
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
for (int i = 0, max = this.dimensions.length; i < max; i++) {
Expression dim;
@@ -184,6 +186,21 @@ public class ArrayAllocationExpression extends Expression {
{
scope.problemReporter().contradictoryNullAnnotations(this.type.annotations[this.type.annotations.length-1]);
}
+ LookupEnvironment environment = scope.environment();
+ if (environment.usesNullTypeAnnotations()
+ && this.annotationsOnDimensions == null // don't annotate if explicit annotations are given on dimensions ...
+ && ((referenceType.tagBits & TagBits.AnnotationNullMASK) == 0) // ... or leaf type
+ && this.expectedType != null) // need this to determine our action
+ {
+ Expression lastDim = this.dimensions[this.dimensions.length-1];
+ if (lastDim instanceof IntLiteral && ((IntLiteral) lastDim).value == 0) {
+ long tagBit = this.expectedType.leafComponentType().tagBits & TagBits.AnnotationNullMASK;
+ // let new X[0] be seen as "@NonNull X[]", or "@Nullable X[]" just as expected
+ AnnotationBinding[] nullAnnotations = environment.nullAnnotationsFromTagBits(tagBit);
+ if (nullAnnotations != null)
+ referenceType = environment.createAnnotatedType(referenceType, nullAnnotations);
+ }
+ }
//{ObjectTeams:
referenceType = RoleTypeCreator.maybeWrapUnqualifiedRoleType(referenceType, scope, this);
// SH}
@@ -214,6 +231,10 @@ public class ArrayAllocationExpression extends Expression {
return this.resolvedType;
}
+ @Override
+ public void setExpectedType(TypeBinding expectedType) {
+ this.expectedType = expectedType;
+ }
public void traverse(ASTVisitor visitor, BlockScope scope) {
if (visitor.visit(this, scope)) {

Back to the top