Fix <?> Wildcard not working in STG, fixes #287
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 2m23s

This commit is contained in:
Daniel Holle 2024-03-13 11:42:32 +01:00
parent 2cb84f9e2b
commit e17f08263e
3 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1,8 @@
import java.util.List;
import java.lang.Number;
public class Wildcards {
public void m1(List<?> a) {}
public void m2(List<? extends Number> a) {}
public void m3(List<? super Number> a) {}
}

View File

@ -2,6 +2,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.exceptions.TypeinferenceException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.antlr.Java17Parser;
import de.dhbwstuttgart.parser.antlr.Java17Parser.IdentifierContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.TypeArgumentsContext;
@ -121,8 +122,10 @@ public class TypeGenerator {
if (wildcardContext.getChildCount() < 3) {
if (!Objects.isNull(wildcardContext.extendsWildcardType())) {
return new ExtendsWildcardType(convert(wildcardContext.extendsWildcardType().typeType(), reg, generics), wildcardContext.getStart());
} else {
} else if (!Objects.isNull(wildcardContext.superWildcardType())) {
return new SuperWildcardType(convert(wildcardContext.superWildcardType().typeType(), reg, generics), wildcardContext.getStart());
} else {
return new ExtendsWildcardType(new RefType(new JavaClassName("java.lang.Object"), new NullToken()), wildcardContext.getStart());
}
} else {
throw new NotImplementedException(); // Wildcard ohne Bound

View File

@ -881,6 +881,14 @@ public class TestComplete {
var instance = clazz.getDeclaredConstructor().newInstance();
}
@Test
public void testWilcards() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Wildcards.jav");
var clazz = classFiles.get("Wildcards");
var instance = clazz.getDeclaredConstructor().newInstance();
}
@Test
public void testBug122() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug122.jav");