extends in Parser implementieren. Dirty fix für fehlende Object-Klasse in der JavaClassNameRegistry

This commit is contained in:
JanUlrich 2017-10-18 16:40:27 +02:00
parent 44f4aa4b27
commit bfa106913b
3 changed files with 25 additions and 9 deletions

View File

@ -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<String> getClassNames(String packageName){
List<String> nameList = new ArrayList();
Set<Class<?>> classes = getClassesInPackage(packageName);
if(packageName.equals("java.lang") && ! classes.contains(Object.class)) {
classes.add(Object.class);
}
for(Class c : classes){
nameList.add(c.getName());
}

View File

@ -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<Method> convertMethods(Java8Parser.ClassBodyContext classBodyContext,

View File

@ -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<String> filenames = new ArrayList<String>();
/*
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();