Change Parser FileInput to InputStream
This commit is contained in:
parent
87d2edaaa6
commit
0ad97251ca
@ -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<String> 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));
|
||||
}
|
||||
}
|
||||
|
@ -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<ClassOrInterface> 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) {
|
||||
|
@ -15,18 +15,16 @@ public class SourceFile extends SyntaxTreeNode{
|
||||
|
||||
private final List<ClassOrInterface> KlassenVektor;
|
||||
private final List<JavaClassName> 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<ClassOrInterface> classDefinitions, List<JavaClassName> imports){
|
||||
public SourceFile(String pkgName, List<ClassOrInterface> classDefinitions, List<JavaClassName> 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);
|
||||
|
@ -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<TypeInsert> result = this.getTypeInserts(f);
|
||||
List<TypeInsert> 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<TypeInsert> 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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user