Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.compiler.regression; |
12 |
|
13 |
import java.io.File; |
14 |
import java.io.IOException; |
15 |
|
16 |
import org.eclipse.jdt.core.ToolFactory; |
17 |
import org.eclipse.jdt.core.tests.util.Util; |
18 |
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; |
19 |
|
20 |
import junit.framework.Test; |
21 |
|
22 |
public class EnclosingMethodAttributeTest extends AbstractComparableTest { |
23 |
public EnclosingMethodAttributeTest(String name) { |
24 |
super(name); |
25 |
} |
26 |
|
27 |
// Static initializer to specify tests subset using TESTS_* static variables |
28 |
// All specified tests which does not belong to the class are skipped... |
29 |
static { |
30 |
// TESTS_NAMES = new String[] { "test127" }; |
31 |
// TESTS_NUMBERS = new int[] { 176 }; |
32 |
// TESTS_RANGE = new int[] { 169, 180 }; |
33 |
} |
34 |
|
35 |
public static Test suite() { |
36 |
Test suite = buildTestSuite(testClass()); |
37 |
TESTS_COUNTERS.put(testClass().getName(), new Integer(suite.countTestCases())); |
38 |
return suite; |
39 |
} |
40 |
|
41 |
public static Class testClass() { |
42 |
return EnclosingMethodAttributeTest.class; |
43 |
} |
44 |
|
45 |
public void test001() { |
46 |
this.runConformTest( |
47 |
new String[] { |
48 |
"X.java", |
49 |
"public class X {\n" + |
50 |
"public static void main(String[] args) throws Exception {\n" + |
51 |
" class MyLocal$A {\n" + |
52 |
" class Member {\n" + |
53 |
" }\n" + |
54 |
" };\n" + |
55 |
" System.out.print(MyLocal$A.Member.class.getEnclosingMethod() != null);\n" + |
56 |
" System.out.print(MyLocal$A.Member.class.getEnclosingConstructor() != null);\n" + |
57 |
"\n" + |
58 |
" System.out.print(MyLocal$A.class.getEnclosingMethod()!= null);\n" + |
59 |
" System.out.print(MyLocal$A.class.getEnclosingConstructor() != null); \n" + |
60 |
" \n" + |
61 |
" System.out.print(X.class.getEnclosingMethod() != null);\n" + |
62 |
" System.out.print(X.class.getEnclosingConstructor() != null); \n" + |
63 |
"}\n" + |
64 |
"public Object foo() {\n" + |
65 |
" return new Object() {};\n" + |
66 |
"}\n" + |
67 |
"}" |
68 |
}, |
69 |
"falsefalsetruefalsefalsefalse"); |
70 |
|
71 |
ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); |
72 |
String actualOutput = null; |
73 |
try { |
74 |
byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1.class")); |
75 |
actualOutput = |
76 |
disassembler.disassemble( |
77 |
classFileBytes, |
78 |
"\n", |
79 |
ClassFileBytesDisassembler.DETAILED); |
80 |
} catch (org.eclipse.jdt.core.util.ClassFormatException e) { |
81 |
assertTrue("ClassFormatException", false); |
82 |
} catch (IOException e) { |
83 |
assertTrue("IOException", false); |
84 |
} |
85 |
|
86 |
String expectedOutput = " Enclosing Method: #23 #25 X.foo()Ljava/lang/Object;\n"; |
87 |
|
88 |
int index = actualOutput.indexOf(expectedOutput); |
89 |
if (index == -1 || expectedOutput.length() == 0) { |
90 |
System.out.println(Util.displayString(actualOutput, 2)); |
91 |
} |
92 |
if (index == -1) { |
93 |
assertEquals("Wrong contents", expectedOutput, actualOutput); |
94 |
} |
95 |
} |
96 |
} |