Letzer Stand mit Pair Bildug waehrend des Typvars sammeln
This commit is contained in:
parent
905dfd8a27
commit
f2d6dae4c7
@ -60,9 +60,17 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
|
||||
|
||||
/*
|
||||
* ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu
|
||||
* ordnet den Fieldnamen ihre jeweiligen Lambda-respraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu
|
||||
*/
|
||||
public HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> nameToField;
|
||||
|
||||
/*
|
||||
* ordnet den Variablennamen ihre jeweiligen Lambda-Respraesentationen der abstrakte Syntax in der jeweiligen aktuellen Klasse zu
|
||||
* wird in jeder Methode neu initialisiert
|
||||
* Einträge werden nicht geloescht, da das Java-Programm korrekt ist und in umgebenden Bloecken nicht die gleichen Variablen vorkommen können
|
||||
*/
|
||||
public HashMap<String,RefTypeOrTPHOrWildcardOrGeneric> nameToLocalVar;
|
||||
|
||||
public final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
||||
public final List<String> tphsClass = new ArrayList<>();
|
||||
MethodAndTPH methodAndTph;
|
||||
@ -207,8 +215,9 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
inMethod = true;
|
||||
this.nameToLocalVar = new HashMap<>();
|
||||
String id = MethodUtility.createID(resolver,method);
|
||||
methodAndTph = new MethodAndTPH(id, (TypePlaceholder)method.getReturnType());
|
||||
methodAndTph = new MethodAndTPH(id, method.getReturnType());
|
||||
|
||||
inLocalOrParamOrReturn = true;
|
||||
method.getReturnType().accept(this);
|
||||
@ -232,7 +241,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
.block
|
||||
.statements
|
||||
.stream()
|
||||
.filter(s -> s instanceof Assign)
|
||||
.filter(s -> s instanceof Assign && ((Assign)s).rightSide instanceof LambdaExpression)
|
||||
.forEach(as ->
|
||||
this.nameToField.put(((AssignToField)(((Assign)as).lefSide)).field.fieldVarName,
|
||||
((AssignToField)(((Assign)as).lefSide)).getType())) ;
|
||||
@ -247,8 +256,10 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
|
||||
@Override
|
||||
public void visit(Constructor cons) {
|
||||
this.nameToLocalVar = new HashMap<>();
|
||||
inMethod = false;
|
||||
//super.visit(cons);
|
||||
|
||||
cons.getParameterList().accept(this);
|
||||
if(cons.block != null)
|
||||
cons.block.accept(this);
|
||||
@ -258,6 +269,12 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
inLambdaExpression = true;
|
||||
lambdaExpression.params.getFormalparalist().forEach(param -> {
|
||||
RefTypeOrTPHOrWildcardOrGeneric varType = resultSet.resolveType(param.getType()).resolvedType;
|
||||
if (varType instanceof RefType && ((RefType)varType).getName().getClassName().endsWith("$$")) {
|
||||
this.nameToLocalVar.put(param.getName(), param.getType());
|
||||
}
|
||||
});
|
||||
super.visit(lambdaExpression);
|
||||
inLambdaExpression = false;
|
||||
}
|
||||
@ -267,7 +284,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
super.visit(assign);
|
||||
RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(assign.rightSide.getType()).resolvedType;
|
||||
RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(assign.lefSide.getType()).resolvedType;
|
||||
if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) {
|
||||
if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) {
|
||||
if (right instanceof TypePlaceholder) {
|
||||
methodAndTph.addPair(allPairs.stream().filter(
|
||||
p -> (p.getLeft() instanceof TypePlaceholder &&
|
||||
@ -284,21 +301,25 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
public void visit(LocalVarDecl localVarDecl) {
|
||||
// inLocalOrParamOrReturn = inMethod;
|
||||
super.visit(localVarDecl);
|
||||
RefTypeOrTPHOrWildcardOrGeneric varType = resultSet.resolveType(localVarDecl.getType()).resolvedType;
|
||||
if (varType instanceof RefType && ((RefType)varType).getName().getClassName().endsWith("$$")) {
|
||||
this.nameToLocalVar.put(localVarDecl.getName(), localVarDecl.getType());
|
||||
}
|
||||
// inLocalOrParamOrReturn = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
String fieldOrMethName;
|
||||
String fieldLocalvarOrMethName;
|
||||
super.visit(methodCall);
|
||||
if (nameToMeth.keySet().contains(fieldOrMethName = methodCall.name) //Method-call of a method in the actuial Sourcefile
|
||||
if (nameToMeth.keySet().contains(fieldLocalvarOrMethName = methodCall.name) //Method-call of a method in the actuial Sourcefile
|
||||
|| (methodCall.name.equals("apply") &&
|
||||
(methodCall.receiver instanceof ExpressionReceiver) &&
|
||||
((((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar) &&
|
||||
nameToField.keySet().contains(fieldOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName)
|
||||
nameToField.keySet().contains(fieldLocalvarOrMethName = ((FieldVar)((ExpressionReceiver)methodCall.receiver).expr).fieldVarName)
|
||||
|| (((ExpressionReceiver)methodCall.receiver).expr instanceof LocalVar) &&
|
||||
nameToField.keySet().contains(fieldOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name)
|
||||
nameToLocalVar.keySet().contains(fieldLocalvarOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name)
|
||||
)
|
||||
//LOKALE VARIABLEN MUESSE NOCH IN nameToField EINGETRAGEN WERDEN
|
||||
)
|
||||
@ -306,8 +327,10 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
{
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt =
|
||||
methodCall.name.equals("apply")
|
||||
? ((RefType)(resultSet.resolveType((nameToField.get(fieldOrMethName))).resolvedType)).getParaList().iterator()
|
||||
: nameToMeth.get(methodCall.name)
|
||||
? (((ExpressionReceiver)methodCall.receiver).expr instanceof FieldVar)
|
||||
? ((RefType)(resultSet.resolveType((nameToField.get(fieldLocalvarOrMethName))).resolvedType)).getParaList().iterator()
|
||||
: ((RefType)(resultSet.resolveType((nameToLocalVar.get(fieldLocalvarOrMethName))).resolvedType)).getParaList().iterator()
|
||||
: nameToMeth.get(fieldLocalvarOrMethName)
|
||||
.getParameterList()
|
||||
.getFormalparalist()
|
||||
.stream()
|
||||
@ -318,7 +341,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
.forEach(x -> {
|
||||
RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType;
|
||||
RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next()).resolvedType;
|
||||
if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) {
|
||||
if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) {
|
||||
if (right instanceof TypePlaceholder) {
|
||||
methodAndTph.addPair(allPairs.stream().filter(
|
||||
p -> (p.getLeft() instanceof TypePlaceholder &&
|
||||
@ -339,7 +362,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
if (!inLambdaExpression) {
|
||||
RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType;
|
||||
RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType;
|
||||
if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) {
|
||||
if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) {
|
||||
if (right instanceof TypePlaceholder) {
|
||||
methodAndTph.addPair(allPairs.stream().filter(
|
||||
p -> (p.getLeft() instanceof TypePlaceholder &&
|
||||
|
@ -142,7 +142,8 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
System.out.println("fogg.classConstraints: "+ fogg.classConstraints);
|
||||
System.out.println("fogg.methodConstraintsWithPosition: "+ fogg.methodConstraintsWithPosition);
|
||||
|
||||
/*
|
||||
///*
|
||||
//Fayez Ansatz Anfang
|
||||
tphsClass = tphExtractor.tphsClass;
|
||||
//PL 2020-01-15
|
||||
//Es muss ggResult aus fogg gebildet werden
|
||||
@ -156,13 +157,15 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
addMethodConstraints(simplifiedConstraints, ggResult, m);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
if(ggResult != null) { //Hinzufuegen von Fayez ggResult
|
||||
//generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
|
||||
generatedGenericsForSF.addGenericGeneratorResultClass(ggResult);
|
||||
}
|
||||
|
||||
|
||||
// Fayez Ansatz Ende
|
||||
//*/
|
||||
|
||||
//Ali Ansatz Anfang
|
||||
List<GenericsGeneratorResult> listOfClassCons = new ArrayList<>();
|
||||
for(TPHConstraint clCons: fogg.classConstraints) {
|
||||
// ExtendsConstraint ec = new ExtendsConstraint(clCons.getLeft(), clCons.getRight());
|
||||
@ -186,10 +189,11 @@ public class GeneratedGenericsFinder implements ASTVisitor {
|
||||
ggResultAlternative = new GenericsGeneratorResultForClass(className, listOfClassCons, ggRfaM);
|
||||
|
||||
if(ggResultAlternative != null) {//hinzufuegen von Alis ggResult
|
||||
generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
|
||||
//generatedGenericsForSF.addGenericGeneratorResultClass(ggResultAlternative);
|
||||
System.out.println(generatedGenericsForSF);
|
||||
}
|
||||
System.out.println(ggResultAlternative);
|
||||
//Ali Ansatz Ende
|
||||
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,8 @@ public class FamilyOfGeneratedGenerics {
|
||||
ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> methodConstraints1Pairs,
|
||||
List<MethodAndTPH> listOfMethodsAndTph) {
|
||||
List<MethodConstraint> cs_m = new ArrayList<>();
|
||||
//List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||
//List<MethodConstraint> methodConstraints1 =
|
||||
typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||
|
||||
List<MethodConstraint> methodConstraints1 =
|
||||
methodConstraints1Pairs.stream()
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
|
||||
@ -20,9 +21,9 @@ public class MethodAndTPH {
|
||||
/*
|
||||
* Returntyp der zugehoerigen Methode in er abstrakten Syntax
|
||||
*/
|
||||
TypePlaceholder returnType;
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
|
||||
public MethodAndTPH(String name, TypePlaceholder returnType) {
|
||||
public MethodAndTPH(String name, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||
this.id = name;
|
||||
this.returnType = returnType;
|
||||
}
|
||||
@ -50,7 +51,7 @@ public class MethodAndTPH {
|
||||
basePairs.add(p);
|
||||
}
|
||||
|
||||
public TypePlaceholder getReturnType() {
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
|
@ -126,6 +126,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
public void visit(Assign assign) {
|
||||
assign.lefSide.accept(this);
|
||||
assign.rightSide.accept(this);
|
||||
assign.rightSide.getType().accept((ASTVisitor) this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -186,6 +187,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
public void visit(MethodCall methodCall) {
|
||||
methodCall.receiver.accept(this);
|
||||
methodCall.getArgumentList().accept(this);
|
||||
methodCall.getArgumentList().getArguments().forEach(a -> a.getType().accept((ASTVisitor) this));
|
||||
}
|
||||
|
||||
|
||||
@ -212,6 +214,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
aReturn.retexpr.accept(this);
|
||||
aReturn.getType().accept((ASTVisitor) this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,8 +31,14 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
private ExceptionList exceptionlist;
|
||||
private GenericDeclarationList generics;
|
||||
private final RefTypeOrTPHOrWildcardOrGeneric returnType;
|
||||
public final Boolean isInherited;
|
||||
|
||||
public final Boolean isInherited;
|
||||
|
||||
/*
|
||||
* its Constraints
|
||||
* eingefuegt PL 2021-02-15
|
||||
*/
|
||||
public final ConstraintSet constraints = new ConstraintSet();
|
||||
|
||||
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
|
||||
GenericDeclarationList gtvDeclarations, Token offset) {
|
||||
super(offset);
|
||||
|
@ -32,8 +32,10 @@ public class TYPE {
|
||||
|
||||
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
|
||||
ConstraintSet ret = new ConstraintSet();
|
||||
ConstraintSet methConstrains;
|
||||
for(Method m : cl.getMethods()){
|
||||
ret.addAll(getConstraintsMethod(m,info, cl));
|
||||
ret.addAll(methConstrains = getConstraintsMethod(m,info, cl));
|
||||
m.constraints.addAll(methConstrains);
|
||||
}
|
||||
for(Constructor m : cl.getConstructors()){
|
||||
ret.addAll(getConstraintsConstructor(m,info, cl));
|
||||
|
Loading…
Reference in New Issue
Block a user