Work on issue
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 2m53s
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 2m53s
This commit is contained in:
parent
e6321ff8bc
commit
c2ee12397f
@ -288,7 +288,7 @@ public class JavaTXCompiler {
|
|||||||
// urm.addUnifyResultListener(resultListener);
|
// urm.addUnifyResultListener(resultListener);
|
||||||
try {
|
try {
|
||||||
logFile = logFile == null ? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName())) : logFile;
|
logFile = logFile == null ? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName())) : logFile;
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, getClassLoader());
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, getClassLoader(), this);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
urm = new UnifyResultModel(cons, finiteClosure);
|
urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
urm.addUnifyResultListener(resultListener);
|
urm.addUnifyResultListener(resultListener);
|
||||||
@ -426,7 +426,7 @@ public class JavaTXCompiler {
|
|||||||
var logFolder = new File(System.getProperty("user.dir") + "/logFiles/");
|
var logFolder = new File(System.getProperty("user.dir") + "/logFiles/");
|
||||||
if (log) logFolder.mkdirs();
|
if (log) logFolder.mkdirs();
|
||||||
Writer logFile = log ? new FileWriter(new File(logFolder, "log_" + sourceFiles.keySet().iterator().next().getName())) : new OutputStreamWriter(new NullOutputStream());
|
Writer logFile = log ? new FileWriter(new File(logFolder, "log_" + sourceFiles.keySet().iterator().next().getName())) : new OutputStreamWriter(new NullOutputStream());
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader, this);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
System.out.println("xxx1");
|
System.out.println("xxx1");
|
||||||
|
@ -6,6 +6,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.SourceLoc;
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
@ -29,7 +30,7 @@ public class UnifyTypeFactory {
|
|||||||
|
|
||||||
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
||||||
|
|
||||||
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses, Writer logFile, ClassLoader classLoader) throws ClassNotFoundException {
|
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses, Writer logFile, ClassLoader classLoader, JavaTXCompiler compiler) throws ClassNotFoundException {
|
||||||
/*
|
/*
|
||||||
Die transitive Hülle muss funktionieren.
|
Die transitive Hülle muss funktionieren.
|
||||||
Man darf schreiben List<A> extends AL<A>
|
Man darf schreiben List<A> extends AL<A>
|
||||||
@ -40,7 +41,7 @@ public class UnifyTypeFactory {
|
|||||||
Generell dürfen sie immer die gleichen Namen haben.
|
Generell dürfen sie immer die gleichen Namen haben.
|
||||||
TODO: die transitive Hülle bilden
|
TODO: die transitive Hülle bilden
|
||||||
*/
|
*/
|
||||||
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses, classLoader), logFile);
|
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses, classLoader), logFile, compiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr, SourceLoc location){
|
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr, SourceLoc location){
|
||||||
@ -64,15 +65,15 @@ public class UnifyTypeFactory {
|
|||||||
* ASTType -> UnifyType
|
* ASTType -> UnifyType
|
||||||
*/
|
*/
|
||||||
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){
|
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){
|
||||||
if(t instanceof GenericRefType){
|
if (t instanceof GenericRefType){
|
||||||
return UnifyTypeFactory.convert((GenericRefType)t, innerType);
|
return UnifyTypeFactory.convert((GenericRefType)t, innerType);
|
||||||
}else if(t instanceof TypePlaceholder){
|
} else if (t instanceof TypePlaceholder){
|
||||||
return UnifyTypeFactory.convert((TypePlaceholder)t, innerType);
|
return UnifyTypeFactory.convert((TypePlaceholder)t, innerType);
|
||||||
}else if(t instanceof ExtendsWildcardType){
|
} else if (t instanceof ExtendsWildcardType){
|
||||||
return UnifyTypeFactory.convert((ExtendsWildcardType)t, innerType);
|
return UnifyTypeFactory.convert((ExtendsWildcardType)t, innerType);
|
||||||
}else if(t instanceof SuperWildcardType){
|
} else if (t instanceof SuperWildcardType) {
|
||||||
return UnifyTypeFactory.convert((SuperWildcardType)t, innerType);
|
return UnifyTypeFactory.convert((SuperWildcardType) t, innerType);
|
||||||
}else if(t instanceof RefType){
|
} else if (t instanceof RefType){
|
||||||
return UnifyTypeFactory.convert((RefType)t, innerType);
|
return UnifyTypeFactory.convert((RefType)t, innerType);
|
||||||
}
|
}
|
||||||
//Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist
|
//Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.interfaces;
|
package de.dhbwstuttgart.typeinference.unify.interfaces;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -73,5 +74,8 @@ public interface IFiniteClosure {
|
|||||||
public Set<UnifyType> getChildren(UnifyType t);
|
public Set<UnifyType> getChildren(UnifyType t);
|
||||||
public Set<UnifyType> getAllTypesByName(String typeName);
|
public Set<UnifyType> getAllTypesByName(String typeName);
|
||||||
|
|
||||||
|
public boolean isFunctionalInterface(ReferenceType t);
|
||||||
|
public List<UnifyType> getFunctionalInterfaceTypeArguments(ReferenceType t);
|
||||||
|
|
||||||
public int compare(UnifyType rhsType, UnifyType rhsType2, PairOperator pairop);
|
public int compare(UnifyType rhsType, UnifyType rhsType2, PairOperator pairop);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify.model;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -20,7 +21,10 @@ import com.google.common.collect.Ordering;
|
|||||||
|
|
||||||
//PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt
|
//PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt
|
||||||
//muss greater noch ersetzt werden ja erledigt 18--04-05
|
//muss greater noch ersetzt werden ja erledigt 18--04-05
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.parser.SourceLoc;
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
|
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.Match;
|
import de.dhbwstuttgart.typeinference.unify.Match;
|
||||||
@ -37,6 +41,8 @@ import org.antlr.v4.runtime.Token;
|
|||||||
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
||||||
implements IFiniteClosure {
|
implements IFiniteClosure {
|
||||||
|
|
||||||
|
final JavaTXCompiler compiler;
|
||||||
|
|
||||||
Writer logFile;
|
Writer logFile;
|
||||||
static Boolean log = false;
|
static Boolean log = false;
|
||||||
public void setLogTrue() {
|
public void setLogTrue() {
|
||||||
@ -71,7 +77,8 @@ implements IFiniteClosure {
|
|||||||
/**
|
/**
|
||||||
* Creates a new instance using the inheritance tree defined in the pairs.
|
* Creates a new instance using the inheritance tree defined in the pairs.
|
||||||
*/
|
*/
|
||||||
public FiniteClosure(Set<UnifyPair> pairs, Writer logFile) {
|
public FiniteClosure(Set<UnifyPair> pairs, Writer logFile, JavaTXCompiler compiler) {
|
||||||
|
this.compiler = compiler;
|
||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
this.pairs = new HashSet<>(pairs);
|
this.pairs = new HashSet<>(pairs);
|
||||||
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
|
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
|
||||||
@ -596,7 +603,22 @@ implements IFiniteClosure {
|
|||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
return strInheritanceGraph.get(typeName).stream().map(x -> x.getContent()).collect(Collectors.toCollection(HashSet::new));
|
return strInheritanceGraph.get(typeName).stream().map(x -> x.getContent()).collect(Collectors.toCollection(HashSet::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFunctionalInterface(ReferenceType t) {
|
||||||
|
return compiler.getClass(new JavaClassName(t.getName())).isFunctionalInterface();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UnifyType> getFunctionalInterfaceTypeArguments(ReferenceType t) {
|
||||||
|
var clazz = compiler.getClass(new JavaClassName(t.getName()));
|
||||||
|
var intfMethod = clazz.getMethods().stream().filter(m -> Modifier.isAbstract(m.modifier)).findFirst().orElseThrow();
|
||||||
|
var args = new ArrayList<UnifyType>();
|
||||||
|
args.add(UnifyTypeFactory.convert(intfMethod.getReturnType(), false));
|
||||||
|
intfMethod.getParameterList().getFormalparalist().forEach(param -> args.add(UnifyTypeFactory.convert(param.getType(), false)));
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<UnifyType> getLeftHandedType(String typeName) {
|
public Optional<UnifyType> getLeftHandedType(String typeName) {
|
||||||
if(!strInheritanceGraph.containsKey(typeName))
|
if(!strInheritanceGraph.containsKey(typeName))
|
||||||
|
Loading…
Reference in New Issue
Block a user