From bfa106913b670e4b6e13bb27402144b634920dc5 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 18 Oct 2017 16:40:27 +0200 Subject: [PATCH] =?UTF-8?q?extends=20in=20Parser=20implementieren.=20Dirty?= =?UTF-8?q?=20fix=20f=C3=BCr=20fehlende=20Object-Klasse=20in=20der=20JavaC?= =?UTF-8?q?lassNameRegistry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../environment/PackageCrawler.java | 5 +++++ .../SyntaxTreeGenerator.java | 18 +++++++++++++++--- test/parser/GeneralParserTest.java | 11 +++++------ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/environment/PackageCrawler.java b/src/de/dhbwstuttgart/environment/PackageCrawler.java index e1e4b70c..47b58128 100644 --- a/src/de/dhbwstuttgart/environment/PackageCrawler.java +++ b/src/de/dhbwstuttgart/environment/PackageCrawler.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.environment; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Set; import org.reflections.Reflections; @@ -12,6 +13,7 @@ import org.reflections.util.ConfigurationBuilder; import org.reflections.util.FilterBuilder; import de.dhbwstuttgart.parser.scope.JavaClassName; +import org.reflections.vfs.SystemDir; /** * Hilft beim Durchsuchen von Packages @@ -57,6 +59,9 @@ public class PackageCrawler { public List getClassNames(String packageName){ List nameList = new ArrayList(); Set> classes = getClassesInPackage(packageName); + if(packageName.equals("java.lang") && ! classes.contains(Object.class)) { + classes.add(Object.class); + } for(Class c : classes){ nameList.add(c.getName()); } diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index e51972ab..830f9d37 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator; import de.dhbwstuttgart.exceptions.NotImplementedException; import java.lang.ClassNotFoundException; +import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.antlr.Java8Parser; import de.dhbwstuttgart.parser.scope.GenericsRegistry; import de.dhbwstuttgart.parser.scope.JavaClassName; @@ -15,6 +16,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import java.lang.reflect.Modifier; +import java.sql.Ref; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -188,7 +190,7 @@ public class SyntaxTreeGenerator{ } } - private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) { + private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) { ClassOrInterface newClass; if(ctx.normalClassDeclaration() != null){ newClass = convertNormal(ctx.normalClassDeclaration()); @@ -199,7 +201,7 @@ public class SyntaxTreeGenerator{ return newClass; } - private ClassOrInterface convertNormal(Java8Parser.NormalClassDeclarationContext ctx){ + private ClassOrInterface convertNormal(Java8Parser.NormalClassDeclarationContext ctx) { int modifiers = 0; if(ctx.classModifier() != null){ for(Java8Parser.ClassModifierContext mod : ctx.classModifier()){ @@ -271,7 +273,17 @@ public class SyntaxTreeGenerator{ } private RefType convert(Java8Parser.SuperclassContext superclass) { - throw new NotImplementedException(); + if(superclass.classType().classOrInterfaceType() != null){ + throw new NotImplementedException(); + }else{ + RefTypeOrTPHOrWildcardOrGeneric ret = TypeGenerator.convertTypeName(superclass.classType().Identifier().getText(), superclass.classType().typeArguments(), + superclass.getStart(), reg, globalGenerics); + if(ret instanceof RefType){ + return (RefType) ret; + }else{ + throw new TypeinferenceException(superclass.getText() + " ist kein gültiger Supertyp", superclass.getStart()); + } + } } private List convertMethods(Java8Parser.ClassBodyContext classBodyContext, diff --git a/test/parser/GeneralParserTest.java b/test/parser/GeneralParserTest.java index 4467bcc7..c48e1320 100644 --- a/test/parser/GeneralParserTest.java +++ b/test/parser/GeneralParserTest.java @@ -5,7 +5,9 @@ import static org.junit.Assert.*; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.parser.JavaTXParser; import org.junit.Test; @@ -25,6 +27,7 @@ public class GeneralParserTest{ List filenames = new ArrayList(); + /* filenames.add("NewTest.jav"); filenames.add("FieldInitializationTest.jav"); filenames.add("ImportTest.jav"); @@ -37,14 +40,10 @@ public class GeneralParserTest{ //filenames.add("GenericFieldVarTest.jav"); filenames.add("FieldVarTest.jav"); filenames.add("StructuralTypes.jav"); + */ filenames.add("ExtendsTest.jav"); - JavaTXParser parser = new JavaTXParser(); try{ - for(String filename : filenames) { - System.out.println("Teste: "+filename); - parser.parse(new File(rootDirectory + filename)); - //TODO: Test ANTLR Parser - } + new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList())); }catch(Exception exc){ exc.printStackTrace(); fail();