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.nio.charset.StandardCharsets;
|
||||
public class RunParser{
|
||||
public static void main(String[] args){
|
||||
try{
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String inputString = sc.nextLine();
|
||||
while(sc.hasNextLine()) inputString = inputString + sc.nextLine();
|
||||
InputStream stream = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
|
||||
ANTLRInputStream input = new ANTLRInputStream(stream);
|
||||
Java8Lexer lexer = new Java8Lexer(input);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
Java8Parser parser = new Java8Parser(tokens);
|
||||
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
|
||||
generator.getNames(tree);
|
||||
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||
for(ClassOrInterface c : f.KlassenVektor){
|
||||
System.out.println(c.getClassName().toString());
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("An exception occured which is unknown and on our TODO list.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args){
|
||||
try{
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String inputString = sc.nextLine();
|
||||
while(sc.hasNextLine()) inputString = inputString + sc.nextLine();
|
||||
InputStream stream = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8));
|
||||
ANTLRInputStream input = new ANTLRInputStream(stream);
|
||||
Java8Lexer lexer = new Java8Lexer(input);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
Java8Parser parser = new Java8Parser(tokens);
|
||||
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator();
|
||||
generator.getNames(tree);
|
||||
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
|
||||
for(ClassOrInterface c : f.KlassenVektor){
|
||||
System.out.println(c.getClassName().toString());
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
System.out.println("An exception occured which is unknown and on our TODO list.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,10 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
|
||||
public void setClassName(JavaClassName 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;
|
||||
|
||||
|
||||
public class SourceFile extends SyntaxTreeNode
|
||||
{
|
||||
public class SourceFile extends SyntaxTreeNode{
|
||||
private String pkgName;
|
||||
|
||||
|
||||
private String pkgName;
|
||||
|
||||
public List<ClassOrInterface> KlassenVektor = new ArrayList<>();
|
||||
public List<ClassOrInterface> KlassenVektor = new ArrayList<>();
|
||||
private List<JavaClassName> imports;
|
||||
|
||||
/**
|
||||
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
||||
* SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar.
|
||||
*/
|
||||
public SourceFile(List<ClassOrInterface> classDefinitions) {
|
||||
this.KlassenVektor = classDefinitions;
|
||||
}
|
||||
|
||||
|
||||
public SourceFile(String pkgName,List<ClassOrInterface> classDefinitions,List<JavaClassName> imports){
|
||||
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