From 905dfd8a27e2e2c4b3aa79d15325460aaa75ce80 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 8 Feb 2021 00:15:25 +0100 Subject: [PATCH] modified: ../../../../main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java modified: ../../../../main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java --- .../dhbwstuttgart/bytecode/TPHExtractor.java | 29 +++++++++++++------ .../FamilyOfGeneratedGenerics.java | 4 +-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java index 7729eb88..d13ef5f4 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java @@ -69,6 +69,7 @@ public class TPHExtractor extends AbstractASTWalker { Boolean inMethod = false; boolean inLocalOrParamOrReturn = false; + Boolean inLambdaExpression = false; public final ArrayList ListOfMethodsAndTph = new ArrayList<>(); final ArrayList> allPairs = new ArrayList<>(); @@ -254,12 +255,19 @@ public class TPHExtractor extends AbstractASTWalker { inMethod = true; } + @Override + public void visit(LambdaExpression lambdaExpression) { + inLambdaExpression = true; + super.visit(lambdaExpression); + inLambdaExpression = false; + } + @Override public void visit(Assign assign) { super.visit(assign); RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(assign.rightSide.getType()).resolvedType; RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(assign.lefSide.getType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { + if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { if (right instanceof TypePlaceholder) { methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && @@ -292,6 +300,7 @@ public class TPHExtractor extends AbstractASTWalker { || (((ExpressionReceiver)methodCall.receiver).expr instanceof LocalVar) && nameToField.keySet().contains(fieldOrMethName = ((LocalVar)((ExpressionReceiver)methodCall.receiver).expr).name) ) + //LOKALE VARIABLEN MUESSE NOCH IN nameToField EINGETRAGEN WERDEN ) ) { @@ -309,7 +318,7 @@ public class TPHExtractor extends AbstractASTWalker { .forEach(x -> { RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType; RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { + if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { if (right instanceof TypePlaceholder) { methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && @@ -327,19 +336,21 @@ public class TPHExtractor extends AbstractASTWalker { @Override public void visit(Return aReturn) { super.visit(aReturn); - RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType; - RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType; - if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) { - if (right instanceof TypePlaceholder) { - methodAndTph.addPair(allPairs.stream().filter( + if (!inLambdaExpression) { + RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(aReturn.retexpr.getType()).resolvedType; + RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(methodAndTph.getReturnType()).resolvedType; + if (left instanceof TypePlaceholder && methodAndTph.getLocalTphs().contains(((TypePlaceholder)left).getName())) { + if (right instanceof TypePlaceholder) { + methodAndTph.addPair(allPairs.stream().filter( p -> (p.getLeft() instanceof TypePlaceholder && p.getRight() instanceof TypePlaceholder) && ((TypePlaceholder)p.getLeft()).getName().equals(((TypePlaceholder)left).getName()) && ((TypePlaceholder)p.getRight()).getName().equals(((TypePlaceholder)right).getName()) ).findFirst() .get()); - } - } + } + } + } } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java index 77d17f00..9de58c59 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java @@ -69,9 +69,9 @@ public class FamilyOfGeneratedGenerics { ArrayList> methodConstraints1Pairs, List listOfMethodsAndTph) { List cs_m = new ArrayList<>(); - List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); + //List methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs); - List methodConstraints1prime = + List methodConstraints1 = methodConstraints1Pairs.stream() .map(p -> new MethodConstraint(p.getLeft().getName(), p.getRight().getName(), Relation.EXTENDS)) .collect(Collectors.toList());