Implementierung und Tests von IntermediateRefType.
This commit is contained in:
parent
3d19d8d729
commit
c681396061
@ -15,6 +15,16 @@ public final class IntermediateRefType extends IntermediateType{
|
|||||||
|
|
||||||
private final List<IntermediateRefType> typParameters;
|
private final List<IntermediateRefType> typParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caches the hashCode after first computation.
|
||||||
|
*/
|
||||||
|
private int hashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Caches the classSignature after first computation.
|
||||||
|
*/
|
||||||
|
private String classSignature = "";
|
||||||
|
|
||||||
public IntermediateRefType(JavaClassName className) {
|
public IntermediateRefType(JavaClassName className) {
|
||||||
this(className, new ArrayList<>());
|
this(className, new ArrayList<>());
|
||||||
}
|
}
|
||||||
@ -26,14 +36,24 @@ public final class IntermediateRefType extends IntermediateType{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getClassSignature() {
|
public String getClassSignature() {
|
||||||
//ToDo
|
String signature = classSignature;
|
||||||
return null;
|
if (!signature.equals("")) return classSignature;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (getClassName().equals("void")) signature = "V";
|
||||||
public String getClassDescriptor() {
|
else {
|
||||||
//ToDo
|
signature += String.format("L%s", getFullyQualifiedName());
|
||||||
return null;
|
if (getTypParameterSize() != 0){
|
||||||
|
signature += "<";
|
||||||
|
for (IntermediateType typParameter:typParameters) {
|
||||||
|
signature += String.format("L%s;", typParameter.getFullyQualifiedName());
|
||||||
|
}
|
||||||
|
signature += ">";
|
||||||
|
}
|
||||||
|
signature += ";";
|
||||||
|
}
|
||||||
|
signature.replace('.','/');
|
||||||
|
classSignature = signature;
|
||||||
|
return signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -51,8 +71,16 @@ public final class IntermediateRefType extends IntermediateType{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
//ToDo korrekte Definition auf Basis von equals
|
int prime = 31;
|
||||||
return 0;
|
int result = hashCode;
|
||||||
|
if (result == 0){
|
||||||
|
result += getFullyQualifiedName().hashCode();
|
||||||
|
for (IntermediateType typeParameter:typParameters) {
|
||||||
|
result = prime * result + typeParameter.hashCode();
|
||||||
|
}
|
||||||
|
hashCode = result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTypParameterSize(){ return typParameters.size(); }
|
public int getTypParameterSize(){ return typParameters.size(); }
|
||||||
|
@ -23,7 +23,6 @@ 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(); }
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package intermediate.types;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class IntermediateRefTypeTest {
|
||||||
|
|
||||||
|
private static String integerSignature;
|
||||||
|
private static IntermediateRefType typeToTest_Integer;
|
||||||
|
|
||||||
|
private static String listOfIntegerSignature;
|
||||||
|
private static IntermediateRefType typeToTest_ListofInteger;
|
||||||
|
|
||||||
|
private static String voidSignature;
|
||||||
|
private static IntermediateRefType typeToTest_void;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void StartUp(){
|
||||||
|
integerSignature = "Ljava/lang/Integer;";
|
||||||
|
typeToTest_Integer = new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class)));
|
||||||
|
|
||||||
|
listOfIntegerSignature = "Ljava/util/List<Ljava/lang/Integer;>;";
|
||||||
|
typeToTest_ListofInteger = new IntermediateRefType(
|
||||||
|
new JavaClassName(Type.getInternalName(List.class)),
|
||||||
|
Arrays.asList(typeToTest_Integer));
|
||||||
|
|
||||||
|
voidSignature = "V";
|
||||||
|
typeToTest_void = new IntermediateRefType(new JavaClassName("void"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void SignatureTest_Integer(){
|
||||||
|
assertEquals(integerSignature, typeToTest_Integer.getClassSignature());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void SignatureTest_List(){
|
||||||
|
assertEquals(listOfIntegerSignature, typeToTest_ListofInteger.getClassSignature());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void SignatureTest_Void(){
|
||||||
|
assertEquals(voidSignature, typeToTest_void.getClassSignature());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user