Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Keller2016-04-08 20:06:23 +0000
committerJay Arthanareeswaran2016-04-18 15:59:38 +0000
commit78d592611dbb845af82c1ddde716da6e242698d3 (patch)
treedbb774164f549d146010d3d4b626661c63c3c0dd
parent20b56366f723eb8e189573bd5d192116545af63c (diff)
downloadeclipse.jdt.core-78d592611dbb845af82c1ddde716da6e242698d3.tar.gz
eclipse.jdt.core-78d592611dbb845af82c1ddde716da6e242698d3.tar.xz
eclipse.jdt.core-78d592611dbb845af82c1ddde716da6e242698d3.zip
Bug 491354: [compiler] Wrong "indirectly referenced" error for member
type of raw binary type Change-Id: If9ddb9d8995757703cef0f37a83d403eded97798
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java81
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java9
2 files changed, 86 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
index bf38e4194d..cbf76bed3a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java
@@ -26,7 +26,23 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJarEntryResource;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaModelMarker;
+import org.eclipse.jdt.core.IJavaModelStatusConstants;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.WorkingCopyOwner;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTParser;
@@ -2603,7 +2619,8 @@ public void testBug490724() throws CoreException {
" class MethodInfo<K> {\n" +
" public class InnerMethodInfo<V> {}\n" +
" }\n" +
- " void addMethod(MethodInfo<String>.InnerMethodInfo<String> mi) { }"
+ " void addMethod(MethodInfo<String>.InnerMethodInfo<String> mi) { }" +
+ "}"
);
project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
@@ -2645,4 +2662,64 @@ public void testBug490724() throws CoreException {
deleteProject(project15);
}
}
+/*
+ * Test that a generic type referenced in a 1.3/1.4 project doesn't result in "indirectly referenced" error
+ * for member type of raw binary type. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=491354)
+ */
+public void testBug491354() throws CoreException {
+ IJavaProject project14 = null;
+ IJavaProject project15 = null;
+ try {
+ project15 = createJavaProject("Bug491354_15", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin");
+ createFolder("/Bug491354_15/src/p");
+ createFile(
+ "/Bug491354_15/src/p/ServiceTracker.java",
+ "package p;\n" +
+ "public class ServiceTracker<S, T> {\n" +
+ " private Tracked tracked() { return null; }\n" +
+ " private class Tracked { }\n" +
+ "}\n" +
+ ""
+ );
+ project15.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
+ project15.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
+ project15.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
+
+ project14 = createJavaProject("Bug491354_14", new String[] {"src"}, new String[] {"JCL_LIB"}, "bin");
+ project14.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
+ project14.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_3);
+ project14.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_3);
+
+ IClasspathEntry[] oldClasspath = project14.getRawClasspath();
+ int oldLength = oldClasspath.length;
+ IClasspathEntry[] newClasspath = new IClasspathEntry[oldLength+1];
+ System.arraycopy(oldClasspath, 0, newClasspath, 0, oldLength);
+ newClasspath[oldLength] = JavaCore.newProjectEntry(new Path("/Bug491354_15"));
+ project14.setRawClasspath(newClasspath, null);
+
+ createFolder("/Bug491354_14/src/p1");
+ String source =
+ "package p1;\n" +
+ "import p.ServiceTracker;\n" +
+ "public final class HttpServiceTracker extends ServiceTracker {\n" +
+ "}";
+
+ createFile(
+ "/Bug491354_14/src/p1/HttpServiceTracker.java",
+ source
+ );
+ waitForManualRefresh();
+ waitForAutoBuild();
+ project15.getProject().build(IncrementalProjectBuilder.AUTO_BUILD, null);
+ project14.getProject().build(IncrementalProjectBuilder.AUTO_BUILD, null);
+ IMarker[] markers = project14.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
+ markers = project14.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
+ assertMarkers("Unexpected markers", "", markers);
+ } finally {
+ if (project14 != null)
+ deleteProject(project14);
+ if (project15 != null)
+ deleteProject(project15);
+ }
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java
index 163b79939d..9cf8c6f079 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -94,10 +94,15 @@ ReferenceBinding resolve(LookupEnvironment environment, boolean convertGenericTo
}
targetType = this.resolvedType;
if (targetType == null) {
- targetType = this.fPackage.getType0(this.compoundName[this.compoundName.length - 1]);
+ char[] typeName = this.compoundName[this.compoundName.length - 1];
+ targetType = this.fPackage.getType0(typeName);
if (targetType == this) { //$IDENTITY-COMPARISON$
targetType = environment.askForType(this.compoundName);
}
+ if ((targetType == null || targetType == this) && CharOperation.contains('.', typeName)) { //$IDENTITY-COMPARISON$
+ // bug 491354: this complements the NameLookup#seekTypes(..), which performs the same adaptation
+ targetType = environment.askForType(this.fPackage, CharOperation.replaceOnCopy(typeName, '.', '$'));
+ }
if (targetType == null || targetType == this) { // could not resolve any better, error was already reported against it //$IDENTITY-COMPARISON$
// report the missing class file first - only if not resolving a previously missing type
if ((this.tagBits & TagBits.HasMissingType) == 0 && !environment.mayTolerateMissingType) {

Back to the top