mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-22 06:21:25 +07:00
allow compile-time constants to be used from static field initializers (IDEA-142243)
This commit is contained in:
@@ -639,7 +639,7 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
/**
|
||||
* JLS 15.28
|
||||
*/
|
||||
public static boolean isCompileTimeConstant(@NotNull final PsiField field) {
|
||||
public static boolean isCompileTimeConstant(@NotNull final PsiVariable field) {
|
||||
return field.hasModifierProperty(PsiModifier.FINAL)
|
||||
&& (TypeConversionUtil.isPrimitiveAndNotNull(field.getType()) || field.getType().equalsToText(JAVA_LANG_STRING))
|
||||
&& field.hasInitializer()
|
||||
|
||||
@@ -81,7 +81,9 @@ public class VariableResolverProcessor extends ConflictFilterProcessor implement
|
||||
|
||||
@Override
|
||||
public void add(@NotNull PsiElement element, @NotNull PsiSubstitutor substitutor) {
|
||||
final boolean staticProblem = myStaticScopeFlag && !((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC);
|
||||
final boolean staticProblem = myStaticScopeFlag &&
|
||||
!((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC) &&
|
||||
!(element instanceof PsiVariable && PsiUtil.isCompileTimeConstant((PsiVariable)element));
|
||||
add(new CandidateInfo(element, substitutor, myPlace, myAccessClass, staticProblem, myCurrentFileContext));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
void m() {
|
||||
final String s = "b";
|
||||
final Object o = null;
|
||||
class A {
|
||||
static final String t = s;
|
||||
<error descr="Inner classes cannot have static declarations">static</error> final Object j = <error descr="Non-static variable 'o' cannot be referenced from a static context">o</error>;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,5 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testAgentPremain() { doTest(false, false); }
|
||||
public void testInitializedBeforeUsed() { doTest(false, false); }
|
||||
public void testUnreachableAssignments() { doTest(false, false); }
|
||||
public void testCompileTypeConstantsAccessibleFromStaticFieldInitializers() { doTest(false, false);}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user