forked from JavaTX/JavaCompilerCore
fixed Construct. Changed Field and Method Types to GenericRefType.
This commit is contained in:
parent
ab46709390
commit
a17342458e
@ -51,7 +51,7 @@ public class Construct extends DefaultASTVisitor {
|
|||||||
this.newInterf.forEach(i -> i.accept(this));
|
this.newInterf.forEach(i -> i.accept(this));
|
||||||
return constructedInterfaces;
|
return constructedInterfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InferredTypes getInferredTypes() {
|
public InferredTypes getInferredTypes() {
|
||||||
return inferredTypes;
|
return inferredTypes;
|
||||||
}
|
}
|
||||||
@ -59,8 +59,8 @@ public class Construct extends DefaultASTVisitor {
|
|||||||
public List<SubTypeConstraint> getSubTypeConstraints() {
|
public List<SubTypeConstraint> getSubTypeConstraints() {
|
||||||
return subTypeConstraints;
|
return subTypeConstraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UnifyPair> getSubTypeConstraintsAsUnifyPairs(){
|
public Set<UnifyPair> getSubTypeConstraintsAsUnifyPairs() {
|
||||||
return subTypeConstraints.stream().map(SubTypeConstraint::getAsUnifyPair).collect(Collectors.toSet());
|
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));
|
this.constructedInterfaces.add(this.constructInterface(typePlaceholder, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
//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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,15 +17,8 @@ public class GenericRefType extends RefTypeOrTPHOrWildcardOrGeneric
|
|||||||
public String getParsedName(){
|
public String getParsedName(){
|
||||||
return name.toString();
|
return name.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
|
||||||
return "GRT " + this.name ;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user