Implementierung der von convert(..) in ASTToIntermediate.

This commit is contained in:
Etienne Zink 2022-03-21 17:15:03 +01:00
parent 6381d09174
commit 21adeb7f26

View File

@ -1,5 +1,50 @@
package de.dhbwstuttgart.intermediate.convert;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.intermediate.types.*;
import de.dhbwstuttgart.syntaxtree.type.*;
import java.util.stream.Collectors;
public class ASTToIntermediate {
//ToDo
public IntermediateRefType convert(RefType originalType){
return new IntermediateRefType(originalType.getName(),
originalType
.getParaList()
.stream()
.map(this::convert)
.collect(Collectors.toList()));
}
//ToDo abklären: darf hier kein <T extends Integer> stehen? da hier kein Typparameter existiert
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);
}
public IntermediateWildcard convert(){
//thows RuntimeException because in the AST is no typ defined which represents a normal wildcard
throw new NotImplementedException("There is no conversion defined for this type.");
}
public IntermediateRefType convert(RefTypeOrTPHOrWildcardOrGeneric originalType){
//default implementation which shouldn't be called because of polymorphism
throw new NotImplementedException("There is no conversion defined for this type.");
}
}