From 5cc418371d8835b4eb22efe5866550c2b1a346b7 Mon Sep 17 00:00:00 2001 From: Jakob Herrmann Date: Thu, 20 Apr 2017 13:47:06 +0200 Subject: [PATCH] Main class for JavaTXParser. --- src/de/dhbwstuttgart/parser/RunTXParser.java | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/de/dhbwstuttgart/parser/RunTXParser.java diff --git a/src/de/dhbwstuttgart/parser/RunTXParser.java b/src/de/dhbwstuttgart/parser/RunTXParser.java new file mode 100644 index 000000000..8d4c6d9ea --- /dev/null +++ b/src/de/dhbwstuttgart/parser/RunTXParser.java @@ -0,0 +1,57 @@ +package de.dhbwstuttgart.parser; +import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator; +import de.dhbwstuttgart.parser.antlr.Java8Lexer; +import de.dhbwstuttgart.parser.antlr.Java8Parser; +import de.dhbwstuttgart.typecheck.JavaClassName; +import de.dhbwstuttgart.typecheck.JavaClassRegistry; +import org.antlr.v4.runtime.ANTLRInputStream; +import org.antlr.v4.runtime.CommonTokenStream; +import de.dhbwstuttgart.syntaxtree.*; + +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Scanner; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +public class RunTXParser{ + public static void main(String[] args){ + try{ + JavaTXParser parser = new JavaTXParser(); + SourceFile f = parser.parse(new File(args[0])); + String pkgName = f.getPkgName(); + System.out.println("package: " + pkgName); + System.out.println("Imports:"); + for(JavaClassName c : f.getImports()){ + System.out.println(c.toString()); + } + System.out.println("classes:"); + for(ClassOrInterface c : f.getClasses()){ + int mod = c.getModifiers(); + System.out.println(Modifier.toString(mod)); + System.out.println(c.getClassName().toString()); + System.out.println("{"); + for(Field field : c.getFieldDecl()){ + System.out.println(field.getName()); + } + System.out.println("}"); + } + } + catch(java.util.NoSuchElementException e){ + System.out.println("Error: Source seems to be empty."); + } + catch(ClassNotFoundException e){ + System.out.println("Class not found."); + } + catch(FileNotFoundException e){ + System.out.println("File not found."); + } + catch(IOException e){ + System.out.println("An exception occured which is on our TODO list."); + e.printStackTrace(); + } + } +}