From 378374fff119e3de1883fc4bdf162002fe480c10 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 8 Jan 2021 11:51:46 +0100 Subject: [PATCH] Remove not used isInherited --- .../syntaxtree/factory/UnifyTypeFactory.java | 2 +- .../assumptions/MethodAssumption.java | 8 +------ .../typeinference/constraints/Constraint.java | 24 ++++--------------- .../constraints/ConstraintSet.java | 5 ++-- .../typeinference/typeAlgo/TYPEStmt.java | 10 ++++---- .../typeinference/unify/RuleSet.java | 3 +-- .../typeinference/unify/TypeUnifyTask.java | 9 +++---- 7 files changed, 17 insertions(+), 44 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index b60270b3..9d5c3b3c 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -154,7 +154,7 @@ public class UnifyTypeFactory { public static Constraint convert(Constraint constraint){ Constraint unifyPairConstraint = constraint.stream() .map(UnifyTypeFactory::convert) - .collect(Collectors.toCollection( () -> new Constraint (constraint.isInherited(), convert(constraint.getExtendConstraint())))); + .collect(Collectors.toCollection( () -> new Constraint(convert(constraint.getExtendConstraint())))); return unifyPairConstraint; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index 6e6c5c5a..c1a6d449 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -17,15 +17,13 @@ public class MethodAssumption extends Assumption{ private ClassOrInterface receiver; private RefTypeOrTPHOrWildcardOrGeneric retType; List params; - private final Boolean isInherited; public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType, - List params, TypeScope scope, Boolean isInherited){ + List params, TypeScope scope){ super(scope); this.receiver = receiver; this.retType = retType; this.params = params; - this.isInherited = isInherited; } /* @@ -72,8 +70,4 @@ public class MethodAssumption extends Assumption{ return receiverType; } - - public Boolean isInherited() { - return isInherited; - } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java index cbd5c8fa..842e9a4f 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java @@ -9,30 +9,14 @@ import java.util.Set; //TODO: Remove this class public class Constraint extends HashSet { private static final long serialVersionUID = 1L; - private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt private Constraint extendConstraint = null; + + public Constraint(){} - public Constraint() { - super(); - } - - public Constraint(Boolean isInherited) { - this.isInherited = isInherited; - } - - public Constraint(Boolean isInherited, Constraint extendConstraint) { - this.isInherited = isInherited; + public Constraint(Constraint extendConstraint) { this.extendConstraint = extendConstraint; } - public void setIsInherited(Boolean isInherited) { - this.isInherited = isInherited; - } - - public Boolean isInherited() { - return isInherited; - } - public Constraint getExtendConstraint() { return extendConstraint; } @@ -42,7 +26,7 @@ public class Constraint extends HashSet { } public String toString() { - return super.toString() + " isInherited = " + isInherited + return super.toString() //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" ) + "\n" ; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 31a466dd..c703c49f 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -68,9 +68,8 @@ public class ConstraintSet { Constraint newConst = as.stream() .map(o) .collect(Collectors.toCollection((as.getExtendConstraint() != null) - ? () -> new Constraint (as.isInherited(), - as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new))) - : () -> new Constraint (as.isInherited()) + ? () -> new Constraint (as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new))) + : () -> new Constraint () )); //CSA2CSB.put(as, newConst); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index c3c23079..b659c55b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -179,7 +179,7 @@ public class TYPEStmt implements StatementVisitor{ !(x.TA2 instanceof TypePlaceholder)) ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) : x) - .collect(Collectors.toCollection(() -> new Constraint(oneMethodConstraint.isInherited()))); + .collect(Collectors.toCollection(() -> new Constraint())); oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint); extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint); methodConstraints.add(extendsOneMethodConstraint); @@ -574,7 +574,7 @@ public class TYPEStmt implements StatementVisitor{ protected Constraint generateConstraint(MethodCall forMethod, MethodAssumption assumption, TypeInferenceBlockInformation info, GenericsResolver resolver){ - Constraint methodConstraint = new Constraint<>(assumption.isInherited()); + Constraint methodConstraint = new Constraint<>(); ClassOrInterface receiverCl = assumption.getReceiver(); /* List params = new ArrayList<>(); @@ -636,7 +636,7 @@ public class TYPEStmt implements StatementVisitor{ public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { throw new NotImplementedException(); } - }, false)); + })); } for(ClassOrInterface cl : info.getAvailableClasses()){ for(Method m : cl.getMethods()){ @@ -645,7 +645,7 @@ public class TYPEStmt implements StatementVisitor{ RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType()); ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info), - createTypeScope(cl, m), m.isInherited)); + createTypeScope(cl, m))); } } } @@ -680,7 +680,7 @@ public class TYPEStmt implements StatementVisitor{ for(Method m : cl.getConstructors()){ if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){ ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(), - info), createTypeScope(cl, m), m.isInherited)); + info), createTypeScope(cl, m))); } } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 93f33d08..646b8307 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -682,9 +682,8 @@ public class RuleSet implements IRuleSet{ Function,? extends Constraint> applyUni = b -> b.stream().map( x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null) ? () -> new Constraint( - b.isInherited(), b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new))) - : () -> new Constraint(b.isInherited()) + : () -> new Constraint() )); oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); /* diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 6de6b9de..23a2cd1d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -1304,7 +1304,6 @@ public class TypeUnifyTask extends RecursiveTask>> { Set a_new = aParDefIt.next(); List> smallerSetasList = oup.smallerThan(a_new, nextSetasList); List> notInherited = smallerSetasList.stream() - .filter(x -> !((Constraint)x).isInherited()) .collect(Collectors.toCollection(ArrayList::new)); List> notErased = new ArrayList<>(); notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); }); @@ -1346,11 +1345,10 @@ public class TypeUnifyTask extends RecursiveTask>> { List> greaterSetasList = oup.greaterThan(a_new, nextSetasList); //a_new muss hingefuegt werden, wenn es nicht vererbt ist, dann wird es spaeter wieder geloescht - if (!((Constraint)a_new).isInherited()) { - greaterSetasList.add(a_new); - } + + greaterSetasList.add(a_new); + List> notInherited = greaterSetasList.stream() - .filter(x -> !((Constraint)x).isInherited()) .collect(Collectors.toCollection(ArrayList::new)); List> notErased = new ArrayList<>(); @@ -1401,7 +1399,6 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Removed: " + nextSetasListOderConstraints); List> smallerSetasList = oup.smallerThan(a, nextSetasList); List> notInherited = smallerSetasList.stream() - .filter(x -> !((Constraint)x).isInherited()) .collect(Collectors.toCollection(ArrayList::new)); List> notErased = new ArrayList<>(); notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); });