From 03d1727cbfe88445f93c13bd62fc6aed914ec72a Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 28 Jan 2015 01:26:42 +0100 Subject: [PATCH] =?UTF-8?q?Unn=C3=B6tige=20GenericVariables=20nicht=20mehr?= =?UTF-8?q?=20einf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/logger/Section.java | 2 +- .../assumptions/TypeAssumptions.java | 4 +-- .../GenericTypeInsertPoint.java | 33 +++++++++++++++++++ .../typedeployment/TypeInsertSet.java | 3 ++ .../TypeInsertTests/OverloadingInMethod.jav | 10 ------ .../TypeInsertTests/OverloadingInMethod2.jav | 10 ++++++ .../TypeInsertTests/OverloadingInMethod2.java | 19 +++++++++++ 7 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.jav create mode 100644 test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.java diff --git a/src/de/dhbwstuttgart/logger/Section.java b/src/de/dhbwstuttgart/logger/Section.java index d99907d1f..0ea53b92a 100644 --- a/src/de/dhbwstuttgart/logger/Section.java +++ b/src/de/dhbwstuttgart/logger/Section.java @@ -4,5 +4,5 @@ public enum Section { TYPEINFERENCE, PARSER, CODEGEN, - UNIFY, FINITECLOSURE; + UNIFY, FINITECLOSURE, ASSUMPTIONS; } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 564fd4728..14b2ab489 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -328,11 +328,11 @@ public class TypeAssumptions { //if(ass.inheritsType(t))return t; if(ass.getIdentifier().equals(t.getName())){ if(! ass.getAssumedType().getParentClass().equals(inNode.getParentClass())){ //hier muss nach der ParentClass von inNode gefragt werden, da die ParentClass von t nicht immer korrekt ist! (TODO: Überprüfen) - TypeAssumptions.log.debug(t+" ist NICHT in Klasse: "+ass.getAssumedType().getParentClass(), Section.TYPEINFERENCE); + TypeAssumptions.log.debug(t+" ist NICHT in Klasse: "+ass.getAssumedType().getParentClass(), Section.ASSUMPTIONS); //Ist die Generische Variable nicht aus dieser Klasse, so muss sie zu einem TPH umgewandelt werden: return new ConstraintType(ass.getAssumedType().getTypePlaceHolder(inNode)); } - TypeAssumptions.log.debug(t+" ist in Klasse: "+ass.getAssumedType().getParentClass(), Section.TYPEINFERENCE); + TypeAssumptions.log.debug(t+" ist in Klasse: "+ass.getAssumedType().getParentClass(), Section.ASSUMPTIONS); return new ConstraintType(ass.getAssumedType()); } } diff --git a/src/de/dhbwstuttgart/typeinference/typedeployment/GenericTypeInsertPoint.java b/src/de/dhbwstuttgart/typeinference/typedeployment/GenericTypeInsertPoint.java index a66448877..bd16e90bf 100644 --- a/src/de/dhbwstuttgart/typeinference/typedeployment/GenericTypeInsertPoint.java +++ b/src/de/dhbwstuttgart/typeinference/typedeployment/GenericTypeInsertPoint.java @@ -92,6 +92,7 @@ class GenericVarPatch { private Vector genericVarExtendDeclarations = new Vector(); private Vector genericVarDeclarations = new Vector(); + private Vector usedTPHs; /** * Fügt eine generische Variable in Form eines Pairs an. @@ -111,6 +112,20 @@ class GenericVarPatch { } public String getInsertString(ResultSet rs){ + //Alle Generische Einsetzungen verwerfen, welche nicht benötigt werden: + /* + * Dies geht mit der momentanen Variante nur für die genericVarDeclarations. + * Es kann passieren, dass bei den genericVarExtendDeclarations extend-Verknüpfungen enthalten sind, + * welche nicht im eingesetzten Typ auftauchen, aber dennoch notwendig sind. + */ + Vector tmpGenVars = new Vector<>(); + for(GenericVarDeclarationPatch gv : this.genericVarDeclarations){ + if(this.usedTPHs.contains(gv.genericVar)){ + tmpGenVars.add(gv); + } + } + this.genericVarDeclarations = tmpGenVars; + //Hier sollten TPHs nicht aufgelöst sondern in Generische Variablen umgewandelt werden: String ret = ""; Iterator it1 = this.genericVarDeclarations.iterator(); @@ -151,6 +166,19 @@ class GenericVarPatch { public void addPairs(Vector pairs) { for(Pair pair : pairs)this.add(pair); } + + public void removeUnusedTPHs(Vector usedTPHs) { + this.usedTPHs = usedTPHs; + return; + /* + for(TypePlaceholder tph : usedTPHs){ + //Zuerst alle extends Typen kontrollieren und entfernen: + for(GenericVarExtendsDeclarationPatch p : this.genericVarExtendDeclarations){ + if(p.definesGenericVar(tph))return; + } + } + */ + } } @@ -163,6 +191,11 @@ class GenericVarExtendsDeclarationPatch { private Pair genericPair; + /** + * Kontrolliert ob der T1 mit tph übereinstimmt im Constraint: T1 extends T2 + * @param tph + * @return + */ public boolean definesGenericVar(TypePlaceholder tph){ if(genericPair.TA1.equals(tph))return true; return false; diff --git a/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java b/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java index 4c33c7ad5..c588aaea6 100644 --- a/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java +++ b/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java @@ -119,6 +119,9 @@ public class TypeInsertSet { } */ + //Nur Generische Variablen einsetzen, welche auch verwendet werden: + gPatch.removeUnusedTPHs(tip.getInsertType().getInvolvedTypePlaceholder()); + GenericTypeInsertPoint gip = new GenericTypeInsertPoint(tip.getGenericTypeVarInsertNode(), gPatch, resultSet); typinferenzLog.debug("Erstellter GenericTypeInsertPoint: "+gip, Section.TYPEINFERENCE); tpj.add(tip); diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingInMethod.jav b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod.jav index 4c014c9a8..fb1da409b 100644 --- a/test/plugindevelopment/TypeInsertTests/OverloadingInMethod.jav +++ b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod.jav @@ -7,13 +7,3 @@ class OverloadingInMethod{ } } - -class OverloadingInMethod2{ - - Fun1>, ? super C> m () { - Fun1>, ? super C> op; - op = (m) -> (f) -> f.apply(m); - return op; - } - -} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.jav b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.jav new file mode 100644 index 000000000..e3ef83288 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.jav @@ -0,0 +1,10 @@ + +class OverloadingInMethod2{ + + Fun1>, ? super C> m () { + Fun1>, ? super C> op; + op = (m) -> (f) -> f.apply(m); + return op; + } + +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.java b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.java new file mode 100644 index 000000000..af53fcdb6 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod2.java @@ -0,0 +1,19 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class OverloadingInMethod2 { + + private static final String TEST_FILE = "OverloadingInMethod2.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + + //mustContain.add("Fun0>> op"); + MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); + } + +}