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
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 2m23s
This commit is contained in:
parent
2cb84f9e2b
commit
e17f08263e
8
resources/bytecode/javFiles/Wildcards.jav
Normal file
8
resources/bytecode/javFiles/Wildcards.jav
Normal 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) {}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.IdentifierContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.IdentifierContext;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.TypeArgumentsContext;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser.TypeArgumentsContext;
|
||||||
@ -121,8 +122,10 @@ public class TypeGenerator {
|
|||||||
if (wildcardContext.getChildCount() < 3) {
|
if (wildcardContext.getChildCount() < 3) {
|
||||||
if (!Objects.isNull(wildcardContext.extendsWildcardType())) {
|
if (!Objects.isNull(wildcardContext.extendsWildcardType())) {
|
||||||
return new ExtendsWildcardType(convert(wildcardContext.extendsWildcardType().typeType(), reg, generics), wildcardContext.getStart());
|
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());
|
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 {
|
} else {
|
||||||
throw new NotImplementedException(); // Wildcard ohne Bound
|
throw new NotImplementedException(); // Wildcard ohne Bound
|
||||||
|
@ -881,6 +881,14 @@ public class TestComplete {
|
|||||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
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
|
@Test
|
||||||
public void testBug122() throws Exception {
|
public void testBug122() throws Exception {
|
||||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug122.jav");
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug122.jav");
|
||||||
|
Loading…
Reference in New Issue
Block a user