modified: ../src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: ../src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Vererbung korrigiert
This commit is contained in:
parent
ed1bb44089
commit
850af6a6ae
@ -135,7 +135,16 @@ public class JavaTXCompiler {
|
|||||||
//sf enthaelt neues Source-File, neue Klassen-Objekte und neue
|
//sf enthaelt neues Source-File, neue Klassen-Objekte und neue
|
||||||
//ArrayListen-Objekte fuer Fields, Construktoren und Methoden
|
//ArrayListen-Objekte fuer Fields, Construktoren und Methoden
|
||||||
//Alle anderen Objekte werden nur kopiert.
|
//Alle anderen Objekte werden nur kopiert.
|
||||||
sf.KlassenVektor.forEach(cl -> {
|
SourceFile sf_new = sf;
|
||||||
|
sf.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, importedClasses, objectClass));
|
||||||
|
allClasses.addAll(sf.getClasses());
|
||||||
|
}
|
||||||
|
allClasses.addAll(importedClasses);
|
||||||
|
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addMethods(SourceFile sf, ClassOrInterface cl, List<ClassOrInterface> importedClasses, ClassOrInterface objectClass) {
|
||||||
|
if (!cl.areMethodsAdded()) {
|
||||||
ClassOrInterface superclass = null;
|
ClassOrInterface superclass = null;
|
||||||
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
|
||||||
superclass = objectClass;
|
superclass = objectClass;
|
||||||
@ -147,10 +156,19 @@ public class JavaTXCompiler {
|
|||||||
if (optSuperclass.isPresent()) {
|
if (optSuperclass.isPresent()) {
|
||||||
superclass = optSuperclass.get();
|
superclass = optSuperclass.get();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
optSuperclass =
|
||||||
|
sf.KlassenVektor.stream().filter(x -> x.getClassName().equals(
|
||||||
|
cl.getSuperClass().getName())).findFirst();
|
||||||
|
if (optSuperclass.isPresent()) {
|
||||||
|
superclass = optSuperclass.get();
|
||||||
|
addMethods(sf, superclass, importedClasses, objectClass);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
//throw new ClassNotFoundException("");
|
//throw new ClassNotFoundException("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
Iterator<RefTypeOrTPHOrWildcardOrGeneric> paraIt= cl.getSuperClass().getParaList().iterator();
|
||||||
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
Iterator<GenericTypeVar> tvarVarIt = superclass.getGenerics().iterator();
|
||||||
|
|
||||||
@ -173,13 +191,12 @@ public class JavaTXCompiler {
|
|||||||
m.getOffset()));
|
m.getOffset()));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
allClasses.addAll(sf.getClasses());
|
|
||||||
}
|
}
|
||||||
allClasses.addAll(importedClasses);
|
cl.setMethodsAdded();
|
||||||
return new TYPE(sourceFiles.values(), allClasses).getConstraints();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
public List<ClassOrInterface> getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
|
||||||
//PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
|
//PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
|
||||||
//List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
//List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
|
@ -23,6 +23,7 @@ import java.util.Optional;
|
|||||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||||
*/
|
*/
|
||||||
public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||||
|
private Boolean methodAdded = false; //wird benoetigt bei in JavaTXCompiler.getConstraints()
|
||||||
protected int modifiers;
|
protected int modifiers;
|
||||||
protected JavaClassName name;
|
protected JavaClassName name;
|
||||||
private List<Field> fields = new ArrayList<>();
|
private List<Field> fields = new ArrayList<>();
|
||||||
@ -68,6 +69,16 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
this.constructors = new ArrayList<>(cl.constructors);
|
this.constructors = new ArrayList<>(cl.constructors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gets if it is added
|
||||||
|
public Boolean areMethodsAdded() {
|
||||||
|
return methodAdded;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Sets taht it is added
|
||||||
|
public void setMethodsAdded() {
|
||||||
|
methodAdded = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Gets class name
|
// Gets class name
|
||||||
public JavaClassName getClassName(){
|
public JavaClassName getClassName(){
|
||||||
return this.name;
|
return this.name;
|
||||||
|
@ -641,6 +641,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
x.getPairOp() == PairOperator.EQUALSDOT)
|
x.getPairOp() == PairOperator.EQUALSDOT)
|
||||||
.map(x -> ((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
|
.map(x -> ((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
|
||||||
.findAny();
|
.findAny();
|
||||||
|
//Fuer Operatorenaufrufe wird variance auf 2 gesetzt
|
||||||
|
//Es werden alle Elemente des Kartesischen Produkts abgearbeitet
|
||||||
variance = optVariance.isPresent() ? optVariance.get() : 2;
|
variance = optVariance.isPresent() ? optVariance.get() : 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user