forked from JavaTX/JavaCompilerCore
extends in Parser implementieren. Dirty fix für fehlende Object-Klasse in der JavaClassNameRegistry
This commit is contained in:
parent
44f4aa4b27
commit
bfa106913b
@ -3,6 +3,7 @@ package de.dhbwstuttgart.environment;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
@ -12,6 +13,7 @@ import org.reflections.util.ConfigurationBuilder;
|
|||||||
import org.reflections.util.FilterBuilder;
|
import org.reflections.util.FilterBuilder;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import org.reflections.vfs.SystemDir;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hilft beim Durchsuchen von Packages
|
* Hilft beim Durchsuchen von Packages
|
||||||
@ -57,6 +59,9 @@ public class PackageCrawler {
|
|||||||
public List<String> getClassNames(String packageName){
|
public List<String> getClassNames(String packageName){
|
||||||
List<String> nameList = new ArrayList();
|
List<String> nameList = new ArrayList();
|
||||||
Set<Class<?>> classes = getClassesInPackage(packageName);
|
Set<Class<?>> classes = getClassesInPackage(packageName);
|
||||||
|
if(packageName.equals("java.lang") && ! classes.contains(Object.class)) {
|
||||||
|
classes.add(Object.class);
|
||||||
|
}
|
||||||
for(Class c : classes){
|
for(Class c : classes){
|
||||||
nameList.add(c.getName());
|
nameList.add(c.getName());
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
|||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import java.lang.ClassNotFoundException;
|
import java.lang.ClassNotFoundException;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
@ -15,6 +16,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.sql.Ref;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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;
|
ClassOrInterface newClass;
|
||||||
if(ctx.normalClassDeclaration() != null){
|
if(ctx.normalClassDeclaration() != null){
|
||||||
newClass = convertNormal(ctx.normalClassDeclaration());
|
newClass = convertNormal(ctx.normalClassDeclaration());
|
||||||
@ -199,7 +201,7 @@ public class SyntaxTreeGenerator{
|
|||||||
return newClass;
|
return newClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassOrInterface convertNormal(Java8Parser.NormalClassDeclarationContext ctx){
|
private ClassOrInterface convertNormal(Java8Parser.NormalClassDeclarationContext ctx) {
|
||||||
int modifiers = 0;
|
int modifiers = 0;
|
||||||
if(ctx.classModifier() != null){
|
if(ctx.classModifier() != null){
|
||||||
for(Java8Parser.ClassModifierContext mod : ctx.classModifier()){
|
for(Java8Parser.ClassModifierContext mod : ctx.classModifier()){
|
||||||
@ -271,7 +273,17 @@ public class SyntaxTreeGenerator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RefType convert(Java8Parser.SuperclassContext superclass) {
|
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,
|
private List<Method> convertMethods(Java8Parser.ClassBodyContext classBodyContext,
|
||||||
|
@ -5,7 +5,9 @@ import static org.junit.Assert.*;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -25,6 +27,7 @@ public class GeneralParserTest{
|
|||||||
|
|
||||||
|
|
||||||
List<String> filenames = new ArrayList<String>();
|
List<String> filenames = new ArrayList<String>();
|
||||||
|
/*
|
||||||
filenames.add("NewTest.jav");
|
filenames.add("NewTest.jav");
|
||||||
filenames.add("FieldInitializationTest.jav");
|
filenames.add("FieldInitializationTest.jav");
|
||||||
filenames.add("ImportTest.jav");
|
filenames.add("ImportTest.jav");
|
||||||
@ -37,14 +40,10 @@ public class GeneralParserTest{
|
|||||||
//filenames.add("GenericFieldVarTest.jav");
|
//filenames.add("GenericFieldVarTest.jav");
|
||||||
filenames.add("FieldVarTest.jav");
|
filenames.add("FieldVarTest.jav");
|
||||||
filenames.add("StructuralTypes.jav");
|
filenames.add("StructuralTypes.jav");
|
||||||
|
*/
|
||||||
filenames.add("ExtendsTest.jav");
|
filenames.add("ExtendsTest.jav");
|
||||||
JavaTXParser parser = new JavaTXParser();
|
|
||||||
try{
|
try{
|
||||||
for(String filename : filenames) {
|
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
|
||||||
System.out.println("Teste: "+filename);
|
|
||||||
parser.parse(new File(rootDirectory + filename));
|
|
||||||
//TODO: Test ANTLR Parser
|
|
||||||
}
|
|
||||||
}catch(Exception exc){
|
}catch(Exception exc){
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
fail();
|
fail();
|
||||||
|
Loading…
Reference in New Issue
Block a user