From a17342458edc345b510b87bdc5ed3ce78c3c2884 Mon Sep 17 00:00:00 2001 From: Aldaron7 Date: Mon, 7 May 2018 18:37:21 +0200 Subject: [PATCH] fixed Construct. Changed Field and Method Types to GenericRefType. --- .../dhbwstuttgart/strucTypes/Construct.java | 34 ++++++++++--------- .../syntaxtree/type/GenericRefType.java | 7 ---- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/de/dhbwstuttgart/strucTypes/Construct.java b/src/de/dhbwstuttgart/strucTypes/Construct.java index 15f6c952..6e8565a4 100644 --- a/src/de/dhbwstuttgart/strucTypes/Construct.java +++ b/src/de/dhbwstuttgart/strucTypes/Construct.java @@ -51,7 +51,7 @@ public class Construct extends DefaultASTVisitor { this.newInterf.forEach(i -> i.accept(this)); return constructedInterfaces; } - + public InferredTypes getInferredTypes() { return inferredTypes; } @@ -59,8 +59,8 @@ public class Construct extends DefaultASTVisitor { public List getSubTypeConstraints() { return subTypeConstraints; } - - public Set getSubTypeConstraintsAsUnifyPairs(){ + + public Set getSubTypeConstraintsAsUnifyPairs() { return subTypeConstraints.stream().map(SubTypeConstraint::getAsUnifyPair).collect(Collectors.toSet()); } @@ -79,10 +79,11 @@ public class Construct extends DefaultASTVisitor { this.constructedInterfaces.add(this.constructInterface(typePlaceholder, name)); } - //check nur TPH in newInterf + // check nur TPH in newInterf @Override 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) { @@ -94,12 +95,11 @@ public class Construct extends DefaultASTVisitor { // Schleife über alle FieldConstraints mit ClassType i this.constraintsSet.getFieldConstraints().stream().filter(fc -> fc.getClassType().equals(i)).forEach(fc -> { - TypePlaceholder type = TypePlaceholder.fresh(offset); - //TODO welcher Typ für field TPH, GenRT,...? - GenericRefType grt = new GenericRefType(type.getName(), offset); + TypePlaceholder tph = TypePlaceholder.fresh(offset); + // Typ für field: GenericRefType + GenericRefType grt = new GenericRefType(tph.getName(), offset); parameterInhTyterm.add(fc.getFieldType()); - generics.add(new GenericTypeVar( type.getName(), - new ArrayList<>(), offset, offset)); + generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset)); Field field = new Field(fc.getFieldName(), grt, Modifier.PUBLIC, offset); fielddecl.add(field); }); @@ -113,15 +113,17 @@ public class Construct extends DefaultASTVisitor { GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), offset); List params = new ArrayList<>(); 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); - 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); generics.add(new GenericTypeVar(tph.getName(), new ArrayList<>(), offset, offset)); }); ParameterList parameterList = new ParameterList(params, offset); - //TODO Welcher returnType für method - Method method = new Method(Modifier.PUBLIC, mc.getMethodName(), returnType, parameterList, block, gtvDeclarations, offset); + // returnType für method: GenericRefType + Method method = new Method(Modifier.PUBLIC, mc.getMethodName(), + new GenericRefType(returnType.getName(), offset), parameterList, block, gtvDeclarations, offset); methods.add(method); }); @@ -131,14 +133,14 @@ public class Construct extends DefaultASTVisitor { this.inferredTypes.put(i, x); this.subTypeConstraints.forEach(sc -> sc.inferTypes(this.inferredTypes)); - final int modifiers = Modifier.PUBLIC; final RefType superClass = this.createSuperClass(); final boolean isInterface = true; final List constructors = new ArrayList<>(); final List implementedInterfaces = new ArrayList<>(); 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; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java index 9c1a7ece..a14813e7 100644 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericRefType.java @@ -17,15 +17,8 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric public String getParsedName(){ return name.toString(); } - - @Override - public String toString() { - return "GRT " + this.name ; - } - - @Override public void accept(ASTVisitor visitor) { visitor.visit(this); }