forked from JavaTX/JavaCompilerCore
Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bigRefactoring
This commit is contained in:
commit
240d57a8ba
4
pom.xml
4
pom.xml
@ -83,8 +83,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -57,48 +57,55 @@ public class FCGenerator {
|
||||
params.add(gtvs.get(gtv.getName()));
|
||||
}
|
||||
|
||||
Optional<ClassOrInterface> hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny();
|
||||
ClassOrInterface superClass;
|
||||
if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception
|
||||
{
|
||||
superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(forType.getSuperClass().getName().toString()));
|
||||
}else{
|
||||
superClass = hasSuperclass.get();
|
||||
}
|
||||
/*
|
||||
Die Parameter der superklasse müssen jetzt nach den Angaben in der Subklasse
|
||||
modifiziert werden
|
||||
Beispie: Matrix<A> extends Vector<Vector<A>>
|
||||
Den ersten Parameter mit Vector<A> austauschen und dort alle Generics zu den Typplaceholdern in gtvs austauschen
|
||||
*/
|
||||
//Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen
|
||||
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = forType.getSuperClass().getParaList().iterator();
|
||||
while(itGenParams.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
|
||||
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
|
||||
RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs));
|
||||
newGTVs.put(itGenParams.next().getName(), setSetType);
|
||||
}
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric superType = forType.getSuperClass().acceptTV(new TypeExchanger(newGTVs));
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric t1 = new RefType(forType.getClassName(), params, new NullToken());
|
||||
RefTypeOrTPHOrWildcardOrGeneric t2 = superType;
|
||||
|
||||
Pair ret = new Pair(t1, t2, PairOperator.SMALLER);
|
||||
|
||||
List<Pair> superTypes;
|
||||
//Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse:
|
||||
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
|
||||
superTypes = Arrays.asList(new Pair(ASTFactory.createObjectType(), ASTFactory.createObjectType(), PairOperator.SMALLER));
|
||||
}else{
|
||||
superTypes = getSuperTypes(superClass, availableClasses, newGTVs);
|
||||
}
|
||||
List<RefType> superClasses = new ArrayList<>();
|
||||
superClasses.add(forType.getSuperClass());
|
||||
superClasses.addAll(forType.getSuperInterfaces());
|
||||
|
||||
List<Pair> retList = new ArrayList<>();
|
||||
retList.add(ret);
|
||||
retList.addAll(superTypes);
|
||||
for(RefType superType : superClasses){
|
||||
Optional<ClassOrInterface> hasSuperclass = availableClasses.stream().filter(cl -> superType.getName().equals(cl.getClassName())).findAny();
|
||||
ClassOrInterface superClass;
|
||||
if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception
|
||||
{
|
||||
superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(superType.getName().toString()));
|
||||
}else{
|
||||
superClass = hasSuperclass.get();
|
||||
}
|
||||
/*
|
||||
Die Parameter der superklasse müssen jetzt nach den Angaben in der Subklasse
|
||||
modifiziert werden
|
||||
Beispie: Matrix<A> extends Vector<Vector<A>>
|
||||
Den ersten Parameter mit Vector<A> austauschen und dort alle Generics zu den Typplaceholdern in gtvs austauschen
|
||||
*/
|
||||
//Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen
|
||||
Iterator<GenericTypeVar> itGenParams = superClass.getGenerics().iterator();
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> itSetParams = superType.getParaList().iterator();
|
||||
while(itGenParams.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next();
|
||||
//In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen:
|
||||
RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs));
|
||||
newGTVs.put(itGenParams.next().getName(), setSetType);
|
||||
}
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric superRefType = superType.acceptTV(new TypeExchanger(newGTVs));
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric t1 = new RefType(forType.getClassName(), params, new NullToken());
|
||||
RefTypeOrTPHOrWildcardOrGeneric t2 = superRefType;
|
||||
|
||||
Pair ret = new Pair(t1, t2, PairOperator.SMALLER);
|
||||
|
||||
List<Pair> superTypes;
|
||||
//Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse:
|
||||
if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){
|
||||
superTypes = Arrays.asList(new Pair(ASTFactory.createObjectType(), ASTFactory.createObjectType(), PairOperator.SMALLER));
|
||||
}else{
|
||||
superTypes = getSuperTypes(superClass, availableClasses, newGTVs);
|
||||
}
|
||||
|
||||
retList.add(ret);
|
||||
retList.addAll(superTypes);
|
||||
}
|
||||
|
||||
return retList;
|
||||
}
|
||||
|
@ -203,20 +203,20 @@ public class SyntaxTreeGenerator{
|
||||
}
|
||||
|
||||
Boolean isInterface = false;
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces = convert(ctx.superinterfaces(), generics);
|
||||
List<RefType> implementedInterfaces = convert(ctx.superinterfaces(), generics);
|
||||
return new ClassOrInterface(modifiers, name, fielddecl, methods, konstruktoren, genericClassParameters, superClass,
|
||||
isInterface, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) {
|
||||
private List<RefType> 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<>();
|
||||
private List<RefType> convert(Java8Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) {
|
||||
List<RefType> ret = new ArrayList<>();
|
||||
for(Java8Parser.InterfaceTypeContext interfaceType : ctx.interfaceType()){
|
||||
ret.add(TypeGenerator.convert(interfaceType.classType(), reg, generics));
|
||||
ret.add((RefType) TypeGenerator.convert(interfaceType.classType(), reg, generics));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -400,7 +400,7 @@ public class SyntaxTreeGenerator{
|
||||
List<Field> fields = convertFields(ctx.interfaceBody());
|
||||
List<Method> methods = convertMethods(ctx.interfaceBody(), name, superClass, generics);
|
||||
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> extendedInterfaces = convert(ctx.extendsInterfaces(), generics);
|
||||
List<RefType> extendedInterfaces = convert(ctx.extendsInterfaces(), generics);
|
||||
|
||||
return new ClassOrInterface(modifiers, name, fields, methods, new ArrayList<>(),
|
||||
genericParams, superClass, true, extendedInterfaces, ctx.getStart());
|
||||
@ -423,7 +423,7 @@ public class SyntaxTreeGenerator{
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) {
|
||||
private List<RefType> convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) {
|
||||
if(extendsInterfacesContext == null)return new ArrayList<>();
|
||||
return convert(extendsInterfacesContext.interfaceTypeList(), generics);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -26,11 +27,11 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private RefType superClass;
|
||||
protected boolean isInterface;
|
||||
private List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces;
|
||||
private List<RefType> implementedInterfaces;
|
||||
private List<Constructor> constructors;
|
||||
|
||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||
RefType superClass, Boolean isInterface, List<? extends RefTypeOrTPHOrWildcardOrGeneric> implementedInterfaces, Token offset){
|
||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||
super(offset);
|
||||
this.modifiers = modifiers;
|
||||
this.name = name;
|
||||
@ -101,4 +102,8 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
public Collection<RefType> getSuperInterfaces() {
|
||||
return implementedInterfaces;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user