Index: src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java,v retrieving revision 1.43 diff -u -r1.43 AbstractRegressionTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 18 Nov 2004 18:22:45 -0000 1.43 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java 23 Nov 2004 15:54:56 -0000 @@ -353,7 +353,7 @@ String[] classLib, boolean shouldFlushOutputDirectory, Map customOptions) { - + runNegativeTest(testFiles, expectedProblemLog, classLib, shouldFlushOutputDirectory, customOptions, false); } /** @@ -367,6 +367,20 @@ Map customOptions, boolean generateOutput) { + runNegativeTest(testFiles, expectedProblemLog, classLib, shouldFlushOutputDirectory, customOptions, generateOutput, null); + } + /** + * Log contains all problems (warnings+errors) + */ + protected void runNegativeTest( + String[] testFiles, + String expectedProblemLog, + String[] classLib, + boolean shouldFlushOutputDirectory, + Map customOptions, + boolean generateOutput, + ICompilerRequestor clientRequestor) { + if (shouldFlushOutputDirectory) Util.flushDirectoryContent(new File(OUTPUT_DIR)); @@ -376,7 +390,7 @@ problemFactory, OUTPUT_DIR.endsWith(File.separator) ? OUTPUT_DIR : OUTPUT_DIR + File.separator, generateOutput, - null/*no custom requestor*/); + clientRequestor); Map options = getCompilerOptions(); if (customOptions != null) { options.putAll(customOptions); Index: src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java,v retrieving revision 1.24 diff -u -r1.24 LookupTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 27 Oct 2004 10:13:43 -0000 1.24 +++ src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 23 Nov 2004 15:54:57 -0000 @@ -30,8 +30,15 @@ public LookupTest(String name) { super(name); } +//static { +// TESTS_NUMBERS = new int[] { 50 }; +// TESTS_RANGE = new int[] { 50, -1 }; +//} public static Test suite() { - return setupSuite(testClass()); + return buildTestSuite(testClass()); +} +public static Class testClass() { + return LookupTest.class; } /** * Non-static member class @@ -1683,7 +1690,149 @@ "Cannot make a static reference to the non-static method format(Date) from the type DateFormat\n" + "----------\n"); } -public static Class testClass() { - return LookupTest.class; +// 79163 - [compiler] Dependency on indirectly referenced types not correctly computed +public void test050() { + this.runNegativeTest( + new String[] { + "p/Client.java", + "package p;\n" + + "import q.FooFactory;\n" + + "public class Client {\n" + + " void foo() {\n" + + " FooFactory.createFoo().bar();\n" + + " }\n" + + "}\n", + "q/Foo.java", + "package q;\n" + + "class Foo {\n" + // Foo not public to get visibility problems + " public void bar() {}\n" + + "}\n", + "q/FooFactory.java", + "package q;\n" + + "public class FooFactory {\n" + + " public static Foo createFoo() {\n" + + " return new Foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\Client.java (at line 5)\n" + + " FooFactory.createFoo().bar();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Foo is not visible\n" + + "----------\n", + Util.concatWithClassLibs(OUTPUT_DIR, true/*output in front*/), + false, // do not flush output + null, // options + false, // do not generate output + new ICompilerRequestor() { + public void acceptResult(CompilationResult result) { + assertNotNull("missing reference information",result.simpleNameReferences); + boolean found = false; + char[] foo = "Foo".toCharArray(); + for (int i = 0, length = result.simpleNameReferences.length; i < length; i++) { + char[] name = result.simpleNameReferences[i]; + if (CharOperation.equals(foo, name)) + found = true; + } + assertTrue(new String(result.compilationUnit.getMainTypeName())+" should contain reference to Foo", found); + } + }); +} +public void test051() { + this.runNegativeTest( + new String[] { + "p/Client.java", + "package p;\n" + + "import q.FooFactory;\n" + + "public class Client {\n" + + " void foo() { \n" + + " FooFactory.createFoos().clone();\n" + + " }\n" + + "}\n", + "q/Foo.java", + "package q;\n" + + "class Foo {\n" + // Foo not public to get visibility problems + " public Foo[] bar() { return null; }\n" + + "}\n", + "q/FooFactory.java", + "package q;\n" + + "public class FooFactory {\n" + + " public static Foo[] createFoos() {\n" + + " return new Foo[] { new Foo() };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\Client.java (at line 5)\n" + + " FooFactory.createFoos().clone();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Foo is not visible\n" + + "----------\n", + Util.concatWithClassLibs(OUTPUT_DIR, true/*output in front*/), + false, // do not flush output + null, // options + false, // do not generate output + new ICompilerRequestor() { + public void acceptResult(CompilationResult result) { + assertNotNull("missing reference information",result.simpleNameReferences); + boolean found = false; + char[] foo = "Foo".toCharArray(); + for (int i = 0, length = result.simpleNameReferences.length; i < length; i++) { + char[] name = result.simpleNameReferences[i]; + if (CharOperation.equals(foo, name)) + found = true; + } + assertTrue(new String(result.compilationUnit.getMainTypeName())+" should contain reference to Foo", found); + } + }); +} +public void test052() { + this.runNegativeTest( + new String[] { + "p/Client.java", + "package p;\n" + + "import q.FooFactory;\n" + + "public class Client {\n" + + " int foo() { \n" + + " return FooFactory.createFoos().length;\n" + + " }\n" + + "}\n", + "q/Foo.java", + "package q;\n" + + "class Foo {\n" + // Foo not public to get visibility problems + " public Foo[][] foos;\n" + + "}\n", + "q/FooFactory.java", + "package q;\n" + + "public class FooFactory {\n" + + " public static Foo[] createFoos() {\n" + + " return new Foo[] { new Foo() };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\Client.java (at line 5)\n" + + " return FooFactory.createFoos().length;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Foo is not visible\n" + + "----------\n", + Util.concatWithClassLibs(OUTPUT_DIR, true/*output in front*/), + false, // do not flush output + null, // options + false, // do not generate output + new ICompilerRequestor() { + public void acceptResult(CompilationResult result) { + assertNotNull("missing reference information",result.simpleNameReferences); + boolean found = false; + char[] foo = "Foo".toCharArray(); + for (int i = 0, length = result.simpleNameReferences.length; i < length; i++) { + char[] name = result.simpleNameReferences[i]; + if (CharOperation.equals(foo, name)) + found = true; + } + assertTrue(new String(result.compilationUnit.getMainTypeName())+" should contain reference to Foo", found); + } + }); } }