modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java

modified:   src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/Method.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/SourceFile.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java
AndConstraints einer Methode in Methode.java und iin MethodAndTPH.java eingefuegt
	modified:   src/test/resources/insertGenericsJav/TestAny.jav
This commit is contained in:
pl@gohorb.ba-horb.de 2021-02-19 13:58:48 +01:00
parent ab99889c3c
commit 7e35e09c47
6 changed files with 31 additions and 6 deletions

View File

@ -185,7 +185,7 @@ public class TPHExtractor extends AbstractASTWalker {
public void visit(Method method) { public void visit(Method method) {
inMethod = true; inMethod = true;
String id = MethodUtility.createID(resolver,method); String id = MethodUtility.createID(resolver,method);
methodAndTph = new MethodAndTPH(id); methodAndTph = new MethodAndTPH(id, method.getConstraints());
inLocalOrParamOrReturn = true; inLocalOrParamOrReturn = true;
method.getReturnType().accept(this); method.getReturnType().accept(this);

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultPair;
@ -15,9 +16,15 @@ public class MethodAndTPH {
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>(); private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
// tphs of local variables and parameters // tphs of local variables and parameters
private final ArrayList<String> localTphs = new ArrayList<>(); private final ArrayList<String> localTphs = new ArrayList<>();
/*
* its Constraints
* eingefuegt PL 2021-02-15
*/
public final ConstraintSet constraints;
public MethodAndTPH(String name) { public MethodAndTPH(String name, ConstraintSet constraints) {
this.id = name; this.id = name;
this.constraints = constraints;
} }
public ArrayList<String> getTphs() { public ArrayList<String> getTphs() {

View File

@ -31,8 +31,14 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
private ExceptionList exceptionlist; private ExceptionList exceptionlist;
private GenericDeclarationList generics; private GenericDeclarationList generics;
private final RefTypeOrTPHOrWildcardOrGeneric returnType; private final RefTypeOrTPHOrWildcardOrGeneric returnType;
public final Boolean isInherited; public final Boolean isInherited;
/*
* its Constraints
* eingefuegt PL 2021-02-15
*/
public final ConstraintSet constraints = new ConstraintSet();
public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block, public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block,
GenericDeclarationList gtvDeclarations, Token offset) { GenericDeclarationList gtvDeclarations, Token offset) {
super(offset); super(offset);
@ -70,6 +76,10 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope
return this.returnType; return this.returnType;
} }
public ConstraintSet getConstraints() {
return this.constraints;
}
@Override @Override
public void accept(ASTVisitor visitor) { public void accept(ASTVisitor visitor) {
visitor.visit(this); visitor.visit(this);

View File

@ -45,6 +45,12 @@ public class SourceFile extends SyntaxTreeNode{
public List<ClassOrInterface> getClasses() { public List<ClassOrInterface> getClasses() {
return KlassenVektor; return KlassenVektor;
} }
public List<Method> getAllMethods() {
List<Method> ret = new ArrayList<>();
getClasses().forEach(cl -> ret.addAll(cl.getMethods()));
return ret;
}
@Override @Override
public void accept(ASTVisitor visitor) { public void accept(ASTVisitor visitor) {

View File

@ -32,8 +32,10 @@ public class TYPE {
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) { private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
ConstraintSet ret = new ConstraintSet(); ConstraintSet ret = new ConstraintSet();
ConstraintSet methConstrains;
for(Method m : cl.getMethods()){ for(Method m : cl.getMethods()){
ret.addAll(getConstraintsMethod(m,info, cl)); ret.addAll(methConstrains = getConstraintsMethod(m,info, cl));
m.constraints.addAll(methConstrains);
} }
for(Constructor m : cl.getConstructors()){ for(Constructor m : cl.getConstructors()){
ret.addAll(getConstraintsConstructor(m,info, cl)); ret.addAll(getConstraintsConstructor(m,info, cl));

View File

@ -1,4 +1,4 @@
class Example { class TestAny {
a; a;
b = a; b = a;
anyMethod() { anyMethod() {