From d64823ea302de727f66f02fc9e07593c576ed0c2 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 30 Jun 2017 12:14:07 +0200 Subject: [PATCH] Fehler bei GenericInsertPoints beheben --- .../syntaxtree/statement/NewClass.java | 2 +- .../syntaxtree/visual/OutputGenerator.java | 3 ++- .../syntaxtree/visual/TypeOutputGenerator.java | 2 -- .../typedeployment/TypeInsertFactory.java | 8 +++++--- .../typedeployment/TypeInsertPoint.java | 2 +- test/typeinference/JavaTXCompilerTest.java | 13 ++----------- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index 911fd0561..b6f2a795f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -31,7 +31,7 @@ public class NewClass extends MethodCall * @param start */ public NewClass(RefType newClass, ArgumentList args, Token start) { - super(newClass, new Receiver(new EmptyStmt(start)), "new "+newClass.getName().toString(), args, start); + super(newClass, new Receiver(new EmptyStmt(start)), newClass.getName().toString(), args, start); } @Override diff --git a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java index 7c79da9c6..637a5ef5c 100644 --- a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java +++ b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java @@ -245,7 +245,8 @@ public class OutputGenerator implements ASTVisitor { @Override public void visit(NewClass methodCall) { out.append("new "); - visit((MethodCall) methodCall); + out.append(methodCall.name); + methodCall.getArgumentList().accept(this); } @Override diff --git a/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java b/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java index 5591ac2b6..c0628ef94 100644 --- a/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java +++ b/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java @@ -173,8 +173,6 @@ public class TypeOutputGenerator extends OutputGenerator { @Override public void visit(NewClass methodCall) { super.visit(methodCall); - this.out.append("::"); - methodCall.getType().accept(this); } @Override diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java index 55b052ee4..e30f0aa4d 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java @@ -128,10 +128,11 @@ public class TypeInsertFactory { //Offset zum Einstzen bestimmen: Token offset; String insert = ""; - String end =" "; + String end; if(cl.getGenerics().iterator().hasNext()){ - offset = cl.getGenerics().iterator().next().getOffset(); - insert+=","; + //offset = cl.getGenerics().iterator().next().getOffset(); + offset = cl.getGenerics().getOffset(); + end=","; }else{ offset = cl.getGenerics().getOffset(); insert += "<"; @@ -154,6 +155,7 @@ public class TypeInsertFactory { //String zum Einsetzen (Generics mit bounds) generieren: Iterator it = genericsAndBounds.keySet().iterator(); + if(! it.hasNext())return new TypeInsertPoint(offset, ""); while(it.hasNext()){ TypePlaceholder tph = it.next(); insert += tph.getName(); diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java index 3a444c7d8..0ecf638f6 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertPoint.java @@ -11,7 +11,7 @@ public class TypeInsertPoint { public TypeInsertPoint(Token point, String toInsert){ this.point = point; - this.insertString = toInsert + " "; + this.insertString = (toInsert.length()>1) ? toInsert + " " : toInsert; } public String insert(String intoSource, List additionalOffset){ diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 3cba764e3..1a02861c2 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -30,8 +30,8 @@ public class JavaTXCompilerTest extends JavaTXCompiler { @Test public void test() throws IOException, ClassNotFoundException { - filesToTest.add(new File(rootDirectory+"Faculty.jav")); - //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); + //filesToTest.add(new File(rootDirectory+"Faculty.jav")); + filesToTest.add(new File(rootDirectory+"mathStruc.jav")); //filesToTest.add(new File(rootDirectory+"Lambda.jav")); //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); @@ -58,13 +58,4 @@ public class JavaTXCompilerTest extends JavaTXCompiler { return new String(encoded, encoding); } - static String showTPHInformation(Iterable tphs){ - StringBuilder ret = new StringBuilder(); - OutputGenerator gen = new OutputGenerator(ret); - for(TypePlaceholder tph : tphs){ - gen.visit(tph); - } - return ret.toString(); - } - } \ No newline at end of file