Vor Fertigstellung Ersetzung Generics.
This commit is contained in:
parent
6e9eae38ca
commit
7343ea1701
@ -43,9 +43,8 @@ public class GenericGenratorResultForSourceFile {
|
||||
return genericGeneratorResultForAllClasses.stream()
|
||||
.filter(sr -> sr.getClassName().equals(name))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new NoSuchElementException(
|
||||
"Simplify results for the class " + pkgName + "." + name + " are not found"));
|
||||
.orElse(new GenericsGeneratorResultForClass(name));
|
||||
}
|
||||
throw new NoSuchElementException("Simplify results for the class " + pkgName + "." + name + " are not found");
|
||||
return new GenericsGeneratorResultForClass(name);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author fayez
|
||||
@ -56,12 +59,16 @@ public class GenericsGeneratorResultForClass {
|
||||
.anyMatch(i -> i.equals(id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<GenericsGeneratorResult> getMethodConstraintsByID(String id) {
|
||||
return methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id))
|
||||
.findFirst().get().getConstraints();
|
||||
Optional<MethodAndConstraints> methodConstraints = methodsAndTheirConstraints.getMethodsAndConstraints()
|
||||
.stream()
|
||||
.filter(mc -> mc.getMethodID().equals(id))
|
||||
.findFirst();
|
||||
|
||||
if (methodConstraints.isPresent()) {
|
||||
return methodConstraints.get().getConstraints();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package de.dhbwstuttgart.typedeployment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.antlr.v4.parse.BlockSetTransformer.setAlt_return;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
@ -23,10 +28,15 @@ public class TypeInsert {
|
||||
|
||||
public String insert(String intoSource){
|
||||
List<TypeInsertPoint> offsets = new ArrayList<>();
|
||||
String ret = point.insert(intoSource, offsets);
|
||||
offsets.add(point);
|
||||
for(TypeInsertPoint insertPoint : inserts){
|
||||
ret = insertPoint.insert(ret, offsets);
|
||||
String ret = intoSource;
|
||||
|
||||
List<TypeInsertPoint> insertsSorted = new ArrayList<>();
|
||||
insertsSorted.add(point);
|
||||
insertsSorted.addAll(inserts);
|
||||
Collections.sort(insertsSorted, new TypeInsertPoint.TypeInsertPointPositionComparator().reversed());
|
||||
|
||||
for(TypeInsertPoint insertPoint : insertsSorted) {
|
||||
ret = insertPoint.insert(ret, new ArrayList<>());
|
||||
offsets.add(insertPoint);
|
||||
}
|
||||
return ret;
|
||||
@ -56,7 +66,14 @@ public class TypeInsert {
|
||||
}
|
||||
|
||||
public Set<TypeInsertPoint> getAdditionalPoints() {
|
||||
return this.inserts;
|
||||
TypeInsertPoint.TypeInsertPointPositionComparator comparator = new TypeInsertPoint.TypeInsertPointPositionComparator();
|
||||
TreeSet<TypeInsertPoint> result = new TreeSet<>(comparator.reversed());
|
||||
result.addAll(inserts);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Set<TypeInsertPoint> getAdditionalPointsUnsorted() {
|
||||
return inserts;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
@ -44,7 +44,7 @@ public class TypeInsertFactory {
|
||||
try {
|
||||
ResolvedType resolvedType = resultSet.resolveType(type);
|
||||
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
|
||||
new TypeToInsertString(resolvedType.resolvedType).insert);
|
||||
new TypeToInsertString(resolvedType.resolvedType).insert, KindOfTypeInsertPoint.NORMAL_INSERT);
|
||||
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles(newResults);
|
||||
for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) {
|
||||
GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName("", cl.getClassName().toString());
|
||||
@ -60,22 +60,22 @@ public class TypeInsertFactory {
|
||||
|
||||
private static synchronized Set<TypeInsertPoint> createGenericInsert(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl, Method m, ResultSet resultSet, Token mOffset){
|
||||
Set<TypeInsertPoint> result = createGenericClassInserts(genericResult, cl);
|
||||
|
||||
for (Method method : cl.getMethods()) {
|
||||
Resolver resolver = new Resolver(resultSet);
|
||||
List<GenericsGeneratorResult> methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, method));
|
||||
result.addAll(createMethodConstraints(method, methodConstraints, mOffset));
|
||||
}
|
||||
|
||||
Resolver resolver = new Resolver(resultSet);
|
||||
|
||||
if (m != null) {
|
||||
List<GenericsGeneratorResult> methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, m));
|
||||
result.addAll(createMethodConstraints(methodConstraints, mOffset));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Set<TypeInsertPoint> createMethodConstraints(Method method, List<GenericsGeneratorResult> constraints, Token mOffset) {
|
||||
private static Set<TypeInsertPoint> createMethodConstraints(List<GenericsGeneratorResult> constraints, Token mOffset) {
|
||||
Set<TypeInsertPoint> result = new HashSet<>();
|
||||
Token offset = mOffset;
|
||||
|
||||
if (constraints.size() == 0) {
|
||||
result.add(new TypeInsertPoint(offset, ""));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -85,14 +85,15 @@ public class TypeInsertFactory {
|
||||
if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
|
||||
insert += genericInsertConstraint.getConstraint().getLeft();
|
||||
} else {
|
||||
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", ";
|
||||
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight();
|
||||
}
|
||||
insert += ", ";
|
||||
}
|
||||
|
||||
insert = insert.substring(0, insert.length() -2);
|
||||
insert += ">";
|
||||
|
||||
result.add(new TypeInsertPoint(offset, insert));
|
||||
result.add(new TypeInsertPoint(offset, insert, KindOfTypeInsertPoint.GENERERIC_METHOD_INSERT));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -103,7 +104,6 @@ public class TypeInsertFactory {
|
||||
List<GenericsGeneratorResult> classConstraints = genericResult.getClassConstraints();
|
||||
|
||||
if (classConstraints.size() == 0) {
|
||||
result.add(new TypeInsertPoint(offset, ""));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -113,14 +113,15 @@ public class TypeInsertFactory {
|
||||
if (genericInsertConstraint.getConstraint().getRight().equals(Type.getInternalName(Object.class))) {
|
||||
insert += genericInsertConstraint.getConstraint().getLeft();
|
||||
} else {
|
||||
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight() + ", ";
|
||||
insert += genericInsertConstraint.getConstraint().getLeft() + " extends " + genericInsertConstraint.getConstraint().getRight();
|
||||
}
|
||||
insert += ", ";
|
||||
}
|
||||
|
||||
insert = insert.substring(0, insert.length() -2);
|
||||
insert += ">";
|
||||
|
||||
result.add(new TypeInsertPoint(offset, insert));
|
||||
result.add(new TypeInsertPoint(offset, insert, KindOfTypeInsertPoint.GENERIC_CLASS_INSERT));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.antlr.v4.runtime.Token;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@ -13,11 +14,17 @@ public class TypeInsertPoint {
|
||||
public Token point;
|
||||
private String insertString;
|
||||
private int extraOffset = 0;
|
||||
private KindOfTypeInsertPoint kind;
|
||||
|
||||
public TypeInsertPoint(Token point, String toInsert){
|
||||
public TypeInsertPoint(Token point, String toInsert, KindOfTypeInsertPoint kind){
|
||||
this.point = point;
|
||||
this.kind = kind;
|
||||
this.insertString = (toInsert.endsWith(" ")) ? toInsert : toInsert + " " ;
|
||||
}
|
||||
|
||||
public boolean isGenericClassInsertPoint() {
|
||||
return kind == KindOfTypeInsertPoint.GENERIC_CLASS_INSERT;
|
||||
}
|
||||
|
||||
public String insert(String intoSource, List<TypeInsertPoint> additionalOffset){
|
||||
int offset = additionalOffset.stream().filter((token ->
|
||||
@ -61,4 +68,18 @@ public class TypeInsertPoint {
|
||||
public String toString() {
|
||||
return point.toString() + " " + insertString.toString();
|
||||
}
|
||||
|
||||
public static final class TypeInsertPointPositionComparator implements Comparator<TypeInsertPoint> {
|
||||
|
||||
@Override
|
||||
public int compare(TypeInsertPoint o1, TypeInsertPoint o2) {
|
||||
if (o1.getPositionInCode() > o2.getPositionInCode()) {
|
||||
return 1;
|
||||
} else if (o1.getPositionInCode() < o2.getPositionInCode()) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user