Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 98656 Details for
Bug 228109
[1.5][compiler] Enum static field initializer in enum constructor failed to give compilation error
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
228109.txt (text/plain), 51.46 KB, created by
Philipe Mulet
on 2008-05-05 12:05:59 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2008-05-05 12:05:59 EDT
Size:
51.46 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java,v >retrieving revision 1.122 >diff -u -r1.122 EnumTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java 21 Apr 2008 10:45:07 -0000 1.122 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java 5 May 2008 16:05:30 -0000 >@@ -3860,20 +3860,20 @@ > " ^^^^^\n" + > "Cannot refer to the static enum field X.VALUE within an initializer\n" + > "----------\n" + >- "2. ERROR in X.java (at line 8)\n" + >- " VALUE = null;\n" + >- " ^^^^^\n" + >- "The final field X.VALUE cannot be assigned\n" + >- "----------\n" + >- "3. ERROR in X.java (at line 9)\n" + >+ "2. ERROR in X.java (at line 9)\n" + > " ASD = 5;\n" + > " ^^^\n" + > "Cannot refer to the static enum field X.ASD within an initializer\n" + > "----------\n" + >- "4. ERROR in X.java (at line 10)\n" + >+ "3. ERROR in X.java (at line 10)\n" + > " X.VALUE = null;\n" + > " ^^^^^\n" + >- "The final field X.VALUE cannot be assigned\n" + >+ "Cannot refer to the static enum field X.VALUE within an initializer\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 11)\n" + >+ " X.ASD = 5;\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field X.ASD within an initializer\n" + > "----------\n"); > } > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=101713 - variation >@@ -3895,11 +3895,6 @@ > " BLEU = null;\n" + > " ^^^^\n" + > "Cannot refer to the static enum field X.BLEU within an initializer\n" + >- "----------\n" + >- "2. ERROR in X.java (at line 6)\n" + >- " BLEU = null;\n" + >- " ^^^^\n" + >- "The final field X.BLEU cannot be assigned\n" + > "----------\n"); > } > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=101713 - variation >@@ -3933,37 +3928,47 @@ > " ^^^^\n" + > "Cannot refer to the static enum field X.BLEU within an initializer\n" + > "----------\n" + >- "2. WARNING in X.java (at line 6)\n" + >+ "2. ERROR in X.java (at line 6)\n" + >+ " X x = BLEU.BLANC; // ko\n" + >+ " ^^^^^\n" + >+ "Cannot refer to the static enum field X.BLANC within an initializer\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 6)\n" + > " X x = BLEU.BLANC; // ko\n" + > " ^^^^^\n" + > "The static field X.BLANC should be accessed in a static way\n" + > "----------\n" + >- "3. ERROR in X.java (at line 7)\n" + >+ "4. ERROR in X.java (at line 7)\n" + > " X x2 = BLEU; // ko\n" + > " ^^^^\n" + > "Cannot refer to the static enum field X.BLEU within an initializer\n" + > "----------\n" + >- "4. WARNING in X.java (at line 10)\n" + >+ "5. WARNING in X.java (at line 10)\n" + > " X x = BLEU.BLANC; // ok\n" + > " ^^^^^\n" + > "The static field X.BLANC should be accessed in a static way\n" + > "----------\n" + >- "5. ERROR in X.java (at line 13)\n" + >+ "6. ERROR in X.java (at line 13)\n" + > " X dummy = BLEU; // ko\n" + > " ^^^^\n" + > "Cannot refer to the static enum field X.BLEU within an initializer\n" + > "----------\n" + >- "6. ERROR in X.java (at line 16)\n" + >+ "7. ERROR in X.java (at line 16)\n" + > " X x = BLEU.BLANC; // ko\n" + > " ^^^^\n" + > "Cannot refer to the static enum field X.BLEU within an initializer\n" + > "----------\n" + >- "7. WARNING in X.java (at line 16)\n" + >+ "8. ERROR in X.java (at line 16)\n" + >+ " X x = BLEU.BLANC; // ko\n" + >+ " ^^^^^\n" + >+ "Cannot refer to the static enum field X.BLANC within an initializer\n" + >+ "----------\n" + >+ "9. WARNING in X.java (at line 16)\n" + > " X x = BLEU.BLANC; // ko\n" + > " ^^^^^\n" + > "The static field X.BLANC should be accessed in a static way\n" + > "----------\n" + >- "8. ERROR in X.java (at line 17)\n" + >+ "10. ERROR in X.java (at line 17)\n" + > " X x2 = BLEU; // ko\n" + > " ^^^^\n" + > "Cannot refer to the static enum field X.BLEU within an initializer\n" + >@@ -4063,7 +4068,12 @@ > " ^\n" + > "Cannot refer to the static enum field X.B within an initializer\n" + > "----------\n" + >- "3. WARNING in X.java (at line 5)\n" + >+ "3. ERROR in X.java (at line 5)\n" + >+ " final X a2 = B.A;\n" + >+ " ^\n" + >+ "Cannot refer to the static enum field X.A within an initializer\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 5)\n" + > " final X a2 = B.A;\n" + > " ^\n" + > "The static field X.A should be accessed in a static way\n" + >@@ -4087,12 +4097,7 @@ > "}\n", > }, > "----------\n" + >- "1. WARNING in X.java (at line 5)\n" + >- " private static String error;\n" + >- " ^^^^^\n" + >- "The field X.error is never read locally\n" + >- "----------\n" + >- "2. ERROR in X.java (at line 8)\n" + >+ "1. ERROR in X.java (at line 8)\n" + > " error = \"error\";\n" + > " ^^^^^\n" + > "Cannot refer to the static enum field X.error within an initializer\n" + >@@ -5262,4 +5267,320 @@ > false, > null); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 >+public void test153() { >+ this.runNegativeTest( >+ new String[] { >+ "TestEnum.java", >+ "public enum TestEnum {\n" + >+ " RED, GREEN, BLUE; \n" + >+ " static int test = 0; \n" + >+ "\n" + >+ " TestEnum() {\n" + >+ " TestEnum.test=10;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in TestEnum.java (at line 6)\n" + >+ " TestEnum.test=10;\n" + >+ " ^^^^\n" + >+ "Cannot refer to the static enum field TestEnum.test within an initializer\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation >+public void test154() { >+ this.runNegativeTest( >+ new String[] { >+ "TestEnum2.java", >+ "public enum TestEnum2 {\n" + >+ " ; \n" + >+ " static int test = 0; \n" + >+ " TestEnum2() {\n" + >+ " TestEnum2.test=11;\n" + >+ " }\n" + >+ "}\n" + >+ "class X {\n" + >+ " static int test = 0;\n" + >+ " X() {\n" + >+ " X.test = 13;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in TestEnum2.java (at line 5)\n" + >+ " TestEnum2.test=11;\n" + >+ " ^^^^\n" + >+ "Cannot refer to the static enum field TestEnum2.test within an initializer\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation >+public void test155() { >+ this.runConformTest( >+ new String[] { >+ "TestEnum.java", >+ "public enum TestEnum {\n" + >+ " RED, GREEN, BLUE; \n" + >+ " static int test = 0; \n" + >+ "}\n" + >+ "\n" + >+ "enum TestEnum2 {\n" + >+ " ; \n" + >+ " TestEnum2() {\n" + >+ " TestEnum.test=12;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ ""); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation >+public void test156() { >+ this.runConformTest( >+ new String[] { >+ "TestEnum.java", >+ "public enum TestEnum {\n" + >+ " RED, GREEN, BLUE; \n" + >+ " static int test = 0; \n" + >+ "\n" + >+ " TestEnum() {\n" + >+ " new Object() {\n" + >+ " { TestEnum.test=10; }\n" + >+ " };\n" + >+ " }\n" + >+ "}\n" >+ }, >+ ""); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation >+public void test157() { >+ this.runNegativeTest( >+ new String[] { >+ "Foo.java", >+ "enum Foo {\n" + >+ " ONE, TWO, THREE;\n" + >+ " static int val = 10;\n" + >+ " Foo () {\n" + >+ " this(Foo.val);\n" + >+ " System.out.println(Foo.val);\n" + >+ " }\n" + >+ " Foo(int i){}\n" + >+ " {\n" + >+ " System.out.println(Foo.val);\n" + >+ " }\n" + >+ " int field = Foo.val;\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in Foo.java (at line 5)\n" + >+ " this(Foo.val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "2. ERROR in Foo.java (at line 6)\n" + >+ " System.out.println(Foo.val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "3. ERROR in Foo.java (at line 10)\n" + >+ " System.out.println(Foo.val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "4. ERROR in Foo.java (at line 12)\n" + >+ " int field = Foo.val;\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation >+public void test158() { >+ this.runNegativeTest( >+ new String[] { >+ "Foo.java", >+ "enum Foo {\n" + >+ " ONE, TWO, THREE;\n" + >+ " static int val = 10;\n" + >+ " Foo () {\n" + >+ " this(val);\n" + >+ " System.out.println(val);\n" + >+ " }\n" + >+ " Foo(int i){}\n" + >+ " {\n" + >+ " System.out.println(val);\n" + >+ " }\n" + >+ " int field = val;\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in Foo.java (at line 5)\n" + >+ " this(val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "2. ERROR in Foo.java (at line 6)\n" + >+ " System.out.println(val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "3. ERROR in Foo.java (at line 10)\n" + >+ " System.out.println(val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "4. ERROR in Foo.java (at line 12)\n" + >+ " int field = val;\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation >+public void test159() { >+ this.runNegativeTest( >+ new String[] { >+ "Foo.java", >+ "enum Foo {\n" + >+ " ONE, TWO, THREE;\n" + >+ " static int val = 10;\n" + >+ " Foo () {\n" + >+ " this(get().val);\n" + >+ " System.out.println(get().val);\n" + >+ " }\n" + >+ " Foo(int i){}\n" + >+ " {\n" + >+ " System.out.println(get().val);\n" + >+ " }\n" + >+ " int field = get().val;\n" + >+ " Foo get() { return ONE; }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in Foo.java (at line 5)\n" + >+ " this(get().val);\n" + >+ " ^^^\n" + >+ "Cannot refer to an instance method while explicitly invoking a constructor\n" + >+ "----------\n" + >+ "2. WARNING in Foo.java (at line 5)\n" + >+ " this(get().val);\n" + >+ " ^^^\n" + >+ "The static field Foo.val should be accessed in a static way\n" + >+ "----------\n" + >+ "3. ERROR in Foo.java (at line 5)\n" + >+ " this(get().val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "4. WARNING in Foo.java (at line 6)\n" + >+ " System.out.println(get().val);\n" + >+ " ^^^\n" + >+ "The static field Foo.val should be accessed in a static way\n" + >+ "----------\n" + >+ "5. ERROR in Foo.java (at line 6)\n" + >+ " System.out.println(get().val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "6. WARNING in Foo.java (at line 10)\n" + >+ " System.out.println(get().val);\n" + >+ " ^^^\n" + >+ "The static field Foo.val should be accessed in a static way\n" + >+ "----------\n" + >+ "7. ERROR in Foo.java (at line 10)\n" + >+ " System.out.println(get().val);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "8. WARNING in Foo.java (at line 12)\n" + >+ " int field = get().val;\n" + >+ " ^^^\n" + >+ "The static field Foo.val should be accessed in a static way\n" + >+ "----------\n" + >+ "9. ERROR in Foo.java (at line 12)\n" + >+ " int field = get().val;\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation >+public void test160() { >+ this.runNegativeTest( >+ new String[] { >+ "Foo.java", >+ "enum Foo {\n" + >+ " ONE, TWO, THREE;\n" + >+ " static int val = 10;\n" + >+ " Foo () {\n" + >+ " this(get().val = 1);\n" + >+ " System.out.println(get().val = 2);\n" + >+ " }\n" + >+ " Foo(int i){}\n" + >+ " {\n" + >+ " System.out.println(get().val = 3);\n" + >+ " }\n" + >+ " int field = get().val = 4;\n" + >+ " Foo get() { return ONE; }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in Foo.java (at line 5)\n" + >+ " this(get().val = 1);\n" + >+ " ^^^\n" + >+ "Cannot refer to an instance method while explicitly invoking a constructor\n" + >+ "----------\n" + >+ "2. WARNING in Foo.java (at line 5)\n" + >+ " this(get().val = 1);\n" + >+ " ^^^\n" + >+ "The static field Foo.val should be accessed in a static way\n" + >+ "----------\n" + >+ "3. ERROR in Foo.java (at line 5)\n" + >+ " this(get().val = 1);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "4. WARNING in Foo.java (at line 6)\n" + >+ " System.out.println(get().val = 2);\n" + >+ " ^^^\n" + >+ "The static field Foo.val should be accessed in a static way\n" + >+ "----------\n" + >+ "5. ERROR in Foo.java (at line 6)\n" + >+ " System.out.println(get().val = 2);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "6. WARNING in Foo.java (at line 10)\n" + >+ " System.out.println(get().val = 3);\n" + >+ " ^^^\n" + >+ "The static field Foo.val should be accessed in a static way\n" + >+ "----------\n" + >+ "7. ERROR in Foo.java (at line 10)\n" + >+ " System.out.println(get().val = 3);\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n" + >+ "8. WARNING in Foo.java (at line 12)\n" + >+ " int field = get().val = 4;\n" + >+ " ^^^\n" + >+ "The static field Foo.val should be accessed in a static way\n" + >+ "----------\n" + >+ "9. ERROR in Foo.java (at line 12)\n" + >+ " int field = get().val = 4;\n" + >+ " ^^^\n" + >+ "Cannot refer to the static enum field Foo.val within an initializer\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation >+public void test161() { >+ this.runConformTest( >+ new String[] { >+ "EnumTest1.java", >+ "enum EnumTest1 {\n" + >+ " ;\n" + >+ " static int foo = EnumTest2.bar;\n" + >+ "}\n" + >+ "enum EnumTest2 {\n" + >+ " ;\n" + >+ " static int bar = EnumTest1.foo;\n" + >+ "}\n" >+ }, >+ ""); >+} > } >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java,v >retrieving revision 1.114 >diff -u -r1.114 FieldReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java 22 Feb 2008 09:49:36 -0000 1.114 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java 5 May 2008 16:05:32 -0000 >@@ -12,11 +12,26 @@ > > import org.eclipse.jdt.core.compiler.CharOperation; > import org.eclipse.jdt.internal.compiler.ASTVisitor; >-import org.eclipse.jdt.internal.compiler.impl.*; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; >-import org.eclipse.jdt.internal.compiler.codegen.*; >-import org.eclipse.jdt.internal.compiler.flow.*; >-import org.eclipse.jdt.internal.compiler.lookup.*; >+import org.eclipse.jdt.internal.compiler.codegen.CodeStream; >+import org.eclipse.jdt.internal.compiler.flow.FlowContext; >+import org.eclipse.jdt.internal.compiler.flow.FlowInfo; >+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; >+import org.eclipse.jdt.internal.compiler.impl.Constant; >+import org.eclipse.jdt.internal.compiler.lookup.Binding; >+import org.eclipse.jdt.internal.compiler.lookup.BlockScope; >+import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; >+import org.eclipse.jdt.internal.compiler.lookup.InvocationSite; >+import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; >+import org.eclipse.jdt.internal.compiler.lookup.MethodScope; >+import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; >+import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding; >+import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; >+import org.eclipse.jdt.internal.compiler.lookup.Scope; >+import org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; >+import org.eclipse.jdt.internal.compiler.lookup.TagBits; >+import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; >+import org.eclipse.jdt.internal.compiler.lookup.TypeIds; > > public class FieldReference extends Reference implements InvocationSite { > >@@ -33,30 +48,30 @@ > public TypeBinding genericCast; > > public FieldReference(char[] source, long pos) { >- token = source; >- nameSourcePosition = pos; >+ this.token = source; >+ this.nameSourcePosition = pos; > //by default the position are the one of the field (not true for super access) >- sourceStart = (int) (pos >>> 32); >- sourceEnd = (int) (pos & 0x00000000FFFFFFFFL); >- bits |= Binding.FIELD; >+ this.sourceStart = (int) (pos >>> 32); >+ this.sourceEnd = (int) (pos & 0x00000000FFFFFFFFL); >+ this.bits |= Binding.FIELD; > > } > > public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) { > // compound assignment extra work > if (isCompound) { // check the variable part is initialized if blank final >- if (binding.isBlankFinal() >- && receiver.isThis() >- && currentScope.needBlankFinalFieldInitializationCheck(binding) >- && (!flowInfo.isDefinitelyAssigned(binding))) { >- currentScope.problemReporter().uninitializedBlankFinalField(binding, this); >+ if (this.binding.isBlankFinal() >+ && this.receiver.isThis() >+ && currentScope.needBlankFinalFieldInitializationCheck(this.binding) >+ && (!flowInfo.isDefinitelyAssigned(this.binding))) { >+ currentScope.problemReporter().uninitializedBlankFinalField(this.binding, this); > // we could improve error msg here telling "cannot use compound assignment on final blank field" > } > manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/); > } > flowInfo = >- receiver >- .analyseCode(currentScope, flowContext, flowInfo, !binding.isStatic()) >+ this.receiver >+ .analyseCode(currentScope, flowContext, flowInfo, !this.binding.isStatic()) > .unconditionalInits(); > if (assignment.expression != null) { > flowInfo = >@@ -68,25 +83,25 @@ > manageSyntheticAccessIfNecessary(currentScope, flowInfo, false /*write-access*/); > > // check if assigning a final field >- if (binding.isFinal()) { >+ if (this.binding.isFinal()) { > // in a context where it can be assigned? >- if (binding.isBlankFinal() >+ if (this.binding.isBlankFinal() > && !isCompound >- && receiver.isThis() >- && !(receiver instanceof QualifiedThisReference) >- && ((receiver.bits & ParenthesizedMASK) == 0) // (this).x is forbidden >- && currentScope.allowBlankFinalFieldAssignment(binding)) { >- if (flowInfo.isPotentiallyAssigned(binding)) { >+ && this.receiver.isThis() >+ && !(this.receiver instanceof QualifiedThisReference) >+ && ((this.receiver.bits & ASTNode.ParenthesizedMASK) == 0) // (this).x is forbidden >+ && currentScope.allowBlankFinalFieldAssignment(this.binding)) { >+ if (flowInfo.isPotentiallyAssigned(this.binding)) { > currentScope.problemReporter().duplicateInitializationOfBlankFinalField( >- binding, >+ this.binding, > this); > } else { >- flowContext.recordSettingFinal(binding, this, flowInfo); >+ flowContext.recordSettingFinal(this.binding, this, flowInfo); > } >- flowInfo.markAsDefinitelyAssigned(binding); >+ flowInfo.markAsDefinitelyAssigned(this.binding); > } else { > // assigning a final field outside an initializer or constructor or wrong reference >- currentScope.problemReporter().cannotAssignToFinalField(binding, this); >+ currentScope.problemReporter().cannotAssignToFinalField(this.binding, this); > } > } > return flowInfo; >@@ -97,10 +112,10 @@ > } > > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) { >- boolean nonStatic = !binding.isStatic(); >- receiver.analyseCode(currentScope, flowContext, flowInfo, nonStatic); >+ boolean nonStatic = !this.binding.isStatic(); >+ this.receiver.analyseCode(currentScope, flowContext, flowInfo, nonStatic); > if (nonStatic) { >- receiver.checkNPE(currentScope, flowContext, flowInfo); >+ this.receiver.checkNPE(currentScope, flowContext, flowInfo); > } > > if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) { >@@ -122,7 +137,7 @@ > // extra cast needed if method return type is type variable > if (originalBinding != this.binding > && originalType != this.binding.type >- && runtimeTimeType.id != T_JavaLangObject >+ && runtimeTimeType.id != TypeIds.T_JavaLangObject > && (originalType.tagBits & TagBits.HasTypeVariable) != 0) { > TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType()) > ? compileTimeType // unboxing: checkcast before conversion >@@ -144,12 +159,12 @@ > } > > public FieldBinding fieldBinding() { >- return binding; >+ return this.binding; > } > > public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) { > int pc = codeStream.position; >- receiver.generateCode( >+ this.receiver.generateCode( > currentScope, > codeStream, > !this.codegenBinding.isStatic()); >@@ -158,7 +173,7 @@ > fieldStore( > codeStream, > this.codegenBinding, >- syntheticAccessors == null ? null : syntheticAccessors[WRITE], >+ this.syntheticAccessors == null ? null : this.syntheticAccessors[FieldReference.WRITE], > valueRequired); > if (valueRequired) { > codeStream.generateImplicitConversion(assignment.implicitConversion); >@@ -175,9 +190,9 @@ > */ > public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { > int pc = codeStream.position; >- if (constant != Constant.NotAConstant) { >+ if (this.constant != Constant.NotAConstant) { > if (valueRequired) { >- codeStream.generateConstant(constant, implicitConversion); >+ codeStream.generateConstant(this.constant, this.implicitConversion); > } > codeStream.recordPositionsFrom(pc, this.sourceStart); > return; >@@ -187,50 +202,50 @@ > Constant fieldConstant = this.codegenBinding.constant(); > if (fieldConstant != Constant.NotAConstant) { > if (!isThisReceiver) { >- receiver.generateCode(currentScope, codeStream, !isStatic); >+ this.receiver.generateCode(currentScope, codeStream, !isStatic); > if (!isStatic){ > codeStream.invokeObjectGetClass(); > codeStream.pop(); > } > } > if (valueRequired) { >- codeStream.generateConstant(fieldConstant, implicitConversion); >+ codeStream.generateConstant(fieldConstant, this.implicitConversion); > } > codeStream.recordPositionsFrom(pc, this.sourceStart); > return; > } > if (valueRequired > || (!isThisReceiver && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) >- || ((implicitConversion & TypeIds.UNBOXING) != 0) >+ || ((this.implicitConversion & TypeIds.UNBOXING) != 0) > || (this.genericCast != null)) { >- receiver.generateCode(currentScope, codeStream, !isStatic); >+ this.receiver.generateCode(currentScope, codeStream, !isStatic); > pc = codeStream.position; > if (this.codegenBinding.declaringClass == null) { // array length > codeStream.arraylength(); > if (valueRequired) { >- codeStream.generateImplicitConversion(implicitConversion); >+ codeStream.generateImplicitConversion(this.implicitConversion); > } else { > // could occur if !valueRequired but compliance >= 1.4 > codeStream.pop(); > } > } else { >- if (syntheticAccessors == null || syntheticAccessors[READ] == null) { >+ if (this.syntheticAccessors == null || this.syntheticAccessors[FieldReference.READ] == null) { > if (isStatic) { > codeStream.getstatic(this.codegenBinding); > } else { > codeStream.getfield(this.codegenBinding); > } > } else { >- codeStream.invokestatic(syntheticAccessors[READ]); >+ codeStream.invokestatic(this.syntheticAccessors[FieldReference.READ]); > } > // required cast must occur even if no value is required > if (this.genericCast != null) codeStream.checkcast(this.genericCast); > if (valueRequired) { >- codeStream.generateImplicitConversion(implicitConversion); >+ codeStream.generateImplicitConversion(this.implicitConversion); > } else { >- boolean isUnboxing = (implicitConversion & TypeIds.UNBOXING) != 0; >+ boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0; > // conversion only generated if unboxing >- if (isUnboxing) codeStream.generateImplicitConversion(implicitConversion); >+ if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion); > switch (isUnboxing ? postConversionType(currentScope).id : this.codegenBinding.type.id) { > case T_long : > case T_double : >@@ -246,7 +261,7 @@ > if (isStatic){ > // if no valueRequired, still need possible side-effects of <clinit> invocation, if field belongs to different class > if (this.binding.original().declaringClass != this.receiverType.erasure()) { >- MethodBinding accessor = syntheticAccessors == null ? null : syntheticAccessors[READ]; >+ MethodBinding accessor = this.syntheticAccessors == null ? null : this.syntheticAccessors[FieldReference.READ]; > if (accessor == null) { > codeStream.getstatic(this.codegenBinding); > } else { >@@ -263,7 +278,7 @@ > } > } > } else { >- receiver.generateCode(currentScope, codeStream, !isStatic); >+ this.receiver.generateCode(currentScope, codeStream, !isStatic); > if (!isStatic){ > codeStream.invokeObjectGetClass(); // perform null check > codeStream.pop(); >@@ -275,26 +290,26 @@ > > public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) { > boolean isStatic; >- receiver.generateCode( >+ this.receiver.generateCode( > currentScope, > codeStream, > !(isStatic = this.codegenBinding.isStatic())); > if (isStatic) { >- if (syntheticAccessors == null || syntheticAccessors[READ] == null) { >+ if (this.syntheticAccessors == null || this.syntheticAccessors[FieldReference.READ] == null) { > codeStream.getstatic(this.codegenBinding); > } else { >- codeStream.invokestatic(syntheticAccessors[READ]); >+ codeStream.invokestatic(this.syntheticAccessors[FieldReference.READ]); > } > } else { > codeStream.dup(); >- if (syntheticAccessors == null || syntheticAccessors[READ] == null) { >+ if (this.syntheticAccessors == null || this.syntheticAccessors[FieldReference.READ] == null) { > codeStream.getfield(this.codegenBinding); > } else { >- codeStream.invokestatic(syntheticAccessors[READ]); >+ codeStream.invokestatic(this.syntheticAccessors[FieldReference.READ]); > } > } > int operationTypeID; >- switch(operationTypeID = (implicitConversion & IMPLICIT_CONVERSION_MASK) >> 4) { >+ switch(operationTypeID = (this.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4) { > case T_JavaLangString : > case T_JavaLangObject : > case T_undefined : >@@ -304,10 +319,10 @@ > if (this.genericCast != null) > codeStream.checkcast(this.genericCast); > // promote the array reference to the suitable operation type >- codeStream.generateImplicitConversion(implicitConversion); >+ codeStream.generateImplicitConversion(this.implicitConversion); > // generate the increment value (will by itself be promoted to the operation value) > if (expression == IntLiteral.One) { // prefix operation >- codeStream.generateConstant(expression.constant, implicitConversion); >+ codeStream.generateConstant(expression.constant, this.implicitConversion); > } else { > expression.generateCode(currentScope, codeStream, true); > } >@@ -319,29 +334,29 @@ > fieldStore( > codeStream, > this.codegenBinding, >- syntheticAccessors == null ? null : syntheticAccessors[WRITE], >+ this.syntheticAccessors == null ? null : this.syntheticAccessors[FieldReference.WRITE], > valueRequired); > // no need for generic cast as value got dupped > } > > public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { > boolean isStatic; >- receiver.generateCode( >+ this.receiver.generateCode( > currentScope, > codeStream, > !(isStatic = this.codegenBinding.isStatic())); > if (isStatic) { >- if (syntheticAccessors == null || syntheticAccessors[READ] == null) { >+ if (this.syntheticAccessors == null || this.syntheticAccessors[FieldReference.READ] == null) { > codeStream.getstatic(this.codegenBinding); > } else { >- codeStream.invokestatic(syntheticAccessors[READ]); >+ codeStream.invokestatic(this.syntheticAccessors[FieldReference.READ]); > } > } else { > codeStream.dup(); >- if (syntheticAccessors == null || syntheticAccessors[READ] == null) { >+ if (this.syntheticAccessors == null || this.syntheticAccessors[FieldReference.READ] == null) { > codeStream.getfield(this.codegenBinding); > } else { >- codeStream.invokestatic(syntheticAccessors[READ]); >+ codeStream.invokestatic(this.syntheticAccessors[FieldReference.READ]); > } > } > if (valueRequired) { >@@ -367,10 +382,10 @@ > codeStream.generateConstant( > postIncrement.expression.constant, > this.implicitConversion); >- codeStream.sendOperator(postIncrement.operator, this.implicitConversion & COMPILE_TYPE_MASK); >+ codeStream.sendOperator(postIncrement.operator, this.implicitConversion & TypeIds.COMPILE_TYPE_MASK); > codeStream.generateImplicitConversion( > postIncrement.preAssignImplicitConversion); >- fieldStore(codeStream, this.codegenBinding, syntheticAccessors == null ? null : syntheticAccessors[WRITE], false); >+ fieldStore(codeStream, this.codegenBinding, this.syntheticAccessors == null ? null : this.syntheticAccessors[FieldReference.WRITE], false); > } > > /** >@@ -380,11 +395,11 @@ > return null; > } > public boolean isSuperAccess() { >- return receiver.isSuper(); >+ return this.receiver.isSuper(); > } > > public boolean isTypeAccess() { >- return receiver != null && receiver.isTypeReference(); >+ return this.receiver != null && this.receiver.isTypeReference(); > } > > /* >@@ -396,42 +411,42 @@ > // if field from parameterized type got found, use the original field at codegen time > this.codegenBinding = this.binding.original(); > >- if (binding.isPrivate()) { >+ if (this.binding.isPrivate()) { > if ((currentScope.enclosingSourceType() != this.codegenBinding.declaringClass) >- && binding.constant() == Constant.NotAConstant) { >- if (syntheticAccessors == null) >- syntheticAccessors = new MethodBinding[2]; >- syntheticAccessors[isReadAccess ? READ : WRITE] = >+ && this.binding.constant() == Constant.NotAConstant) { >+ if (this.syntheticAccessors == null) >+ this.syntheticAccessors = new MethodBinding[2]; >+ this.syntheticAccessors[isReadAccess ? FieldReference.READ : FieldReference.WRITE] = > ((SourceTypeBinding) this.codegenBinding.declaringClass).addSyntheticMethod(this.codegenBinding, isReadAccess); > currentScope.problemReporter().needToEmulateFieldAccess(this.codegenBinding, this, isReadAccess); > return; > } > >- } else if (receiver instanceof QualifiedSuperReference) { // qualified super >+ } else if (this.receiver instanceof QualifiedSuperReference) { // qualified super > > // qualified super need emulation always > SourceTypeBinding destinationType = >- (SourceTypeBinding) (((QualifiedSuperReference) receiver) >+ (SourceTypeBinding) (((QualifiedSuperReference) this.receiver) > .currentCompatibleType); >- if (syntheticAccessors == null) >- syntheticAccessors = new MethodBinding[2]; >- syntheticAccessors[isReadAccess ? READ : WRITE] = destinationType.addSyntheticMethod(this.codegenBinding, isReadAccess); >+ if (this.syntheticAccessors == null) >+ this.syntheticAccessors = new MethodBinding[2]; >+ this.syntheticAccessors[isReadAccess ? FieldReference.READ : FieldReference.WRITE] = destinationType.addSyntheticMethod(this.codegenBinding, isReadAccess); > currentScope.problemReporter().needToEmulateFieldAccess(this.codegenBinding, this, isReadAccess); > return; > >- } else if (binding.isProtected()) { >+ } else if (this.binding.isProtected()) { > > SourceTypeBinding enclosingSourceType; >- if (((bits & DepthMASK) != 0) >- && binding.declaringClass.getPackage() >+ if (((this.bits & ASTNode.DepthMASK) != 0) >+ && this.binding.declaringClass.getPackage() > != (enclosingSourceType = currentScope.enclosingSourceType()).getPackage()) { > > SourceTypeBinding currentCompatibleType = > (SourceTypeBinding) enclosingSourceType.enclosingTypeAt( >- (bits & DepthMASK) >> DepthSHIFT); >- if (syntheticAccessors == null) >- syntheticAccessors = new MethodBinding[2]; >- syntheticAccessors[isReadAccess ? READ : WRITE] = currentCompatibleType.addSyntheticMethod(this.codegenBinding, isReadAccess); >+ (this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT); >+ if (this.syntheticAccessors == null) >+ this.syntheticAccessors = new MethodBinding[2]; >+ this.syntheticAccessors[isReadAccess ? FieldReference.READ : FieldReference.WRITE] = currentCompatibleType.addSyntheticMethod(this.codegenBinding, isReadAccess); > currentScope.problemReporter().needToEmulateFieldAccess(this.codegenBinding, this, isReadAccess); > return; > } >@@ -446,8 +461,8 @@ > && this.binding.constant() == Constant.NotAConstant) { > CompilerOptions options = currentScope.compilerOptions(); > if ((options.targetJDK >= ClassFileConstants.JDK1_2 >- && (options.complianceLevel >= ClassFileConstants.JDK1_4 || !(receiver.isImplicitThis() && this.codegenBinding.isStatic())) >- && this.binding.declaringClass.id != T_JavaLangObject) // no change for Object fields >+ && (options.complianceLevel >= ClassFileConstants.JDK1_4 || !(this.receiver.isImplicitThis() && this.codegenBinding.isStatic())) >+ && this.binding.declaringClass.id != TypeIds.T_JavaLangObject) // no change for Object fields > || !this.binding.declaringClass.canBeSeenBy(currentScope)) { > > this.codegenBinding = >@@ -479,7 +494,7 @@ > TypeBinding convertedType = this.resolvedType; > if (this.genericCast != null) > convertedType = this.genericCast; >- int runtimeType = (this.implicitConversion & IMPLICIT_CONVERSION_MASK) >> 4; >+ int runtimeType = (this.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4; > switch (runtimeType) { > case T_boolean : > convertedType = TypeBinding.BOOLEAN; >@@ -507,14 +522,14 @@ > break; > default : > } >- if ((this.implicitConversion & BOXING) != 0) { >+ if ((this.implicitConversion & TypeIds.BOXING) != 0) { > convertedType = scope.environment().computeBoxingType(convertedType); > } > return convertedType; > } > > public StringBuffer printExpression(int indent, StringBuffer output) { >- return receiver.printExpression(0, output).append('.').append(token); >+ return this.receiver.printExpression(0, output).append('.').append(this.token); > } > > public TypeBinding resolveType(BlockScope scope) { >@@ -525,12 +540,12 @@ > //always ignore receiver cast, since may affect constant pool reference > boolean receiverCast = false; > if (this.receiver instanceof CastExpression) { >- this.receiver.bits |= DisableUnnecessaryCastCheck; // will check later on >+ this.receiver.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on > receiverCast = true; > } > this.receiverType = this.receiver.resolveType(scope); > if (this.receiverType == null) { >- constant = Constant.NotAConstant; >+ this.constant = Constant.NotAConstant; > return null; > } > if (receiverCast) { >@@ -540,9 +555,9 @@ > } > } > // the case receiverType.isArrayType and token = 'length' is handled by the scope API >- FieldBinding fieldBinding = this.codegenBinding = this.binding = scope.getField(this.receiverType, token, this); >+ FieldBinding fieldBinding = this.codegenBinding = this.binding = scope.getField(this.receiverType, this.token, this); > if (!fieldBinding.isValidBinding()) { >- constant = Constant.NotAConstant; >+ this.constant = Constant.NotAConstant; > if (this.receiver.resolvedType instanceof ProblemReferenceBinding) { > // problem already got signaled on receiver, do not report secondary problem > return null; >@@ -557,27 +572,39 @@ > } > } > this.receiver.computeConversion(scope, this.receiverType, this.receiverType); >- if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & IsStrictlyAssigned) !=0)) { >+ if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) !=0)) { > scope.problemReporter().deprecatedField(fieldBinding, this); > } >- boolean isImplicitThisRcv = receiver.isImplicitThis(); >- constant = isImplicitThisRcv ? fieldBinding.constant() : Constant.NotAConstant; >+ boolean isImplicitThisRcv = this.receiver.isImplicitThis(); >+ this.constant = isImplicitThisRcv ? fieldBinding.constant() : Constant.NotAConstant; > if (fieldBinding.isStatic()) { > // static field accessed through receiver? legal but unoptimal (optional warning) > if (!(isImplicitThisRcv >- || (receiver instanceof NameReference >- && (((NameReference) receiver).bits & Binding.TYPE) != 0))) { >+ || (this.receiver instanceof NameReference >+ && (((NameReference) this.receiver).bits & Binding.TYPE) != 0))) { > scope.problemReporter().nonStaticAccessToStaticField(this, fieldBinding); > } >+ ReferenceBinding declaringClass = this.binding.declaringClass; > if (!isImplicitThisRcv >- && fieldBinding.declaringClass != receiverType >- && fieldBinding.declaringClass.canBeSeenBy(scope)) { >+ && declaringClass != this.receiverType >+ && declaringClass.canBeSeenBy(scope)) { > scope.problemReporter().indirectAccessToStaticField(this, fieldBinding); > } >+ // check if accessing enum static field in initializer >+ if (declaringClass.isEnum()) { >+ MethodScope methodScope = scope.methodScope(); >+ SourceTypeBinding sourceType = scope.enclosingSourceType(); >+ if (this.constant == Constant.NotAConstant >+ && !methodScope.isStatic >+ && (sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body >+ && methodScope.isInsideInitializerOrConstructor()) { >+ scope.problemReporter().enumStaticFieldUsedDuringInitialization(this.binding, this); >+ } >+ } > } > TypeBinding fieldType = fieldBinding.type; > if (fieldType != null) { >- if ((this.bits & IsStrictlyAssigned) == 0) { >+ if ((this.bits & ASTNode.IsStrictlyAssigned) == 0) { > fieldType = fieldType.capture(scope, this.sourceEnd); // perform capture conversion if read access > } > this.resolvedType = fieldType; >@@ -594,9 +621,9 @@ > } > > public void setDepth(int depth) { >- bits &= ~DepthMASK; // flush previous depth if any >+ this.bits &= ~ASTNode.DepthMASK; // flush previous depth if any > if (depth > 0) { >- bits |= (depth & 0xFF) << DepthSHIFT; // encoded on 8 bits >+ this.bits |= (depth & 0xFF) << ASTNode.DepthSHIFT; // encoded on 8 bits > } > } > >@@ -606,7 +633,7 @@ > > public void traverse(ASTVisitor visitor, BlockScope scope) { > if (visitor.visit(this, scope)) { >- receiver.traverse(visitor, scope); >+ this.receiver.traverse(visitor, scope); > } > visitor.endVisit(this, scope); > } >Index: compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java,v >retrieving revision 1.101 >diff -u -r1.101 SingleNameReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 22 Feb 2008 09:49:36 -0000 1.101 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 5 May 2008 16:05:32 -0000 >@@ -89,21 +89,8 @@ > case Binding.FIELD : // assigning to a field > manageSyntheticAccessIfNecessary(currentScope, flowInfo, false /*write-access*/); > >- FieldBinding fieldBinding = (FieldBinding) this.binding; >- ReferenceBinding declaringClass = fieldBinding.declaringClass; >- // check if accessing enum static field in initializer >- if (declaringClass.isEnum()) { >- MethodScope methodScope = currentScope.methodScope(); >- SourceTypeBinding sourceType = currentScope.enclosingSourceType(); >- if (fieldBinding.isStatic() >- && this.constant == Constant.NotAConstant >- && !methodScope.isStatic >- && (sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body >- && methodScope.isInsideInitializerOrConstructor()) { >- currentScope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this); >- } >- } > // check if assigning a final field >+ FieldBinding fieldBinding = (FieldBinding) this.binding; > if (fieldBinding.isFinal()) { > // inside a context where allowed > if (!isCompound && fieldBinding.isBlankFinal() && currentScope.allowBlankFinalFieldAssignment(fieldBinding)) { >@@ -158,21 +145,8 @@ > if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) { > manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/); > } >- FieldBinding fieldBinding = (FieldBinding) this.binding; >- ReferenceBinding declaringClass = fieldBinding.declaringClass; >- // check if accessing enum static field in initializer >- if (declaringClass.isEnum()) { >- MethodScope methodScope = currentScope.methodScope(); >- SourceTypeBinding sourceType = currentScope.enclosingSourceType(); >- if (fieldBinding.isStatic() >- && this.constant == Constant.NotAConstant >- && !methodScope.isStatic >- && (sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body >- && methodScope.isInsideInitializerOrConstructor()) { >- currentScope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this); >- } >- } > // check if reading a final blank field >+ FieldBinding fieldBinding = (FieldBinding) this.binding; > if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) { > if (!flowInfo.isDefinitelyAssigned(fieldBinding)) { > currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this); >@@ -198,20 +172,33 @@ > > public TypeBinding checkFieldAccess(BlockScope scope) { > FieldBinding fieldBinding = (FieldBinding) this.binding; >+ this.constant = fieldBinding.constant(); > > this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits > this.bits |= Binding.FIELD; > MethodScope methodScope = scope.methodScope(); >- boolean isStatic = fieldBinding.isStatic(); >- if (!isStatic) { >+ if (fieldBinding.isStatic()) { >+ // check if accessing enum static field in initializer >+ ReferenceBinding declaringClass = fieldBinding.declaringClass; >+ if (declaringClass.isEnum()) { >+ SourceTypeBinding sourceType = scope.enclosingSourceType(); >+ if (this.constant == Constant.NotAConstant >+ && !methodScope.isStatic >+ && (sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body >+ && methodScope.isInsideInitializerOrConstructor()) { >+ scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this); >+ } >+ } >+ } else { >+ if (scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) { >+ scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding); >+ } > // must check for the static status.... > if (methodScope.isStatic) { > scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding); >- this.constant = Constant.NotAConstant; > return fieldBinding.type; > } > } >- this.constant = fieldBinding.constant(); > > if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) !=0)) > scope.problemReporter().deprecatedField(fieldBinding, this); >@@ -858,10 +845,6 @@ > this.constant = (this.bits & ASTNode.IsStrictlyAssigned) == 0 ? variable.constant() : Constant.NotAConstant; > } else { > // a field >- FieldBinding field = (FieldBinding) this.binding; >- if (!field.isStatic() && scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) { >- scope.problemReporter().unqualifiedFieldAccess(this, field); >- } > variableType = checkFieldAccess(scope); > } > // perform capture conversion if read access >Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java,v >retrieving revision 1.123 >diff -u -r1.123 QualifiedNameReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 3 Mar 2008 09:30:56 -0000 1.123 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 5 May 2008 16:05:32 -0000 >@@ -70,21 +70,6 @@ > if (needValue || complyTo14) { > manageSyntheticAccessIfNecessary(currentScope, lastFieldBinding, this.actualReceiverType, 0, flowInfo); > } >- if (this.indexOfFirstFieldBinding == 1) { // was an implicit reference to the first field binding >- ReferenceBinding declaringClass = lastFieldBinding.declaringClass; >- // check if accessing enum static field in initializer >- if (declaringClass.isEnum()) { >- MethodScope methodScope = currentScope.methodScope(); >- SourceTypeBinding sourceType = methodScope.enclosingSourceType(); >- if (lastFieldBinding.isStatic() >- && (sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body >- && lastFieldBinding.constant() == Constant.NotAConstant >- && !methodScope.isStatic >- && methodScope.isInsideInitializerOrConstructor()) { >- currentScope.problemReporter().enumStaticFieldUsedDuringInitialization(lastFieldBinding, this); >- } >- } >- } > // check if final blank field > if (lastFieldBinding.isBlankFinal() > && this.otherBindings != null // the last field binding is only assigned >@@ -225,19 +210,6 @@ > } > if (this.indexOfFirstFieldBinding == 1) { // was an implicit reference to the first field binding > FieldBinding fieldBinding = (FieldBinding) this.binding; >- ReferenceBinding declaringClass = fieldBinding.declaringClass; >- // check if accessing enum static field in initializer >- if (declaringClass.isEnum()) { >- MethodScope methodScope = currentScope.methodScope(); >- SourceTypeBinding sourceType = methodScope.enclosingSourceType(); >- if (fieldBinding.isStatic() >- && (sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body >- && fieldBinding.constant() == Constant.NotAConstant >- && !methodScope.isStatic >- && methodScope.isInsideInitializerOrConstructor()) { >- currentScope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this); >- } >- } > // check if reading a final blank field > if (fieldBinding.isBlankFinal() > && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding) >@@ -739,13 +711,10 @@ > scope.problemReporter().staticFieldAccessToNonStaticVariable(this, field); > return null; > } >- } else { >- // indirect static reference ? >- if (this.indexOfFirstFieldBinding > 1 >+ } else if (this.indexOfFirstFieldBinding > 1 > && field.declaringClass != this.actualReceiverType > && field.declaringClass.canBeSeenBy(scope)) { >- scope.problemReporter().indirectAccessToStaticField(this, field); >- } >+ scope.problemReporter().indirectAccessToStaticField(this, field); > } > // only last field is actually a write access if any > if (isFieldUseDeprecated(field, scope, (this.bits & ASTNode.IsStrictlyAssigned) != 0 && this.indexOfFirstFieldBinding == length)) >@@ -808,6 +777,18 @@ > } > > if (field.isStatic()) { >+ // check if accessing enum static field in initializer >+ ReferenceBinding declaringClass = field.declaringClass; >+ if (declaringClass.isEnum()) { >+ MethodScope methodScope = scope.methodScope(); >+ SourceTypeBinding sourceType = methodScope.enclosingSourceType(); >+ if ((sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body >+ && field.constant() == Constant.NotAConstant >+ && !methodScope.isStatic >+ && methodScope.isInsideInitializerOrConstructor()) { >+ scope.problemReporter().enumStaticFieldUsedDuringInitialization(field, this); >+ } >+ } > // static field accessed through receiver? legal but unoptimal (optional warning) > scope.problemReporter().nonStaticAccessToStaticField(this, field, index); > // indirect static reference ? >@@ -1029,9 +1010,19 @@ > && (!fieldBinding.isStatic() || methodScope.isStatic)) { > scope.problemReporter().forwardReference(this, 0, methodScope.enclosingSourceType()); > } >- if (!fieldBinding.isStatic() >- && this.indexOfFirstFieldBinding == 1 >- && scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) { >+ if (fieldBinding.isStatic()) { >+ ReferenceBinding declaringClass = fieldBinding.declaringClass; >+ // check if accessing enum static field in initializer >+ if (declaringClass.isEnum()) { >+ SourceTypeBinding sourceType = methodScope.enclosingSourceType(); >+ if ((sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body >+ && fieldBinding.constant() == Constant.NotAConstant >+ && !methodScope.isStatic >+ && methodScope.isInsideInitializerOrConstructor()) { >+ scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this); >+ } >+ } >+ } else if (this.indexOfFirstFieldBinding == 1 && scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) { > scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding); > } > this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 228109
: 98656