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/parser/SyntaxTreeGenerator/StatementGenerator.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/statement/Statement.java modified: src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: src/test/java/insertGenerics/TestLocalVarLambda.java
This commit is contained in:
parent
3363037854
commit
be9ee49878
@ -209,10 +209,12 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
|
||||
csS.getOderConstraints()
|
||||
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
|
||||
oConSSet.forEach(OConS -> { setCons.add(
|
||||
oConSSet.forEach(OConS -> { Constraint<Pair> newConsPair = new Constraint<Pair>();
|
||||
newConsPair.isStatement = OConS.isStatement;
|
||||
setCons.add(
|
||||
OConS.stream()
|
||||
.filter(filterUndConstraints)
|
||||
.collect(Collectors.toCollection(Constraint<Pair>::new)) );
|
||||
.collect(Collectors.toCollection(() -> newConsPair)) );
|
||||
} );
|
||||
ret.addOderConstraint(setCons);} );
|
||||
return ret;
|
||||
|
@ -8,6 +8,7 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
@ -590,8 +591,9 @@ public class FamilyOfGeneratedGenerics {
|
||||
Iterator<Pair> itExtends2 = extendsSet.iterator();
|
||||
while(itExtends2.hasNext()) {
|
||||
Pair pairExtends2 = itExtends2.next();
|
||||
Set<String> containedVars = new HashSet<>(methodAndTPH.getTphs());
|
||||
String pairExtends2RHSName = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
|
||||
Iterator<Pair> itEqual2 = equalSet.iterator();
|
||||
|
||||
while (itEqual2.hasNext()) {
|
||||
boolean transClo = false;
|
||||
Pair pairEqual2 = itEqual2.next();
|
||||
@ -635,23 +637,29 @@ public class FamilyOfGeneratedGenerics {
|
||||
tempSet2.add(pairExtends2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
containedVars.remove(((TypePlaceholder)newPair2.TA2).getName());
|
||||
}
|
||||
|
||||
}
|
||||
Set<String> containedVars = new HashSet<>();
|
||||
String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
|
||||
|
||||
//String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
|
||||
//TODO: containedVars stimmt noch nicht. Ueberpruefen, ob ggf. mit den containedVars möglicherweise auch die anderen Faelle
|
||||
// rEqExRtilde isPairInTExTapostrophe abgedeckt sind => ggf. integrieren
|
||||
/*
|
||||
posOfTphs.forEach((x,y) -> {
|
||||
if (y.contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
|
||||
containedVars.add(x);
|
||||
};
|
||||
}
|
||||
);
|
||||
if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(key, v, Relation.EXTENDS)))
|
||||
*/
|
||||
if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(pairExtends2RHSName, v, Relation.EXTENDS)))
|
||||
.count() > 0) {
|
||||
tempSet2.add(pairExtends2);
|
||||
}
|
||||
if (posOfTphs.containsKey(key)) {
|
||||
if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
|
||||
if (posOfTphs.containsKey(pairExtends2RHSName)) {
|
||||
if (posOfTphs.get(pairExtends2RHSName).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
|
||||
tempSet2.add(pairExtends2);
|
||||
}
|
||||
}
|
||||
|
@ -213,10 +213,10 @@ public class StatementGenerator {
|
||||
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream()
|
||||
.map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart()))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
MethodCall ret = new MethodCall(//new Void(new NullToken()),
|
||||
TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
|
||||
argTypes, methodInvocationContext.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -303,33 +303,45 @@ public class StatementGenerator {
|
||||
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
|
||||
.map(x -> TypePlaceholder.fresh(newExpression.getStart()))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
return new NewClass(newClass, args, null, argTypes, newExpression.getStart());
|
||||
Statement ret = new NewClass(newClass, args, null, argTypes, newExpression.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
||||
Expression argument = convert(stmt.unaryExpression());
|
||||
Token offset = stmt.getStart();
|
||||
return new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset);
|
||||
}
|
||||
Statement ret = new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset);
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
|
||||
return new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()),
|
||||
Statement ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()),
|
||||
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
|
||||
return new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()),
|
||||
Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()),
|
||||
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
|
||||
return new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()),
|
||||
Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()),
|
||||
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.AssignmentContext stmt) {
|
||||
AssignLeftSide leftHandSide = convert(stmt.leftHandSide());
|
||||
return new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart());
|
||||
Statement ret = new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart());
|
||||
ret.setStatement();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) {
|
||||
|
@ -24,13 +24,9 @@ public class MethodCall extends Statement
|
||||
|
||||
public final ArgumentList arglist;
|
||||
|
||||
/*
|
||||
* noetig fuer Bytecodegenerierung
|
||||
*/
|
||||
public RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes;
|
||||
|
||||
|
||||
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
|
||||
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||
super(retType,offset);
|
||||
@ -40,6 +36,7 @@ public class MethodCall extends Statement
|
||||
this.receiverType = receiverType;
|
||||
this.argTypes = argTypes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
|
@ -6,11 +6,20 @@ import org.antlr.v4.runtime.Token;
|
||||
|
||||
public abstract class Statement extends Expression
|
||||
{
|
||||
|
||||
/* zeigt an, dass eine StatementExpression als Statement benutzt wird
|
||||
*/
|
||||
private boolean isStatement = false;
|
||||
|
||||
public Statement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset)
|
||||
{
|
||||
super(type, offset);
|
||||
}
|
||||
|
||||
public void setStatement() {
|
||||
isStatement=true;
|
||||
}
|
||||
|
||||
public boolean getStatement() {
|
||||
return isStatement;
|
||||
}
|
||||
}
|
@ -9,6 +9,12 @@ import java.util.Set;
|
||||
public class Constraint<A> extends HashSet<A> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt
|
||||
|
||||
/* es darf kein Constraint für den Return-Type erstellt werden, sonst gibt
|
||||
* es Probleme beim Generated Generics
|
||||
*/
|
||||
public boolean isStatement = false;
|
||||
|
||||
private Constraint<A> extendConstraint = null;
|
||||
|
||||
public Constraint() {
|
||||
@ -41,7 +47,7 @@ public class Constraint<A> extends HashSet<A> {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + " isInherited = " + isInherited
|
||||
return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement
|
||||
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
|
||||
+ "\n" ;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
@ -180,6 +181,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
|
||||
: x)
|
||||
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
|
||||
extendsOneMethodConstraint.isStatement = oneMethodConstraint.isStatement;
|
||||
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
||||
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
||||
methodConstraints.add(extendsOneMethodConstraint);
|
||||
@ -594,9 +596,11 @@ public class TYPEStmt implements StatementVisitor{
|
||||
//methodConstraint.add(new Pair(forMethod.receiverType, retType,
|
||||
// PairOperator.EQUALSDOT));
|
||||
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
|
||||
|
||||
|
||||
|
||||
methodConstraint.isStatement = forMethod.getStatement();
|
||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||
PairOperator.EQUALSDOT));
|
||||
PairOperator.EQUALSDOT));
|
||||
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
||||
return methodConstraint;
|
||||
}
|
||||
|
@ -76,7 +76,15 @@ public class TestLocalVarLambda {
|
||||
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
|
||||
}
|
||||
else {
|
||||
else if (fogg.allConstraints.contains((new MethodConstraint("O", "DIV", Relation.EXTENDS)))) {
|
||||
lmc.add(new MethodConstraint("O", "DIV", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("DIV", "N", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
|
||||
methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc);
|
||||
}
|
||||
else
|
||||
{
|
||||
lmc.add(new MethodConstraint("O", "DIU", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
|
||||
lmc.add(new MethodConstraint("DIU", "N", Relation.EXTENDS));
|
||||
|
Loading…
Reference in New Issue
Block a user