Felder aktivieren
This commit is contained in:
parent
4ca671631d
commit
1061f355ff
@ -1,20 +1,29 @@
|
||||
package de.dhbwstuttgart.typeinference.assumptions;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.constraints.GenericsResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FieldAssumption extends Assumption{
|
||||
private ClassOrInterface receiverClass;
|
||||
private RefTypeOrTPHOrWildcardOrGeneric type;
|
||||
private String name;
|
||||
|
||||
public FieldAssumption(ClassOrInterface receiverType,
|
||||
public FieldAssumption(String fieldName, ClassOrInterface receiverType,
|
||||
RefTypeOrTPHOrWildcardOrGeneric type, TypeScope scope){
|
||||
super(scope);
|
||||
this.type = type;
|
||||
this.receiverClass = receiverType;
|
||||
this.name = fieldName;
|
||||
}
|
||||
|
||||
public ClassOrInterface getReceiverClass() {
|
||||
@ -26,7 +35,15 @@ public class FieldAssumption extends Assumption{
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReceiverType(GenericsResolver resolver) {
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(GenericTypeVar gtv : receiverClass.getGenerics()){
|
||||
//Hier wird ein GenericRefType gebildet, welcher einen für dieses Feld eindeutigen Namen hat
|
||||
GenericRefType genericRefType =
|
||||
new GenericRefType(receiverClass.getClassName().toString() + " " + name + " " + gtv.getName()
|
||||
, new NullToken());
|
||||
//Dieser wird dann korrekt aufgelöst vom Resolver:
|
||||
params.add(resolver.resolve(genericRefType));
|
||||
}
|
||||
return new RefType(receiverClass.getClassName(), params, new NullToken());
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class TypeInferenceInformation {
|
||||
for(Field m : cl.getFieldDecl()){
|
||||
if(m.getName().equals(name)){
|
||||
|
||||
ret.add(new FieldAssumption(cl, checkGTV(m.getType()), new TypeScopeContainer(cl, m)));
|
||||
ret.add(new FieldAssumption(name, cl, checkGTV(m.getType()), new TypeScopeContainer(cl, m)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,10 +105,6 @@ public class TYPEStmt implements StatementVisitor{
|
||||
for(FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)){
|
||||
Constraint constraint = new Constraint();
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
/*TODO Hier muss der Typ der Klasse ermittelt werden. In diesem müssen Generics mit TPHs ausgetauscht werden
|
||||
constraint.add(ConstraintsFactory.createPair(
|
||||
fieldVar.receiver.getType(),fieldAssumption.getReceiverType(), info.getCurrentTypeScope(), fieldAssumption.getTypeScope(), resolver));
|
||||
*/
|
||||
constraint.add(new Pair(fieldVar.receiver.getType(), fieldAssumption.getReceiverType(resolver), PairOperator.EQUALSDOT));
|
||||
constraint.add(new Pair(
|
||||
fieldVar.getType(), fieldAssumption.getType(resolver), PairOperator.EQUALSDOT));
|
||||
@ -117,9 +113,6 @@ public class TYPEStmt implements StatementVisitor{
|
||||
if(oderConstraints.size() == 0)
|
||||
throw new TypeinferenceException("Kein Feld "+fieldVar.fieldVarName+ " gefunden", fieldVar.getOffset());
|
||||
constraintsSet.addOderConstraint(oderConstraints);
|
||||
|
||||
//Wegen dem Problem oben:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user