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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-6 / +16 lines)
Lines 256-265 Link Here
256
	
256
	
257
	/** Classfile debug information, may contain source file name, line numbers, local variable tables, etc... */
257
	/** Classfile debug information, may contain source file name, line numbers, local variable tables, etc... */
258
	public int produceDebugAttributes; 
258
	public int produceDebugAttributes; 
259
	/** Compliance level for the compiler, refers to a JDK version, e.g. {link {@link ClassFileConstants#JDK1_4} */
259
	/** Compliance level for the compiler, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4} */
260
	public long complianceLevel;
260
	public long complianceLevel;
261
	/** Java source level, refers to a JDK version, e.g. {link {@link ClassFileConstants#JDK1_4} */
261
	/** Original compliance level for the compiler, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4},
262
	 *  Usually same as the field complianceLevel, though the latter could deviate to create temporary sandbox
263
	 *  modes during reconcile operations. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=323633
264
	 */
265
	public long originalComplianceLevel;
266
	/** Java source level, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4} */
262
	public long sourceLevel;
267
	public long sourceLevel;
268
	/** Original Java source level, refers to a JDK version, e.g. {@link ClassFileConstants#JDK1_4} 
269
	 *  Usually same as the field sourceLevel, though the latter could deviate to create temporary sandbox
270
	 *  modes during reconcile operations. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=323633
271
	 * */
272
	public long originalSourceLevel;
263
	/** VM target level, refers to a JDK version, e.g. {link {@link ClassFileConstants#JDK1_4} */
273
	/** VM target level, refers to a JDK version, e.g. {link {@link ClassFileConstants#JDK1_4} */
264
	public long targetJDK;
274
	public long targetJDK;
265
	/** Source encoding format */
275
	/** Source encoding format */
Lines 953-960 Link Here
953
		
963
		
954
		// by default only lines and source attributes are generated.
964
		// by default only lines and source attributes are generated.
955
		this.produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES;
965
		this.produceDebugAttributes = ClassFileConstants.ATTR_SOURCE | ClassFileConstants.ATTR_LINES;
956
		this.complianceLevel = ClassFileConstants.JDK1_4; // by default be compliant with 1.4
966
		this.complianceLevel = this.originalComplianceLevel = ClassFileConstants.JDK1_4; // by default be compliant with 1.4
957
		this.sourceLevel = ClassFileConstants.JDK1_3; //1.3 source behavior by default
967
		this.sourceLevel = this.originalSourceLevel = ClassFileConstants.JDK1_3; //1.3 source behavior by default
958
		this.targetJDK = ClassFileConstants.JDK1_2; // default generates for JVM1.2
968
		this.targetJDK = ClassFileConstants.JDK1_2; // default generates for JVM1.2
959
969
960
		this.defaultEncoding = null; // will use the platform default encoding
970
		this.defaultEncoding = null; // will use the platform default encoding
Lines 1117-1127 Link Here
1117
		}
1127
		}
1118
		if ((optionValue = optionsMap.get(OPTION_Compliance)) != null) {
1128
		if ((optionValue = optionsMap.get(OPTION_Compliance)) != null) {
1119
			long level = versionToJdkLevel(optionValue);
1129
			long level = versionToJdkLevel(optionValue);
1120
			if (level != 0) this.complianceLevel = level;
1130
			if (level != 0) this.complianceLevel = this.originalComplianceLevel = level;
1121
		}
1131
		}
1122
		if ((optionValue = optionsMap.get(OPTION_Source)) != null) {
1132
		if ((optionValue = optionsMap.get(OPTION_Source)) != null) {
1123
			long level = versionToJdkLevel(optionValue);
1133
			long level = versionToJdkLevel(optionValue);
1124
			if (level != 0) this.sourceLevel = level;
1134
			if (level != 0) this.sourceLevel = this.originalSourceLevel = level;
1125
		}
1135
		}
1126
		if ((optionValue = optionsMap.get(OPTION_TargetPlatform)) != null) {
1136
		if ((optionValue = optionsMap.get(OPTION_TargetPlatform)) != null) {
1127
			long level = versionToJdkLevel(optionValue);
1137
			long level = versionToJdkLevel(optionValue);
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 149-155 Link Here
149
	this.fPackage = packageBinding;
149
	this.fPackage = packageBinding;
150
	this.fileName = binaryType.getFileName();
150
	this.fileName = binaryType.getFileName();
151
151
152
	char[] typeSignature = environment.globalOptions.sourceLevel >= ClassFileConstants.JDK1_5 ? binaryType.getGenericSignature() : null;
152
	char[] typeSignature = environment.globalOptions.originalSourceLevel >= ClassFileConstants.JDK1_5 ? binaryType.getGenericSignature() : null;
153
	this.typeVariables = typeSignature != null && typeSignature.length > 0 && typeSignature[0] == '<'
153
	this.typeVariables = typeSignature != null && typeSignature.length > 0 && typeSignature[0] == '<'
154
		? null // is initialized in cachePartsFrom (called from LookupEnvironment.createBinaryTypeFrom())... must set to null so isGenericType() answers true
154
		? null // is initialized in cachePartsFrom (called from LookupEnvironment.createBinaryTypeFrom())... must set to null so isGenericType() answers true
155
		: Binding.NO_TYPE_VARIABLES;
155
		: Binding.NO_TYPE_VARIABLES;
Lines 260-266 Link Here
260
			}
260
			}
261
		}
261
		}
262
262
263
		long sourceLevel = this.environment.globalOptions.sourceLevel;
263
		long sourceLevel = this.environment.globalOptions.originalSourceLevel;
264
		char[] typeSignature = null;
264
		char[] typeSignature = null;
265
		if (sourceLevel >= ClassFileConstants.JDK1_5) {
265
		if (sourceLevel >= ClassFileConstants.JDK1_5) {
266
			typeSignature = binaryType.getGenericSignature();
266
			typeSignature = binaryType.getGenericSignature();
Lines 558-564 Link Here
558
	if (iMethods != null) {
558
	if (iMethods != null) {
559
		total = initialTotal = iMethods.length;
559
		total = initialTotal = iMethods.length;
560
		boolean keepBridgeMethods = sourceLevel < ClassFileConstants.JDK1_5
560
		boolean keepBridgeMethods = sourceLevel < ClassFileConstants.JDK1_5
561
			&& this.environment.globalOptions.complianceLevel >= ClassFileConstants.JDK1_5;
561
			&& this.environment.globalOptions.originalComplianceLevel >= ClassFileConstants.JDK1_5;
562
		for (int i = total; --i >= 0;) {
562
		for (int i = total; --i >= 0;) {
563
			IBinaryMethod method = iMethods[i];
563
			IBinaryMethod method = iMethods[i];
564
			if ((method.getModifiers() & ClassFileConstants.AccSynthetic) != 0) {
564
			if ((method.getModifiers() & ClassFileConstants.AccSynthetic) != 0) {
(-)model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java (-2 / +7 lines)
Lines 293-299 Link Here
293
293
294
		// convert 1.5 specific constructs only if compliance is 1.5 or above
294
		// convert 1.5 specific constructs only if compliance is 1.5 or above
295
		TypeParameter[] typeParams = null;
295
		TypeParameter[] typeParams = null;
296
		if (this.has1_5Compliance) {
296
		// Digest type parameters if compliance level of current project or its prerequisite is >= 1.5
297
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=323633 && https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
298
		if (this.has1_5Compliance || this.problemReporter.options.complianceLevel >= ClassFileConstants.JDK1_5) {
297
			/* convert type parameters */
299
			/* convert type parameters */
298
			char[][] typeParameterNames = methodInfo.getTypeParameterNames();
300
			char[][] typeParameterNames = methodInfo.getTypeParameterNames();
299
			if (typeParameterNames != null) {
301
			if (typeParameterNames != null) {
Lines 462-468 Link Here
462
		if (this.has1_5Compliance) {
464
		if (this.has1_5Compliance) {
463
			/* convert annotations */
465
			/* convert annotations */
464
			type.annotations = convertAnnotations(typeHandle);
466
			type.annotations = convertAnnotations(typeHandle);
465
467
		}
468
		// Digest type parameters if compliance level of current project or its prerequisite is >= 1.5
469
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=323633 && https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259
470
		if (this.has1_5Compliance || this.problemReporter.options.complianceLevel >= ClassFileConstants.JDK1_5) {
466
			/* convert type parameters */
471
			/* convert type parameters */
467
			char[][] typeParameterNames = typeInfo.getTypeParameterNames();
472
			char[][] typeParameterNames = typeInfo.getTypeParameterNames();
468
			if (typeParameterNames.length > 0) {
473
			if (typeParameterNames.length > 0) {
(-)model/org/eclipse/jdt/internal/compiler/parser/TypeConverter.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
2
 * Copyright (c) 2008, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 40-46 Link Here
40
40
41
	protected TypeConverter(ProblemReporter problemReporter, char memberTypeSeparator) {
41
	protected TypeConverter(ProblemReporter problemReporter, char memberTypeSeparator) {
42
		this.problemReporter = problemReporter;
42
		this.problemReporter = problemReporter;
43
		this.has1_5Compliance = problemReporter.options.complianceLevel >= ClassFileConstants.JDK1_5;
43
		this.has1_5Compliance = problemReporter.options.originalComplianceLevel >= ClassFileConstants.JDK1_5;
44
		this.memberTypeSeparator = memberTypeSeparator;
44
		this.memberTypeSeparator = memberTypeSeparator;
45
	}
45
	}
46
46
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (+175 lines)
Lines 4632-4635 Link Here
4632
			deleteProject(project15);
4632
			deleteProject(project15);
4633
	}
4633
	}
4634
}
4634
}
4635
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=323633
4636
public void testGenericAPIUsageFromA14Project3() throws CoreException {
4637
	IJavaProject project14 = null;
4638
	IJavaProject project15 = null;
4639
	try {
4640
		project15 = createJavaProject("Reconciler15API", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin");
4641
		createFolder("/Reconciler15API/src/p2");
4642
		createFile(
4643
			"/Reconciler15API/src/p2/X.java",
4644
			"package p2;\n" +
4645
			"import java.util.Collection;\n" +
4646
			"import java.util.Iterator;\n" +
4647
			"public class X<E> implements Collection<E>{\n" +
4648
			"   public static X getX() {\n" +
4649
			"        	return new X();\n" +
4650
			"	}\n" +
4651
			"	public int size() {\n" +
4652
			"		return 0;\n" +
4653
			"	}\n" +
4654
			"	public boolean isEmpty() {\n" +
4655
			"		return false;\n" +
4656
			"	}\n" +
4657
			"	public boolean contains(Object o) {\n" +
4658
			"		return false;\n" +
4659
			"	}\n" +
4660
			"	public Iterator<E> iterator() {\n" +
4661
			"		return null;\n" +
4662
			"	}\n" +
4663
			"	public Object[] toArray() {\n" +
4664
			"		return null;\n" +
4665
			"	}\n" +
4666
			"	public <T> T[] toArray(T[] a) {\n" +
4667
			"		return null;\n" +
4668
			"	}\n" +
4669
			"	public boolean add(E e) {\n" +
4670
			"		return false;\n" +
4671
			"	}\n" +
4672
			"	public boolean remove(Object o) {\n" +
4673
			"		return false;\n" +
4674
			"	}\n" +
4675
			"	public boolean containsAll(Collection<?> c) {\n" +
4676
			"		return false;\n" +
4677
			"	}\n" +
4678
			"	public boolean addAll(Collection<? extends E> c) {\n" +
4679
			"		return false;\n" +
4680
			"	}\n" +
4681
			"	public boolean removeAll(Collection<?> c) {\n" +
4682
			"		return false;\n" +
4683
			"	}\n" +
4684
			"	public boolean retainAll(Collection<?> c) {\n" +
4685
			"		return false;\n" +
4686
			"	}\n" +
4687
			"	public void clear() {\n" +
4688
			"	}\n" +
4689
			"}\n"
4690
		);
4691
		project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
4692
		project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
4693
		project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
4694
		
4695
		project14 = createJavaProject("Reconciler1415", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin");
4696
		project14.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
4697
		project14.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
4698
		project14.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4);
4699
		
4700
		IClasspathEntry[] oldClasspath = project14.getRawClasspath();
4701
		int oldLength = oldClasspath.length;
4702
		IClasspathEntry[] newClasspath = new IClasspathEntry[oldLength+1];
4703
		System.arraycopy(oldClasspath, 0, newClasspath, 0, oldLength);
4704
		newClasspath[oldLength] = JavaCore.newProjectEntry(new Path("/Reconciler15API"));
4705
		project14.setRawClasspath(newClasspath, null);
4706
		
4707
		createFolder("/Reconciler1415/src/p1");
4708
		String source = 
4709
			"package p1;\n" +
4710
			"import java.util.Collection;\n" +
4711
			"public class X {\n" +
4712
			"  public static void main(String string) {\n" +
4713
			"  Collection c = p2.X.getX(); \n" +
4714
			"  }\n" +
4715
			"}";
4716
4717
		createFile(
4718
			"/Reconciler1415/src/p1/X.java",
4719
			source
4720
		);
4721
		
4722
		this.workingCopies = new ICompilationUnit[1];
4723
		char[] sourceChars = source.toCharArray();
4724
		this.problemRequestor.initialize(sourceChars);
4725
		this.workingCopies[0] = getCompilationUnit("/Reconciler1415/src/p1/X.java").getWorkingCopy(this.wcOwner, null);
4726
		assertProblems(
4727
			"Unexpected problems",
4728
			"----------\n" + 
4729
			"1. WARNING in /Reconciler1415/src/p1/X.java (at line 5)\n" + 
4730
			"	Collection c = p2.X.getX(); \n" + 
4731
			"	           ^\n" + 
4732
			"The local variable c is never read\n" + 
4733
			"----------\n"
4734
		);
4735
	} finally {
4736
		if (project14 != null)
4737
			deleteProject(project14);
4738
		if (project15 != null)
4739
			deleteProject(project15);
4740
	}
4741
}
4742
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=323633 (variation: 15 uses 14)
4743
public void testGenericAPIUsageFromA14Project4() throws CoreException {
4744
	IJavaProject project14 = null;
4745
	IJavaProject project15 = null;
4746
	try {
4747
		project14 = createJavaProject("Reconciler1415", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin");
4748
		createFolder("/Reconciler1415/src/p1");
4749
		String source = 
4750
			"package p1;\n" +
4751
			"import java.lang.Comparable;\n" +
4752
			"public class X implements Comparable {\n" +
4753
			"  public static X getX() {\n" +
4754
			"      return new X();\n" +
4755
			"  }\n" +
4756
			"}";
4757
4758
		createFile(
4759
			"/Reconciler1415/src/p1/X.java",
4760
			source
4761
		);
4762
4763
		project14.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
4764
		project14.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
4765
		project14.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4);
4766
4767
		project15 = createJavaProject("Reconciler15API", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin");
4768
		createFolder("/Reconciler15API/src/p2");
4769
		String otherSource = "package p2;\n" +
4770
		                     "public class X { \n" +
4771
		                     " private p1.X x = p1.X.getX();\n" +
4772
		                     " Comparable<String> y = null;\n" +
4773
		                     "}\n";   
4774
		                 
4775
		createFile(
4776
			"/Reconciler15API/src/p2/X.java",
4777
			otherSource
4778
		);
4779
		project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
4780
		project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
4781
		project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
4782
		
4783
		IClasspathEntry[] oldClasspath = project15.getRawClasspath();
4784
		int oldLength = oldClasspath.length;
4785
		IClasspathEntry[] newClasspath = new IClasspathEntry[oldLength+1];
4786
		System.arraycopy(oldClasspath, 0, newClasspath, 0, oldLength);
4787
		newClasspath[oldLength] = JavaCore.newProjectEntry(new Path("/Reconciler1415"));
4788
		project15.setRawClasspath(newClasspath, null);
4789
				
4790
		this.workingCopies = new ICompilationUnit[1];
4791
		char[] sourceChars = otherSource.toCharArray();
4792
		this.problemRequestor.initialize(sourceChars);
4793
		this.workingCopies[0] = getCompilationUnit("/Reconciler15API/src/p2/X.java").getWorkingCopy(this.wcOwner, null);
4794
		assertProblems(
4795
			"Unexpected problems",
4796
			"----------\n" + 
4797
			"1. WARNING in /Reconciler15API/src/p2/X.java (at line 3)\n" + 
4798
			"	private p1.X x = p1.X.getX();\n" + 
4799
			"	             ^\n" + 
4800
			"The field X.x is never read locally\n" + 
4801
			"----------\n"
4802
		);
4803
	} finally {
4804
		if (project14 != null)
4805
			deleteProject(project14);
4806
		if (project15 != null)
4807
			deleteProject(project15);
4808
	}
4809
}
4635
}
4810
}

Return to bug 323633