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:
parent
92bc3d626c
commit
f270686b3c
@ -25,9 +25,11 @@ import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
|||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
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 Felder werden iKopf der Klasse definiert
|
||||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||||
public final SourceFile sf;
|
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, Method> nameToMeth;
|
||||||
|
|
||||||
public final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
public final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
||||||
public final List<String> tphsClass = new ArrayList<>();
|
public final List<String> tphsClass = new ArrayList<>();
|
||||||
MethodAndTPH methodAndTph;
|
MethodAndTPH methodAndTph;
|
||||||
@ -193,7 +200,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, (TypePlaceholder)method.getReturnType());
|
||||||
|
|
||||||
inLocalOrParamOrReturn = true;
|
inLocalOrParamOrReturn = true;
|
||||||
method.getReturnType().accept(this);
|
method.getReturnType().accept(this);
|
||||||
@ -217,6 +224,24 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
inMethod = true;
|
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
|
@Override
|
||||||
public void visit(LocalVarDecl localVarDecl) {
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
// inLocalOrParamOrReturn = inMethod;
|
// inLocalOrParamOrReturn = inMethod;
|
||||||
@ -228,20 +253,47 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
super.visit(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();
|
Iterator<FormalParameter> paraIt = nameToMeth.get(methodCall.name).getParameterList().iterator();
|
||||||
methodCall.getArgumentList()
|
methodCall.getArgumentList()
|
||||||
.getArguments()
|
.getArguments()
|
||||||
.forEach(x -> {
|
.forEach(x -> {
|
||||||
RefTypeOrTPHOrWildcardOrGeneric left = null;
|
RefTypeOrTPHOrWildcardOrGeneric left = resultSet.resolveType(x.getType()).resolvedType;
|
||||||
RefTypeOrTPHOrWildcardOrGeneric right = null;
|
RefTypeOrTPHOrWildcardOrGeneric right = resultSet.resolveType(paraIt.next().getType()).resolvedType;
|
||||||
if ((left = x.getType()) instanceof TypePlaceholder) {
|
if (left instanceof TypePlaceholder && methodAndTph.getTphs().contains(((TypePlaceholder)left).getName())) {
|
||||||
if ((right = paraIt.next().getType()) instanceof TypePlaceholder) {
|
if (right instanceof TypePlaceholder) {
|
||||||
methodAndTph.addPair(((TypePlaceholder)left).getName(),
|
methodAndTph.addPair(allPairs.stream().filter(
|
||||||
((TypePlaceholder)left).getName());
|
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
|
@Override
|
||||||
public void visit(LocalVar localVar) {
|
public void visit(LocalVar localVar) {
|
||||||
// inLocalOrParamOrReturn = inMethod;
|
// inLocalOrParamOrReturn = inMethod;
|
||||||
|
@ -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) {
|
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> cs_m = new ArrayList<>();
|
||||||
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
List<MethodConstraint> methodConstraints1 = typeOfTheMethodInClSigma(cs, posOfTphs);
|
||||||
|
//List<MethodConstraint> methodConstraints1 = listOfMethodsAndTph.
|
||||||
for (MethodConstraint cons: methodConstraints1) {
|
for (MethodConstraint cons: methodConstraints1) {
|
||||||
if (!checkForDuplicates(cons, cs_m)) {
|
if (!checkForDuplicates(cons, cs_m)) {
|
||||||
cs_m.add(cons);
|
cs_m.add(cons);
|
||||||
|
@ -15,9 +15,16 @@ 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<>();
|
||||||
|
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> basePairs = new ArrayList<>();
|
||||||
|
|
||||||
public MethodAndTPH(String name) {
|
/*
|
||||||
|
* Returntyp der zugehoerigen Methode in er abstrakten Syntax
|
||||||
|
*/
|
||||||
|
TypePlaceholder returnType;
|
||||||
|
|
||||||
|
public MethodAndTPH(String name, TypePlaceholder returnType) {
|
||||||
this.id = name;
|
this.id = name;
|
||||||
|
this.returnType = returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getTphs() {
|
public ArrayList<String> getTphs() {
|
||||||
@ -39,4 +46,12 @@ public class MethodAndTPH {
|
|||||||
return localTphs;
|
return localTphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPair(ResultPair<TypePlaceholder, TypePlaceholder> p) {
|
||||||
|
basePairs.add(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypePlaceholder getReturnType() {
|
||||||
|
return returnType;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
public void visit(Assign assign) {
|
public void visit(Assign assign) {
|
||||||
assign.lefSide.accept(this);
|
assign.lefSide.accept(this);
|
||||||
assign.rightSide.accept(this);
|
assign.rightSide.accept(this);
|
||||||
//assign.rightSide.getType().accept(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -187,11 +186,9 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
methodCall.getArgumentList().accept(this);
|
methodCall.getArgumentList().accept(this);
|
||||||
//methodCall.getArgumentList()
|
|
||||||
// .getArguments()
|
|
||||||
// .forEach(x -> x.getType().accept(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(NewClass methodCall) {
|
public void visit(NewClass methodCall) {
|
||||||
visit((MethodCall) methodCall);
|
visit((MethodCall) methodCall);
|
||||||
@ -215,7 +212,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Return aReturn) {
|
public void visit(Return aReturn) {
|
||||||
aReturn.retexpr.accept(this);
|
aReturn.retexpr.accept(this);
|
||||||
// aReturn.retexpr.getType().accept(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,7 +24,7 @@ public class FamilyOfGenerics {
|
|||||||
public void generateBC() throws Exception {
|
public void generateBC() throws Exception {
|
||||||
SourceFile sf = generateAST();
|
SourceFile sf = generateAST();
|
||||||
PositionFinder.getPositionOfTPH(sf, null);
|
PositionFinder.getPositionOfTPH(sf, null);
|
||||||
TPHExtractor tphExtractor = new TPHExtractor();
|
TPHExtractor tphExtractor = new TPHExtractor(sf);
|
||||||
List<ResultSet> results = new ArrayList<ResultSet>();
|
List<ResultSet> results = new ArrayList<ResultSet>();
|
||||||
GeneratedGenericsFinder generatedGenericsFinder = new GeneratedGenericsFinder(sf, results);
|
GeneratedGenericsFinder generatedGenericsFinder = new GeneratedGenericsFinder(sf, results);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user