forked from JavaTX/JavaCompilerCore
Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into strucTypes_dev_PL
Versuche zu mergen dass auch Interfaces geparst werden könne
This commit is contained in:
commit
7dbc2bbd4c
@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.ClassNotFoundException;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
@ -33,6 +33,7 @@ public class JavaTXParser {
|
|||||||
}
|
}
|
||||||
//TODO: Wieso muss man das händisch anhängen?
|
//TODO: Wieso muss man das händisch anhängen?
|
||||||
ret.add("java.lang.Object");
|
ret.add("java.lang.Object");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,40 +33,7 @@ public class StatementGenerator {
|
|||||||
this.generics = generics;
|
this.generics = generics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass) {
|
public ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
|
||||||
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
|
|
||||||
String name = header.methodDeclarator().Identifier().getText();
|
|
||||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), methodDeclarationContext.methodHeader().getStart());
|
|
||||||
if(methodDeclarationContext.methodHeader().typeParameters() != null){
|
|
||||||
gtvDeclarations = TypeGenerator.convert(methodDeclarationContext.methodHeader().typeParameters(), parentClass, name,reg, generics);
|
|
||||||
}
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric retType;
|
|
||||||
if(header.result() != null){
|
|
||||||
if(header.result().unannType() != null){
|
|
||||||
retType = TypeGenerator.convert(header.result().unannType(), reg, generics);
|
|
||||||
}
|
|
||||||
else retType = new de.dhbwstuttgart.syntaxtree.type.Void(header.result().getStart());
|
|
||||||
}else{
|
|
||||||
retType = TypePlaceholder.fresh(header.getStart());
|
|
||||||
}
|
|
||||||
int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier());
|
|
||||||
ParameterList parameterList = convert(header.methodDeclarator().formalParameterList());
|
|
||||||
Block block = null;
|
|
||||||
if(methodDeclarationContext.methodBody().block() == null){
|
|
||||||
if(! Modifier.isAbstract(modifiers)){
|
|
||||||
//TODO: Error! Abstrakte Methode ohne abstrakt Keyword
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
block = this.convert(methodDeclarationContext.methodBody().block());
|
|
||||||
}
|
|
||||||
if(parentClass.equals(new JavaClassName(name))){
|
|
||||||
return new Constructor(name, retType, modifiers, parameterList, block, gtvDeclarations, methodDeclarationContext.getStart());
|
|
||||||
}else{
|
|
||||||
return new Method(name, retType, modifiers, parameterList,block, gtvDeclarations, methodDeclarationContext.getStart());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
|
|
||||||
List<FormalParameter> ret = new ArrayList<>();
|
List<FormalParameter> ret = new ArrayList<>();
|
||||||
List<Java8Parser.FormalParameterContext> fps = new ArrayList<>();
|
List<Java8Parser.FormalParameterContext> fps = new ArrayList<>();
|
||||||
if(formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null)
|
if(formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null)
|
||||||
@ -832,9 +799,9 @@ public class StatementGenerator {
|
|||||||
funNParams.add(TypePlaceholder.fresh(expression.getStart()));//ret-Type
|
funNParams.add(TypePlaceholder.fresh(expression.getStart()));//ret-Type
|
||||||
params.getFormalparalist().forEach(formalParameter -> //Für jeden Parameter einen TPH anfügen:
|
params.getFormalparalist().forEach(formalParameter -> //Für jeden Parameter einen TPH anfügen:
|
||||||
funNParams.add(TypePlaceholder.fresh(expression.getStart())));
|
funNParams.add(TypePlaceholder.fresh(expression.getStart())));
|
||||||
RefType lambdaType = new RefType(reg.getName("Fun"+params.getFormalparalist().size()),
|
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
|
||||||
funNParams, expression.getStart());
|
//RefType lambdaType = new RefType(reg.getName("Fun"+params.getFormalparalist().size()),
|
||||||
|
//funNParams, expression.getStart());
|
||||||
return new LambdaExpression(lambdaType, params, block, expression.getStart());
|
return new LambdaExpression(lambdaType, params, block, expression.getStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import jdk.internal.dynalink.support.TypeConverterFactory;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
@ -24,7 +25,6 @@ public class SyntaxTreeGenerator{
|
|||||||
private JavaClassRegistry reg;
|
private JavaClassRegistry reg;
|
||||||
private String pkgName = "";
|
private String pkgName = "";
|
||||||
List<JavaClassName> imports = new ArrayList();
|
List<JavaClassName> imports = new ArrayList();
|
||||||
private GenericsRegistry generics = new GenericsRegistry();
|
|
||||||
|
|
||||||
public SyntaxTreeGenerator(JavaClassRegistry reg){
|
public SyntaxTreeGenerator(JavaClassRegistry reg){
|
||||||
this.reg = reg;
|
this.reg = reg;
|
||||||
@ -52,11 +52,13 @@ public class SyntaxTreeGenerator{
|
|||||||
nameString = typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
nameString = typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
||||||
}
|
}
|
||||||
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
||||||
|
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
|
||||||
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
||||||
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
||||||
//this.reg.add(tp.Identifier().toString());
|
//this.reg.add(tp.Identifier().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
this.reg.add(nameString);
|
this.reg.add(nameString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,12 +70,14 @@ public class SyntaxTreeGenerator{
|
|||||||
else{
|
else{
|
||||||
nameString = typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
|
nameString = typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
|
||||||
}
|
}
|
||||||
//Die Generic TypeParameter Definitionen ebenfalls an die JavaClassName-Registry anfügen:
|
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
||||||
|
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
|
||||||
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
||||||
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
||||||
this.reg.add(tp.Identifier().toString());
|
this.reg.add(tp.Identifier().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
this.reg.add(nameString);
|
this.reg.add(nameString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,6 +184,60 @@ public class SyntaxTreeGenerator{
|
|||||||
return new SourceFile(this.pkgName, classes, this.imports);
|
return new SourceFile(this.pkgName, classes, this.imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Method convert(Java8Parser.MethodDeclarationContext methodDeclarationContext, JavaClassName parentClass, GenericsRegistry generics) {
|
||||||
|
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
|
||||||
|
int modifiers = SyntaxTreeGenerator.convert(methodDeclarationContext.methodModifier());
|
||||||
|
GenericsRegistry localGenerics = createGenerics(methodDeclarationContext.methodHeader().typeParameters(),
|
||||||
|
parentClass, header.methodDeclarator().Identifier().getText());
|
||||||
|
localGenerics.putAll(generics);
|
||||||
|
return convert(modifiers, header, methodDeclarationContext.methodBody(),parentClass, localGenerics);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Method convert(Java8Parser.InterfaceMethodDeclarationContext ctx, JavaClassName parentClass, GenericsRegistry generics) {
|
||||||
|
Java8Parser.MethodHeaderContext header = ctx.methodHeader();
|
||||||
|
int modifiers = SyntaxTreeGenerator.convertInterfaceModifier(ctx.interfaceMethodModifier());
|
||||||
|
|
||||||
|
GenericsRegistry localGenerics = createGenerics(header.typeParameters(), parentClass, header.methodDeclarator().Identifier().getText());
|
||||||
|
localGenerics.putAll(generics);
|
||||||
|
|
||||||
|
return convert(modifiers, header, ctx.methodBody(),parentClass, localGenerics);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method convert(int modifiers, Java8Parser.MethodHeaderContext header, Java8Parser.MethodBodyContext body,
|
||||||
|
JavaClassName parentClass, GenericsRegistry localGenerics) {
|
||||||
|
|
||||||
|
StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics);
|
||||||
|
|
||||||
|
String name = header.methodDeclarator().Identifier().getText();
|
||||||
|
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart());
|
||||||
|
if(header.typeParameters() != null){
|
||||||
|
gtvDeclarations = TypeGenerator.convert(header.typeParameters(), parentClass, name,reg, localGenerics);
|
||||||
|
}
|
||||||
|
RefTypeOrTPHOrWildcardOrGeneric retType;
|
||||||
|
if(header.result() != null){
|
||||||
|
if(header.result().unannType() != null){
|
||||||
|
retType = TypeGenerator.convert(header.result().unannType(), reg, localGenerics);
|
||||||
|
}
|
||||||
|
else retType = new de.dhbwstuttgart.syntaxtree.type.Void(header.result().getStart());
|
||||||
|
}else{
|
||||||
|
retType = TypePlaceholder.fresh(header.getStart());
|
||||||
|
}
|
||||||
|
ParameterList parameterList = stmtGen.convert(header.methodDeclarator().formalParameterList());
|
||||||
|
Block block = null;
|
||||||
|
if(body.block() == null){
|
||||||
|
if(! Modifier.isAbstract(modifiers)){
|
||||||
|
//TODO: Error! Abstrakte Methode ohne abstrakt Keyword
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
block = stmtGen.convert(body.block());
|
||||||
|
}
|
||||||
|
if(parentClass.equals(new JavaClassName(name))){
|
||||||
|
return new Constructor(name, retType, modifiers, parameterList, block, gtvDeclarations, header.getStart());
|
||||||
|
}else{
|
||||||
|
return new Method(name, retType, modifiers, parameterList,block, gtvDeclarations, header.getStart());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) {
|
private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) {
|
||||||
ClassOrInterface newClass;
|
ClassOrInterface newClass;
|
||||||
if(ctx.normalClassDeclaration() != null){
|
if(ctx.normalClassDeclaration() != null){
|
||||||
@ -200,10 +258,11 @@ public class SyntaxTreeGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
JavaClassName name = reg.getName(ctx.Identifier().getText());
|
JavaClassName name = reg.getName(ctx.Identifier().getText());
|
||||||
|
GenericsRegistry generics = createGenerics(ctx.typeParameters(), name, "");
|
||||||
Token offset = ctx.getStart();
|
Token offset = ctx.getStart();
|
||||||
GenericDeclarationList genericClassParameters = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
GenericDeclarationList genericClassParameters = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
||||||
List<Field> fielddecl = convertFields(ctx.classBody());
|
List<Field> fielddecl = convertFields(ctx.classBody(), generics);
|
||||||
List<Method> methods = convertMethods(ctx.classBody(), name);
|
List<Method> methods = convertMethods(ctx.classBody(), name, generics);
|
||||||
List<Constructor> konstruktoren = new ArrayList<>();
|
List<Constructor> konstruktoren = new ArrayList<>();
|
||||||
for(int i = 0; i<methods.size();i++){
|
for(int i = 0; i<methods.size();i++){
|
||||||
Method m = methods.get(i);
|
Method m = methods.get(i);
|
||||||
@ -227,8 +286,22 @@ public class SyntaxTreeGenerator{
|
|||||||
superClass = new RefType(new JavaClassName("java.lang.Object"), new NullToken());
|
superClass = new RefType(new JavaClassName("java.lang.Object"), new NullToken());
|
||||||
}
|
}
|
||||||
Boolean isInterface = false;
|
Boolean isInterface = false;
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = null;
|
List<RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = convert(ctx.superinterfaces(), generics);
|
||||||
return new ClassOrInterface(modifiers, name, fielddecl, methods, konstruktoren, genericClassParameters, superClass, isInterface, implementedInterfaces, offset);
|
return new ClassOrInterface(modifiers, name, fielddecl, methods, konstruktoren, genericClassParameters, superClass,
|
||||||
|
isInterface, implementedInterfaces, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) {
|
||||||
|
if(ctx == null)return new ArrayList<>();
|
||||||
|
return convert(ctx.interfaceTypeList(), generics);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) {
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
|
||||||
|
for(Java8Parser.InterfaceTypeContext interfaceType : ctx.interfaceType()){
|
||||||
|
ret.add(TypeGenerator.convert(interfaceType.classType(), reg, generics));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Constructor generateStandardConstructor(String className, GenericDeclarationList classGenerics, Token offset){
|
private Constructor generateStandardConstructor(String className, GenericDeclarationList classGenerics, Token offset){
|
||||||
@ -244,7 +317,8 @@ public class SyntaxTreeGenerator{
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Method> convertMethods(Java8Parser.ClassBodyContext classBodyContext, JavaClassName parentClass) {
|
private List<Method> convertMethods(Java8Parser.ClassBodyContext classBodyContext,
|
||||||
|
JavaClassName parentClass, GenericsRegistry generics) {
|
||||||
List<Method> ret = new ArrayList<>();
|
List<Method> ret = new ArrayList<>();
|
||||||
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
|
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
|
||||||
if(classMember.classMemberDeclaration() != null){
|
if(classMember.classMemberDeclaration() != null){
|
||||||
@ -252,21 +326,21 @@ public class SyntaxTreeGenerator{
|
|||||||
if(classMemberDeclarationContext.fieldDeclaration() != null){
|
if(classMemberDeclarationContext.fieldDeclaration() != null){
|
||||||
//Do nothing!
|
//Do nothing!
|
||||||
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
|
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
|
||||||
StatementGenerator stmtGen = new StatementGenerator(reg, generics);
|
|
||||||
ret.add(stmtGen.convert(classMemberDeclarationContext.methodDeclaration(), parentClass));
|
ret.add(this.convert(classMemberDeclarationContext.methodDeclaration(), parentClass, generics));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Field> convertFields(Java8Parser.ClassBodyContext classBodyContext) {
|
private List<Field> convertFields(Java8Parser.ClassBodyContext classBodyContext, GenericsRegistry generics) {
|
||||||
List<Field> ret = new ArrayList<>();
|
List<Field> ret = new ArrayList<>();
|
||||||
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
|
for(Java8Parser.ClassBodyDeclarationContext classMember : classBodyContext.classBodyDeclaration()){
|
||||||
if(classMember.classMemberDeclaration() != null){
|
if(classMember.classMemberDeclaration() != null){
|
||||||
Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
|
Java8Parser.ClassMemberDeclarationContext classMemberDeclarationContext = classMember.classMemberDeclaration();
|
||||||
if(classMemberDeclarationContext.fieldDeclaration() != null){
|
if(classMemberDeclarationContext.fieldDeclaration() != null){
|
||||||
ret.addAll(convert(classMember.classMemberDeclaration().fieldDeclaration()));
|
ret.addAll(convert(classMember.classMemberDeclaration().fieldDeclaration(), generics));
|
||||||
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
|
}else if(classMemberDeclarationContext.methodDeclaration()!= null){
|
||||||
//Do nothing!
|
//Do nothing!
|
||||||
}
|
}
|
||||||
@ -283,7 +357,15 @@ public class SyntaxTreeGenerator{
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<? extends Field> convert(Java8Parser.FieldDeclarationContext fieldDeclarationContext) {
|
public static int convertInterfaceModifier(List<Java8Parser.InterfaceMethodModifierContext> methodModifierContexts) {
|
||||||
|
int ret = 0;
|
||||||
|
for(Java8Parser.InterfaceMethodModifierContext mod : methodModifierContexts){
|
||||||
|
if(mod.annotation() == null)convertModifier(mod.getText());
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<? extends Field> convert(Java8Parser.FieldDeclarationContext fieldDeclarationContext, GenericsRegistry generics) {
|
||||||
List<Field> ret = new ArrayList<>();
|
List<Field> ret = new ArrayList<>();
|
||||||
int modifiers = 0;
|
int modifiers = 0;
|
||||||
for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
|
for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
|
||||||
@ -333,7 +415,7 @@ public class SyntaxTreeGenerator{
|
|||||||
modifiers.put(Modifier.toString(Modifier.INTERFACE), Modifier.INTERFACE);
|
modifiers.put(Modifier.toString(Modifier.INTERFACE), Modifier.INTERFACE);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
for(String m : modifiers.keySet()){
|
for(String m : modifiers.keySet()){
|
||||||
if(modifier.startsWith(m))ret+=modifiers.get(m);
|
if(modifier.contains(m))ret+=modifiers.get(m);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -347,13 +429,86 @@ public class SyntaxTreeGenerator{
|
|||||||
if(ctx.annotation() != null)return 0;
|
if(ctx.annotation() != null)return 0;
|
||||||
return convertModifier(ctx.getText());
|
return convertModifier(ctx.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int convert(Java8Parser.InterfaceModifierContext ctx) {
|
||||||
|
if(ctx.annotation() != null)return 0;
|
||||||
|
return convertModifier(ctx.getText());
|
||||||
|
}
|
||||||
|
|
||||||
private ClassOrInterface convertEnum(Java8Parser.EnumDeclarationContext ctx){
|
private ClassOrInterface convertEnum(Java8Parser.EnumDeclarationContext ctx){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassOrInterface convertInterface(Java8Parser.InterfaceDeclarationContext ctx){
|
private ClassOrInterface convertInterface(Java8Parser.InterfaceDeclarationContext ctx){
|
||||||
return null;
|
if(ctx.normalInterfaceDeclaration() != null){
|
||||||
|
return convertNormal(ctx.normalInterfaceDeclaration());
|
||||||
|
}else{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ClassOrInterface convertNormal(Java8Parser.NormalInterfaceDeclarationContext ctx) {
|
||||||
|
int modifiers = 0;
|
||||||
|
if(ctx.interfaceModifier() != null){
|
||||||
|
for( Java8Parser.InterfaceModifierContext mod : ctx.interfaceModifier()){
|
||||||
|
int newModifier = convert(mod);
|
||||||
|
modifiers += newModifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JavaClassName name = reg.getName(ctx.Identifier().getText());
|
||||||
|
|
||||||
|
GenericsRegistry generics = createGenerics(ctx.typeParameters(), name, "");
|
||||||
|
|
||||||
|
List<Field> fields = convertFields(ctx.interfaceBody());
|
||||||
|
List<Method> methods = convertMethods(ctx.interfaceBody(), name, generics);
|
||||||
|
|
||||||
|
GenericDeclarationList genericParams = TypeGenerator.convert(ctx.typeParameters(), name, "",reg, generics);
|
||||||
|
RefType superClass = new ASTFactory(reg).createObjectClass().getType();
|
||||||
|
|
||||||
|
List<RefTypeOrTPHOrWildcardOrGeneric> extendedInterfaces = convert(ctx.extendsInterfaces(), generics);
|
||||||
|
|
||||||
|
return new ClassOrInterface(modifiers, name, fields, methods, new ArrayList<>(),
|
||||||
|
genericParams, superClass, true, extendedInterfaces, ctx.getStart());
|
||||||
|
}
|
||||||
|
|
||||||
|
private GenericsRegistry createGenerics(Java8Parser.TypeParametersContext ctx, JavaClassName parentClass, String parentMethod) {
|
||||||
|
GenericsRegistry ret = new GenericsRegistry();
|
||||||
|
if(ctx == null || ctx.typeParameterList() == null)return ret;
|
||||||
|
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
||||||
|
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) {
|
||||||
|
if(extendsInterfacesContext == null)return new ArrayList<>();
|
||||||
|
return convert(extendsInterfacesContext.interfaceTypeList(), generics);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Method> convertMethods(Java8Parser.InterfaceBodyContext interfaceBodyContext,
|
||||||
|
JavaClassName parentClass, GenericsRegistry generics) {
|
||||||
|
List<Method> ret = new ArrayList<>();
|
||||||
|
for(Java8Parser.InterfaceMemberDeclarationContext member : interfaceBodyContext.interfaceMemberDeclaration()){
|
||||||
|
if(member.interfaceMethodDeclaration() != null){
|
||||||
|
ret.add(this.convert(member.interfaceMethodDeclaration(), parentClass, generics));
|
||||||
|
//new Method(name, type, modifier, params, null, genericDecls, member.interfaceMethodDeclaration().getStart());
|
||||||
|
}else{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Field> convertFields(Java8Parser.InterfaceBodyContext interfaceBodyContext) {
|
||||||
|
List<Field> ret = new ArrayList<>();
|
||||||
|
for(Java8Parser.InterfaceMemberDeclarationContext member : interfaceBodyContext.interfaceMemberDeclaration()){
|
||||||
|
if(member.constantDeclaration() != null){
|
||||||
|
//TODO: Erstelle hier ein Feld!
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -125,4 +125,9 @@ public class TypeGenerator {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassTypeContext ctx, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||||
|
if(ctx.classOrInterfaceType() != null)throw new NotImplementedException();
|
||||||
|
return convertTypeName(ctx.Identifier().getText(), ctx.typeArguments(), ctx.getStart(), reg, generics);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,8 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(GenericRefType t){
|
public static UnifyType convert(GenericRefType t){
|
||||||
return new PlaceholderType(TypePlaceholder.fresh(t.getOffset()).getName());
|
throw new NotImplementedException();
|
||||||
|
//return new PlaceholderType(TypePlaceholder.fresh(t.getOffset()).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(WildcardType t){
|
public static UnifyType convert(WildcardType t){
|
||||||
|
@ -48,7 +48,8 @@ public class LambdaExpression extends Expression implements TypeScope {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
public RefTypeOrTPHOrWildcardOrGeneric getReturnType() {
|
||||||
RefType type = (RefType) this.getType();
|
//RefType type = (RefType) this.getType();
|
||||||
return type.getParaList().get(0);
|
//return type.getParaList().get(0);
|
||||||
|
return methodBody.getType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,17 @@ String var;
|
|||||||
|
|
||||||
methode(){
|
methode(){
|
||||||
return () -> (f) -> {
|
return () -> (f) -> {
|
||||||
f.apply(this,var);
|
f.apply(this, var);
|
||||||
return var;
|
return var;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Fun1<A,B>{
|
||||||
|
A apply(B b);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Fun2<A,B,C>{
|
||||||
|
A apply(B b, C c);
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package parser;
|
package parser;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.ClassNotFoundException;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package parser;
|
package parser;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.ClassNotFoundException;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
@ -14,7 +15,7 @@ public class FieldTest {
|
|||||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException, ClassNotFoundException {
|
public void test() throws IOException, ClassNotFoundException, ClassNotFoundException {
|
||||||
|
|
||||||
JavaTXParser parser = new JavaTXParser();
|
JavaTXParser parser = new JavaTXParser();
|
||||||
SourceFile f = parser.parse(new File(rootDirectory + "FieldVarTest.jav"));
|
SourceFile f = parser.parse(new File(rootDirectory + "FieldVarTest.jav"));
|
||||||
|
@ -30,10 +30,7 @@ public class GeneralParserTest{
|
|||||||
filenames.add("ImportTest.jav");
|
filenames.add("ImportTest.jav");
|
||||||
filenames.add("CastTest.jav");
|
filenames.add("CastTest.jav");
|
||||||
filenames.add("StatementsTest.jav");
|
filenames.add("StatementsTest.jav");
|
||||||
<<<<<<< HEAD
|
|
||||||
//filenames.add("Methods.jav");
|
//filenames.add("Methods.jav");
|
||||||
=======
|
|
||||||
>>>>>>> f05222fb563282945ba395047f54f6b3059b10c5
|
|
||||||
filenames.add("ImportTestGeneric.jav");
|
filenames.add("ImportTestGeneric.jav");
|
||||||
filenames.add("CastTest.jav");
|
filenames.add("CastTest.jav");
|
||||||
//filenames.add("BoundedParameter.jav");
|
//filenames.add("BoundedParameter.jav");
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package parser;
|
package parser;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.RunParser;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package typeinference;
|
package typeinference;
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.parser.ClassNotFoundException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -18,8 +19,8 @@ public class JavaTXCompilerTest {
|
|||||||
JavaTXCompiler compiler = new JavaTXCompiler();
|
JavaTXCompiler compiler = new JavaTXCompiler();
|
||||||
//compiler.parse(new File(rootDirectory+"Methods.jav"));
|
//compiler.parse(new File(rootDirectory+"Methods.jav"));
|
||||||
//compiler.parse(new File(rootDirectory+"Generics.jav"));
|
//compiler.parse(new File(rootDirectory+"Generics.jav"));
|
||||||
compiler.parse(new File(rootDirectory+"MethodsEasy.jav"));
|
//compiler.parse(new File(rootDirectory+"MethodsEasy.jav"));
|
||||||
//compiler.parse(new File(rootDirectory+"Lambda.jav"));
|
compiler.parse(new File(rootDirectory+"Lambda.jav"));
|
||||||
compiler.typeInference();
|
compiler.typeInference();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user