Skip to content

Commit

Permalink
Regression fixes:
Browse files Browse the repository at this point in the history
+ avoid j.l.Number which is absent from jclMin!
+ fix JCL_LIB -> JCL18_LIB in ImportRewrite18Test
+ propagate HasMissingType through substitution
+ protect collectMissingTypes() against infinite recursion
  • Loading branch information
stephan-herrmann committed Jul 2, 2024
1 parent 404720f commit f030900
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ParameterizedMethodBinding(final ParameterizedTypeBinding parameterizedDe
for (int i = 0; i < length; i++) { // copy original type variable to relocate
TypeVariableBinding originalVariable = originalVariables[i];
substitutedVariables[i] = new TypeVariableBinding(originalVariable.sourceName, this, originalVariable.rank, parameterizedDeclaringClass.environment);
substitutedVariables[i].tagBits |= (originalVariable.tagBits & (TagBits.AnnotationNullMASK|TagBits.HasNullTypeAnnotation));
substitutedVariables[i].tagBits |= (originalVariable.tagBits & (TagBits.AnnotationNullMASK|TagBits.HasNullTypeAnnotation|TagBits.HasMissingType));
}
this.typeVariables = substitutedVariables;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,17 @@ public boolean canBeInstantiated() {

@Override
public List<TypeBinding> collectMissingTypes(List<TypeBinding> missingTypes) {
if ((this.tagBits & TagBits.HasMissingType) != 0) {
if (this.superclass != null) {
missingTypes = this.superclass.collectMissingTypes(missingTypes);
}
for (ReferenceBinding superIfc : this.superInterfaces) {
missingTypes = superIfc.collectMissingTypes(missingTypes);
if ((this.tagBits & TagBits.HasMissingType) != 0 && !this.inRecursiveFunction) {
this.inRecursiveFunction = true;
try {
if (this.superclass != null) {
missingTypes = this.superclass.collectMissingTypes(missingTypes);
}
for (ReferenceBinding superIfc : this.superInterfaces) {
missingTypes = superIfc.collectMissingTypes(missingTypes);
}
} finally {
this.inRecursiveFunction = false;
}
}
return missingTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,14 @@ private String buildBindingKey(String contents) throws JavaModelException {
}

private IBinding[] createBindings(String contents, IJavaElement element) throws JavaModelException {
return createBindings(contents, element, false);
}
private IBinding[] createBindings(String contents, IJavaElement element, boolean recoverBindings) throws JavaModelException {
this.workingCopy.getBuffer().setContents(contents);
this.workingCopy.makeConsistent(null);
ASTParser parser = ASTParser.newParser(JLS3_INTERNAL);
parser.setProject(getJavaProject("P"));
parser.setBindingsRecovery(recoverBindings);
IJavaElement[] elements = new IJavaElement[] {element};
return parser.createBindings(elements, null);
}
Expand Down Expand Up @@ -1175,6 +1179,22 @@ public void testCreateBindings14a() throws JavaModelException {
IBinding[] bindings = createBindings(
"public class X<T extends java.lang.Number> {\n" +
"}",
this.workingCopy.getType("X").getTypeParameter("T"),
true // recover bindings, java.lang.Number is missing from jclMin!
);
assertBindingsEqual(
"LX;:TT;",
bindings);
}

/*
* Ensures that the correct IBindings are created for a given set of IJavaElement
* (type parameter with bound)
*/
public void testCreateBindings14a2() throws JavaModelException {
IBinding[] bindings = createBindings(
"public class X<T extends java.lang.Exception> {\n" + // j.l.Exception is present
"}",
this.workingCopy.getType("X").getTypeParameter("T")
);
assertBindingsEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static Test suite() {
protected void setUp() throws Exception {
super.setUp();

IJavaProject proj= createJavaProject(PROJECT, new String[] {"src"}, new String[] {"JCL_LIB"}, "bin", "1.8");
IJavaProject proj= createJavaProject(PROJECT, new String[] {"src"}, new String[] {"JCL18_LIB"}, "bin", "1.8");
proj.setOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
proj.setOption(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
proj.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
Expand Down Expand Up @@ -794,6 +794,7 @@ public void testBug474270_since_8() throws Exception {
parser.setSource(cu);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
TypeDeclaration type= (TypeDeclaration) astRoot.types().get(1);
MethodDeclaration [] methods = type.getMethods();
Expand Down

0 comments on commit f030900

Please sign in to comment.