Löchen des Intermediate-Packages und Erstellung einer Utility-Klasse zur FunN Bytecodegenerierung.

Übertragung der Funktionalität zur Generierung von FunN auf FunNGenerator.
This commit is contained in:
Etienne Zink 2022-03-28 22:34:07 +02:00
parent fedf33a006
commit 0e363cfae3
20 changed files with 219 additions and 1111 deletions

View File

@ -15,12 +15,11 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import de.dhbwstuttgart.bytecode.funN.FunNGenerator;
import de.dhbwstuttgart.bytecode.funN.FunNUtilities;
import de.dhbwstuttgart.bytecode.utilities.*; import de.dhbwstuttgart.bytecode.utilities.*;
import de.dhbwstuttgart.environment.DirectoryClassLoader; import de.dhbwstuttgart.environment.DirectoryClassLoader;
import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.intermediate.convert.ASTToIntermediate;
import de.dhbwstuttgart.intermediate.generation.FunN;
import de.dhbwstuttgart.intermediate.types.IntermediateInnerType;
import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr.Operator; import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr.Operator;
@ -595,8 +594,9 @@ public class BytecodeGenMethod implements StatementVisitor {
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression); String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
//ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path); //old //ByteCodeForFunNGenerator.generateBCForFunN(lambdaExpression, typeErasure,path); //old
//ToDo Etienne: umbauen //ToDo Etienne: umbauen
//ToDo Refactor
/*
FunN f; FunN f;
//ToDo refactor with code for FunN underneath
ASTToIntermediate converter = new ASTToIntermediate(); ASTToIntermediate converter = new ASTToIntermediate();
//Fehler in return Typ //Fehler in return Typ
IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(lambdaExpression.getReturnType())); IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(lambdaExpression.getReturnType()));
@ -612,6 +612,22 @@ public class BytecodeGenMethod implements StatementVisitor {
f = new FunN(arguments, returnType); f = new FunN(arguments, returnType);
FunN.writeClassFile(f.getSuperClassName(), f.getSuperBytecode(), path); FunN.writeClassFile(f.getSuperClassName(), f.getSuperBytecode(), path);
FunN.writeClassFile(f.getClassName(), f.getBytecode(), path); FunN.writeClassFile(f.getClassName(), f.getBytecode(), path);
*/
///*
RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(lambdaExpression.getReturnType());
List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes = lambdaExpression
.params
.getFormalparalist()
.stream()
.map(FormalParameter::getType)
.map(resolver::resolve)
.collect(Collectors.toList());
FunNUtilities funNUtilities = FunNGenerator.getInstance();
byte[] superBytecode = funNUtilities.generateSuperBytecode(argumentTypes.size());
byte[] specializedBytecode = funNUtilities.generateSpecializedBytecode(argumentTypes, returnType);
FunNUtilities.writeClassFile(funNUtilities.getSuperClassName(argumentTypes.size()), superBytecode, path);
FunNUtilities.writeClassFile(funNUtilities.getSpecializedClassName(argumentTypes, returnType), specializedBytecode, path);
//*/
//ToDo Etienne: umbauen end //ToDo Etienne: umbauen end
Lambda lam = new Lambda(lambdaExpression); Lambda lam = new Lambda(lambdaExpression);
String lamDesc = lam.accept(new DescriptorToString(resultSet)); String lamDesc = lam.accept(new DescriptorToString(resultSet));
@ -835,16 +851,14 @@ public class BytecodeGenMethod implements StatementVisitor {
if(clazz.contains(CONSTANTS.$$)) { if(clazz.contains(CONSTANTS.$$)) {
mDesc = helper.getDescriptorOfApplyMethod(methCallType); mDesc = helper.getDescriptorOfApplyMethod(methCallType);
//helper.generateBCForFunN(mDesc); //old //helper.generateBCForFunN(mDesc); //old
//ToDo Etienne: check if it works //ToDo Etienne: Refactor
/*
FunN f; FunN f;
ASTToIntermediate converter = new ASTToIntermediate(); ASTToIntermediate converter = new ASTToIntermediate();
//Fehler
IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(methodCall.getType())); IntermediateInnerType returnType = (IntermediateInnerType) converter.convert(resolver.resolve(methodCall.getType()));
List<IntermediateInnerType> arguments = methodCall List<IntermediateInnerType> arguments = methodCall
.arglist .argTypes
.getArguments()
.stream() .stream()
.map(TypableStatement::getType)
.map(resolver::resolve) .map(resolver::resolve)
.map(converter::convert) .map(converter::convert)
.filter(t -> t instanceof IntermediateInnerType) .filter(t -> t instanceof IntermediateInnerType)
@ -854,6 +868,20 @@ public class BytecodeGenMethod implements StatementVisitor {
FunN.writeClassFile(f.getSuperClassName(), f.getSuperBytecode(), path); FunN.writeClassFile(f.getSuperClassName(), f.getSuperBytecode(), path);
FunN.writeClassFile(f.getClassName(), f.getBytecode(), path); FunN.writeClassFile(f.getClassName(), f.getBytecode(), path);
*/
///*
RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(methodCall.getType());
List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes = methodCall
.argTypes
.stream()
.map(resolver::resolve)
.collect(Collectors.toList());
FunNUtilities funNUtilities = FunNGenerator.getInstance();
byte[] superBytecode = funNUtilities.generateSuperBytecode(argumentTypes.size());
byte[] specializedBytecode = funNUtilities.generateSpecializedBytecode(argumentTypes, returnType);
FunNUtilities.writeClassFile(funNUtilities.getSuperClassName(argumentTypes.size()), superBytecode, path);
FunNUtilities.writeClassFile(funNUtilities.getSpecializedClassName(argumentTypes, returnType), specializedBytecode, path);
//*/
//ToDo Etienne End //ToDo Etienne End
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams); // mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
}else { }else {

View File

@ -1,22 +1,17 @@
package de.dhbwstuttgart.bytecode.descriptor; package de.dhbwstuttgart.bytecode.descriptor;
import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.bytecode.funN.FunNGenerator;
import de.dhbwstuttgart.intermediate.convert.ASTToIntermediate; import de.dhbwstuttgart.bytecode.funN.FunNUtilities;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
public class TypeToDescriptor implements TypeVisitor<String>{ public class TypeToDescriptor implements TypeVisitor<String>{
@Override @Override
public String visit(RefType refType) { public String visit(RefType refType) {
//ToDo Etienne: check if it works //ToDo Etienne: check if it works
if (refType.getName().toString().matches("Fun\\d+\\$\\$")) { if (refType.getName().toString().matches("Fun\\d+\\$\\$") && refType.getParaList().size() > 0) {
String descriptor = new ASTToIntermediate().convert(refType).getDescriptor(); FunNUtilities funNUtilities = FunNGenerator.getInstance();
return descriptor.substring(1, descriptor.length() - 1); return funNUtilities.getSpecializedDescriptor(funNUtilities.getArguments(refType.getParaList()), funNUtilities.getReturnType(refType.getParaList()));
} }
return refType.getName().toString().replace(".", "/"); return refType.getName().toString().replace(".", "/");

View File

@ -0,0 +1,136 @@
package de.dhbwstuttgart.bytecode.funN;
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
import de.dhbwstuttgart.bytecode.utilities.CONSTANTS;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import java.util.stream.Collectors;
import static org.objectweb.asm.Opcodes.*;
//ToDo Kommentieren
public class FunNGenerator implements FunNUtilities{
private static FunNGenerator funNGenerator = new FunNGenerator();
public static FunNGenerator getInstance(){
return funNGenerator;
}
private final String argumentGenericBase = "T";
private final String returnGeneric = "R";
private final String methodName = "apply";
private final int bytecodeVersion = V1_8;
private final String objectSuperType = Type.getInternalName(Object.class).replace('.','/');
private final RefType objectRefType = new RefType(new JavaClassName(objectSuperType), null);
private final String objectSignature = applySignature(objectRefType);
private static String applyDescriptor(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToDescriptor()); }
private static String applySignature(RefTypeOrTPHOrWildcardOrGeneric a) { return a.acceptTV(new TypeToSignature()); }
@Override
public byte[] generateSuperBytecode(int numberArguments) {
StringBuilder superFunNClassSignature = new StringBuilder("<");
StringBuilder superFunNMethodSignature = new StringBuilder("(");
StringBuilder superFunNMethodDescriptor = new StringBuilder("(");
for (int currentParameter = 1; currentParameter <= numberArguments; currentParameter++){
superFunNClassSignature.append(String.format("%s%d:%s",argumentGenericBase, currentParameter, objectSignature));
superFunNMethodSignature.append(applySignature( new GenericRefType(argumentGenericBase + currentParameter, null)));
superFunNMethodDescriptor.append(objectSignature);
}
superFunNClassSignature.append(String.format("%s:%s>%s", returnGeneric, objectSignature, objectSignature));
superFunNMethodSignature.append(String.format(")%s", applySignature(new GenericRefType(returnGeneric, null))));
superFunNMethodDescriptor.append(String.format(")%s", objectSignature));
ClassWriter classWriter = new ClassWriter(0);
MethodVisitor methodVisitor;
classWriter.visit(bytecodeVersion, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, getSuperClassName(numberArguments), superFunNClassSignature.toString(), objectSuperType, null);
methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, methodName, superFunNMethodDescriptor.toString(), superFunNMethodSignature.toString(), null);
methodVisitor.visitEnd();
classWriter.visitEnd();
return classWriter.toByteArray();
}
@Override
public String getSuperClassName(int numberArguments) {
return String.format("Fun%d$$", numberArguments);
}
@Override
public byte[] generateSpecializedBytecode(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
StringBuilder funNClassSignature = new StringBuilder(objectSignature + applySignature(new RefType(new JavaClassName(getSuperClassName(argumentTypes.size())), null)));
boolean containsGeneric = false;
String genericSignature = "<";
for (int currentTypArgumentIndex = 0; currentTypArgumentIndex < argumentTypes.size(); currentTypArgumentIndex++) {
RefTypeOrTPHOrWildcardOrGeneric typArgument = argumentTypes.get(currentTypArgumentIndex);
if (typArgument == null) continue;
if (typArgument instanceof GenericRefType){
GenericRefType generic = (GenericRefType) typArgument;
genericSignature += String.format("%s:%s", generic.getParsedName(), applyDescriptor(generic));
containsGeneric = true;
}
}
genericSignature += ">";
if (containsGeneric) funNClassSignature.insert(0, genericSignature);
ClassWriter classWriter = new ClassWriter(0);
classWriter.visit(bytecodeVersion, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, getSpecializedClassName(argumentTypes, returnType), funNClassSignature.toString(), objectSuperType, new String[]{getSuperClassName(argumentTypes.size())});
classWriter.visitEnd();
return classWriter.toByteArray();
}
@Override
public String getSpecializedClassName(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
if (returnType instanceof TypePlaceholder) returnType = objectRefType;
return String.format("Fun%d$$%s%s",
argumentTypes.size(),
argumentTypes
.stream()
.map(r -> r instanceof TypePlaceholder ? objectRefType : r)
.map(FunNGenerator::applyDescriptor)
.map(d -> String.format("L%s;", d))
.collect(Collectors.joining()),
applyDescriptor(returnType))
.replace('/', '$')
.replace(";", "$_$");
}
@Override
public String getSpecializedDescriptor(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
return applyDescriptor(new RefType(new JavaClassName(getSpecializedClassName(argumentTypes, returnType)), null));
}
@Override
public String getSpecializedSignature(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
return applySignature(new RefType(new JavaClassName(getSpecializedClassName(argumentTypes, returnType)), null));
}
@Override
public List<RefTypeOrTPHOrWildcardOrGeneric> getArguments(List<RefTypeOrTPHOrWildcardOrGeneric> list) {
return list
.stream()
.limit(Math.max(0, list.size() - 1))
.collect(Collectors.toList());
}
@Override
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(List<RefTypeOrTPHOrWildcardOrGeneric> list) {
if(list.size() == 0)
throw new IndexOutOfBoundsException();
return list.get(list.size() - 1);
}
}

View File

@ -0,0 +1,34 @@
package de.dhbwstuttgart.bytecode.funN;
import de.dhbwstuttgart.bytecode.utilities.CONSTANTS;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
public interface FunNUtilities {
byte[] generateSuperBytecode(int numberArguments);
String getSuperClassName(int numberArguments);
byte[] generateSpecializedBytecode(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType);
String getSpecializedClassName(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType);
String getSpecializedDescriptor(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType);
String getSpecializedSignature(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType);
List<RefTypeOrTPHOrWildcardOrGeneric> getArguments(List<RefTypeOrTPHOrWildcardOrGeneric> list);
RefTypeOrTPHOrWildcardOrGeneric getReturnType(List<RefTypeOrTPHOrWildcardOrGeneric> list);
@Deprecated
public static boolean writeClassFile(String className, byte[] bytecode, File directory) {
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
output.write(bytecode);
output.flush();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

View File

@ -5,8 +5,9 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import de.dhbwstuttgart.bytecode.funN.FunNGenerator;
import de.dhbwstuttgart.bytecode.funN.FunNUtilities;
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericsGeneratorResult;
import de.dhbwstuttgart.intermediate.convert.ASTToIntermediate;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
@ -31,9 +32,10 @@ public class TypeToSignature implements TypeVisitor<String> {
if(refType.getName().toString().equals("void")) if(refType.getName().toString().equals("void"))
return "V"; return "V";
//ToDo Etienne: check if it works //ToDo Etienne: check if it works
if (refType.getName().toString().matches("Fun\\d+\\$\\$")) if (refType.getName().toString().matches("Fun\\d+\\$\\$") && refType.getParaList().size() > 0){
return new ASTToIntermediate().convert(refType).getSignature(); FunNUtilities funNUtilities = FunNGenerator.getInstance();
return funNUtilities.getSpecializedSignature(funNUtilities.getArguments(refType.getParaList()), funNUtilities.getReturnType(refType.getParaList()));
}
// return refType.toString().replace(".", "/"); // return refType.toString().replace(".", "/");
String params = ""; String params = "";
if(refType.getParaList().size()>0){ if(refType.getParaList().size()>0){

View File

@ -1,73 +0,0 @@
package de.dhbwstuttgart.intermediate.convert;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.intermediate.generation.FunN;
import de.dhbwstuttgart.intermediate.types.*;
import de.dhbwstuttgart.syntaxtree.type.*;
import java.util.List;
import java.util.stream.Collectors;
public class ASTToIntermediate {
public IntermediateRefType convert(RefType originalType){
//ToDo Etienne: check if it works
System.out.println(originalType.getName());
System.out.println(originalType.getParaList().size());
if (originalType.getName().toString().matches("Fun\\d+\\$\\$")){
if(originalType.getParaList().size() == 0)
throw new RuntimeException("Incorrect FunN Type: No params are defined!");
List<RefTypeOrTPHOrWildcardOrGeneric> parameters = originalType.getParaList();
IntermediateInnerType returnType = (IntermediateInnerType) convert(parameters.get(parameters.size() - 1));
return new FunN(parameters
.stream()
.limit((parameters.size() - 1) > 0 ? (parameters.size() - 1) : 0)
.map(this::convert)
.filter(t -> t instanceof IntermediateInnerType)
.map(t -> (IntermediateInnerType) t)
.collect(Collectors.toList()), returnType);
}
return new IntermediateRefType(originalType.getName(),
originalType
.getParaList()
.stream()
.map(this::convert)
.collect(Collectors.toList()));
}
public IntermediateGenericType convert(GenericRefType originalType){
//no typ argument for e.g. <T extends Integer> is present in the definition of GenericRefType
return new IntermediateGenericType(originalType.getParsedName());
}
public IntermediateSuperWildcard convert(SuperWildcardType originalType){
IntermediateType innerType = convert(originalType.getInnerType());
//throws RuntimeException, because only IntermediateInnerType (no wildcards) are allowed as inner types of wildcards
if (!(innerType instanceof IntermediateInnerType)) throw new RuntimeException("False inner type!");
return new IntermediateSuperWildcard((IntermediateInnerType) innerType);
}
public IntermediateExtendsWildcard convert(ExtendsWildcardType originalType){
IntermediateType innerType = convert(originalType.getInnerType());
//throws RuntimeException because only IntermediateInnerType (no wildcards) are allowed as inner types of wildcards
if (!(innerType instanceof IntermediateInnerType)) throw new RuntimeException("False inner type!");
return new IntermediateExtendsWildcard((IntermediateInnerType) innerType);
}
//ToDo Etienne: check if it works
public IntermediateGenericType convert(TypePlaceholder originalType){
//ToDo muss zu einem Generic werden
return new IntermediateGenericType(originalType.getName());
}
public IntermediateType convert(RefTypeOrTPHOrWildcardOrGeneric originalType){
if (originalType instanceof RefType) return convert((RefType) originalType);
if (originalType instanceof GenericRefType) return convert((GenericRefType) originalType);
if (originalType instanceof SuperWildcardType) return convert((SuperWildcardType) originalType);
if (originalType instanceof ExtendsWildcardType) return convert((ExtendsWildcardType) originalType);
if (originalType instanceof TypePlaceholder) return convert((TypePlaceholder) originalType);
throw new NotImplementedException("There is no conversion defined for this type." + originalType.getClass().getName());
}
}

View File

@ -1,152 +0,0 @@
package de.dhbwstuttgart.intermediate.generation;
import de.dhbwstuttgart.bytecode.utilities.CONSTANTS;
import de.dhbwstuttgart.intermediate.types.IntermediateGenericType;
import de.dhbwstuttgart.intermediate.types.IntermediateInnerType;
import de.dhbwstuttgart.intermediate.types.IntermediateRefType;
import de.dhbwstuttgart.intermediate.types.IntermediateType;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.objectweb.asm.Opcodes.*;
/**
* Class which represents a function type.
* Offers different methods to generate or interact with this real function type.
*
* @since Studienarbeit Type Erasure
* @author etiennezink
*/
public final class FunN extends IntermediateRefType {
private final String argumentGenericBase = "T";
private final String returnGeneric = "R";
private final String methodName = "apply";
private final int bytecodeVersion = V1_8;
private final String objectSuperType = Type.getInternalName(Object.class).replace('.','/');
private final String objectSignature = new IntermediateRefType(new JavaClassName(Type.getInternalName(Object.class))).getSignature();
/**
* Represents the super interface of this specialized function.
*/
private final IntermediateRefType superFunN;
/**
* Caches the superBytecode after first computation.
*/
private byte[] superBytecode;
/**
* Caches the bytecode after first computation.
*/
private byte[] bytecode;
public FunN(IntermediateInnerType returnType){ this(Collections.emptyList(), returnType); }
public FunN(List<IntermediateInnerType> typArguments, IntermediateInnerType returnType) {
//using stream-API for single line processing of relevant data in the super()-call
super(new JavaClassName(
String.format("Fun%d$$%s%s",
typArguments.size(),
typArguments
.stream()
.map(IntermediateInnerType::getDescriptor)
.collect(Collectors.joining()),
returnType.getDescriptor())
.replace('/', '$')
.replace(";", "$_$")),
Stream.concat(typArguments.stream(), Stream.of(returnType)).collect(Collectors.toList()));
superFunN = new IntermediateRefType(new JavaClassName(String.format("Fun%d$$", typArguments.size())),
Stream.concat(typArguments.stream(), Stream.of(returnType)).collect(Collectors.toList()));
}
public String getSuperClassName() { return superFunN.getClassName(); }
/**
* @return the bytecode for the super FunN type
*/
public byte[] getSuperBytecode(){
byte[] superBytecode = this.superBytecode;
if (superBytecode == null){
String superFunNClassSignature = "<";
String superFunNMethodSignature = "(";
String superFunNMethodDescriptor = "(";
//currentParameter < getTypArgumentSize() because the return type is stored in the typArguments as well
for (int currentParameter = 1; currentParameter < getTypArgumentSize(); currentParameter++){
superFunNClassSignature += String.format("%s%d:%s",argumentGenericBase, currentParameter, objectSignature);
superFunNMethodSignature += new IntermediateGenericType(argumentGenericBase + currentParameter).getSignature();
superFunNMethodDescriptor += objectSignature;
}
superFunNClassSignature += String.format("%s:%s>%s", returnGeneric, objectSignature, objectSignature);
superFunNMethodSignature += String.format(")%s", new IntermediateGenericType(returnGeneric).getSignature());
superFunNMethodDescriptor += String.format(")%s", objectSignature);
ClassWriter classWriter = new ClassWriter(0);
MethodVisitor methodVisitor;
classWriter.visit(bytecodeVersion, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, superFunN.getClassName(), superFunNClassSignature, objectSuperType, null);
methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, methodName, superFunNMethodDescriptor, superFunNMethodSignature , null);
methodVisitor.visitEnd();
classWriter.visitEnd();
superBytecode = classWriter.toByteArray();
this.superBytecode = superBytecode;
}
return superBytecode;
}
/**
* Generates the bytecode for this FunN type.
* Make sure to generate the bytecode for the super FunN as well.
* @return the bytecode for this explicit FunN type
*/
public byte[] getBytecode(){
byte[] bytecode = this.bytecode;
if (bytecode == null){
String funNClassSignature = objectSignature + superFunN.getSignature();
boolean containsGeneric = false;
String genericSignature = "<";
for (int currentTypArgumentIndex = 0; currentTypArgumentIndex < getTypArgumentSize(); currentTypArgumentIndex++) {
IntermediateType typArgument = getTypArgument(currentTypArgumentIndex);
if (typArgument == null) continue;
if (typArgument instanceof IntermediateGenericType){
IntermediateGenericType generic = (IntermediateGenericType) typArgument;
genericSignature += String.format("%s:%s", generic.getGenericName(), generic.getDescriptor());
containsGeneric = true;
}
}
genericSignature += ">";
if (containsGeneric) funNClassSignature = genericSignature + funNClassSignature;
ClassWriter classWriter = new ClassWriter(0);
classWriter.visit(bytecodeVersion, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, getClassName(), funNClassSignature, objectSuperType, new String[]{superFunN.getClassName()});
classWriter.visitEnd();
bytecode = classWriter.toByteArray();
this.bytecode = bytecode;
}
return bytecode;
}
//ToDo Etienne: Auslagern in andere Klasse;
@Deprecated
public static boolean writeClassFile(String className, byte[] bytecode, File directory) {
try (FileOutputStream output = new FileOutputStream(new File(directory , className + CONSTANTS.EXTENSIONCLASS))){
output.write(bytecode);
output.flush();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

View File

@ -1,57 +0,0 @@
package de.dhbwstuttgart.intermediate.types;
/**
* Represents a Java Wildcard with a extends-operator.
* E.g. {@code &lt? extends String&gt;}
*
* @since Studienarbeit Type Erasure
* @author etiennezink
*/
public final class IntermediateExtendsWildcard extends IntermediateType {
private final IntermediateInnerType innerType;
/**
* Caches the hashCode after first computation.
*/
private int hashCode;
/**
* Caches the signature after first computation.
*/
private String signature = "";
public IntermediateExtendsWildcard(IntermediateInnerType innerType) {
this.innerType = innerType;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof IntermediateExtendsWildcard)) return false;
IntermediateExtendsWildcard intermediateExtendsWildcard = (IntermediateExtendsWildcard) o;
if(!innerType.equals(intermediateExtendsWildcard.innerType)) return false;
return true;
}
@Override
public int hashCode() {
int prime = 31;
int hashCode = this.hashCode;
if (hashCode == 0){
hashCode += innerType.hashCode();
hashCode = prime * hashCode + "extends".hashCode();
this.hashCode = hashCode;
}
return hashCode;
}
@Override
public String getSignature() {
String signature = this.signature;
if (!signature.equals("")) return this.signature;
signature = String.format("+%s", innerType.getSignature());
this.signature = signature;
return signature;
}
}

View File

@ -1,85 +0,0 @@
package de.dhbwstuttgart.intermediate.types;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import org.objectweb.asm.Type;
/**
* Represents a Java typ variable.
* E.g. {@code &lt;T&gt;} or {@code &lt;T extends String&gt;}.
*
* @since Studienarbeit Type Erasure
* @author etiennezink
*/
public final class IntermediateGenericType extends IntermediateInnerType {
private final String genericName;
private final IntermediateInnerType innerType;
/**
* Caches the hashCode after first computation.
*/
private int hashCode;
/**
* Caches the signature after first computation.
*/
private String signature = "";
/**
* Caches the descriptor after first computation.
*/
private String descriptor = "";
public IntermediateGenericType(String genericName){
this(genericName, new IntermediateRefType(new JavaClassName(Type.getInternalName(Object.class))));
}
public IntermediateGenericType(String genericName, IntermediateInnerType innerType) {
this.innerType = innerType;
this.genericName = genericName;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof IntermediateGenericType)) return false;
IntermediateGenericType intermediateGenericType = (IntermediateGenericType) o;
if(!innerType.equals(intermediateGenericType.innerType)) return false;
if(!genericName.equals(intermediateGenericType.genericName)) return false;
return true;
}
@Override
public int hashCode() {
int prime = 31;
int hashCode = this.hashCode;
if (hashCode == 0){
hashCode += innerType.hashCode();
hashCode = prime * hashCode + genericName.hashCode();
this.hashCode = hashCode;
}
return hashCode;
}
@Override
public String getSignature() {
String signature = this.signature;
if (!signature.equals("")) return this.signature;
signature += String.format("T%s;", genericName);
this.signature = signature;
return signature;
}
@Override
public String getDescriptor() {
String descriptor = this.descriptor;
if (!descriptor.equals("")) return this.descriptor;
descriptor = innerType.getDescriptor();
this.descriptor = descriptor;
return descriptor;
}
public String getGenericName() {
return genericName;
}
}

View File

@ -1,8 +0,0 @@
package de.dhbwstuttgart.intermediate.types;
/**
* Only Java types which can be used as an inner type, have a descriptor definition.
*/
public abstract class IntermediateInnerType extends IntermediateType {
public abstract String getDescriptor();
}

View File

@ -1,115 +0,0 @@
package de.dhbwstuttgart.intermediate.types;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Represents a Java reference type.
*
* @since Studienarbeit Type Erasure
* @author etiennezink
*/
public class IntermediateRefType extends IntermediateInnerType{
private final List<IntermediateType> typArguments;
private final JavaClassName className;
/**
* Caches the hashCode after first computation.
*/
private int hashCode;
/**
* Caches the signature after first computation.
*/
private String signature = "";
/**
* Caches the descriptor after first computation.
*/
private String descriptor = "";
public IntermediateRefType(JavaClassName className) { this(className, Collections.emptyList()); }
public IntermediateRefType(JavaClassName className, List<IntermediateType> typArguments){
this.className = className;
this.typArguments = Collections.unmodifiableList(typArguments);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof IntermediateRefType)) return false;
IntermediateRefType intermediateRefType = (IntermediateRefType) o;
if(!getFullyQualifiedName().equals(intermediateRefType.getFullyQualifiedName())) return false;
for(int index = 0; index < typArguments.size(); index++){
if(!typArguments.get(index).equals(intermediateRefType.typArguments.get(index))) return false;
}
return true;
}
@Override
public int hashCode() {
int prime = 31;
int hashCode = this.hashCode;
if (hashCode == 0){
hashCode += getFullyQualifiedName().hashCode();
for (IntermediateType typeArgument: typArguments) {
hashCode = prime * hashCode + typeArgument.hashCode();
}
this.hashCode = hashCode;
}
return hashCode;
}
@Override
public String getSignature() {
String signature = this.signature;
if (!signature.equals("")) return this.signature;
if (className.getClassName().equals("void")) signature = "V";
else {
signature += String.format("L%s", getFullyQualifiedName());
if (typArguments.size() != 0){
signature += "<";
for (IntermediateType typArgument: typArguments) {
signature += typArgument.getSignature();
}
signature += ">";
}
signature += ";";
}
signature = signature.replace('.','/');
this.signature = signature;
return signature;
}
@Override
public String getDescriptor() {
String descriptor = this.descriptor;
if (!descriptor.equals("")) return this.descriptor;
descriptor = getSignature().replaceAll("<.+>", "");
this.descriptor = descriptor;
return descriptor;
}
public boolean isParametrized() { return typArguments.size() > 0; }
public int getTypArgumentSize(){ return typArguments.size(); }
/**
* @param index
* @return the typ parameter at {@code index} or {@code null}, iff {@code |typ parameters| < index}
*/
public IntermediateType getTypArgument(int index) {
if(typArguments.size() < index) return null;
return typArguments.get(index);
}
public String getClassName(){ return className.getClassName(); }
public String getPackageName(){ return className.getPackageName(); }
public String getFullyQualifiedName(){ return className.toString(); }
}

View File

@ -1,56 +0,0 @@
package de.dhbwstuttgart.intermediate.types;
/**
* Represents a Java Wildcard with a super-operator.
* E.g. {@code &lt? super String&gt;}
*
* @since Studienarbeit Type Erasure
* @author etiennezink
*/
public final class IntermediateSuperWildcard extends IntermediateType {
private final IntermediateInnerType innerType;
/**
* Caches the hashCode after first computation.
*/
private int hashCode;
/**
* Caches the signature after first computation.
*/
private String signature = "";
public IntermediateSuperWildcard(IntermediateInnerType innerType) {
this.innerType = innerType;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof IntermediateSuperWildcard)) return false;
IntermediateSuperWildcard intermediateSuperWildcard = (IntermediateSuperWildcard) o;
if(!innerType.equals(intermediateSuperWildcard.innerType)) return false;
return true;
}
@Override
public int hashCode() {
int prime = 31;
int hashCode = this.hashCode;
if (hashCode == 0){
hashCode += innerType.hashCode();
hashCode = prime * hashCode + "super".hashCode();
this.hashCode = hashCode;
}
return hashCode;
}
@Override
public String getSignature() {
String signature = this.signature;
if (!signature.equals("")) return this.signature;
signature = String.format("-%s", innerType.getSignature());
this.signature = signature;
return signature;
}
}

View File

@ -1,23 +0,0 @@
package de.dhbwstuttgart.intermediate.types;
/**
* Base class for Java data types which is used as an intermediate representation after type resolution.
* This class and it's subtypes have to be immutable (e.g. no mutators) to ensure side effect freedom.
* Immutability and final subtypes are essential for future parallel processing.
*
* @since Studienarbeit Type Erasure
* @author etiennezink
*/
public abstract class IntermediateType {
@Override
public abstract boolean equals(Object o);
@Override
public abstract int hashCode();
public abstract String getSignature();
@Override
public String toString() { return getSignature(); }
}

View File

@ -1,33 +0,0 @@
package de.dhbwstuttgart.intermediate.types;
/**
* Represents a Java wildcard {@code &lt;?&gt;}.
*
* @since Studienarbeit Type Erasure
* @author etiennezink
*/
public final 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,117 +0,0 @@
package intermediate.generation;
import de.dhbwstuttgart.intermediate.generation.FunN;
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.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.objectweb.asm.Opcodes.*;
public class FunNTest {
private static FunN fun0T;
private static String fun1IntIntSignature;
private static String fun1IntIntDescriptor;
private static FunN fun1IntInt;
private static FunN fun2IntIntString;
@BeforeClass
public static void SetUp(){
IntermediateRefType integer = new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class)));
IntermediateRefType string = new IntermediateRefType(new JavaClassName(Type.getInternalName(String.class)));
fun0T = new FunN(new IntermediateGenericType("T"));
fun1IntIntSignature = "LFun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$<Ljava/lang/Integer;Ljava/lang/Integer;>;";
fun1IntIntDescriptor = "LFun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$;";
fun1IntInt = new FunN(Arrays.asList(integer), integer);
fun2IntIntString = new FunN(Arrays.asList(integer, integer), string);
}
@Test
public void SignatureTest_Fun1IntegerInteger(){ assertEquals(fun1IntIntSignature, fun1IntInt.getSignature()); }
@Test
public void DescriptorTest_Fun1IntegerInteger(){ assertEquals(fun1IntIntDescriptor, fun1IntInt.getDescriptor()); }
@Test
public void BytecodeTest_Super0(){ assertArrayEquals(generatedASMFun0(), fun0T.getSuperBytecode()) ;}
@Test
public void BytecodeTest_Fun0T(){ assertArrayEquals(generatedASMFun0T(), fun0T.getBytecode()) ;}
@Test
public void BytecodeTest_Super1(){ assertArrayEquals(generatedASMFun1(), fun1IntInt.getSuperBytecode()) ;}
@Test
public void BytecodeTest_Fun1IntInt(){ assertArrayEquals(generatedASMFun1IntInt(), fun1IntInt.getBytecode()) ;}
@Test
public void BytecodeTest_Super2(){ assertArrayEquals(generatedASMFun2(), fun2IntIntString.getSuperBytecode()) ;}
@Test
public void BytecodeTest_Fun2IntIntString(){ assertArrayEquals(generatedASMFun2IntIntString(), fun2IntIntString.getBytecode()) ;}
private byte[] generatedASMFun0() {
ClassWriter classWriter = new ClassWriter(0);
MethodVisitor methodVisitor;
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun0$$", "<R:Ljava/lang/Object;>Ljava/lang/Object;", "java/lang/Object", null);
methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "apply", "()Ljava/lang/Object;", "()TR;", null);
methodVisitor.visitEnd();
classWriter.visitEnd();
return classWriter.toByteArray();
}
private byte[] generatedASMFun0T() {
ClassWriter classWriter = new ClassWriter(0);
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun0$$TT$_$", "<T:Ljava/lang/Object;>Ljava/lang/Object;LFun0$$<TT;>;", "java/lang/Object", new String[]{"Fun0$$"});
classWriter.visitEnd();
return classWriter.toByteArray();
}
private byte[] generatedASMFun1() {
ClassWriter classWriter = new ClassWriter(0);
MethodVisitor methodVisitor;
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun1$$", "<T1:Ljava/lang/Object;R:Ljava/lang/Object;>Ljava/lang/Object;", "java/lang/Object", null);
methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "apply", "(Ljava/lang/Object;)Ljava/lang/Object;", "(TT1;)TR;", null);
methodVisitor.visitEnd();
classWriter.visitEnd();
return classWriter.toByteArray();
}
private byte[] generatedASMFun1IntInt() {
ClassWriter classWriter = new ClassWriter(0);
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", "Ljava/lang/Object;LFun1$$<Ljava/lang/Integer;Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun1$$"});
classWriter.visitEnd();
return classWriter.toByteArray();
}
private byte[] generatedASMFun2() {
ClassWriter classWriter = new ClassWriter(0);
MethodVisitor methodVisitor;
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun2$$", "<T1:Ljava/lang/Object;T2:Ljava/lang/Object;R:Ljava/lang/Object;>Ljava/lang/Object;", "java/lang/Object", null);
methodVisitor = classWriter.visitMethod(ACC_PUBLIC | ACC_ABSTRACT, "apply", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", "(TT1;TT2;)TR;", null);
methodVisitor.visitEnd();
classWriter.visitEnd();
return classWriter.toByteArray();
}
private byte[] generatedASMFun2IntIntString() {
ClassWriter classWriter = new ClassWriter(0);
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun2$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$Ljava$lang$String$_$", "Ljava/lang/Object;LFun2$$<Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/String;>;", "java/lang/Object", new String[]{"Fun2$$"});
classWriter.visitEnd();
return classWriter.toByteArray();
}
}

View File

@ -1,62 +0,0 @@
package intermediate.types;
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 {
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

@ -1,80 +0,0 @@
package intermediate.types;
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 IntermediateGenericTypeTest {
private static String tSignature;
private static String tDescriptor;
private static IntermediateGenericType t;
private static String sExtendsStringSignature;
private static String sExtendsStringDescriptor;
private static IntermediateGenericType sExtendsString;
private static String rExtendsSSignature;
private static String rExtendsSDescriptor;
private static IntermediateGenericType rExtendsS;
private static IntermediateGenericType rSame;
@BeforeClass
public static void StartUp(){
tSignature = "TT;";
tDescriptor = "Ljava/lang/Object;";
t = new IntermediateGenericType("T");
sExtendsStringSignature = "TS;";
sExtendsStringDescriptor = "Ljava/util/List;";
sExtendsString = new IntermediateGenericType("S",
new IntermediateRefType(new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class))))));
rExtendsSSignature = "TR;";
rExtendsSDescriptor = sExtendsStringDescriptor;
rExtendsS = new IntermediateGenericType("R", sExtendsString);
rSame = new IntermediateGenericType("R", sExtendsString);
}
@Test
public void SignatureTest_T(){ assertEquals(tSignature, t.getSignature()); }
@Test
public void DescriptorTest_T(){ assertEquals(tDescriptor, t.getDescriptor()); }
@Test
public void SignatureTest_TExtendsString(){ assertEquals(sExtendsStringSignature, sExtendsString.getSignature()); }
@Test
public void DescriptorTest_TExtendsString(){ assertEquals(sExtendsStringDescriptor, sExtendsString.getDescriptor()); }
@Test
public void SignatureTest_TExtendsS(){ assertEquals(rExtendsSSignature, rExtendsS.getSignature()); }
@Test
public void DescriptorTest_TExtendsS(){ assertEquals(rExtendsSDescriptor, rExtendsS.getDescriptor()); }
@Test
public void HashCodeTest_Succeed() { assertEquals(rSame.hashCode(), rExtendsS.hashCode());}
@Test
public void HashCodeTest_Fail() { assertNotEquals(rSame.hashCode(), t.hashCode()); }
@Test
public void EqualsTest_Succeed() { assertEquals(rSame, rExtendsS); }
@Test
public void EqualsTest_Fail() { assertNotEquals(rSame, t); }
}

View File

@ -1,107 +0,0 @@
package intermediate.types;
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 IntermediateRefTypeTest {
private static String integerSignature;
private static String integerDescriptor;
private static IntermediateRefType typeToTest_Integer;
private static String listOfIntegerSignature;
private static String listOfIntegerDescriptor;
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 voidDescriptor;
private static IntermediateRefType typeToTest_void;
private static IntermediateRefType typeToTest_ListOfIntegerSame;
@BeforeClass
public static void StartUp(){
integerSignature = "Ljava/lang/Integer;";
integerDescriptor = "Ljava/lang/Integer;";
typeToTest_Integer = new IntermediateRefType(new JavaClassName(Type.getInternalName(Integer.class)));
listOfIntegerSignature = "Ljava/util/List<Ljava/lang/Integer;>;";
listOfIntegerDescriptor = "Ljava/util/List;";
typeToTest_ListOfInteger = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
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";
voidDescriptor = "V";
typeToTest_void = new IntermediateRefType(new JavaClassName("void"));
typeToTest_ListOfIntegerSame = new IntermediateRefType(
new JavaClassName(Type.getInternalName(List.class)),
Arrays.asList(typeToTest_Integer));
}
@Test
public void SignatureTest_Integer(){
assertEquals(integerSignature, typeToTest_Integer.getSignature());
}
@Test
public void DescriptorTest_Integer(){
assertEquals(integerDescriptor, typeToTest_Integer.getDescriptor());
}
@Test
public void SignatureTest_List(){ assertEquals(listOfIntegerSignature, typeToTest_ListOfInteger.getSignature()); }
@Test
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
public void SignatureTest_Void(){
assertEquals(voidSignature, typeToTest_void.getSignature());
}
@Test
public void DescriptorTest_Void(){
assertEquals(voidDescriptor, typeToTest_void.getDescriptor());
}
@Test
public void HashCodeTest_Succeed() { assertEquals(typeToTest_ListOfIntegerSame.hashCode(), typeToTest_ListOfInteger.hashCode());}
@Test
public void HashCodeTest_Fail() { assertNotEquals(typeToTest_ListOfIntegerSame.hashCode(), typeToTest_Integer.hashCode()); }
@Test
public void EqualsTest_Succeed() { assertEquals(typeToTest_ListOfIntegerSame, typeToTest_ListOfInteger); }
@Test
public void EqualsTest_Fail() { assertNotEquals(typeToTest_ListOfIntegerSame, typeToTest_Integer); }
}

View File

@ -1,62 +0,0 @@
package intermediate.types;
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 {
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

@ -1,57 +0,0 @@
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); }
}