Make not-null compile-time constants non-flexible
This commit is contained in:
+8
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiExpression;
|
import com.intellij.psi.PsiExpression;
|
||||||
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
||||||
|
import com.intellij.psi.util.PsiUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
@@ -43,4 +44,11 @@ public class JavaPropertyInitializerEvaluatorImpl implements JavaPropertyInitial
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isNotNullCompileTimeConstant(@NotNull JavaField field) {
|
||||||
|
// PsiUtil.isCompileTimeConstant returns false for null-initialized fields,
|
||||||
|
// see com.intellij.psi.util.IsConstantExpressionVisitor.visitLiteralExpression()
|
||||||
|
return PsiUtil.isCompileTimeConstant(((JavaFieldImpl) field).getPsi());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -287,10 +287,18 @@ public abstract class LazyJavaMemberScope(
|
|||||||
|
|
||||||
private fun getPropertyType(field: JavaField): JetType {
|
private fun getPropertyType(field: JavaField): JetType {
|
||||||
// Fields do not have their own generic parameters
|
// Fields do not have their own generic parameters
|
||||||
val propertyType = c.typeResolver.transformJavaType(field.getType(), LazyJavaTypeAttributes(c, field, TypeUsage.MEMBER_SIGNATURE_INVARIANT))
|
val finalStatic = field.isFinal() && field.isStatic()
|
||||||
if (!PLATFORM_TYPES && field.isFinal() && field.isStatic()) {
|
|
||||||
|
// simple static constants should not have flexible types:
|
||||||
|
val allowFlexible = PLATFORM_TYPES && !(finalStatic && c.javaPropertyInitializerEvaluator.isNotNullCompileTimeConstant(field))
|
||||||
|
val propertyType = c.typeResolver.transformJavaType(
|
||||||
|
field.getType(),
|
||||||
|
LazyJavaTypeAttributes(c, field, TypeUsage.MEMBER_SIGNATURE_INVARIANT, allowFlexible)
|
||||||
|
)
|
||||||
|
if ((!allowFlexible || !PLATFORM_TYPES) && finalStatic) {
|
||||||
return TypeUtils.makeNotNullable(propertyType)
|
return TypeUtils.makeNotNullable(propertyType)
|
||||||
}
|
}
|
||||||
|
|
||||||
return propertyType
|
return propertyType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
@@ -24,4 +24,6 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
|||||||
public interface JavaPropertyInitializerEvaluator {
|
public interface JavaPropertyInitializerEvaluator {
|
||||||
@Nullable
|
@Nullable
|
||||||
CompileTimeConstant<?> getInitializerConstant(@NotNull JavaField field, @NotNull PropertyDescriptor descriptor);
|
CompileTimeConstant<?> getInitializerConstant(@NotNull JavaField field, @NotNull PropertyDescriptor descriptor);
|
||||||
|
|
||||||
|
boolean isNotNullCompileTimeConstant(@NotNull JavaField field);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user