From ae7a63fbca6509f0665794fa6c884575364f04cc Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Mar 2018 14:22:30 +0100 Subject: [PATCH 1/7] Tests fix --- .../parser/SyntaxTreeGenerator/FCGenerator.java | 2 +- test/javFiles/MethodCallGenerics.jav | 14 ++++++++++++++ test/typeinference/JavaTXCompilerTest.java | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/javFiles/MethodCallGenerics.jav diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java index 24abec67..43743378 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java @@ -56,7 +56,7 @@ public class FCGenerator { } params.add(gtvs.get(gtv.getName())); } - + Optional hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny(); ClassOrInterface superClass; if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception diff --git a/test/javFiles/MethodCallGenerics.jav b/test/javFiles/MethodCallGenerics.jav new file mode 100644 index 00000000..0d02509b --- /dev/null +++ b/test/javFiles/MethodCallGenerics.jav @@ -0,0 +1,14 @@ +import java.lang.String; + +class Generics { + // A mt1(A a, B b){ + B mt1(B a, B b){ + return mt1(a, a); + } +} + +class Test { + methode(String s){ + return new Generics().mt1(s,s); + } +} diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 3ba22bc6..7c4c3582 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -50,7 +50,8 @@ public class JavaTXCompilerTest { } @Test public void genericsMethodCall() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"MethodCallGenerics.jav")); + TestResultSet result = execute(new File(rootDirectory+"MethodCallGenerics.jav")); + //TODO: Hier sollte der Rückgabetyp der Methode String sein } @Test public void faculty() throws IOException, ClassNotFoundException { From 45ccfb58e309627bfd963f10a1d9ca6beb08842b Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Mar 2018 17:10:40 +0100 Subject: [PATCH 2/7] Test commit --- .../dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java index 43743378..24abec67 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java @@ -56,7 +56,7 @@ public class FCGenerator { } params.add(gtvs.get(gtv.getName())); } - + Optional hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny(); ClassOrInterface superClass; if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception From dd18c7c40e63edc0250a7e86ca59bba4bc4e5e27 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Wed, 21 Mar 2018 15:15:31 +0100 Subject: [PATCH 3/7] =?UTF-8?q?Test=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/finiteClosure/SuperInterfacesTest.java | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/finiteClosure/SuperInterfacesTest.java diff --git a/test/finiteClosure/SuperInterfacesTest.java b/test/finiteClosure/SuperInterfacesTest.java new file mode 100644 index 00000000..f00bf068 --- /dev/null +++ b/test/finiteClosure/SuperInterfacesTest.java @@ -0,0 +1,31 @@ +package finiteClosure; + +import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class SuperInterfacesTest { + @Test + public void test() throws ClassNotFoundException { + Collection classes = new ArrayList<>(); + classes.add(ASTFactory.createClass(TestClass.class)); + System.out.println(FCGenerator.toFC(classes)); + } +} + +class TestClass implements Test2, Test3{ + +} + +interface Test2 { + +} + +interface Test3{ + +} \ No newline at end of file From 9a735e86dd2e8c59870ecf567f81460ee1741dd9 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Mar 2018 17:26:43 +0100 Subject: [PATCH 4/7] =?UTF-8?q?GenericFC=20Test=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/finiteClosure/SuperInterfacesTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/finiteClosure/SuperInterfacesTest.java b/test/finiteClosure/SuperInterfacesTest.java index f00bf068..0e1368c3 100644 --- a/test/finiteClosure/SuperInterfacesTest.java +++ b/test/finiteClosure/SuperInterfacesTest.java @@ -16,16 +16,31 @@ public class SuperInterfacesTest { classes.add(ASTFactory.createClass(TestClass.class)); System.out.println(FCGenerator.toFC(classes)); } + + @Test + public void testGeneric() throws ClassNotFoundException { + Collection classes = new ArrayList<>(); + classes.add(ASTFactory.createClass(TestClassGeneric.class)); + System.out.println(FCGenerator.toFC(classes)); + } } class TestClass implements Test2, Test3{ } +class TestClassGeneric implements Test4{ + +} + interface Test2 { } interface Test3{ +} + +interface Test4{ + } \ No newline at end of file From 06bb978cf6f1929adcbb95a5787fd2a066f5a4e1 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 21 Mar 2018 18:08:33 +0100 Subject: [PATCH 5/7] Testfall erweitern --- .../dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java | 2 +- test/finiteClosure/SuperInterfacesTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java index ceb3b817..1714570e 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java @@ -81,7 +81,7 @@ public class FCGenerator { //Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen Iterator itGenParams = superClass.getGenerics().iterator(); Iterator itSetParams = superType.getParaList().iterator(); - while(itGenParams.hasNext()){ + while(itSetParams.hasNext()){ RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next(); //In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen: RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs)); diff --git a/test/finiteClosure/SuperInterfacesTest.java b/test/finiteClosure/SuperInterfacesTest.java index 0e1368c3..d96e5ecc 100644 --- a/test/finiteClosure/SuperInterfacesTest.java +++ b/test/finiteClosure/SuperInterfacesTest.java @@ -21,6 +21,7 @@ public class SuperInterfacesTest { public void testGeneric() throws ClassNotFoundException { Collection classes = new ArrayList<>(); classes.add(ASTFactory.createClass(TestClassGeneric.class)); + //TODO: Die ASTFactory generiert hier den Supertyp falsch. Es fehlt die Parameterliste System.out.println(FCGenerator.toFC(classes)); } } From 72f27fab7a8ca4bb430a17c2ffcadbca669da948 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 22 Mar 2018 11:17:51 +0100 Subject: [PATCH 6/7] Fehler in ASTFactory Generierung von Superinterfaces beheben --- src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java | 9 +++++++-- test/finiteClosure/SuperInterfacesTest.java | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index c438bc67..67e1b14c 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -59,7 +59,7 @@ public class ASTFactory { superClass = (RefType) createType(java.lang.Object.class, name, ""); } List implementedInterfaces = new ArrayList<>(); - for(java.lang.Class jreInterface : jreClass.getInterfaces()){ + for(Type jreInterface : jreClass.getGenericInterfaces()){ implementedInterfaces.add((RefType) createType(jreInterface, name, "")); } GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null); @@ -193,7 +193,12 @@ public class ASTFactory { params.add(createType(t, parentClass, parentMethod)); } } - RefType ret = new RefType(new JavaClassName(type.getTypeName()), params, new NullToken()); + String name = type.getTypeName(); + if(name.contains("<")){ //Komischer fix. Type von Generischen Typen kann die Generics im Namen enthalten Type + //Diese entfernen: + name = name.split("<")[0]; + } + RefType ret = new RefType(new JavaClassName(name), params, new NullToken()); return ret; } } diff --git a/test/finiteClosure/SuperInterfacesTest.java b/test/finiteClosure/SuperInterfacesTest.java index d96e5ecc..0e1368c3 100644 --- a/test/finiteClosure/SuperInterfacesTest.java +++ b/test/finiteClosure/SuperInterfacesTest.java @@ -21,7 +21,6 @@ public class SuperInterfacesTest { public void testGeneric() throws ClassNotFoundException { Collection classes = new ArrayList<>(); classes.add(ASTFactory.createClass(TestClassGeneric.class)); - //TODO: Die ASTFactory generiert hier den Supertyp falsch. Es fehlt die Parameterliste System.out.println(FCGenerator.toFC(classes)); } } From bcee5e5209a667625338c0ea79f4f5be35ebe241 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 22 Mar 2018 11:41:59 +0100 Subject: [PATCH 7/7] Fehler im Parsen von Package beheben --- .../SyntaxTreeGenerator/SyntaxTreeGenerator.java | 14 ++++++++++++-- test/javFiles/Package.jav | 5 +++++ test/typeinference/JavaTXCompilerTest.java | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/javFiles/Package.jav diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index 72606713..b7f14f19 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -73,6 +73,7 @@ public class SyntaxTreeGenerator{ } public SourceFile convert(Java8Parser.CompilationUnitContext ctx, PackageCrawler packageCrawler) throws ClassNotFoundException{ + if(ctx.packageDeclaration()!=null)this.pkgName = convert(ctx.packageDeclaration()); List classes = new ArrayList<>(); Map imports = GatherNames.getImports(ctx, packageCrawler); this.imports = imports.keySet().stream().map(name -> reg.getName(name)).collect(Collectors.toSet()); @@ -89,6 +90,15 @@ public class SyntaxTreeGenerator{ return new SourceFile(this.pkgName, classes, this.imports); } + private String convert(Java8Parser.PackageDeclarationContext packageDeclarationContext) { + String ret = ""; + for(TerminalNode identifier : packageDeclarationContext.Identifier()){ + ret += identifier.getText()+"."; + } + ret = ret.substring(0, ret.length()-1); + return ret; + } + public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, RefType superClass, GenericsRegistry generics) { Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader(); int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier()); @@ -165,8 +175,8 @@ public class SyntaxTreeGenerator{ } } String className = this.pkgName + (this.pkgName.length()>0?".":"") + ctx.Identifier().getText(); - JavaClassName name = reg.getName(className); - if(! name.toString().equals(className)){ + JavaClassName name = reg.getName(className); //Holt den Package Namen mit dazu + if(! name.toString().equals(className)){ //Kommt die Klasse schon in einem anderen Package vor? throw new TypeinferenceException("Name " + className + " bereits vorhanden in " + reg.getName(className).toString() ,ctx.getStart()); } diff --git a/test/javFiles/Package.jav b/test/javFiles/Package.jav new file mode 100644 index 00000000..bbc1e51d --- /dev/null +++ b/test/javFiles/Package.jav @@ -0,0 +1,5 @@ +package strucType.input; + +class Neu +{ +} \ No newline at end of file diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 7c4c3582..ba004cb5 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -66,6 +66,10 @@ public class JavaTXCompilerTest { execute(new File(rootDirectory+"Matrix.jav")); } @Test + public void packageTests() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Package.jav")); + } + @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); }