From fb10220da981d9159c94951a6438efa4967154e2 Mon Sep 17 00:00:00 2001 From: Jakob Herrmann Date: Tue, 10 Jan 2017 20:07:23 +0100 Subject: [PATCH] * Set JavaClassName constroctur to public. * Implemented "class resolution" for interfaces. --- src/de/dhbwstuttgart/parser/RunParser.java | 4 ++++ src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java | 10 ++++++++-- src/de/dhbwstuttgart/typecheck/JavaClassName.java | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/RunParser.java b/src/de/dhbwstuttgart/parser/RunParser.java index 62464e58..48ba0fd4 100644 --- a/src/de/dhbwstuttgart/parser/RunParser.java +++ b/src/de/dhbwstuttgart/parser/RunParser.java @@ -5,6 +5,7 @@ import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.tree.ParseTreeWalker; import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.typecheck.*; import java.util.Scanner; import java.io.ByteArrayInputStream; @@ -25,6 +26,9 @@ public class RunParser{ SyntaxTreeGenerator generator = new SyntaxTreeGenerator(); // generator.convert((Java8Parser.CompilationUnitContext) tree); generator.getNames(tree); + for(JavaClassName name : generator.reg.existingClasses){ + System.out.println(name.toString()); + } } catch(Exception e){ System.out.println("An exception occured which is unknown and on our TODO list."); diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index ff604263..1c1448a1 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -12,7 +12,6 @@ public class SyntaxTreeGenerator{ JavaClassRegistry reg = new JavaClassRegistry(); public void getNames(Java8Parser.CompilationUnitContext ctx){ - List names = new ArrayList(); String packageDecl = ""; List decls = ctx.packageDeclaration().Identifier(); if(decls != null){ @@ -20,7 +19,14 @@ public class SyntaxTreeGenerator{ packageDecl = packageDecl + "." + t.toString(); } packageDecl = packageDecl.substring(1); - System.out.println(packageDecl); + } + for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){ + if(typeDecl.interfaceDeclaration() != null){ + if(typeDecl.interfaceDeclaration().normalInterfaceDeclaration() != null){ + String nameString = packageDecl + "." + typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString(); + this.reg.existingClasses.add(new JavaClassName(nameString)); + } + } } } diff --git a/src/de/dhbwstuttgart/typecheck/JavaClassName.java b/src/de/dhbwstuttgart/typecheck/JavaClassName.java index 7536d623..e0a39ea8 100644 --- a/src/de/dhbwstuttgart/typecheck/JavaClassName.java +++ b/src/de/dhbwstuttgart/typecheck/JavaClassName.java @@ -14,7 +14,7 @@ public class JavaClassName { private String name; private PackageName packageName; - JavaClassName(String name){ + public JavaClassName(String name){ if(name == null)throw new NullPointerException(); String[] names = name.split("[.]");