forked from JavaTX/JavaCompilerCore
Implementierung der von convert(..) in ASTToIntermediate.
This commit is contained in:
parent
6381d09174
commit
21adeb7f26
@ -1,5 +1,50 @@
|
|||||||
package de.dhbwstuttgart.intermediate.convert;
|
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 {
|
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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user