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