Bug 167357 - non-empty init block in local member type has no children
Summary: non-empty init block in local member type has no children
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-10 17:29 EST by Andrey Loskutov CLA
Modified: 2007-08-07 05:24 EDT (History)
0 users

See Also:


Attachments
Patch against LocalElementTests.java version 1.11 (3.82 KB, application/octet-stream)
2006-12-10 17:37 EST, Andrey Loskutov CLA
no flags Details
Patch against LocalElementTests.java version 1.11 (3.82 KB, patch)
2006-12-10 17:37 EST, Andrey Loskutov CLA
no flags Details | Diff
Proposed fix + regression test (128.22 KB, patch)
2007-07-17 19:52 EDT, Olivier Thomann CLA
no flags Details | Diff
Parser resources (28.33 KB, application/octet-stream)
2007-07-17 19:54 EDT, Olivier Thomann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Loskutov CLA 2006-12-10 17:29:48 EST
Build ID: M20060921-0945 (3.2.1), but also seen in 3.3M3.

Short description: if above of a non empty init block in local member type exists a field, then the init block doesn't have children.

Example class:
-----------

package P;

public class X {
	void foo(){
		class Y {
			String s = null;
			{
				class Z {
				}
			}
		}
	}

	void foo2(){
		class Y {
			{
				class Z {
				}
			}
			String s = null;			
		}
	}
	
	void foo3(){
		class Y {
			{
				class Z {
				}
			}
		}
	}	
}
-----

The init block inside of foo() shown as empty in the method outline of Java editor, but both other init blocks shown as non-empty. 
JUnit test case follows.
Comment 1 Andrey Loskutov CLA 2006-12-10 17:37:41 EST
Created attachment 55374 [details]
Patch against LocalElementTests.java version 1.11

Attached the patch for LocalElementTests version 1.11 from project org.eclipse.jdt.core.tests.model, R_3_2_1 branch.
Three test cases added, and one of them fails with:

junit.framework.ComparisonFailure: Unexpected compilation unit contents.
----------- Expected ------------
X.java\n
  class X\n
    void foo()\n
      class Y\n
        String s\n
        <initializer #1>\n
          class Z
------------ but was ------------
X.java\n
  class X\n
    void foo()\n
      class Y\n
        String s\n
        <initializer #1>
--------- Difference is ----------
 expected:<...\n
          class Z> but was:<...>
-------

As one can see, <initializer #1> has no children, but should have class Z as a child.
Comment 2 Andrey Loskutov CLA 2006-12-10 17:37:50 EST
Created attachment 55375 [details]
Patch against LocalElementTests.java version 1.11

Attached the patch for LocalElementTests version 1.11 from project org.eclipse.jdt.core.tests.model, R_3_2_1 branch.
Three test cases added, and one of them fails with:

junit.framework.ComparisonFailure: Unexpected compilation unit contents.
----------- Expected ------------
X.java\n
  class X\n
    void foo()\n
      class Y\n
        String s\n
        <initializer #1>\n
          class Z
------------ but was ------------
X.java\n
  class X\n
    void foo()\n
      class Y\n
        String s\n
        <initializer #1>
--------- Difference is ----------
 expected:<...\n
          class Z> but was:<...>
-------

As one can see, <initializer #1> has no children, but should have class Z as a child.
Comment 3 Olivier Thomann CLA 2007-07-17 19:52:26 EDT
Created attachment 74013 [details]
Proposed fix + regression test

Parser resources need to be replaced with the second attachment
Comment 4 Olivier Thomann CLA 2007-07-17 19:54:37 EDT
Created attachment 74014 [details]
Parser resources

Extract in the package org.eclipse.jdt.internal.compiler.parser
Comment 5 Olivier Thomann CLA 2007-07-17 20:40:19 EDT
Released for 3.4M1.
Regression tests added in
org.eclipse.jdt.core.tests.model.LocalElementTests#testLocalType6
org.eclipse.jdt.core.tests.model.LocalElementTests#testLocalType7
org.eclipse.jdt.core.tests.model.LocalElementTests#testLocalType8
org.eclipse.jdt.core.tests.model.LocalElementTests#testLocalType9
org.eclipse.jdt.core.tests.model.LocalElementTests#testLocalType10
Comment 6 Frederic Fusier CLA 2007-08-07 05:24:03 EDT
Verified for 3.4M1 using build I20070806-1800.