5151import junit .framework .Test ;
5252import org .eclipse .jdt .core .JavaCore ;
5353import org .eclipse .jdt .core .compiler .CharOperation ;
54+ import org .eclipse .jdt .core .tests .junit .extension .TestCase ;
5455import org .eclipse .jdt .core .tests .util .AbstractCompilerTest ;
5556import org .eclipse .jdt .core .tests .util .Util ;
5657import org .eclipse .jdt .internal .compiler .batch .ClasspathDirectory ;
6465import org .eclipse .jdt .internal .compiler .lookup .TypeConstants ;
6566import org .eclipse .jdt .internal .compiler .util .ManifestAnalyzer ;
6667
67- @ SuppressWarnings ({ "unchecked" , "rawtypes" })
6868public class BatchCompilerTest extends AbstractBatchCompilerTest {
6969
7070 static {
71- // TESTS_NAMES = new String[] { "test3445 " };
71+ // TESTS_NAMES = new String[] { "testBug550255 " };
7272// TESTS_NUMBERS = new int[] { 306 };
7373// TESTS_RANGE = new int[] { 298, -1 };
7474 }
@@ -84,7 +84,7 @@ public BatchCompilerTest(String name) {
8484 public static Test suite () {
8585 return buildMinimalComplianceTestSuite (testClass (), FIRST_SUPPORTED_JAVA_VERSION );
8686 }
87- public static Class testClass () {
87+ public static Class <? extends TestCase > testClass () {
8888 return BatchCompilerTest .class ;
8989 }
9090 static class StringMatcher extends Matcher {
@@ -8187,12 +8187,12 @@ public void test230_sourcepath_vs_classpath() throws IOException, InterruptedExc
81878187 assertTrue (this .verifier .getExecutionOutput ().startsWith ("2" )); // skip trailing newline
81888188 // 2 means we selected src2
81898189 // recompile and run result using various levels of javac
8190- Iterator javacCompilersIterator = javacCompilers .iterator ();
8190+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
81918191 String specialOptions = commonOptions + " -Xprefer:source " ;
81928192 String sourceFileNames [] = new String [] {sourceFilePath };
81938193 File outputDir = new File (OUTPUT_DIR );
81948194 while (javacCompilersIterator .hasNext ()) {
8195- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8195+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
81968196 assertTrue (javacCompiler .compile (
81978197 outputDir , /* directory */
81988198 commonOptions /* options */ ,
@@ -8270,11 +8270,11 @@ public void test231_sourcepath_vs_classpath() throws IOException, InterruptedExc
82708270 false /* shouldFlushOutputDirectory */ ,
82718271 null /* progress */ );
82728272 if (RUN_JAVAC ) {
8273- Iterator javacCompilersIterator = javacCompilers .iterator ();
8273+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
82748274 String sourceFileNames [] = new String [] {sourceFilePath };
82758275 File outputDir = new File (OUTPUT_DIR );
82768276 while (javacCompilersIterator .hasNext ()) {
8277- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8277+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
82788278 assertFalse (javacCompiler .compile (
82798279 outputDir /* directory */ ,
82808280 commonOptions /* options */ ,
@@ -8329,11 +8329,11 @@ public void test232_repeated_classpath() throws IOException, InterruptedExceptio
83298329 if (RUN_JAVAC ) {
83308330 // javac skips all but the last classpath entry (which results into an
83318331 // error in the split case here)
8332- Iterator javacCompilersIterator = javacCompilers .iterator ();
8332+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
83338333 String sourceFileNames [] = new String [] {sourceFilePath };
83348334 File outputDir = new File (OUTPUT_DIR );
83358335 while (javacCompilersIterator .hasNext ()) {
8336- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8336+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
83378337 assertTrue (javacCompiler .compile (
83388338 outputDir /* directory */ ,
83398339 combinedClasspathOptions /* options */ ,
@@ -8381,12 +8381,12 @@ public void test233_repeated_sourcepath() throws IOException, InterruptedExcepti
83818381 true /* shouldFlushOutputDirectory */ ,
83828382 null /* progress */ );
83838383 if (RUN_JAVAC ) {
8384- Iterator javacCompilersIterator = javacCompilers .iterator ();
8384+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
83858385 String sourceFileNamesZ [] = new String [] {sourceFilePathZ };
83868386 String sourceFileNamesW [] = new String [] {sourceFilePathW };
83878387 File outputDir = new File (OUTPUT_DIR );
83888388 while (javacCompilersIterator .hasNext ()) {
8389- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8389+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
83908390 // succeeds because it picks src2 up
83918391 assertTrue (javacCompiler .compile (
83928392 outputDir /* directory */ ,
@@ -8436,11 +8436,11 @@ public void test234_sourcepath_vs_classpath() throws IOException, InterruptedExc
84368436 // in contrast with test#232 when src1 is on the classpath, javac fails
84378437 // to find src1/X.java; this is because -sourcepath inhibits source files
84388438 // search in classpath directories
8439- Iterator javacCompilersIterator = javacCompilers .iterator ();
8439+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
84408440 String sourceFileNames [] = new String [] {sourceFilePath };
84418441 File outputDir = new File (OUTPUT_DIR );
84428442 while (javacCompilersIterator .hasNext ()) {
8443- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8443+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
84448444 assertFalse (javacCompiler .compile (
84458445 outputDir , /* directory */
84468446 commonOptions /* options */ ,
@@ -8518,11 +8518,11 @@ public void test235_classpath() throws IOException, InterruptedException {
85188518 // javac passes, using the most recent file amongst source and class files
85198519 // present on the classpath
85208520 if (RUN_JAVAC ) {
8521- Iterator javacCompilersIterator = javacCompilers .iterator ();
8521+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
85228522 String sourceFileNames [] = new String [] {sourceFilePath };
85238523 File outputDir = new File (OUTPUT_DIR );
85248524 while (javacCompilersIterator .hasNext ()) {
8525- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8525+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
85268526 assertTrue (javacCompiler .compile (
85278527 outputDir /* directory */ ,
85288528 commonOptions /* options */ ,
@@ -8590,11 +8590,11 @@ public void test236_classpath() throws IOException, InterruptedException {
85908590 this .verifier .execute ("Y" , new String [] {OUTPUT_DIR + File .separator + "bin" });
85918591 assertTrue (this .verifier .getExecutionOutput ().startsWith ("1" )); // skip trailing newline
85928592 if (RUN_JAVAC ) {
8593- Iterator javacCompilersIterator = javacCompilers .iterator ();
8593+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
85948594 String sourceFileNames [] = new String [] {sourceFilePath };
85958595 File outputDir = new File (OUTPUT_DIR );
85968596 while (javacCompilersIterator .hasNext ()) {
8597- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8597+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
85988598 assertTrue (javacCompiler .compile (
85998599 outputDir /* directory */ ,
86008600 commonOptions /* options */ ,
@@ -8657,11 +8657,11 @@ public void test237_classpath() throws IOException, InterruptedException {
86578657 this .verifier .execute ("Y" , new String [] {OUTPUT_DIR + File .separator + "bin" });
86588658 assertTrue (this .verifier .getExecutionOutput ().startsWith ("1" )); // skip trailing newline
86598659 if (RUN_JAVAC ) {
8660- Iterator javacCompilersIterator = javacCompilers .iterator ();
8660+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
86618661 String sourceFileNames [] = new String [] {sourceFilePath };
86628662 File outputDir = new File (OUTPUT_DIR );
86638663 while (javacCompilersIterator .hasNext ()) {
8664- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8664+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
86658665 assertTrue (javacCompiler .compile (
86668666 outputDir /* directory */ ,
86678667 commonOptions /* options */ ,
@@ -8717,11 +8717,11 @@ public void test238_classpath() throws IOException, InterruptedException {
87178717 this .verifier .execute ("Y" , new String [] {OUTPUT_DIR + File .separator + "bin" });
87188718 assertTrue (this .verifier .getExecutionOutput ().startsWith ("1" )); // skip trailing newline
87198719 if (RUN_JAVAC ) {
8720- Iterator javacCompilersIterator = javacCompilers .iterator ();
8720+ Iterator < JavacCompiler > javacCompilersIterator = javacCompilers .iterator ();
87218721 String sourceFileNames [] = new String [] {sourceFilePath };
87228722 File outputDir = new File (OUTPUT_DIR );
87238723 while (javacCompilersIterator .hasNext ()) {
8724- JavacCompiler javacCompiler = ( JavacCompiler ) javacCompilersIterator .next ();
8724+ JavacCompiler javacCompiler = javacCompilersIterator .next ();
87258725 assertTrue (javacCompiler .compile (
87268726 outputDir /* directory */ ,
87278727 commonOptions /* options */ ,
@@ -10103,8 +10103,8 @@ public void test291_jar_ref_in_jar() throws Exception {
1010310103 "Class-Path: \r \n " +
1010410104 "\r \n "
1010510105 ));
10106- List calledFileNames = analyzer .getCalledFileNames ();
10107- String actual = calledFileNames == null ? "<null>" : Util .toString (( String []) calledFileNames .toArray (new String [calledFileNames .size ()]), false /*don't add extra new lines*/ );
10106+ List < String > calledFileNames = analyzer .getCalledFileNames ();
10107+ String actual = calledFileNames == null ? "<null>" : Util .toString (calledFileNames .toArray (new String [calledFileNames .size ()]), false /*don't add extra new lines*/ );
1010810108 assertStringEquals (
1010910109 "<null>" ,
1011010110 actual ,
@@ -13326,4 +13326,35 @@ public static void main(String[] args) {
1332613326 "" ,
1332713327 true );
1332813328}
13329+ public void testBug550255 () {
13330+ this .runConformTest (
13331+ new String [] {
13332+ "X.java" ,
13333+ "public class X {\n " +
13334+ " public static int field1;\n " +
13335+ " public static int field2;\n " +
13336+ " private synchronized String foo() {\n " +
13337+ " return null;\n " +
13338+ " }\n " +
13339+ " public synchronized void foo1() {\n " +
13340+ " System.out.println(1);\n " +
13341+ " }\n " +
13342+ " public final void foo2() {\n " +
13343+ " System.out.println(2);\n " +
13344+ " }\n " +
13345+ "}\n " ,
13346+ },
13347+ "\" " + OUTPUT_DIR + File .separator + "X.java\" "
13348+ + " -sourcepath \" " + OUTPUT_DIR + "\" "
13349+ + " -warn:all-static-method -proc:none -d \" " + OUTPUT_DIR + "\" " ,
13350+ "" ,
13351+ "----------\n " +
13352+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 10)\n "
13353+ + " public final void foo2() {\n "
13354+ + " ^^^^^^\n "
13355+ + "The method foo2() from the type X can be declared as static\n "
13356+ + "----------\n "
13357+ + "1 problem (1 warning)\n " ,
13358+ true );
13359+ }
1332913360}
0 commit comments