forked from JavaTX/JavaCompilerCore
Implementierung neuer ASTGen fortgesetzt
This commit is contained in:
parent
3bdc3b764d
commit
1cf23bec90
@ -19,6 +19,8 @@ import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassOrInterfaceModifierContext;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ClassorinterfacedeclContext;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberdeclContext;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.MemberfieldContext;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.ModifierContext;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.NoclassorinterfaceContext;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.SrcfileContext;
|
||||
@ -153,7 +155,7 @@ public class ASTGen {
|
||||
} else {
|
||||
superClass = new RefType(ASTFactory.createObjectClass().getClassName(), ctx.getStart());
|
||||
}
|
||||
// List<Field> fielddecl = convertFields(ctx.classBody(), generics);
|
||||
List<Field> fielddecl = convertFields(ctx.classBody(), generics);
|
||||
}
|
||||
|
||||
private RefType convert(Java17Parser.TypeTypeContext typeType) {
|
||||
@ -179,19 +181,52 @@ public class ASTGen {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int convertModifier(Java17Parser.ClassOrInterfaceModifierContext ctx) {
|
||||
int ret = 0;
|
||||
if (ctx.annotation() != null) {
|
||||
return ret;
|
||||
} else {
|
||||
for (String m : this.allmodifiers.keySet()) {
|
||||
if (ctx.getText().contains(m))
|
||||
ret += allmodifiers.get(m);
|
||||
private List<Field> convertFields(Java17Parser.ClassBodyContext classBodyContext, GenericsRegistry generics) {
|
||||
List<Field> ret = new ArrayList<>();
|
||||
for (Java17Parser.ClassBodyDeclarationContext classBody : classBodyContext.classBodyDeclaration()) {
|
||||
if (classBody instanceof MemberdeclContext) {
|
||||
MemberdeclContext memberdecl = new MemberdeclContext(classBody);
|
||||
int modifiers = 0;
|
||||
for (ModifierContext mod : memberdecl.modifier()) {
|
||||
modifiers += convert(mod);
|
||||
}
|
||||
if (memberdecl.memberDeclaration() instanceof MemberfieldContext) {
|
||||
ret.addAll(
|
||||
convert(new MemberfieldContext(memberdecl.memberDeclaration()).fieldDeclaration(), modifiers, generics));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<? extends Field> convert(Java17Parser.FieldDeclarationContext fieldDeclContext, int modifiers,
|
||||
GenericsRegistry generics) {
|
||||
List<Field> ret = new ArrayList<>();
|
||||
RefTypeOrTPHOrWildcardOrGeneric fieldType;
|
||||
if (fieldDeclContext.typeType() != null) {
|
||||
// TODO: fieldType = TypeGenerator.convert()
|
||||
}
|
||||
}
|
||||
|
||||
private int convert(Java17Parser.ClassOrInterfaceModifierContext ctx) {
|
||||
if (ctx.annotation() != null)
|
||||
return 0;
|
||||
return convertModifier(ctx.getText());
|
||||
}
|
||||
|
||||
private int convert(Java17Parser.ModifierContext ctx) {
|
||||
return convertModifier(ctx.getText());
|
||||
}
|
||||
|
||||
public int convertModifier(String modifier) {
|
||||
int ret = 0;
|
||||
for (String m : this.allmodifiers.keySet()) {
|
||||
if (modifier.contains(m))
|
||||
ret += allmodifiers.get(m);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private GenericsRegistry createGenerics(Java17Parser.GenericDeclarationListContext ctx, JavaClassName parentClass,
|
||||
String parentMethod, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
|
||||
|
@ -26,7 +26,7 @@ import java.util.regex.Pattern;
|
||||
public class TypeGenerator {
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(
|
||||
Java17Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg,
|
||||
Java17Parser.ClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg,
|
||||
GenericsRegistry generics) {
|
||||
Java17Parser.TypeArgumentsContext arguments = null;
|
||||
/*
|
||||
@ -92,24 +92,28 @@ public class TypeGenerator {
|
||||
return convertTypeName(name, arguments, unannClassOrInterfaceTypeContext.getStart(), reg, generics);
|
||||
}
|
||||
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.UnannTypeContext unannTypeContext,
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java17Parser.TypeTypeContext typeContext,
|
||||
JavaClassRegistry reg, GenericsRegistry genericsRegistry) {
|
||||
if (unannTypeContext.unannPrimitiveType() != null) {
|
||||
if (unannTypeContext.unannPrimitiveType().getText().equals("boolean")) {
|
||||
return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), unannTypeContext.getStart());
|
||||
if (typeContext.primitiveType() != null) {
|
||||
if (typeContext.primitiveType().getText().equals("boolean")) {
|
||||
return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), typeContext.getStart());
|
||||
} else {
|
||||
Java17Parser.NumericTypeContext numericType = unannTypeContext.unannPrimitiveType().numericType();
|
||||
/*
|
||||
* Nicht benötigt, wenn danach eine Exception erstellt wird
|
||||
* Java17Parser.NumericTypeContext numericType =
|
||||
* typeContext.unannPrimitiveType().numericType();
|
||||
*/
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
} else if (unannTypeContext.unannReferenceType().unannArrayType() != null) {
|
||||
} else if (!typeContext.LBRACK().isEmpty()) { // ArrayType über eckige Klammer prüfen
|
||||
// System.out.println(unannTypeContext.getText());
|
||||
throw new NotImplementedException();
|
||||
} else if (unannTypeContext.unannReferenceType().unannTypeVariable() != null) {
|
||||
} else if (typeContext.classOrInterfaceType() != null) {
|
||||
JavaClassName name = reg
|
||||
.getName(unannTypeContext.unannReferenceType().unannTypeVariable().Identifier().toString());
|
||||
return new RefType(name, unannTypeContext.getStart());
|
||||
.getName(typeContext.classOrInterfaceType().typeIdentifier().getText());
|
||||
return new RefType(name, typeContext.getStart());
|
||||
}
|
||||
return TypeGenerator.convert(unannTypeContext.unannReferenceType().unannClassOrInterfaceType(), reg,
|
||||
return TypeGenerator.convert(typeContext.classOrInterfaceType(), reg,
|
||||
genericsRegistry);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user