From 60f2e3def4e6c7e15eb7042b0961e1a2f79fbe27 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Feb 2021 00:13:29 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 32 +++++++++++++++++-- .../constraints/ConstraintSet.java | 12 +++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index b26c4da3..b908afa6 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -10,6 +10,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; @@ -30,6 +33,9 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultSet; @@ -185,7 +191,29 @@ public class TPHExtractor extends AbstractASTWalker { public void visit(Method method) { inMethod = true; String id = MethodUtility.createID(resolver,method); - methodAndTph = new MethodAndTPH(id, method.getConstraints()); + Predicate filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA1 instanceof TypePlaceholder) && + (resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) && + (resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder)); + + Function, ConstraintSet> filterConstrRemainingTVar = + csS -> { + ConstraintSet ret = new ConstraintSet<>(); + ret.addAllUndConstraint( + csS.getUndConstraints() + .stream().filter(filterUndConstraints) + .collect(Collectors.toCollection(Constraint::new))); + + csS.getOderConstraints() + .forEach(oConSSet -> { Set> setCons = new HashSet<>(); + oConSSet.forEach(OConS -> { setCons.add( + OConS.stream() + .filter(filterUndConstraints) + .collect(Collectors.toCollection(Constraint::new)) ); + } ); + ret.addOderConstraint(setCons);} ); + return ret; + }; + methodAndTph = new MethodAndTPH(id, filterConstrRemainingTVar.apply(method.getConstraints())); inLocalOrParamOrReturn = true; method.getReturnType().accept(this); @@ -194,7 +222,7 @@ public class TPHExtractor extends AbstractASTWalker { if(method.block != null) method.block.accept(this); - + inMethod = false; ListOfMethodsAndTph.add(methodAndTph); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 31a466dd..1c7b7439 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -23,9 +23,17 @@ public class ConstraintSet { oderConstraints.add(methodConstraints); } + public void addAllUndConstraint(Constraint allUndConstraints){ + undConstraints.addAll(allUndConstraints); + } + + public void addAllOderConstraint(List>> allOderConstraints){ + this.oderConstraints.addAll(allOderConstraints); + } + public void addAll(ConstraintSet constraints) { - this.undConstraints.addAll(constraints.undConstraints); - this.oderConstraints.addAll(constraints.oderConstraints); + this.addAllUndConstraint(constraints.undConstraints); + this.addAllOderConstraint(constraints.oderConstraints); } @Override