Skip to content

Commit

Permalink
Revert #630 (#1079)
Browse files Browse the repository at this point in the history
* Revert #630

* Point-fix for NullTypeAnnotationTest.testBug522142_bogusError() in
absence of #630.

Disable testGH854 to enable running of more test suites

---------

Co-authored-by: Stephan Herrmann <stephan.herrmann@berlin.de>
  • Loading branch information
srikanth-sankaran and stephan-herrmann committed May 23, 2023
1 parent 7addeea commit da0a6d8
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 27 deletions.
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();
}
}

0 comments on commit da0a6d8

Please sign in to comment.