From 58cd4906397bfc05c62d7ab3345f6ebb9df606c7 Mon Sep 17 00:00:00 2001 From: luca9913 Date: Thu, 1 Dec 2022 22:20:39 +0100 Subject: [PATCH] rootDirectory GeneralParserTest, dep. Klasse JavaTXParser --- src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java | 6 ++++-- .../parser/SyntaxTreeGenerator/StatementGenerator.java | 2 +- .../parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java | 3 +-- src/test/java/parser/GeneralParserTest.java | 2 +- src/test/java/typeinference/JavaTXCompilerTest.java | 6 +++--- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java b/src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java index aad0a575..07f79998 100644 --- a/src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java +++ b/src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java @@ -7,7 +7,8 @@ import de.dhbwstuttgart.parser.antlr.Java8Parser; import de.dhbwstuttgart.parser.scope.JavaClassRegistry; import de.dhbwstuttgart.syntaxtree.SourceFile; -import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import java.io.*; @@ -18,7 +19,8 @@ import java.util.List; public class JavaTXParser { public static Java8Parser.CompilationUnitContext parse(File source) throws IOException, java.lang.ClassNotFoundException { InputStream stream = new FileInputStream(source); - ANTLRInputStream input = new ANTLRInputStream(stream); + //DEPRECATED: ANTLRInputStream input = new ANTLRInputStream(stream); + CharStream input = CharStreams.fromStream(stream); Java8Lexer lexer = new Java8Lexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); Java8Parser parser = new Java8Parser(tokens); diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index bcc4f841..cdfce63c 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -818,7 +818,7 @@ public class StatementGenerator { private Expression convert(Java8Parser.PrimaryNoNewArray_lfno_primaryContext expression) { if(expression.literal() != null){ return convert(expression.literal()); - }else if(expression.parExpression().expression()!=null){ + }else if(expression.parExpression()!=null){ return convert(expression.parExpression().expression()); }else if(expression.methodInvocation_lfno_primary() != null){ return convert(expression.methodInvocation_lfno_primary()); diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index 33559a8e..8ebeea11 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -204,8 +204,7 @@ public class SyntaxTreeGenerator{ List methods = new ArrayList<>(); List konstruktoren = new ArrayList<>(); //int noOfMethods = methods.size(); - for(int i = 0; i < methodsAndConstructors.size(); i++){ - Method m = methodsAndConstructors.get(i); + for(Method m : methodsAndConstructors){ if(m instanceof Constructor){ konstruktoren.add((Constructor) m); } diff --git a/src/test/java/parser/GeneralParserTest.java b/src/test/java/parser/GeneralParserTest.java index 4e7d9868..b4328147 100644 --- a/src/test/java/parser/GeneralParserTest.java +++ b/src/test/java/parser/GeneralParserTest.java @@ -20,7 +20,7 @@ import org.junit.Test; * */ public class GeneralParserTest{ - private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/"; + private static final String rootDirectory = System.getProperty("user.dir")+"/src/test/java/parser/"; @Test public void run(){ diff --git a/src/test/java/typeinference/JavaTXCompilerTest.java b/src/test/java/typeinference/JavaTXCompilerTest.java index 63570d95..c0e69e28 100644 --- a/src/test/java/typeinference/JavaTXCompilerTest.java +++ b/src/test/java/typeinference/JavaTXCompilerTest.java @@ -132,9 +132,9 @@ public class JavaTXCompilerTest { //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); //filesToTest.add(new File(rootDirectory+"Matrix.jav")); //filesToTest.add(new File(rootDirectory+"Import.jav")); - // //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+"Faculty.jav")); + //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); + //filesToTest.add(new File(rootDirectory+"test.jav")); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); for(File f : compiler.sourceFiles.keySet()){ SourceFile sf = compiler.sourceFiles.get(f);