From 99d3ecf0306889b7f05a165c64c0517aca7e70a6 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 23 Jan 2015 15:28:15 +0100 Subject: [PATCH] Fehler behoben, Fehler behoben, Fehler behoben. --- .../GenericTypeInsertPoint.java | 46 +++++++++++++++---- .../TypeInsertTests/OverloadingInMethod.jav | 9 ++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/typedeployment/GenericTypeInsertPoint.java b/src/de/dhbwstuttgart/typeinference/typedeployment/GenericTypeInsertPoint.java index dadcb904..a6644887 100644 --- a/src/de/dhbwstuttgart/typeinference/typedeployment/GenericTypeInsertPoint.java +++ b/src/de/dhbwstuttgart/typeinference/typedeployment/GenericTypeInsertPoint.java @@ -99,19 +99,37 @@ class GenericVarPatch { */ public void add(Pair p){ GenericVarExtendsDeclarationPatch toAdd = new GenericVarExtendsDeclarationPatch(p); + boolean mussDeklariertWerden = true; + for(GenericVarDeclarationPatch patch : genericVarDeclarations){ + if(patch.genericVar.equals(p.TA2)){ + mussDeklariertWerden = false; + break; + } + } if(!this.genericVarExtendDeclarations.contains(toAdd))this.genericVarExtendDeclarations.add(toAdd); + if(mussDeklariertWerden && p.TA2 instanceof TypePlaceholder)this.add((TypePlaceholder)p.TA2); } public String getInsertString(ResultSet rs){ //Hier sollten TPHs nicht aufgelöst sondern in Generische Variablen umgewandelt werden: String ret = ""; Iterator it1 = this.genericVarDeclarations.iterator(); + boolean bereitsVorhanden = false; while(it1.hasNext()){ + bereitsVorhanden = false; GenericVarDeclarationPatch p = it1.next(); - ret += p.getInsertString(rs); - if(it1.hasNext())ret += ", "; + //Kontrollieren, ob GenericVar bereits von den Extends Declarations definiert wird: + for(GenericVarExtendsDeclarationPatch pe : this.genericVarExtendDeclarations){ + if(pe.definesGenericVar(p.genericVar)){ + bereitsVorhanden = true; + } + } + if(bereitsVorhanden == false){ + ret += p.getInsertString(rs); + if(it1.hasNext())ret += ", "; + } } - if(this.genericVarExtendDeclarations.size()>0)ret+=", "; + if(this.genericVarExtendDeclarations.size()>0 && bereitsVorhanden == false)ret+=", "; Iterator it2 = this.genericVarExtendDeclarations.iterator(); while(it2.hasNext()){ GenericVarExtendsDeclarationPatch p = it2.next(); @@ -120,7 +138,7 @@ class GenericVarPatch { } return ret; } - + public void add(TypePlaceholder tph) { GenericVarDeclarationPatch toAdd = new GenericVarDeclarationPatch(tph); if(!this.genericVarDeclarations.contains(toAdd))this.genericVarDeclarations.add(toAdd); @@ -145,6 +163,11 @@ class GenericVarExtendsDeclarationPatch { private Pair genericPair; + public boolean definesGenericVar(TypePlaceholder tph){ + if(genericPair.TA1.equals(tph))return true; + return false; + } + public GenericVarExtendsDeclarationPatch(Pair p) { this.genericPair = p; } @@ -178,17 +201,17 @@ class GenericVarExtendsDeclarationPatch { */ class GenericVarDeclarationPatch { - private TypePlaceholder genericPair; + TypePlaceholder genericVar; public GenericVarDeclarationPatch(TypePlaceholder p) { - this.genericPair = p; + this.genericVar = p; } public String getInsertString(ResultSet resultSet){ String ret = ""; - if(this.genericPair != null){ + if(this.genericVar != null){ //ret += this.genericPair.printJavaCode(resultSet); - ret += this.genericPair.getName().toString(); + ret += this.genericVar.getName().toString(); } return ret; } @@ -196,7 +219,12 @@ class GenericVarDeclarationPatch { @Override public boolean equals(Object o){ if(!(o instanceof GenericVarDeclarationPatch))return false; - if(!(this.genericPair.equals(((GenericVarDeclarationPatch)o).genericPair)))return false; + if(!(this.genericVar.equals(((GenericVarDeclarationPatch)o).genericVar)))return false; return true; } + + @Override + public String toString(){ + return genericVar.toString(); + } } diff --git a/test/plugindevelopment/TypeInsertTests/OverloadingInMethod.jav b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod.jav index e66e1a7c..4c014c9a 100644 --- a/test/plugindevelopment/TypeInsertTests/OverloadingInMethod.jav +++ b/test/plugindevelopment/TypeInsertTests/OverloadingInMethod.jav @@ -8,3 +8,12 @@ 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