From 82ee42da9ff7141d74be705507cd177aa401b6cd Mon Sep 17 00:00:00 2001 From: Stephan Herrmann Date: Thu, 11 Jul 2024 14:53:12 +0200 Subject: [PATCH] clean-up and fix regression: + revert duplicate tagging with HasMissingType (already in initialize()) + fix tests by adding required import + create one test variant with missing import and POTENTIAL_MATCH --- .../lookup/ParameterizedTypeBinding.java | 7 ++-- .../tests/model/JavaSearchBugsTests2.java | 40 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java index 158154973c4..32df901927e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java @@ -91,11 +91,12 @@ public ParameterizedTypeBinding(ReferenceBinding type, TypeBinding[] arguments, for (TypeBinding argument : arguments) { if (argument instanceof UnresolvedReferenceBinding) ((UnresolvedReferenceBinding) argument).addWrapper(this, environment); - this.tagBits |= argument.tagBits & (TagBits.HasNullTypeAnnotation | TagBits.HasMissingType); + if (argument.hasNullTypeAnnotations()) + this.tagBits |= TagBits.HasNullTypeAnnotation; } } - if (enclosingType != null) - this.tagBits |= enclosingType.tagBits & (TagBits.HasNullTypeAnnotation | TagBits.HasMissingType); + if (enclosingType != null && enclosingType.hasNullTypeAnnotations()) + this.tagBits |= TagBits.HasNullTypeAnnotation; this.tagBits |= TagBits.HasUnresolvedTypeVariables; // cleared in resolve() this.typeBits = type.typeBits; } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java index 355c86465d9..cb991bf3b25 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 IBM Corporation and others. + * Copyright (c) 2014, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -210,6 +210,7 @@ public void testBug123836c() throws CoreException { // create the common project and create an interface project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); createFile("/P/Test.java", + "import java.io.Serializable;\n" + "class Test {\n"+ " void calc(Property prop, Property p2) {\n"+ " prop.compute(null);\n"+ @@ -232,6 +233,36 @@ public void testBug123836c() throws CoreException { deleteProject(project); } } + public void testBug123836c_missingImport() throws CoreException { + // original version with missing import, will now give POTENTIAL_MATCH + IJavaProject project = null; + try + { + // create the common project and create an interface + project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); + createFile("/P/Test.java", + "class Test {\n"+ + " void calc(Property prop, Property p2) {\n"+ + " prop.compute(null);\n"+ + " p2.compute(null);\n"+ + " }\n"+ + "}\n"+ + "abstract class Property {\n"+ + " public abstract void compute(E e);\n"+ + "}\n"+ + "class StringProperty extends Property {\n"+ + " @Override public void compute(String e) {\n"+ + " System.out.println(e);\n"+ + " }"); + IType type = getCompilationUnit("/P/Test.java").getType("StringProperty"); + IMethod method = type.getMethod("compute", new String[]{"QString;"}); + search(method, REFERENCES, EXACT_RULE, SearchEngine.createWorkspaceScope(), this.resultCollector); + assertSearchResults("Test.java void Test.calc(Property, Property) [compute(null)] EXACT_MATCH\n" + + "Test.java void Test.calc(Property, Property) [compute(null)] POTENTIAL_MATCH"); + } finally { + deleteProject(project); + } + } // Test inner class public void testBug123836d() throws CoreException { IJavaProject project = null; @@ -240,6 +271,7 @@ public void testBug123836d() throws CoreException { // create the common project and create an interface project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); createFile("/P/Test.java", + "import java.io.Serializable;\n" + "class Test {\n"+ " void calc(Property prop, Property p2) {\n"+ " prop.compute(null);\n"+ @@ -271,6 +303,7 @@ public void testBug123836e() throws CoreException { // create the common project and create an interface project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); createFile("/P/Test.java", + "import java.io.Serializable;\n" + "class Test {\n"+ " void calc(Property prop, Property p2) {\n"+ " prop.compute(null);\n"+ @@ -301,6 +334,7 @@ public void testBug123836f() throws CoreException { // create the common project and create an interface project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); createFile("/P/Test.java", + "import java.io.Serializable;\n" + "class Test {\n"+ " void calc(Property prop, Property p2) {\n"+ " prop.compute(null);\n"+ @@ -331,6 +365,7 @@ public void testBug123836g() throws CoreException { // create the common project and create an interface project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); createFile("/P/Test.java", + "import java.io.Serializable;\n" + "class Test {\n"+ " {\n" + " new Property() {\n" + @@ -361,6 +396,7 @@ public void testBug123836h() throws CoreException { // create the common project and create an interface project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); createFile("/P/Test.java", + "import java.io.Serializable;\n" + "class Test {\n"+ " static {\n" + " new Property() {\n" + @@ -391,6 +427,7 @@ public void testBug123836i() throws CoreException { // create the common project and create an interface project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); createFile("/P/Test.java", + "import java.io.Serializable;\n" + "class Test {\n"+ " Property p = new Property() {\n" + " @Override public void compute(String e) {}\n" + @@ -418,6 +455,7 @@ public void testBug123836j() throws CoreException { // create the common project and create an interface project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "","1.5"); createFile("/P/Test.java", + "import java.io.Serializable;\n" + "class Test {\n"+ " void calc(Property prop, Property p2) {\n"+ " prop.compute(null);\n"+