forked from JavaTX/JavaCompilerCore
Generic generator algorithm v0.1
This commit is contained in:
parent
7a4bc32974
commit
87d0a46ba5
@ -62,7 +62,7 @@ public class GenericsGenerator {
|
|||||||
final ConstraintsSimplierResult simplifiedConstraints, final List<String> tphsClass) {
|
final ConstraintsSimplierResult simplifiedConstraints, final List<String> tphsClass) {
|
||||||
final List<GenericsGeneratorResult> constraints = new ArrayList<>();
|
final List<GenericsGeneratorResult> constraints = new ArrayList<>();
|
||||||
|
|
||||||
if(tphsClass.isEmpty())
|
if (tphsClass.isEmpty())
|
||||||
return constraints;
|
return constraints;
|
||||||
|
|
||||||
final List<TPHConstraint> allCons = tphExtractor.allCons;
|
final List<TPHConstraint> allCons = tphExtractor.allCons;
|
||||||
@ -71,18 +71,8 @@ public class GenericsGenerator {
|
|||||||
|
|
||||||
final List<String> methodTPHs = tphExtractor.ListOfMethodsAndTph.stream().map(m -> m.getLocalTphs())
|
final List<String> methodTPHs = tphExtractor.ListOfMethodsAndTph.stream().map(m -> m.getLocalTphs())
|
||||||
.flatMap(l -> l.stream()).collect(Collectors.toList());
|
.flatMap(l -> l.stream()).collect(Collectors.toList());
|
||||||
for (String tph : tphsClass) {
|
|
||||||
|
|
||||||
if (visitedTPHs.contains(tph))
|
createConstraintsForClassTphs(simplifiedConstraints, tphsClass, constraints, allCons, visitedTPHs, methodTPHs);
|
||||||
continue;
|
|
||||||
|
|
||||||
final LinkedList<String> tphsInRel = GenericsGeneratorUtility
|
|
||||||
.createLinkedListForTPHsInRelationClass(allCons, tphsClass, methodTPHs, visitedTPHs, tph);
|
|
||||||
if(!tphsInRel.isEmpty()) {
|
|
||||||
GenericsGeneratorResult constraint = generateGGResultForClass(tphsInRel, simplifiedConstraints, tphsClass);
|
|
||||||
constraints.add(constraint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GenericsGeneratorUtility.addTPHsToClassTPHs(constraints, tphsClass);
|
GenericsGeneratorUtility.addTPHsToClassTPHs(constraints, tphsClass);
|
||||||
GenericsGeneratorUtility.removeClassTPHsFromMethodTPHs(tphsClass, tphExtractor);
|
GenericsGeneratorUtility.removeClassTPHsFromMethodTPHs(tphsClass, tphExtractor);
|
||||||
@ -92,6 +82,21 @@ public class GenericsGenerator {
|
|||||||
return constraints;
|
return constraints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void createConstraintsForClassTphs(ConstraintsSimplierResult simplifiedConstraints, List<String> tphsClass, List<GenericsGeneratorResult> constraints, List<TPHConstraint> allCons, Set<String> visitedTPHs, List<String> methodTPHs) {
|
||||||
|
for (String tph : tphsClass) {
|
||||||
|
|
||||||
|
if (visitedTPHs.contains(tph))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
final LinkedList<String> tphsInRel = GenericsGeneratorUtility
|
||||||
|
.createLinkedListForTPHsInRelationClass(allCons, tphsClass, methodTPHs, visitedTPHs, tph);
|
||||||
|
if (!tphsInRel.isEmpty()) {
|
||||||
|
GenericsGeneratorResult constraint = generateGGResultForClass(tphsInRel, simplifiedConstraints, tphsClass);
|
||||||
|
constraints.add(constraint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static GenericsGeneratorResult generateGGResultForClass(LinkedList<String> tphsInRel,
|
private static GenericsGeneratorResult generateGGResultForClass(LinkedList<String> tphsInRel,
|
||||||
ConstraintsSimplierResult simplifiedConstraints, List<String> tphsClass) {
|
ConstraintsSimplierResult simplifiedConstraints, List<String> tphsClass) {
|
||||||
String subType = tphsInRel.getFirst();
|
String subType = tphsInRel.getFirst();
|
||||||
@ -128,10 +133,10 @@ public class GenericsGenerator {
|
|||||||
List<GenericsGeneratorResult> constraints = new ArrayList<>();
|
List<GenericsGeneratorResult> constraints = new ArrayList<>();
|
||||||
MethodAndConstraints result = new MethodAndConstraints(m.getId(), constraints);
|
MethodAndConstraints result = new MethodAndConstraints(m.getId(), constraints);
|
||||||
|
|
||||||
if(localTphs.isEmpty())
|
if (localTphs.isEmpty())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
if(localTphs.size() == 1 && tphsClass.isEmpty()) {
|
if (localTphs.size() == 1 && tphsClass.isEmpty()) {
|
||||||
generateGGConstraintsForTPH(localTphs, constraints, simplifiedConstraints);
|
generateGGConstraintsForTPH(localTphs, constraints, simplifiedConstraints);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -145,9 +150,9 @@ public class GenericsGenerator {
|
|||||||
|
|
||||||
final LinkedList<String> tphsInRel = GenericsGeneratorUtility.createLinkedListForTPHsInRelation(allCons,
|
final LinkedList<String> tphsInRel = GenericsGeneratorUtility.createLinkedListForTPHsInRelation(allCons,
|
||||||
localTphs, tphsClass, visitedTPHs, tph);
|
localTphs, tphsClass, visitedTPHs, tph);
|
||||||
if(!tphsInRel.isEmpty()) {
|
if (!tphsInRel.isEmpty()) {
|
||||||
GenericsGeneratorUtility.removeNotLocalTphs(tphsInRel, localTphs, tphsClass);
|
GenericsGeneratorUtility.removeNotLocalTphs(tphsInRel, localTphs, tphsClass);
|
||||||
if(!GenericsGeneratorUtility.isInResult(tphsInRel.getFirst(),constraints)) {
|
if (!GenericsGeneratorUtility.isInResult(tphsInRel.getFirst(), constraints)) {
|
||||||
GenericsGeneratorResult constraint = generateGGResult(tphsInRel, simplifiedConstraints);
|
GenericsGeneratorResult constraint = generateGGResult(tphsInRel, simplifiedConstraints);
|
||||||
constraints.add(constraint);
|
constraints.add(constraint);
|
||||||
}
|
}
|
||||||
@ -163,8 +168,8 @@ public class GenericsGenerator {
|
|||||||
|
|
||||||
localTphs.forEach(tph -> {
|
localTphs.forEach(tph -> {
|
||||||
boolean isInSimplifiedConstraints = GenericsGeneratorUtility.isTPHInGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(), tph);
|
boolean isInSimplifiedConstraints = GenericsGeneratorUtility.isTPHInGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(), tph);
|
||||||
if(isInSimplifiedConstraints) {
|
if (isInSimplifiedConstraints) {
|
||||||
GenericsGeneratorResult ggResult = GenericsGeneratorUtility.getGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(),tph).get();
|
GenericsGeneratorResult ggResult = GenericsGeneratorUtility.getGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(), tph).get();
|
||||||
// GenericsGeneratorUtility.removeGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(),ggResult);
|
// GenericsGeneratorUtility.removeGenericGeneratorResult(simplifiedConstraints.getGenericsGenResults(),ggResult);
|
||||||
constraints.add(ggResult);
|
constraints.add(ggResult);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user