forked from JavaTX/JavaCompilerCore
Extend constructor of SourceFile.
This commit is contained in:
parent
647196bf16
commit
e4e98797fc
@ -12,27 +12,27 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
public class RunParser{
|
public class RunParser{
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
try{
|
try{
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
String inputString = sc.nextLine();
|
String inputString = sc.nextLine();
|
||||||
while(sc.hasNextLine()) inputString = inputString + sc.nextLine();
|
while(sc.hasNextLine()) inputString = inputString + sc.nextLine();
|
||||||
InputStream stream = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
|
InputStream stream = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
|
||||||
ANTLRInputStream input = new ANTLRInputStream(stream);
|
ANTLRInputStream input = new ANTLRInputStream(stream);
|
||||||
Java8Lexer lexer = new Java8Lexer(input);
|
Java8Lexer lexer = new Java8Lexer(input);
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
Java8Parser parser = new Java8Parser(tokens);
|
Java8Parser parser = new Java8Parser(tokens);
|
||||||
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
||||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
|
||||||
generator.getNames(tree);
|
generator.getNames(tree);
|
||||||
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||||
for(ClassOrInterface c : f.KlassenVektor){
|
for(ClassOrInterface c : f.KlassenVektor){
|
||||||
System.out.println(c.getClassName().toString());
|
System.out.println(c.getClassName().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e){
|
catch(Exception e){
|
||||||
System.out.println("An exception occured which is unknown and on our TODO list.");
|
System.out.println("An exception occured which is unknown and on our TODO list.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,10 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
|
|||||||
public void setClassName(JavaClassName name){
|
public void setClassName(JavaClassName name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets interface "switch".
|
||||||
|
public void setInterface(Boolean isInterface){
|
||||||
|
this.isInterface = isInterface;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,23 +5,35 @@ import java.util.*;
|
|||||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||||
|
|
||||||
|
|
||||||
public class SourceFile extends SyntaxTreeNode
|
public class SourceFile extends SyntaxTreeNode{
|
||||||
{
|
private String pkgName;
|
||||||
|
|
||||||
|
public List<ClassOrInterface> KlassenVektor = new ArrayList<>();
|
||||||
private String pkgName;
|
|
||||||
|
|
||||||
public List<ClassOrInterface> KlassenVektor = new ArrayList<>();
|
|
||||||
private List<JavaClassName> imports;
|
private List<JavaClassName> imports;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
||||||
* SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar.
|
* SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar.
|
||||||
*/
|
*/
|
||||||
public SourceFile(List<ClassOrInterface> classDefinitions) {
|
public SourceFile(String pkgName,List<ClassOrInterface> classDefinitions,List<JavaClassName> imports){
|
||||||
this.KlassenVektor = classDefinitions;
|
this.KlassenVektor = classDefinitions;
|
||||||
}
|
if(pkgName != null){
|
||||||
|
this.pkgName = pkgName;
|
||||||
|
}
|
||||||
|
if(imports != null){
|
||||||
|
this.imports = imports;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SourceFile(List<ClassOrInterface> classDefinitions){
|
||||||
|
this(null, classDefinitions, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SourceFile(String pkgName, List<ClassOrInterface> classDefinitions){
|
||||||
|
this(pkgName, classDefinitions, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SourceFile(List<ClassOrInterface> classDefinitions, List<JavaClassName> imports){
|
||||||
|
this(null, classDefinitions, imports);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ino.end
|
|
||||||
|
Loading…
Reference in New Issue
Block a user