Verbesserung typParameter von IntermediateRefType: Können IntermediateInnerType sein! Nicht nur IntermediateRefType wie zuvor.

Hizufügen entsprechender Tests.
This commit is contained in:
Etienne Zink 2022-03-20 16:59:24 +01:00
parent f1f028f0b9
commit 0207c7d1b0
3 changed files with 26 additions and 4 deletions

View File

@ -13,7 +13,7 @@ import java.util.List;
*/ */
public final class IntermediateRefType extends IntermediateInnerType{ public final class IntermediateRefType extends IntermediateInnerType{
private final List<IntermediateRefType> typParameters; private final List<IntermediateInnerType> typParameters;
private final JavaClassName className; private final JavaClassName className;
/** /**
@ -35,7 +35,7 @@ public final class IntermediateRefType extends IntermediateInnerType{
this(className, new ArrayList<>()); this(className, new ArrayList<>());
} }
public IntermediateRefType(JavaClassName className, List<IntermediateRefType> typParameters){ public IntermediateRefType(JavaClassName className, List<IntermediateInnerType> typParameters){
this.className = className; this.className = className;
this.typParameters = Collections.unmodifiableList(typParameters); this.typParameters = Collections.unmodifiableList(typParameters);
} }

View File

@ -7,6 +7,10 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
@ -33,9 +37,10 @@ public class IntermediateGenericTypeTest {
t = new IntermediateGenericType("T"); t = new IntermediateGenericType("T");
sExtendsStringSignature = "TS;"; sExtendsStringSignature = "TS;";
sExtendsStringDescriptor = "Ljava/lang/String;"; sExtendsStringDescriptor = "Ljava/util/List;";
sExtendsString = new IntermediateGenericType("S", sExtendsString = new IntermediateGenericType("S",
new IntermediateRefType(new JavaClassName(Type.getInternalName(String.class)))); new IntermediateRefType(new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class))))));
rExtendsSSignature = "TR;"; rExtendsSSignature = "TR;";
rExtendsSDescriptor = sExtendsStringDescriptor; rExtendsSDescriptor = sExtendsStringDescriptor;

View File

@ -1,5 +1,6 @@
package intermediate.types; package intermediate.types;
import de.dhbwstuttgart.intermediate.types.IntermediateGenericType;
import de.dhbwstuttgart.intermediate.types.IntermediateRefType; import de.dhbwstuttgart.intermediate.types.IntermediateRefType;
import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassName;
@ -23,6 +24,10 @@ public class IntermediateRefTypeTest {
private static String listOfIntegerDescriptor; private static String listOfIntegerDescriptor;
private static IntermediateRefType typeToTest_ListOfInteger; private static IntermediateRefType typeToTest_ListOfInteger;
private static String listOfTSignature;
private static String listOfTDescriptor;
private static IntermediateRefType typeToTest_ListOfT;
private static String voidSignature; private static String voidSignature;
private static String voidDescriptor; private static String voidDescriptor;
private static IntermediateRefType typeToTest_void; private static IntermediateRefType typeToTest_void;
@ -41,6 +46,12 @@ public class IntermediateRefTypeTest {
new JavaClassName(Type.getInternalName(List.class)), new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(typeToTest_Integer)); Arrays.asList(typeToTest_Integer));
listOfTSignature = "Ljava/util/List<TT;>;";
listOfTDescriptor = "Ljava/util/List;";
typeToTest_ListOfT = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateGenericType("T")));
voidSignature = "V"; voidSignature = "V";
voidDescriptor = "V"; voidDescriptor = "V";
typeToTest_void = new IntermediateRefType(new JavaClassName("void")); typeToTest_void = new IntermediateRefType(new JavaClassName("void"));
@ -66,6 +77,12 @@ public class IntermediateRefTypeTest {
@Test @Test
public void DescriptorTest_List(){ assertEquals(listOfIntegerDescriptor, typeToTest_ListOfInteger.getDescriptor()); } public void DescriptorTest_List(){ assertEquals(listOfIntegerDescriptor, typeToTest_ListOfInteger.getDescriptor()); }
@Test
public void SignatureTest_ListT(){ assertEquals(listOfTSignature, typeToTest_ListOfT.getSignature()); }
@Test
public void DescriptorTest_ListT(){ assertEquals(listOfTDescriptor, typeToTest_ListOfT.getDescriptor()); }
@Test @Test
public void SignatureTest_Void(){ public void SignatureTest_Void(){
assertEquals(voidSignature, typeToTest_void.getSignature()); assertEquals(voidSignature, typeToTest_void.getSignature());