forked from JavaTX/JavaCompilerCore
Hinzufügen von abstract getClassDescriptor in IntermediateType und Implementierung von IntermediateGenericType.
This commit is contained in:
parent
c681396061
commit
eaec7f613a
@ -1,13 +1,76 @@
|
|||||||
package de.dhbwstuttgart.intermediate.types;
|
package de.dhbwstuttgart.intermediate.types;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* //ToDo Beschreiben
|
* Represents a Java typ variable like {@code <T>} or {@code <T extends String>}.
|
||||||
*
|
*
|
||||||
* @since Studienarbeit Type Erasure
|
* @since Studienarbeit Type Erasure
|
||||||
* @author etiennezink
|
* @author etiennezink
|
||||||
*/
|
*/
|
||||||
public final class IntermediateGenericType {
|
//ToDo besprechen ob so korrekt
|
||||||
//ToDo
|
//z.b. Verwendeung von getFullyQualifiedName und co.
|
||||||
|
public final class IntermediateGenericType extends IntermediateType {
|
||||||
|
|
||||||
|
private final String genericName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caches the hashCode after first computation.
|
||||||
|
*/
|
||||||
|
private int hashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caches the classSignature after first computation.
|
||||||
|
*/
|
||||||
|
private String classSignature = "";
|
||||||
|
|
||||||
|
public IntermediateGenericType(String genericName){
|
||||||
|
this(genericName, new JavaClassName(Type.getInternalName(Object.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntermediateGenericType(String genericName, JavaClassName className) {
|
||||||
|
super(className);
|
||||||
|
this.genericName = genericName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof IntermediateGenericType)) return false;
|
||||||
|
|
||||||
|
IntermediateGenericType intermediateGenericType = (IntermediateGenericType) o;
|
||||||
|
if(!getFullyQualifiedName().equals(intermediateGenericType.getFullyQualifiedName())) return false;
|
||||||
|
if(!genericName.equals(intermediateGenericType.getGenericName())) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int prime = 31;
|
||||||
|
int result = hashCode;
|
||||||
|
if (result == 0){
|
||||||
|
result += getFullyQualifiedName().hashCode();
|
||||||
|
result = prime * result + genericName.hashCode();
|
||||||
|
hashCode = result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClassSignature() {
|
||||||
|
String signature = classSignature;
|
||||||
|
if (!signature.equals("")) return classSignature;
|
||||||
|
signature += String.format("T%s;", genericName);
|
||||||
|
classSignature = signature;
|
||||||
|
return signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClassDescriptor() {
|
||||||
|
return String.format("L%s;", getFullyQualifiedName()).replace('.','/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGenericName() {
|
||||||
|
return genericName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public final class IntermediateRefType extends IntermediateType{
|
|||||||
if (getClassName().equals("void")) signature = "V";
|
if (getClassName().equals("void")) signature = "V";
|
||||||
else {
|
else {
|
||||||
signature += String.format("L%s", getFullyQualifiedName());
|
signature += String.format("L%s", getFullyQualifiedName());
|
||||||
if (getTypParameterSize() != 0){
|
if (typParameters.size() != 0){
|
||||||
signature += "<";
|
signature += "<";
|
||||||
for (IntermediateType typParameter:typParameters) {
|
for (IntermediateType typParameter:typParameters) {
|
||||||
signature += String.format("L%s;", typParameter.getFullyQualifiedName());
|
signature += String.format("L%s;", typParameter.getFullyQualifiedName());
|
||||||
@ -56,6 +56,11 @@ public final class IntermediateRefType extends IntermediateType{
|
|||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClassDescriptor() {
|
||||||
|
return getClassSignature().replaceAll("<.+>", "");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof IntermediateRefType)) return false;
|
if (!(o instanceof IntermediateRefType)) return false;
|
||||||
@ -90,7 +95,7 @@ public final class IntermediateRefType extends IntermediateType{
|
|||||||
* @return the typ parameter at {@code index} or {@code null}, iff {@code |typ parameters| < index}
|
* @return the typ parameter at {@code index} or {@code null}, iff {@code |typ parameters| < index}
|
||||||
*/
|
*/
|
||||||
public IntermediateType getTypParameter(int index) {
|
public IntermediateType getTypParameter(int index) {
|
||||||
if(getTypParameterSize() < index) return null;
|
if(typParameters.size() < index) return null;
|
||||||
return typParameters.get(index);
|
return typParameters.get(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ public abstract class IntermediateType {
|
|||||||
public abstract int hashCode();
|
public abstract int hashCode();
|
||||||
|
|
||||||
public abstract String getClassSignature();
|
public abstract String getClassSignature();
|
||||||
|
public abstract String getClassDescriptor();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() { return getFullyQualifiedName(); }
|
public String toString() { return getFullyQualifiedName(); }
|
||||||
|
@ -15,25 +15,31 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class IntermediateRefTypeTest {
|
public class IntermediateRefTypeTest {
|
||||||
|
|
||||||
private static String integerSignature;
|
private static String integerSignature;
|
||||||
|
private static String integerDescriptor;
|
||||||
private static IntermediateRefType typeToTest_Integer;
|
private static IntermediateRefType typeToTest_Integer;
|
||||||
|
|
||||||
private static String listOfIntegerSignature;
|
private static String listOfIntegerSignature;
|
||||||
|
private static String listOfIntegerDescriptor;
|
||||||
private static IntermediateRefType typeToTest_ListofInteger;
|
private static IntermediateRefType typeToTest_ListofInteger;
|
||||||
|
|
||||||
private static String voidSignature;
|
private static String voidSignature;
|
||||||
|
private static String voidDescriptor;
|
||||||
private static IntermediateRefType typeToTest_void;
|
private static IntermediateRefType typeToTest_void;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void StartUp(){
|
public static void StartUp(){
|
||||||
integerSignature = "Ljava/lang/Integer;";
|
integerSignature = "Ljava/lang/Integer;";
|
||||||
|
integerDescriptor = "Ljava/lang/Integer;";
|
||||||
typeToTest_Integer = new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class)));
|
typeToTest_Integer = new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class)));
|
||||||
|
|
||||||
listOfIntegerSignature = "Ljava/util/List<Ljava/lang/Integer;>;";
|
listOfIntegerSignature = "Ljava/util/List<Ljava/lang/Integer;>;";
|
||||||
|
listOfIntegerDescriptor = "Ljava/util/List;";
|
||||||
typeToTest_ListofInteger = new IntermediateRefType(
|
typeToTest_ListofInteger = new IntermediateRefType(
|
||||||
new JavaClassName(Type.getInternalName(List.class)),
|
new JavaClassName(Type.getInternalName(List.class)),
|
||||||
Arrays.asList(typeToTest_Integer));
|
Arrays.asList(typeToTest_Integer));
|
||||||
|
|
||||||
voidSignature = "V";
|
voidSignature = "V";
|
||||||
|
voidDescriptor = "V";
|
||||||
typeToTest_void = new IntermediateRefType(new JavaClassName("void"));
|
typeToTest_void = new IntermediateRefType(new JavaClassName("void"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,12 +49,23 @@ public class IntermediateRefTypeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SignatureTest_List(){
|
public void DescriptorTest_Integer(){
|
||||||
assertEquals(listOfIntegerSignature, typeToTest_ListofInteger.getClassSignature());
|
assertEquals(integerDescriptor, typeToTest_Integer.getClassDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void SignatureTest_List(){ assertEquals(listOfIntegerSignature, typeToTest_ListofInteger.getClassSignature()); }
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void DescriptorTest_List(){ assertEquals(listOfIntegerDescriptor, typeToTest_ListofInteger.getClassDescriptor()); }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SignatureTest_Void(){
|
public void SignatureTest_Void(){
|
||||||
assertEquals(voidSignature, typeToTest_void.getClassSignature());
|
assertEquals(voidSignature, typeToTest_void.getClassSignature());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void DescriptorTest_Void(){
|
||||||
|
assertEquals(voidDescriptor, typeToTest_void.getClassDescriptor());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user