Der Returntyp des Konstruktors wurde mit TypePlaceholders als Parameter bestimmt.
Korrigiert: TypePlaceholders durch GenericRefType ersetzt modified: ../../../../main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java Methode generateTypeOfThisClass eingefuegt. Macht aus der atuellen Klasse den zugehoerigen RefType In getConstructors in new MethodAssumption den ofType-Parameter (Typeplaceholders) durch cl.generateTypeOfThisClass() ersetzt. Dadurch werden GenericRefType in den Typ eingefuegt.
This commit is contained in:
parent
9fc558c21a
commit
33e9b87562
@ -2,8 +2,10 @@ package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
@ -117,6 +119,18 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
||||
return new RefType(name, params, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return die aktuelle Klasse als RefType
|
||||
*/
|
||||
public RefType generateTypeOfThisClass(){
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
for(GenericTypeVar genericTypeVar : this.getGenerics()){
|
||||
//params.add(genericTypeVar.getTypePlaceholder());
|
||||
params.add(new GenericRefType(genericTypeVar.getName(), new NullToken()));
|
||||
}
|
||||
return new RefType(name, params, new NullToken());
|
||||
}
|
||||
/**
|
||||
* Die Superklasse im Kontext dieser ClassOrInterface
|
||||
* Das bedeutet, dass generische Variablen als GenericRefTypes dargestellt sind
|
||||
|
@ -687,7 +687,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
if(cl.getClassName().equals(ofType.getName())){
|
||||
for(Method m : cl.getConstructors()){
|
||||
if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){
|
||||
ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(),
|
||||
ret.add(new MethodAssumption(cl, cl.generateTypeOfThisClass(), convertParams(m.getParameterList(),
|
||||
info), createTypeScope(cl, m), m.isInherited));
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,10 @@ public class AllgemeinTest {
|
||||
//String className = "TestSubTypless";
|
||||
//String className = "addList";
|
||||
//String className = "M";
|
||||
String className = "Wildcard_Andi";
|
||||
//String className = "Wildcard_Andi";
|
||||
//String className = "Box";
|
||||
//String className = "Box_Main";
|
||||
String className ="wildcardPair";
|
||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav";
|
||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||
|
13
src/test/resources/AllgemeinTest/Box.jav
Normal file
13
src/test/resources/AllgemeinTest/Box.jav
Normal file
@ -0,0 +1,13 @@
|
||||
class Box<A>{
|
||||
void m(A a){}
|
||||
}
|
||||
|
||||
class B { }
|
||||
|
||||
class Box_Main extends B {
|
||||
|
||||
m(b) {
|
||||
b.m(new Box_Main());
|
||||
b.m(new B());
|
||||
}
|
||||
}
|
13
src/test/resources/AllgemeinTest/Box_Main.jav
Normal file
13
src/test/resources/AllgemeinTest/Box_Main.jav
Normal file
@ -0,0 +1,13 @@
|
||||
import java.lang.Object;
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
class B { }
|
||||
|
||||
class Box_Main extends B {//Fehler Bugzilla Bug 230
|
||||
|
||||
m(b) {
|
||||
b.f = new Box_Main();
|
||||
b.f = new B();
|
||||
}
|
||||
}
|
@ -2,6 +2,12 @@ class Pair<T, U> {
|
||||
T x;
|
||||
U y;
|
||||
|
||||
public Pair() { }
|
||||
public Pair(T x, U y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public T fst () {
|
||||
return x;
|
||||
}
|
||||
|
@ -3,6 +3,6 @@ class Wildcard_Andi {
|
||||
Test<? extends A> ex = new Test<>();
|
||||
|
||||
Test<? super A> sup = new Test<>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
22
src/test/resources/AllgemeinTest/wildcardPair.jav
Normal file
22
src/test/resources/AllgemeinTest/wildcardPair.jav
Normal file
@ -0,0 +1,22 @@
|
||||
import java.util.List;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Object;
|
||||
import java.lang.Boolean;
|
||||
|
||||
class wildcardPair {
|
||||
|
||||
make(l) {
|
||||
var p = new Pair(l.get(0), l.get(1));
|
||||
return p;
|
||||
}
|
||||
//<X>Boolean compare(Pair<X, X> x) { return true; }
|
||||
void m(l) {
|
||||
Object o = l.get(0);
|
||||
|
||||
//Pair<? extends Object, ? extends Object> p;
|
||||
//List<?> b;
|
||||
//this.compare(p); //1, type incorrect
|
||||
make(l);
|
||||
//this.compare(this.make(b)); //2, OK
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user