View | Details | Raw Unified | Return to bug 325633 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/compiler/parser/TypeConverter.java (-11 / +20 lines)
Lines 401-407 Link Here
401
					result.sourceEnd = end;
401
					result.sourceEnd = end;
402
					return result;
402
					return result;
403
				case '[' :
403
				case '[' :
404
					if (dim == 0) nameFragmentEnd = this.namePos-1;
404
					if (dim == 0 && nameFragmentEnd < 0) nameFragmentEnd = this.namePos-1;
405
					dim++;
405
					dim++;
406
					break;
406
					break;
407
				case ']' :
407
				case ']' :
Lines 414-432 Link Here
414
					identCount ++;
414
					identCount ++;
415
					break;
415
					break;
416
				case '<' :
416
				case '<' :
417
					// convert 1.5 specific constructs only if compliance is 1.5 or above
417
					/* We need to convert and preserve 1.5 specific constructs only if compliance is 1.5 or above,
418
					if (!this.has1_5Compliance)
418
					   but in all cases, we must skip over them to see if there are any applicable type fragments
419
						break typeLoop;
419
					   after the type parameters: i.e we just aren't done having seen a '<' in 1.4 mode. Because of
420
					if (fragments == null) fragments = new ArrayList(2);
420
					   the way type signatures are encoded, TypeConverter.decodeType(String, int, int, int) is immune
421
					   to this problem. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=325633
422
					 */
423
					if (this.has1_5Compliance) {
424
						if (fragments == null) fragments = new ArrayList(2);
425
					}
421
					nameFragmentEnd = this.namePos-1;
426
					nameFragmentEnd = this.namePos-1;
422
					char[][] identifiers = CharOperation.splitOn('.', typeName, nameFragmentStart, this.namePos);
427
					if (this.has1_5Compliance) {
423
					fragments.add(identifiers);
428
						char[][] identifiers = CharOperation.splitOn('.', typeName, nameFragmentStart, this.namePos);
429
						fragments.add(identifiers);
430
					}
424
					this.namePos++; // skip '<'
431
					this.namePos++; // skip '<'
425
					TypeReference[] arguments = decodeTypeArguments(typeName, length, start, end); // positionned on '>' at end
432
					TypeReference[] arguments = decodeTypeArguments(typeName, length, start, end); // positionned on '>' at end
426
					fragments.add(arguments);
433
					if (this.has1_5Compliance) {
427
					identCount = 0;
434
						fragments.add(arguments);
428
					nameFragmentStart = -1;
435
						identCount = 0;
429
					nameFragmentEnd = -1;
436
						nameFragmentStart = -1;
437
						nameFragmentEnd = -1;
438
					}
430
					// next increment will skip '>'
439
					// next increment will skip '>'
431
					break;
440
					break;
432
			}
441
			}
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (+69 lines)
Lines 4807-4810 Link Here
4807
			deleteProject(project15);
4807
			deleteProject(project15);
4808
	}
4808
	}
4809
}
4809
}
4810
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325633
4811
public void testGenericAPIUsageFromA14Project5() throws CoreException {
4812
	IJavaProject project14 = null;
4813
	IJavaProject project15 = null;
4814
	try {
4815
		project15 = createJavaProject("Reconciler15API", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin");
4816
		createFolder("/Reconciler15API/src/p2");
4817
		createFile(
4818
				"/Reconciler15API/src/p2/List.java",
4819
				"package p2;\n" +
4820
				"public  class List<T> {}\n" +
4821
				"  public static List<String> [] getArray() {\n" +
4822
				"      return null;\n" +
4823
				"  }\n" +
4824
				"  public static List<String> [] getBackArray(List<String>[] p) {\n" +
4825
				"      return p;\n" +
4826
				"  }\n" +
4827
				"}"
4828
			);
4829
		project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
4830
		project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
4831
		project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
4832
		
4833
		project14 = createJavaProject("Reconciler1415", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin");
4834
		project14.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
4835
		project14.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
4836
		project14.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4);
4837
		
4838
		IClasspathEntry[] oldClasspath = project14.getRawClasspath();
4839
		int oldLength = oldClasspath.length;
4840
		IClasspathEntry[] newClasspath = new IClasspathEntry[oldLength+1];
4841
		System.arraycopy(oldClasspath, 0, newClasspath, 0, oldLength);
4842
		newClasspath[oldLength] = JavaCore.newProjectEntry(new Path("/Reconciler15API"));
4843
		project14.setRawClasspath(newClasspath, null);
4844
		
4845
		createFolder("/Reconciler1415/src/p1");
4846
		String source = 
4847
			"package p1;\n" +
4848
			"import p2.List;\n" +
4849
			"public class X {\n" +
4850
			"  private List [] l = List.getArray();\n" +
4851
			"  private List [] l2 = List.getBackArray(l);\n" +
4852
			"}";
4853
4854
		createFile(
4855
			"/Reconciler1415/src/p1/X.java",
4856
			source
4857
		);
4858
		
4859
		this.workingCopies = new ICompilationUnit[1];
4860
		char[] sourceChars = source.toCharArray();
4861
		this.problemRequestor.initialize(sourceChars);
4862
		this.workingCopies[0] = getCompilationUnit("/Reconciler1415/src/p1/X.java").getWorkingCopy(this.wcOwner, null);
4863
		assertProblems(
4864
			"Unexpected problems",
4865
			"----------\n" + 
4866
			"1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + 
4867
			"	private List [] l2 = List.getBackArray(l);\n" + 
4868
			"	                ^^\n" + 
4869
			"The field X.l2 is never read locally\n" + 
4870
			"----------\n"
4871
		);
4872
	} finally {
4873
		if (project14 != null)
4874
			deleteProject(project14);
4875
		if (project15 != null)
4876
			deleteProject(project15);
4877
	}
4878
}
4810
}
4879
}

Return to bug 325633