Compare commits
2 Commits
786e0a7a23
...
c2ee12397f
Author | SHA1 | Date | |
---|---|---|---|
c2ee12397f | |||
e6321ff8bc |
4
resources/bytecode/javFiles/Bug301.jav
Normal file
4
resources/bytecode/javFiles/Bug301.jav
Normal file
@ -0,0 +1,4 @@
|
||||
import java.util.HashSet;
|
||||
|
||||
public class Bug301<A> extends HashSet<A> {
|
||||
}
|
@ -57,6 +57,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.sql.Array;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
@ -130,8 +131,10 @@ public class JavaTXCompiler {
|
||||
|
||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||
Set<ClassOrInterface> allClasses = new HashSet<>();// environment.getAllAvailableClasses();
|
||||
ClassOrInterface objectClass = ASTFactory.createClass(classLoader.loadClass(new JavaClassName("java.lang.Object").toString()));
|
||||
ClassOrInterface objectClass = ASTFactory.createClass(Object.class);
|
||||
var recordClass = ASTFactory.createClass(Record.class);
|
||||
allClasses.add(objectClass);
|
||||
allClasses.add(recordClass);
|
||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||
for (Entry<File, SourceFile> source : sourceFiles.entrySet()) {
|
||||
var importedClasses = new ArrayList<ClassOrInterface>();
|
||||
@ -184,17 +187,17 @@ public class JavaTXCompiler {
|
||||
while (paraIt.hasNext()) {
|
||||
gtvs.put(tvarVarIt.next().getName(), paraIt.next());
|
||||
}
|
||||
Iterator<Method> methodIt = superclass.getMethods().iterator();
|
||||
// TODO: PL 2020-05-06: Hier müssen ueberschriebene Methoden noch rausgefiltert
|
||||
// werden
|
||||
while (methodIt.hasNext()) {
|
||||
Method m = methodIt.next();
|
||||
ParameterList newParaList = new ParameterList(m.getParameterList().getFormalparalist().stream().map(fp -> fp.withType(fp.getType().acceptTV(new TypeExchanger(gtvs)))).collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
|
||||
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
||||
// new GenericDeclarationList(newGenericsList,
|
||||
// ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
||||
(GenericDeclarationList) m.getGenerics(), m.getOffset(), true));
|
||||
}
|
||||
|
||||
for (Method m : superclass.getMethods()) {
|
||||
if (m.isInherited || Modifier.isStatic(m.modifier)) continue;
|
||||
// TODO: Add gtvs from method itself
|
||||
|
||||
ParameterList newParaList = new ParameterList(m.getParameterList().getFormalparalist().stream().map(fp -> fp.withType(fp.getType().acceptTV(new TypeExchanger(gtvs)))).collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
|
||||
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
||||
// new GenericDeclarationList(newGenericsList,
|
||||
// ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
||||
(GenericDeclarationList) m.getGenerics(), m.getOffset(), true));
|
||||
}
|
||||
|
||||
}
|
||||
cl.setMethodsAdded();
|
||||
@ -285,7 +288,7 @@ public class JavaTXCompiler {
|
||||
// urm.addUnifyResultListener(resultListener);
|
||||
try {
|
||||
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);
|
||||
urm = new UnifyResultModel(cons, finiteClosure);
|
||||
urm.addUnifyResultListener(resultListener);
|
||||
@ -423,7 +426,7 @@ public class JavaTXCompiler {
|
||||
var logFolder = new File(System.getProperty("user.dir") + "/logFiles/");
|
||||
if (log) logFolder.mkdirs();
|
||||
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);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
System.out.println("xxx1");
|
||||
|
@ -128,7 +128,6 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
||||
public List<Method> getMethods() {
|
||||
return this.methods;
|
||||
}
|
||||
|
||||
/*
|
||||
* public RefType getType() { return generateTypeOfClass(this.getClassName(), this.getGenerics(), this.getOffset()); }
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
@ -93,4 +94,17 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Method method = (Method) o;
|
||||
return Objects.equals(name, method.name) && Objects.equals(parameterlist, method.parameterlist) && Objects.equals(returnType, method.returnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, parameterlist, returnType);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SourceLoc;
|
||||
@ -29,7 +30,7 @@ public class UnifyTypeFactory {
|
||||
|
||||
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.
|
||||
Man darf schreiben List<A> extends AL<A>
|
||||
@ -40,7 +41,7 @@ public class UnifyTypeFactory {
|
||||
Generell dürfen sie immer die gleichen Namen haben.
|
||||
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){
|
||||
@ -64,15 +65,15 @@ public class UnifyTypeFactory {
|
||||
* ASTType -> UnifyType
|
||||
*/
|
||||
public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){
|
||||
if(t instanceof GenericRefType){
|
||||
if (t instanceof GenericRefType){
|
||||
return UnifyTypeFactory.convert((GenericRefType)t, innerType);
|
||||
}else if(t instanceof TypePlaceholder){
|
||||
} else if (t instanceof TypePlaceholder){
|
||||
return UnifyTypeFactory.convert((TypePlaceholder)t, innerType);
|
||||
}else if(t instanceof ExtendsWildcardType){
|
||||
} else if (t instanceof ExtendsWildcardType){
|
||||
return UnifyTypeFactory.convert((ExtendsWildcardType)t, innerType);
|
||||
}else if(t instanceof SuperWildcardType){
|
||||
return UnifyTypeFactory.convert((SuperWildcardType)t, innerType);
|
||||
}else if(t instanceof RefType){
|
||||
} else if (t instanceof SuperWildcardType) {
|
||||
return UnifyTypeFactory.convert((SuperWildcardType) t, innerType);
|
||||
} else if (t instanceof RefType){
|
||||
return UnifyTypeFactory.convert((RefType)t, innerType);
|
||||
}
|
||||
//Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist
|
||||
|
@ -2,6 +2,8 @@ package de.dhbwstuttgart.typeinference.assumptions;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Iterators;
|
||||
import de.dhbwstuttgart.bytecode.CodeGenException;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
@ -33,10 +35,11 @@ public class TypeInferenceBlockInformation extends TypeInferenceInformation {
|
||||
|
||||
public ClassOrInterface getSuperClass() {
|
||||
for (var clazz : getAvailableClasses()) {
|
||||
System.out.println(currentClass.getSuperClass().getName());
|
||||
if (clazz.getClassName().equals(currentClass.getSuperClass().getName()))
|
||||
return clazz;
|
||||
}
|
||||
return null;
|
||||
throw new DebugException("Class has no superclass!");
|
||||
}
|
||||
public TypeScope getCurrentTypeScope() {
|
||||
return methodContext;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.typeinference.unify.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@ -73,5 +74,8 @@ public interface IFiniteClosure {
|
||||
public Set<UnifyType> getChildren(UnifyType t);
|
||||
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);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify.model;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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
|
||||
//muss greater noch ersetzt werden ja erledigt 18--04-05
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
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.Match;
|
||||
@ -37,6 +41,8 @@ import org.antlr.v4.runtime.Token;
|
||||
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
||||
implements IFiniteClosure {
|
||||
|
||||
final JavaTXCompiler compiler;
|
||||
|
||||
Writer logFile;
|
||||
static Boolean log = false;
|
||||
public void setLogTrue() {
|
||||
@ -71,7 +77,8 @@ implements IFiniteClosure {
|
||||
/**
|
||||
* 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.pairs = new HashSet<>(pairs);
|
||||
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
|
||||
@ -596,7 +603,22 @@ implements IFiniteClosure {
|
||||
return new HashSet<>();
|
||||
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
|
||||
public Optional<UnifyType> getLeftHandedType(String typeName) {
|
||||
if(!strInheritanceGraph.containsKey(typeName))
|
||||
|
@ -980,6 +980,7 @@ public class TestComplete {
|
||||
var clazz = classFiles.get("Bug298");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug300() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug300.jav");
|
||||
@ -987,4 +988,11 @@ public class TestComplete {
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
assertEquals(clazz.getDeclaredMethod("m").invoke(instance), "Base");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug301() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug301.jav");
|
||||
var clazz = classFiles.get("Bug301");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user