fixed Construct. Changed Field and Method Types to GenericRefType.

This commit is contained in:
Aldaron7 2018-05-07 18:37:21 +02:00
parent ab46709390
commit a17342458e
2 changed files with 18 additions and 23 deletions

View File

@ -82,7 +82,8 @@ public class Construct extends DefaultASTVisitor {
// check nur TPH in newInterf // check nur TPH in newInterf
@Override @Override
public void visit(RefType refType) { public void visit(RefType refType) {
throw new IllegalInterfaceTypeException(String.format("%s is not a valid type to generate an interface for.", refType)); throw new IllegalInterfaceTypeException(
String.format("%s is not a valid type to generate an interface for.", refType));
} }
private ClassOrInterface constructInterface(TypePlaceholder i, JavaClassName name) { private ClassOrInterface constructInterface(TypePlaceholder i, JavaClassName name) {
@ -94,12 +95,11 @@ public class Construct extends DefaultASTVisitor {
// Schleife über alle FieldConstraints mit ClassType i // Schleife über alle FieldConstraints mit ClassType i
this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> { this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> {
TypePlaceholder type = TypePlaceholder.fresh(offset); TypePlaceholder tph = TypePlaceholder.fresh(offset);
//TODO welcher Typ für field TPH, GenRT,...? // Typ für field: GenericRefType
GenericRefType grt = new GenericRefType(type.getName(), offset); GenericRefType grt = new GenericRefType(tph.getName(), offset);
parameterInhTyterm.add(fc.getFieldType()); parameterInhTyterm.add(fc.getFieldType());
generics.add(new GenericTypeVar( type.getName(), generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
new ArrayList<>(), offset, offset));
Field field = new Field(fc.getFieldName(), grt, Modifier.PUBLIC, offset); Field field = new Field(fc.getFieldName(), grt, Modifier.PUBLIC, offset);
fielddecl.add(field); fielddecl.add(field);
}); });
@ -113,15 +113,17 @@ public class Construct extends DefaultASTVisitor {
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), offset); GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), offset);
List<FormalParameter> params = new ArrayList<>(); List<FormalParameter> params = new ArrayList<>();
mc.getArguments().stream().map(a -> a.getSupertype()).forEach(supertype -> { mc.getArguments().stream().map(a -> a.getSupertype()).forEach(supertype -> {
//TODO welcher Typ für argument? // Typ für argument: GenericRefType
TypePlaceholder tph = TypePlaceholder.fresh(offset); TypePlaceholder tph = TypePlaceholder.fresh(offset);
params.add(new FormalParameter(tph.getName(), tph, offset)); GenericRefType grt = new GenericRefType(tph.getName(), offset);
params.add(new FormalParameter(tph.getName(), grt, offset));
parameterInhTyterm.add(supertype); parameterInhTyterm.add(supertype);
generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset)); generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset));
}); });
ParameterList parameterList = new ParameterList(params, offset); ParameterList parameterList = new ParameterList(params, offset);
//TODO Welcher returnType für method // returnType für method: GenericRefType
Method method = new Method(Modifier.PUBLIC, mc.getMethodName(), returnType, parameterList, block, gtvDeclarations, offset); Method method = new Method(Modifier.PUBLIC, mc.getMethodName(),
new GenericRefType(returnType.getName(), offset), parameterList, block, gtvDeclarations, offset);
methods.add(method); methods.add(method);
}); });
@ -131,14 +133,14 @@ public class Construct extends DefaultASTVisitor {
this.inferredTypes.put(i, x); this.inferredTypes.put(i, x);
this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes)); this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes));
final int modifiers = Modifier.PUBLIC; final int modifiers = Modifier.PUBLIC;
final RefType superClass = this.createSuperClass(); final RefType superClass = this.createSuperClass();
final boolean isInterface = true; final boolean isInterface = true;
final List<Constructor> constructors = new ArrayList<>(); final List<Constructor> constructors = new ArrayList<>();
final List<RefType> implementedInterfaces = new ArrayList<>(); final List<RefType> implementedInterfaces = new ArrayList<>();
GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset()); GenericDeclarationList genericClassParameters = new GenericDeclarationList(generics, i.getOffset());
ClassOrInterface constructedInterface = new ClassOrInterface(modifiers, name, fielddecl, methods, constructors, genericClassParameters, superClass, isInterface, implementedInterfaces, offset); ClassOrInterface constructedInterface = new ClassOrInterface(modifiers, name, fielddecl, methods, constructors,
genericClassParameters, superClass, isInterface, implementedInterfaces, offset);
return constructedInterface; return constructedInterface;
} }

View File

@ -18,13 +18,6 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
return name.toString(); return name.toString();
} }
@Override
public String toString() {
return "GRT " + this.name ;
}
@Override @Override
public void accept(ASTVisitor visitor) { public void accept(ASTVisitor visitor) {
visitor.visit(this); visitor.visit(this);