2017-02-03 14:20:26 +00:00
|
|
|
|
package de.dhbwstuttgart.parser;
|
|
|
|
|
|
2017-09-20 13:52:14 +00:00
|
|
|
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
2017-03-15 15:17:07 +00:00
|
|
|
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
2017-02-03 14:20:26 +00:00
|
|
|
|
import de.dhbwstuttgart.parser.antlr.Java8Lexer;
|
|
|
|
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
2017-09-20 15:26:09 +00:00
|
|
|
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
2017-02-03 14:20:26 +00:00
|
|
|
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
2017-09-20 13:52:14 +00:00
|
|
|
|
|
2017-02-03 14:20:26 +00:00
|
|
|
|
import org.antlr.v4.runtime.ANTLRInputStream;
|
|
|
|
|
import org.antlr.v4.runtime.CommonTokenStream;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
2017-07-05 15:52:23 +00:00
|
|
|
|
import java.nio.charset.StandardCharsets;
|
2017-02-10 16:37:42 +00:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
2017-02-03 14:20:26 +00:00
|
|
|
|
|
2017-09-20 15:26:09 +00:00
|
|
|
|
public class JavaTXParser {
|
|
|
|
|
public static Java8Parser.CompilationUnitContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
|
|
|
|
|
InputStream stream = new FileInputStream(source);
|
2017-02-10 16:37:42 +00:00
|
|
|
|
ANTLRInputStream input = new ANTLRInputStream(stream);
|
|
|
|
|
Java8Lexer lexer = new Java8Lexer(input);
|
|
|
|
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
|
|
|
|
Java8Parser parser = new Java8Parser(tokens);
|
2017-09-20 15:26:09 +00:00
|
|
|
|
return parser.compilationUnit();
|
|
|
|
|
/*
|
|
|
|
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(source));
|
2017-07-05 15:50:38 +00:00
|
|
|
|
return generator.convert(tree);
|
2017-09-20 15:26:09 +00:00
|
|
|
|
*/
|
2017-02-10 16:37:42 +00:00
|
|
|
|
}
|
2017-09-20 15:26:09 +00:00
|
|
|
|
|
|
|
|
|
/* F<EFBFBD>r das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet:
|
2017-07-14 15:47:02 +00:00
|
|
|
|
public SourceFile parse(String fileContent) throws IOException, java.lang.ClassNotFoundException {
|
2017-07-05 15:52:23 +00:00
|
|
|
|
return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)));
|
|
|
|
|
}
|
2017-09-20 15:26:09 +00:00
|
|
|
|
*/
|
2017-02-03 14:20:26 +00:00
|
|
|
|
}
|