diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java index d5dba757..f901036f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -80,7 +80,8 @@ public class BytecodeGen implements ASTVisitor { byte[] bytecode; HashMap classFiles; - ArrayList methodNameAndParamsT = new ArrayList<>(); + private final ArrayList methodNameAndParamsT = new ArrayList<>(); + private final ArrayList fieldNameAndParamsT = new ArrayList<>(); private HashMap simplifyResults = new HashMap<>(); private List> simplifyResultsList = new ArrayList<>(); @@ -501,7 +502,14 @@ public class BytecodeGen implements ASTVisitor { System.out.println(sig); if(sig.charAt(sig.length()-1) != (";").charAt(0)) { sig +=";"; - } + } + String nameAndDesc = field.getName() + "%%" + des; + + if(fieldNameAndParamsT.contains(nameAndDesc)) + return; + + fieldNameAndParamsT.add(nameAndDesc); + cw.visitField(field.modifier, field.getName(), des, sig, null); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index e9f8e257..66723205 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -28,6 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.result.GenericInsertPair; +import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultSet; /** @@ -44,7 +45,7 @@ public class TPHExtractor extends AbstractASTWalker { boolean inLocalOrParam = false; public final ArrayList ListOfMethodsAndTph = new ArrayList<>(); - final ArrayList allPairs = new ArrayList<>(); + final ArrayList> allPairs = new ArrayList<>(); public final ArrayList allCons = new ArrayList<>(); private ResultSet resultSet; @@ -97,7 +98,7 @@ public class TPHExtractor extends AbstractASTWalker { if (inMethod) methodAndTph.getPairs().add(ag); allPairs.add(ag); - TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS); + TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS); if(!containsConstraint(allCons,con)) allCons.add(con); // } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java index 94052f9c..dd7f5d60 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -237,7 +237,7 @@ public class Signature { if(resolved instanceof TypePlaceholder) { //resType.getAdditionalGenerics().forEach(ag ->{ resultSet.genIns.forEach(ag ->{ - TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS); + TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS); if(!contains(res,constr)) { res.add(constr); } @@ -249,7 +249,7 @@ public class Signature { if(resType2.resolvedType instanceof TypePlaceholder) { //resType2.getAdditionalGenerics().forEach(ag ->{ resultSet.genIns.forEach(ag ->{ - TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS); + TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS); if(!contains(res,constr)) { res.add(constr); } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java index e21f974c..c2c0210e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java @@ -2,14 +2,17 @@ package de.dhbwstuttgart.bytecode.utilities; import java.util.ArrayList; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.result.GenericInsertPair; +import de.dhbwstuttgart.typeinference.result.ResultPair; public class MethodAndTPH { private String name; private final ArrayList tphs = new ArrayList<>(); - private final ArrayList pairs = new ArrayList<>(); + //private final ArrayList pairs = new ArrayList<>(); + private final ArrayList> pairs = new ArrayList<>(); // tphs of local variables and parameters private final ArrayList localTphs = new ArrayList<>(); @@ -21,7 +24,10 @@ public class MethodAndTPH { return tphs; } - public ArrayList getPairs(){ +// public ArrayList getPairs(){ +// return pairs; +// } + public ArrayList> getPairs(){ return pairs; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java index 955c388b..8858f364 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -10,11 +10,11 @@ import java.util.stream.Collectors; public class ResultSet { public final Set results; - public Set genIns; + public Set> genIns; public ResultSet(Set results){ this.results = results; this.genIns = results.stream().filter(a -> a instanceof PairTPHsmallerTPH) - .map(b -> new GenericInsertPair( (TypePlaceholder)(b.getLeft()), (TypePlaceholder)(b.getRight()))) + //.map(b -> new GenericInsertPair( (TypePlaceholder)(b.getLeft()), (TypePlaceholder)(b.getRight()))) .collect(Collectors.toCollection(HashSet::new)); } diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 991db9c0..21d37347 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -18,7 +18,7 @@ public class MatrixOP extends Vector> { } } - mul = (m1, m2) -> { + public mul = (m1, m2) -> { var ret = new MatrixOP(); var i = 0; while(i < m1.size()) {