From d63fe45d0811c3682ea1ec4074ab32c85db87fa0 Mon Sep 17 00:00:00 2001 From: Jakob Herrmann Date: Wed, 22 Feb 2017 13:14:32 +0100 Subject: [PATCH] Helper methods to convert type names. --- .../parser/SyntaxTreeGenerator.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index 05685b986..0d659d63b 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -14,6 +14,7 @@ import de.dhbwstuttgart.typecheck.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.lang.ClassNotFoundException; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.TerminalNode; @@ -82,6 +83,30 @@ public class SyntaxTreeGenerator{ return this.reg; } + // Converts type name to String. + public String convertTypeName(Java8Parser.TypeNameContext ctx){ + String ret; + if(ctx.packageOrTypeName() == null){ + ret = ctx.Identifier().toString(); + } + else{ + ret = convertPackageOrTypeName(ctx.packageOrTypeName()) + "." + ctx.Identifier().toString(); + } + return ret; + } + + // Converts PackageOrTypeName to String. + public String convertPackageOrTypeName(Java8Parser.PackageOrTypeNameContext ctx){ + String ret; + if(ctx.packageOrTypeName() == null){ + ret = ctx.Identifier().toString(); + } + else{ + ret = convertPackageOrTypeName(ctx.packageOrTypeName()) + "." + ctx.Identifier().toString(); + } + return ret; + } + public SourceFile convert(Java8Parser.CompilationUnitContext ctx){ List classes = new ArrayList<>(); this.getNames(ctx);