Fix gtvs being strange, #301
This commit is contained in:
parent
786e0a7a23
commit
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.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.sql.Array;
|
import java.sql.Array;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -130,8 +131,10 @@ public class JavaTXCompiler {
|
|||||||
|
|
||||||
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
public ConstraintSet<Pair> getConstraints() throws ClassNotFoundException, IOException {
|
||||||
Set<ClassOrInterface> allClasses = new HashSet<>();// environment.getAllAvailableClasses();
|
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(objectClass);
|
||||||
|
allClasses.add(recordClass);
|
||||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
for (Entry<File, SourceFile> source : sourceFiles.entrySet()) {
|
for (Entry<File, SourceFile> source : sourceFiles.entrySet()) {
|
||||||
var importedClasses = new ArrayList<ClassOrInterface>();
|
var importedClasses = new ArrayList<ClassOrInterface>();
|
||||||
@ -184,17 +187,17 @@ public class JavaTXCompiler {
|
|||||||
while (paraIt.hasNext()) {
|
while (paraIt.hasNext()) {
|
||||||
gtvs.put(tvarVarIt.next().getName(), paraIt.next());
|
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
|
for (Method m : superclass.getMethods()) {
|
||||||
// werden
|
if (m.isInherited || Modifier.isStatic(m.modifier)) continue;
|
||||||
while (methodIt.hasNext()) {
|
// TODO: Add gtvs from method itself
|
||||||
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());
|
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,
|
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
|
||||||
// new GenericDeclarationList(newGenericsList,
|
// new GenericDeclarationList(newGenericsList,
|
||||||
// ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
// ((GenericDeclarationList)m.getGenerics()).getOffset()),
|
||||||
(GenericDeclarationList) m.getGenerics(), m.getOffset(), true));
|
(GenericDeclarationList) m.getGenerics(), m.getOffset(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
cl.setMethodsAdded();
|
cl.setMethodsAdded();
|
||||||
|
@ -128,7 +128,6 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
public List<Method> getMethods() {
|
public List<Method> getMethods() {
|
||||||
return this.methods;
|
return this.methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* public RefType getType() { return generateTypeOfClass(this.getClassName(), this.getGenerics(), this.getOffset()); }
|
* public RefType getType() { return generateTypeOfClass(this.getClassName(), this.getGenerics(), this.getOffset()); }
|
||||||
*/
|
*/
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree;
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
@ -93,4 +94,17 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package de.dhbwstuttgart.typeinference.assumptions;
|
|||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Iterators;
|
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.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
@ -33,10 +35,11 @@ public class TypeInferenceBlockInformation extends TypeInferenceInformation {
|
|||||||
|
|
||||||
public ClassOrInterface getSuperClass() {
|
public ClassOrInterface getSuperClass() {
|
||||||
for (var clazz : getAvailableClasses()) {
|
for (var clazz : getAvailableClasses()) {
|
||||||
|
System.out.println(currentClass.getSuperClass().getName());
|
||||||
if (clazz.getClassName().equals(currentClass.getSuperClass().getName()))
|
if (clazz.getClassName().equals(currentClass.getSuperClass().getName()))
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
return null;
|
throw new DebugException("Class has no superclass!");
|
||||||
}
|
}
|
||||||
public TypeScope getCurrentTypeScope() {
|
public TypeScope getCurrentTypeScope() {
|
||||||
return methodContext;
|
return methodContext;
|
||||||
|
@ -980,6 +980,7 @@ public class TestComplete {
|
|||||||
var clazz = classFiles.get("Bug298");
|
var clazz = classFiles.get("Bug298");
|
||||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBug300() throws Exception {
|
public void testBug300() throws Exception {
|
||||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug300.jav");
|
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug300.jav");
|
||||||
@ -987,4 +988,11 @@ public class TestComplete {
|
|||||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
assertEquals(clazz.getDeclaredMethod("m").invoke(instance), "Base");
|
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