Hinzufügen von IntermediateWildcard und dessen Tests.

Hinzufügen der Tests für IntermediateSuperWildcard und IntermediateExtendsWildcard.
Verbesserung von IntermediateRefType: typParameter können IntermediateType sein und nicht nur IntermediateInnerType.
This commit is contained in:
Etienne Zink 2022-03-20 20:38:54 +01:00
parent 0207c7d1b0
commit 0d84e8361f
8 changed files with 202 additions and 15 deletions

View File

@ -1,7 +1,5 @@
package de.dhbwstuttgart.intermediate.types;
import de.dhbwstuttgart.parser.scope.JavaClassName;
/**
* Represents a Java Wildcard with a extends-operator.
* E.g. {@code &lt? extends String>}

View File

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

View File

@ -1,7 +1,5 @@
package de.dhbwstuttgart.intermediate.types;
import de.dhbwstuttgart.parser.scope.JavaClassName;
/**
* Represents a Java Wildcard with a super-operator.
* E.g. {@code &lt? super String&gt;}

View File

@ -0,0 +1,33 @@
package de.dhbwstuttgart.intermediate.types;
/**
* Represents a Java wildcard {@code &lt;?&gt;}.
*
* @since Studienarbeit Type Erasure
* @author etiennezink
*/
public class IntermediateWildcard extends IntermediateType{
/**
* Caches the hashCode after first computation.
*/
private int hashCode;
@Override
public boolean equals(Object o) { return o instanceof IntermediateWildcard; }
@Override
public int hashCode() {
int prime = 31;
int hashCode = this.hashCode;
if (hashCode == 0){
hashCode += "wildcard".hashCode();
hashCode = prime * hashCode + "*".hashCode();
this.hashCode = hashCode;
}
return hashCode;
}
@Override
public String getSignature() { return "*"; }
}

View File

@ -1,11 +1,62 @@
package intermediate.types;
import org.junit.Assert;
import de.dhbwstuttgart.intermediate.types.IntermediateExtendsWildcard;
import de.dhbwstuttgart.intermediate.types.IntermediateGenericType;
import de.dhbwstuttgart.intermediate.types.IntermediateRefType;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import org.junit.BeforeClass;
import org.junit.Test;
import org.objectweb.asm.Type;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class IntermediateExtensWildcardTest {
@Test
public void ToDo(){
Assert.fail();
private static String integerWildcardSignature;
private static IntermediateRefType integerWildcard;
private static String tWildcardSignature;
private static IntermediateRefType tWildcard;
private static IntermediateRefType tWildcardSame;
@BeforeClass
public static void StartUp(){
integerWildcardSignature = "Ljava/util/List<+Ljava/lang/Integer;>;";
integerWildcard = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateExtendsWildcard(new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class))))));
tWildcardSignature = "Ljava/util/List<+TT;>;";
tWildcard = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateExtendsWildcard(new IntermediateGenericType("T"))));
tWildcardSame = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateExtendsWildcard(new IntermediateGenericType("T"))));
}
@Test
public void SignatureTest_Integer(){ assertEquals(integerWildcardSignature, integerWildcard.getSignature()); }
@Test
public void SignatureTest_T(){ assertEquals(tWildcardSignature, tWildcard.getSignature()); }
@Test
public void HashCodeTest_Succeed() { assertEquals(tWildcardSame.hashCode(), tWildcard.hashCode());}
@Test
public void HashCodeTest_Fail() { assertNotEquals(tWildcardSame.hashCode(), integerWildcard.hashCode()); }
@Test
public void EqualsTest_Succeed() { assertEquals(tWildcardSame, tWildcard); }
@Test
public void EqualsTest_Fail() { assertNotEquals(tWildcardSame, integerWildcard); }
}

View File

@ -8,7 +8,6 @@ import org.junit.Test;
import org.objectweb.asm.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;

View File

@ -1,11 +1,62 @@
package intermediate.types;
import org.junit.Assert;
import de.dhbwstuttgart.intermediate.types.IntermediateGenericType;
import de.dhbwstuttgart.intermediate.types.IntermediateRefType;
import de.dhbwstuttgart.intermediate.types.IntermediateSuperWildcard;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import org.junit.BeforeClass;
import org.junit.Test;
import org.objectweb.asm.Type;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class IntermediateSuperWildcardTest {
@Test
public void ToDo(){
Assert.fail();
private static String integerWildcardSignature;
private static IntermediateRefType integerWildcard;
private static String tWildcardSignature;
private static IntermediateRefType tWildcard;
private static IntermediateRefType tWildcardSame;
@BeforeClass
public static void StartUp(){
integerWildcardSignature = "Ljava/util/List<-Ljava/lang/Integer;>;";
integerWildcard = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateSuperWildcard(new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class))))));
tWildcardSignature = "Ljava/util/List<-TT;>;";
tWildcard = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateSuperWildcard(new IntermediateGenericType("T"))));
tWildcardSame = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateSuperWildcard(new IntermediateGenericType("T"))));
}
@Test
public void SignatureTest_Integer(){ assertEquals(integerWildcardSignature, integerWildcard.getSignature()); }
@Test
public void SignatureTest_T(){ assertEquals(tWildcardSignature, tWildcard.getSignature()); }
@Test
public void HashCodeTest_Succeed() { assertEquals(tWildcardSame.hashCode(), tWildcard.hashCode());}
@Test
public void HashCodeTest_Fail() { assertNotEquals(tWildcardSame.hashCode(), integerWildcard.hashCode()); }
@Test
public void EqualsTest_Succeed() { assertEquals(tWildcardSame, tWildcard); }
@Test
public void EqualsTest_Fail() { assertNotEquals(tWildcardSame, integerWildcard); }
}

View File

@ -0,0 +1,57 @@
package intermediate.types;
import de.dhbwstuttgart.intermediate.types.IntermediateExtendsWildcard;
import de.dhbwstuttgart.intermediate.types.IntermediateGenericType;
import de.dhbwstuttgart.intermediate.types.IntermediateRefType;
import de.dhbwstuttgart.intermediate.types.IntermediateWildcard;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import org.junit.BeforeClass;
import org.junit.Test;
import org.objectweb.asm.Type;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class IntermediateWildcardTest {
private static String wildcardSignature;
private static IntermediateRefType wildcard;
private static IntermediateRefType wildcardSame;
private static IntermediateRefType tWildcard;
@BeforeClass
public static void StartUp(){
wildcardSignature = "Ljava/util/List<*>;";
wildcard = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateWildcard()));
wildcardSame = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateWildcard()));
tWildcard = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateExtendsWildcard(new IntermediateGenericType("T"))));
}
@Test
public void SignatureTest_Wildcard(){ assertEquals(wildcardSignature, wildcard.getSignature()); }
@Test
public void HashCodeTest_Succeed() { assertEquals(wildcardSame.hashCode(), wildcard.hashCode());}
@Test
public void HashCodeTest_Fail() { assertNotEquals(wildcardSame.hashCode(), tWildcard.hashCode()); }
@Test
public void EqualsTest_Succeed() { assertEquals(wildcardSame, wildcard); }
@Test
public void EqualsTest_Fail() { assertNotEquals(wildcardSame, tWildcard); }
}