Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert https://github.com/eclipse-jdt/eclipse.jdt.core/pull/630 #1079

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1667,9 +1667,6 @@ private ReferenceBinding findSupertype(TypeReference typeReference) {
typeReference.aboutToResolve(this); // allows us to trap completion & selection nodes
unitScope.recordQualifiedReference(typeReference.getTypeName());
this.superTypeReference = typeReference;
if (this.compilerOptions().isAnnotationBasedNullAnalysisEnabled) {
this.hasDefaultNullnessFor(0 /*location*/, typeReference.sourceStart);
}
ReferenceBinding superType = (ReferenceBinding) typeReference.resolveSuperType(this);
return superType;
} catch (AbortCompilation e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.JavaFeature;
Expand Down Expand Up @@ -1356,27 +1355,6 @@ public boolean implementsInterface(ReferenceBinding anInterface, boolean searchH
}
}
}
// see https://github.com/eclipse-jdt/eclipse.jdt.core/issues/629
if (nextPosition == 0 && this instanceof SourceTypeBinding) {
SourceTypeBinding sourceType = (SourceTypeBinding) this;
if (sourceType.scope != null && sourceType.scope.referenceContext != null && sourceType.scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled) {
TypeReference[] references = sourceType.scope.referenceContext.superInterfaces;
if (references == null || references.length == 0) {
return false;
}
for (TypeReference reference: references) {
if (!(reference.resolvedType instanceof ReferenceBinding)) {
reference.resolveType(sourceType.scope);
}
if (reference.resolvedType instanceof ReferenceBinding) {
ReferenceBinding binding = (ReferenceBinding) reference.resolvedType;
if (binding.isEquivalentTo(anInterface)) {
return true;
}
}
}
}
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ private TypeConstants.BoundCheckStatus internalBoundCheck(Substitution substitut
break;
}
return BoundCheckStatus.OK;
} else if (checkNullAnnotations && argumentType.kind() == Binding.TYPE_PARAMETER) {
// refresh argumentType in case a nullness default(TYPE_PARAMETER) was applied late:
TypeVariableBinding tvb = (TypeVariableBinding) argumentType;
if (tvb.declaringElement instanceof SourceTypeBinding) {
TypeVariableBinding[] typeVariables = ((SourceTypeBinding) tvb.declaringElement).typeVariables;
if (typeVariables != null && typeVariables.length > tvb.rank) {
TypeVariableBinding refreshed = typeVariables[tvb.rank];
if (refreshed.id == argumentType.id)
argumentType = refreshed;
}
}
}
boolean unchecked = false;
if (this.superclass.id != TypeIds.T_JavaLangObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public void testNullableVar() {
"----------\n";
runner.runNegativeTest();
}
public void testGH629_01() {
public void _testGH629_01() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_18);
options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "test.NonNull");
Expand Down Expand Up @@ -660,7 +660,7 @@ public void testGH629_01() {
options,
"");
}
public void testGH629_02() {
public void _testGH629_02() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_18);
options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "test.NonNull");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18748,4 +18748,119 @@ public void testRedundantNonNull_field() {
runner.classLibraries = this.LIBS;
runner.runWarningTest();
}
public void testGH1007_srikanth() {
Runner runner = new Runner();
runner.testFiles =
new String[] {
"SubClass.java",
"// ECJ error in next line: Type mismatch: cannot convert from Class<SubClass> to Class<? extends SuperClass>[]\n" +
"@AnnotationWithArrayInitializer(annotationArgument = SubClass.class)\n" +
"class AnnotatedClass2 extends AnnotatedSuperClass {}\n" +
"\n" +
"//ECJ error in next line: Type mismatch: cannot convert from Class<SubClass> to Class<? extends SuperClass>\n" +
"@AnnotationWithArrayInitializer(annotationArgument = {SubClass.class})\n" +
"class AnnotatedClass extends AnnotatedSuperClass {}\n" +
"\n" +
"\n" +
"class AnnotatedSuperClass {}\n" +
"\n" +
"@interface AnnotationWithArrayInitializer {\n" +
" Class<? extends SuperClass>[] annotationArgument();\n" +
"}\n" +
"\n" +
"class SubClass extends SuperClass {}\n" +
"abstract class SuperClass {}"
};
runner.runConformTest();
}
public void _testGH854() {
Runner runner = new Runner();
runner.testFiles =
new String[] {
"Annot.java",
"public @interface Annot {\n" +
" Class<? extends Init<? extends Configuration>>[] inits(); \n" +
"}\n",
"Configuration.java",
"public interface Configuration {\n" +
"}\n",
"Init.java",
"public interface Init<C extends Configuration> {\n" +
"}\n",
"App.java",
"interface I<T> {}\n" +
"class IImpl<T> implements I<String>, Init<Configuration> {}\n" +
"@Annot(inits = {App.MyInit.class})\n" +
"public class App {\n" +
" static class MyInit extends IImpl<Configuration> {}\n" +
"}\n"
};
runner.runConformTest();
}
public void testVSCodeIssue3076() {
Runner runner = new Runner();
runner.testFiles =
new String[] {
"demo/cache/AbstractCache.java",
"package demo.cache;\n" +
"\n" +
"public abstract class AbstractCache {\n" +
" public enum Expiry {\n" +
" ONE, TWO, THREE\n" +
" }\n" +
"\n" +
" protected abstract void cacheThis(int param1, Expiry param2);\n" +
"}\n",
"demo/Annot.java",
"package demo;\n" +
"public @interface Annot {\n" +
" String defaultProperty();\n" +
"}\n",
"demo/cache/MyCache.java",
"package demo.cache;\n" +
"\n" +
"import demo.Annot;\n" +
"\n" +
"/**\n" +
" * This annotation is what causes the confusion around the nested Expiry type.\n" +
" *\n" +
" * If you comment out this annotation the language server has no problem\n" +
" * figuring it out.\n" +
" *\n" +
" * It can be *any* annotation.\n" +
" * So it would seem that referring to your own class outside of the\n" +
" * class definition is what triggers this particular bug.\n" +
" */\n" +
"@Annot(defaultProperty = MyCache.DEFAULT_PROPERTY_NAME)\n" +
"public class MyCache extends AbstractCache {\n" +
" public static final String DEFAULT_PROPERTY_NAME = \"WHATEVER\";\n" +
"\n" +
" @Override\n" +
" protected void cacheThis(int param1, Expiry param2) {\n" +
" throw new UnsupportedOperationException(\"Unimplemented method 'doSomethingElse'\");\n" +
" }\n" +
"}\n"
};
runner.runConformTest();
}
public void testGH969() {
Runner runner = new Runner();
runner.testFiles =
new String[] {
"mypackage/Example.java",
"package mypackage;\n" +
"\n" +
"import java.io.Serializable;\n" +
"\n" +
"@Deprecated(since = Example.SINCE)\n" +
"public class Example<T> implements Serializable {\n" +
" \n" +
" static final String SINCE = \"...\";\n" +
"\n" +
" private T target;\n" +
"\n" +
"}"
};
runner.runConformTest();
}
}