diff --git a/src/de/dhbwstuttgart/parser/JavaTXParser.java b/src/de/dhbwstuttgart/parser/JavaTXParser.java index 8d320ecb..800a0537 100644 --- a/src/de/dhbwstuttgart/parser/JavaTXParser.java +++ b/src/de/dhbwstuttgart/parser/JavaTXParser.java @@ -13,8 +13,8 @@ import java.util.ArrayList; import java.util.List; public class JavaTXParser { - public SourceFile parse(File sourceFile) throws IOException, ClassNotFoundException { - InputStream stream = new FileInputStream(sourceFile); + public SourceFile parse(InputStream source) throws IOException, ClassNotFoundException { + InputStream stream = source;//new FileInputStream(sourceFile); ANTLRInputStream input = new ANTLRInputStream(stream); Java8Lexer lexer = new Java8Lexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); @@ -22,7 +22,7 @@ public class JavaTXParser { Java8Parser.CompilationUnitContext tree = parser.compilationUnit(); SyntaxTreeGenerator generator = new SyntaxTreeGenerator(new JavaClassRegistry(generateJavaLangNames())); - return generator.convert(tree, sourceFile); + return generator.convert(tree); } private List generateJavaLangNames() throws IOException, ClassNotFoundException { @@ -36,4 +36,8 @@ public class JavaTXParser { return ret; } + + public SourceFile parse(File file) throws IOException, ClassNotFoundException { + return this.parse(new FileInputStream(file)); + } } diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index 758a1114..d61fcb80 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -170,7 +170,7 @@ public class SyntaxTreeGenerator{ return ret; } - public SourceFile convert(Java8Parser.CompilationUnitContext ctx, File parsedFile) throws ClassNotFoundException{ + public SourceFile convert(Java8Parser.CompilationUnitContext ctx) throws ClassNotFoundException{ List classes = new ArrayList<>(); this.getNames(ctx); this.setImports(ctx); @@ -184,7 +184,7 @@ public class SyntaxTreeGenerator{ } classes.add(newClass); } - return new SourceFile(parsedFile, this.pkgName, classes, this.imports); + return new SourceFile(this.pkgName, classes, this.imports); } public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, GenericsRegistry generics) { diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index c18385ad..2278a00e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -15,18 +15,16 @@ public class SourceFile extends SyntaxTreeNode{ private final List KlassenVektor; private final List imports; - private final File file; /** * Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei. * SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar. */ - public SourceFile(File file, String pkgName, List classDefinitions, List imports){ + public SourceFile(String pkgName, List classDefinitions, List imports){ super(new NullToken()); this.KlassenVektor = classDefinitions; this.pkgName = pkgName; this.imports = imports; - this.file = file; } public String getPkgName(){ @@ -59,10 +57,6 @@ public class SourceFile extends SyntaxTreeNode{ return KlassenVektor; } - public File getFile() { - return file; - } - @Override public void accept(ASTVisitor visitor) { visitor.visit(this); diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index a698980b..c08efd9a 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -43,9 +43,9 @@ public class JavaTXCompilerTest extends JavaTXCompiler { //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); //filesToTest.add(new File(rootDirectory+"Matrix.jav")); for(File f : filesToTest){ - this.parse(f); + SourceFile sf = this.parse(f); System.out.println(ASTTypePrinter.print(this.sourceFiles.get(sourceFiles.size()-1))); - List result = this.getTypeInserts(f); + List result = TypeInsertFactory.createTypeInsertPoints(sf, this.typeInference()); String content = readFile(f.getPath(), StandardCharsets.UTF_8); for(TypeInsert tip : result){ System.out.println(tip.insert(content)); @@ -54,16 +54,6 @@ public class JavaTXCompilerTest extends JavaTXCompiler { } - public List getTypeInserts(File forFile){ - ResultSet result = typeInference(); - for(SourceFile sf : sourceFiles){ - if(sf.getFile().equals(forFile)){ - return TypeInsertFactory.createTypeInsertPoints(sf, result); - } - } - throw new DebugException("Die Datei "+forFile+" wurde nicht geparst"); - } - static String readFile(String path, Charset encoding) throws IOException {