From e8757a179f41da93452422678cf26ec6f0e3ff99 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Mon, 18 Dec 2017 14:43:03 +0100 Subject: [PATCH] ASP-Generierung: parameterListe --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 73 +++++++++++++------ .../SyntaxTreeGenerator/TypeGenerator.java | 2 +- .../dhbwstuttgart/sat/asp/ASPGenerator.java | 41 +++++++++-- src/de/dhbwstuttgart/sat/asp/ASPWriter.java | 24 ++++++ .../sat/asp/model/ASPGenericType.java | 7 ++ .../dhbwstuttgart/sat/asp/model/ASPPair.java | 21 ++++++ .../sat/asp/model/ASPPairEquals.java | 13 ++++ .../sat/asp/model/ASPPairSmaller.java | 13 ++++ .../sat/asp/model/ASPParameterList.java | 40 ++++++++++ .../sat/asp/model/ASPRefType.java | 20 +++++ .../sat/asp/model/ASPStatement.java | 27 +++++++ .../dhbwstuttgart/sat/asp/model/ASPType.java | 7 +- .../sat/asp/model/ASPTypeVar.java | 7 ++ .../typeinference/unify/model/TypeParams.java | 4 +- test/asp/typeinference/ASPTest.java | 68 +++++++++++++++++ test/asp/typeinference/VectorTest.java | 9 +++ test/typeinference/JavaTXCompilerTest.java | 26 ++++++- 17 files changed, 358 insertions(+), 44 deletions(-) create mode 100644 src/de/dhbwstuttgart/sat/asp/ASPWriter.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPPair.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java create mode 100644 src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java create mode 100644 test/asp/typeinference/ASPTest.java create mode 100644 test/asp/typeinference/VectorTest.java diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 51974ce8..cce81107 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -29,7 +29,7 @@ import java.util.stream.Collectors; public class JavaTXCompiler { - final CompilationEnvironment environment; + final CompilationEnvironment environment; public final Map sourceFiles = new HashMap<>(); public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { @@ -38,56 +38,83 @@ public class JavaTXCompiler { public JavaTXCompiler(List sources) throws IOException, ClassNotFoundException { environment = new CompilationEnvironment(sources); - for(File s : sources){ - sourceFiles.put(s,parse(s)); + for (File s : sources) { + sourceFiles.put(s, parse(s)); } } - public List typeInference() throws ClassNotFoundException { + public ConstraintSet getConstraints() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); - for(SourceFile sf : sourceFiles.values()){ + for (SourceFile sf : sourceFiles.values()) { allClasses.addAll(sf.getClasses()); } List importedClasses = new ArrayList<>(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC - for(File forSourceFile : sourceFiles.keySet()) - for(JavaClassName name : sourceFiles.get(forSourceFile).getImports()){ - //TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet + for (File forSourceFile : sourceFiles.keySet()) + for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) { + //TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet ClassOrInterface importedClass = ASTFactory.createClass( ClassLoader.getSystemClassLoader().loadClass(name.toString())); importedClasses.add(importedClass); } allClasses.addAll(importedClasses); - FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); - final ConstraintSet cons = new TYPE(sourceFiles.values(), allClasses).getConstraints(); + return new TYPE(sourceFiles.values(), allClasses).getConstraints(); + } + + public List getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException { + List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); + for (SourceFile sf : sourceFiles.values()) { + allClasses.addAll(sf.getClasses()); + } + List importedClasses = new ArrayList<>(); + for (JavaClassName name : forSourceFile.getImports()) { + //TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet + ClassOrInterface importedClass = ASTFactory.createClass( + ClassLoader.getSystemClassLoader().loadClass(name.toString())); + importedClasses.add(importedClass); + allClasses.addAll(importedClasses); + } + return allClasses; + } + + public List typeInference() throws ClassNotFoundException { + List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); + //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC + for(SourceFile sf : this.sourceFiles.values()) { + allClasses.addAll(getAvailableClasses(sf)); + } + + final ConstraintSet cons = getConstraints(); + + FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); TypeUnify unify = new TypeUnify(); Set> results = new HashSet<>(); - for(List> xCons : unifyCons.cartesianProduct()){ + for (List> xCons : unifyCons.cartesianProduct()) { Set xConsSet = new HashSet<>(); - for(Constraint constraint : xCons){ + for (Constraint constraint : xCons) { xConsSet.addAll(constraint); } - System.out.println(xConsSet); + //System.out.println(xConsSet); Set> result = unify.unify(xConsSet, finiteClosure); //System.out.println("RESULT: " + result); results.addAll(result); } return results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); - } + } - private Map generateTPHMap(ConstraintSet constraints){ + private Map generateTPHMap(ConstraintSet constraints) { HashMap ret = new HashMap<>(); - constraints.map((Pair p)->{ - if(p.TA1 instanceof TypePlaceholder){ - ret.put(((TypePlaceholder)p.TA1).getName(), (TypePlaceholder) p.TA1); + constraints.map((Pair p) -> { + if (p.TA1 instanceof TypePlaceholder) { + ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1); } - if(p.TA2 instanceof TypePlaceholder){ - ret.put(((TypePlaceholder)p.TA2).getName(), (TypePlaceholder) p.TA2); + if (p.TA2 instanceof TypePlaceholder) { + ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2); } return null; }); @@ -97,8 +124,8 @@ public class JavaTXCompiler { private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException { CompilationUnitContext tree = JavaTXParser.parse(sourceFile); SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile), new GenericsRegistry(null)); - SourceFile ret = generator.convert(tree, environment.packageCrawler); + SourceFile ret = generator.convert(tree, environment.packageCrawler); return ret; } - -} + +} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index 2cf41b43..d54b682a 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -43,7 +43,7 @@ public class TypeGenerator { throw new NotImplementedException(); }else if(unannTypeContext.unannReferenceType().unannArrayType()!=null){ - System.out.println(unannTypeContext.getText()); + //System.out.println(unannTypeContext.getText()); throw new NotImplementedException(); }else if(unannTypeContext.unannReferenceType().unannTypeVariable()!=null){ diff --git a/src/de/dhbwstuttgart/sat/asp/ASPGenerator.java b/src/de/dhbwstuttgart/sat/asp/ASPGenerator.java index 26ab0957..07e0e8dd 100644 --- a/src/de/dhbwstuttgart/sat/asp/ASPGenerator.java +++ b/src/de/dhbwstuttgart/sat/asp/ASPGenerator.java @@ -1,24 +1,49 @@ package de.dhbwstuttgart.sat.asp; import de.dhbwstuttgart.parser.scope.JavaClassName; +import de.dhbwstuttgart.sat.asp.model.*; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; +import java.util.Optional; public class ASPGenerator { - public static String toASP(ConstraintSet constraintSet, Collection fcClasses){ - String ret = ""; - for(ClassOrInterface cl : fcClasses){ - String className = toConstant(cl.getClassName()); - String superClassName = toConstant(cl.getSuperClass().getName()); + ASPWriter writer = new ASPWriter(); + private final String asp; - } - return ret; + public ASPGenerator(ConstraintSet constraints, Collection fcClasses){ + asp = toASP(constraints, fcClasses); } + public String getASP(){ + return asp; + } - public static String toConstant(JavaClassName name){ + private String toASP(ConstraintSet constraintSet, Collection fcClasses){ + for(ClassOrInterface cl : fcClasses){ + Optional superClass = + fcClasses.stream().filter(c -> c.getSuperClass().getName().equals(cl.getClassName())).findAny(); + //Für den Fall das es keinen Supertyp in den fcClasses gibt, wird die Klasse immer noch als ihr eigener Subtyp angefügt: + ASPPairSmaller fcEntry = new ASPPairSmaller(convert(cl), convert(superClass.orElse(cl))); + writer.add(new ASPStatement(fcEntry.toASP())); + } + return writer.getASPFile(); + } + + private ASPType convert(ClassOrInterface cl){ + List paramList = new ArrayList<>(); + for(GenericTypeVar gtv : cl.getGenerics()){ + paramList.add(new ASPGenericType(toConstant(gtv.getName()))); + } + ASPParameterList params = new ASPParameterList(paramList, writer); + return new ASPRefType(toConstant(cl.getClassName()), params); + } + + private String toConstant(JavaClassName name){ return "c" + name.toString().replace(".", "_"); } } diff --git a/src/de/dhbwstuttgart/sat/asp/ASPWriter.java b/src/de/dhbwstuttgart/sat/asp/ASPWriter.java new file mode 100644 index 00000000..4d33cbbf --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/ASPWriter.java @@ -0,0 +1,24 @@ +package de.dhbwstuttgart.sat.asp; + +import de.dhbwstuttgart.sat.asp.model.ASPRefType; +import de.dhbwstuttgart.sat.asp.model.ASPStatement; +import de.dhbwstuttgart.sat.asp.model.ASPType; + +import java.util.HashSet; + +public class ASPWriter { + + private HashSet content = new HashSet<>(); + + public void add(ASPStatement stmt){ + content.add(stmt); + } + + public String getASPFile(){ + String ret = ""; + for(ASPStatement statement : content){ + ret += statement.getASP() + ".\n"; + } + return ret; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java b/src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java new file mode 100644 index 00000000..729d678a --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPGenericType.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.sat.asp.model; + +public class ASPGenericType implements ASPType{ + public ASPGenericType(String name){ + + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPPair.java b/src/de/dhbwstuttgart/sat/asp/model/ASPPair.java new file mode 100644 index 00000000..bbd3ff3f --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPPair.java @@ -0,0 +1,21 @@ +package de.dhbwstuttgart.sat.asp.model; + +public abstract class ASPPair { + public final ASPType leftSide; + public final ASPType rightSide; + + public ASPPair(ASPType ls, ASPType rs){ + this.leftSide = ls; + this.rightSide = rs; + } + + public String toASP(){ + return this.getRuleName() + "(" + leftSide + ","+ rightSide + ")"; + } + + public String toString(){ + return toASP(); + } + + protected abstract String getRuleName(); +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java b/src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java new file mode 100644 index 00000000..b67920bd --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPPairEquals.java @@ -0,0 +1,13 @@ +package de.dhbwstuttgart.sat.asp.model; + +public class ASPPairEquals extends ASPPair{ + private final static String ASP_PAIR_EQUALS_NAME = "equals"; + public ASPPairEquals(ASPType ls, ASPType rs){ + super(ls, rs); + } + + @Override + protected String getRuleName() { + return ASP_PAIR_EQUALS_NAME; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java b/src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java new file mode 100644 index 00000000..882054cc --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPPairSmaller.java @@ -0,0 +1,13 @@ +package de.dhbwstuttgart.sat.asp.model; + +public class ASPPairSmaller extends ASPPair{ + private final static String ASP_PAIR_SMALLER_NAME = "smaller"; + public ASPPairSmaller(ASPType ls, ASPType rs){ + super(ls, rs); + } + + @Override + protected String getRuleName() { + return ASP_PAIR_SMALLER_NAME; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java b/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java new file mode 100644 index 00000000..b38f8a38 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPParameterList.java @@ -0,0 +1,40 @@ +package de.dhbwstuttgart.sat.asp.model; + +import de.dhbwstuttgart.sat.asp.ASPWriter; +import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +public class ASPParameterList { + private final static String ASP_PARAMLIST_NAME = "param"; + private final static String ASP_PARAMLIST_END_POINTER = "null"; + public final String name; + private final List types; + + public ASPParameterList(List types, ASPWriter writer){ + this.types = types; + if(types.size() == 0){ + name = ASP_PARAMLIST_END_POINTER; + }else{ + name = NameGenerator.makeNewName(); + String nextPointer = name; + Iterator it = types.iterator(); + while(it.hasNext()){ + ASPType t = it.next(); + String param = nextPointer + "," + t.toString() + ","; + nextPointer = NameGenerator.makeNewName(); + if(! it.hasNext())nextPointer = ASP_PARAMLIST_END_POINTER; + param += nextPointer; + writer.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")")); + //paramDefinitions.add(new ASPStatement(ASP_PARAMLIST_NAME + "(" + param + ")")); + } + } + } + + public String toString(){ + return name; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java b/src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java new file mode 100644 index 00000000..ba318876 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPRefType.java @@ -0,0 +1,20 @@ +package de.dhbwstuttgart.sat.asp.model; + +public class ASPRefType implements ASPType { + public static final String ASP_TYPE = "type"; + private final ASPParameterList params; + private final String name; + + public ASPRefType(String name, ASPParameterList params){ + this.name = name; + this.params = params; + } + + public ASPParameterList getParams() { + return params; + } + + public String toString(){ + return ASP_TYPE + "(" + name +"," + params.name + ")"; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java b/src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java new file mode 100644 index 00000000..8e4a1d35 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPStatement.java @@ -0,0 +1,27 @@ +package de.dhbwstuttgart.sat.asp.model; + +public class ASPStatement { + private final String stmt; + public ASPStatement(String stmt) { + this.stmt = stmt; + } + + public String toString(){ + return stmt; + } + + @Override + public int hashCode() { + return stmt.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if(obj instanceof ASPStatement)return stmt.equals(((ASPStatement) obj).stmt); + return false; + } + + public String getASP() { + return stmt; + } +} diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPType.java b/src/de/dhbwstuttgart/sat/asp/model/ASPType.java index 4de8759d..e703596c 100644 --- a/src/de/dhbwstuttgart/sat/asp/model/ASPType.java +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPType.java @@ -1,9 +1,4 @@ package de.dhbwstuttgart.sat.asp.model; -import java.util.List; - -public class ASPType { - public ASPType(String name, List params){ - - } +public interface ASPType { } diff --git a/src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java b/src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java new file mode 100644 index 00000000..16b79f91 --- /dev/null +++ b/src/de/dhbwstuttgart/sat/asp/model/ASPTypeVar.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.sat.asp.model; + +public class ASPTypeVar implements ASPType{ + public ASPTypeVar(String name){ + + } +} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java b/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java index f40ecb2f..dc90847b 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java @@ -153,8 +153,8 @@ public final class TypeParams implements Iterable{ return false; for(int i = 0; i < this.size(); i++){ - if(this.get(i) == null) - System.out.print("s"); + //if(this.get(i) == null) + //System.out.print("s"); } for(int i = 0; i < this.size(); i++) if(!(this.get(i).equals(other.get(i)))) diff --git a/test/asp/typeinference/ASPTest.java b/test/asp/typeinference/ASPTest.java new file mode 100644 index 00000000..5074e4f3 --- /dev/null +++ b/test/asp/typeinference/ASPTest.java @@ -0,0 +1,68 @@ +package asp.typeinference; + +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.sat.asp.ASPGenerator; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +public class ASPTest { + + public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; + private static final List filesToTest = new ArrayList<>(); + protected File fileToTest = null; + + public ASPTest(){ + } + + + @Test + public void test() throws IOException, ClassNotFoundException { + if(fileToTest != null)filesToTest.add(fileToTest); + else return; + //filesToTest.add(new File(rootDirectory+"Faculty.jav")); + //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); + //filesToTest.add(new File(rootDirectory+"test.jav")); + filesToTest.add(new File(rootDirectory+"EmptyMethod.jav")); + //filesToTest.add(new File(rootDirectory+"fc.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); + //filesToTest.add(new File(rootDirectory+"Vector.jav")); + //filesToTest.add(new File(rootDirectory+"Generics.jav")); + //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); + //filesToTest.add(new File(rootDirectory+"Matrix.jav")); + //filesToTest.add(new File(rootDirectory+"Import.jav")); + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List allClasses = new ArrayList<>(); + for(SourceFile sf : compiler.sourceFiles.values()) { + //allClasses.addAll(compiler.getAvailableClasses(sf)); + } + for(SourceFile sf : compiler.sourceFiles.values()) { + allClasses.addAll(sf.getClasses()); + } + + final ConstraintSet cons = compiler.getConstraints(); + ASPGenerator generator = new ASPGenerator(cons, allClasses); + System.out.println(generator.getASP()); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } + +} + diff --git a/test/asp/typeinference/VectorTest.java b/test/asp/typeinference/VectorTest.java new file mode 100644 index 00000000..77ff4959 --- /dev/null +++ b/test/asp/typeinference/VectorTest.java @@ -0,0 +1,9 @@ +package asp.typeinference; + +import java.io.File; + +public class VectorTest extends ASPTest { + public VectorTest() { + this.fileToTest = new File(rootDirectory+"Vector.jav"); + } +} \ No newline at end of file diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 8e60c803..fbbed9af 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -1,11 +1,23 @@ package typeinference; import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.parser.scope.JavaClassName; +import de.dhbwstuttgart.sat.asp.ASPGenerator; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typedeployment.TypeInsert; import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; +import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import org.junit.Test; import java.io.File; @@ -17,8 +29,10 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; public class JavaTXCompilerTest { @@ -28,11 +42,10 @@ public class JavaTXCompilerTest { public JavaTXCompilerTest(){ } - @Test - public void test() throws IOException, java.lang.ClassNotFoundException { + public void test() throws IOException, ClassNotFoundException { if(fileToTest != null)filesToTest.add(fileToTest); - else return; + else return; //filesToTest.add(new File(rootDirectory+"Faculty.jav")); //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); //filesToTest.add(new File(rootDirectory+"test.jav")); @@ -47,6 +60,7 @@ public class JavaTXCompilerTest { //filesToTest.add(new File(rootDirectory+"Matrix.jav")); //filesToTest.add(new File(rootDirectory+"Import.jav")); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + List results = compiler.typeInference(); for(File f : compiler.sourceFiles.keySet()){ @@ -54,14 +68,18 @@ public class JavaTXCompilerTest { System.out.println(ASTTypePrinter.print(sf)); //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen assert results.size()>0; + Set insertedTypes = new HashSet<>(); for(ResultSet resultSet : results){ Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); assert result.size()>0; String content = readFile(f.getPath(), StandardCharsets.UTF_8); for(TypeInsert tip : result){ - System.out.println(tip.insert(content)); + insertedTypes.add(tip.insert(content)); } } + for(String s : insertedTypes){ + System.out.println(s); + } } }