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

modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/bytecode/utilities/MethodAndTPH.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java
	modified:   src/test/java/constraintSimplify/FamilyOfGenerics.java
This commit is contained in:
pl@gohorb.ba-horb.de 2021-02-04 23:58:49 +01:00
parent 92bc3d626c
commit f270686b3c
5 changed files with 79 additions and 15 deletions

View File

@ -25,9 +25,11 @@ import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.statement.Assign;
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
@ -44,7 +46,12 @@ public class TPHExtractor extends AbstractASTWalker {
// Alle TPHs der Felder werden iKopf der Klasse definiert
// alle TPHs der Klasse: (TPH, is in Method?)
public final SourceFile sf;
/*
* ordnet den Methodennamen ihre jeweiligen Methodenrespraesentationen in der abstrakte Syntax zu
*/
public final HashMap<String, Method> nameToMeth;
public final HashMap<String, Boolean> allTPHS = new HashMap<>();
public final List<String> tphsClass = new ArrayList<>();
MethodAndTPH methodAndTph;
@ -193,7 +200,7 @@ public class TPHExtractor extends AbstractASTWalker {
public void visit(Method method) {
inMethod = true;
String id = MethodUtility.createID(resolver,method);
methodAndTph = new MethodAndTPH(id);
methodAndTph = new MethodAndTPH(id, (TypePlaceholder)method.getReturnType());
inLocalOrParamOrReturn = true;
method.getReturnType().accept(this);
@ -217,6 +224,24 @@ public class TPHExtractor extends AbstractASTWalker {
inMethod = true;
}
@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 (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());
}
}
}
@Override
public void visit(LocalVarDecl localVarDecl) {
// inLocalOrParamOrReturn = inMethod;
@ -228,20 +253,47 @@ public class TPHExtractor extends AbstractASTWalker {
@Override
public void visit(MethodCall methodCall) {
super.visit(methodCall);
if (nameToMeth.keySet().contains(methodCall.name)) {//Method-call of a method in the actuial Sourcefile
Iterator<FormalParameter> paraIt = nameToMeth.get(methodCall.name).getParameterList().iterator();
methodCall.getArgumentList()
.getArguments()
.forEach(x -> {
RefTypeOrTPHOrWildcardOrGeneric left = null;
RefTypeOrTPHOrWildcardOrGeneric right = null;
if ((left = x.getType()) instanceof TypePlaceholder) {
if ((right = paraIt.next().getType()) instanceof TypePlaceholder) {
methodAndTph.addPair(((TypePlaceholder)left).getName(),
((TypePlaceholder)left).getName());
RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType;
RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next().getType()).resolvedType;
if (left instanceof TypePlaceholder && methodAndTph.getTphs().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());
}
}
});
}
}
@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(
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());
}
}
}
@Override
public void visit(LocalVar localVar) {
// inLocalOrParamOrReturn = inMethod;

View File

@ -62,6 +62,7 @@ public class FamilyOfGeneratedGenerics {
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, List<ClassConstraint> cs_cl, HashMap<String, List<PairTphMethod<PositionFinder.Position, String>>> posOfTphs, List<MethodAndTPH> listOfMethodsAndTph) {
List<MethodConstraint> cs_m = new ArrayList<>();
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
//List<MethodConstraint> methodConstraints1 = listOfMethodsAndTph.
for (MethodConstraint cons: methodConstraints1) {
if (!checkForDuplicates(cons, cs_m)) {
cs_m.add(cons);
@ -249,7 +250,7 @@ public class FamilyOfGeneratedGenerics {
}
return tempMC;
}
/**
* Def. FGG: zweite Zeile von cs_m

View File

@ -15,9 +15,16 @@ public class MethodAndTPH {
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
// tphs of local variables and parameters
private final ArrayList<String> localTphs = new ArrayList<>();
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> basePairs = new ArrayList<>();
/*
* Returntyp der zugehoerigen Methode in er abstrakten Syntax
*/
TypePlaceholder returnType;
public MethodAndTPH(String name) {
public MethodAndTPH(String name, TypePlaceholder returnType) {
this.id = name;
this.returnType = returnType;
}
public ArrayList<String> getTphs() {
@ -39,4 +46,12 @@ public class MethodAndTPH {
return localTphs;
}
public void addPair(ResultPair<TypePlaceholder, TypePlaceholder> p) {
basePairs.add(p);
}
public TypePlaceholder getReturnType() {
return returnType;
}
}

View File

@ -126,7 +126,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{
public void visit(Assign assign) {
assign.lefSide.accept(this);
assign.rightSide.accept(this);
//assign.rightSide.getType().accept(this);
}
@Override
@ -187,11 +186,9 @@ public abstract class AbstractASTWalker implements ASTVisitor{
public void visit(MethodCall methodCall) {
methodCall.receiver.accept(this);
methodCall.getArgumentList().accept(this);
//methodCall.getArgumentList()
// .getArguments()
// .forEach(x -> x.getType().accept(this));
}
@Override
public void visit(NewClass methodCall) {
visit((MethodCall) methodCall);
@ -215,7 +212,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{
@Override
public void visit(Return aReturn) {
aReturn.retexpr.accept(this);
// aReturn.retexpr.getType().accept(this);
}
@Override

View File

@ -24,7 +24,7 @@ public class FamilyOfGenerics {
public void generateBC() throws Exception {
SourceFile sf = generateAST();
PositionFinder.getPositionOfTPH(sf, null);
TPHExtractor tphExtractor = new TPHExtractor();
TPHExtractor tphExtractor = new TPHExtractor(sf);
List<ResultSet> results = new ArrayList<ResultSet>();
GeneratedGenericsFinder generatedGenericsFinder = new GeneratedGenericsFinder(sf, results);
}