forked from JavaTX/JavaCompilerCore
Plugin: Additional generic insert points.
This commit is contained in:
parent
3ecb202a90
commit
25fb7a2e28
@ -38,14 +38,13 @@ public class GenericGenratorResultForSourceFile {
|
||||
}
|
||||
|
||||
public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) {
|
||||
|
||||
if (this.pkgName.equals(pkgName)) {
|
||||
return genericGeneratorResultForAllClasses.stream()
|
||||
.filter(sr -> sr.getClassName().equals(name))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new NoSuchElementException(
|
||||
"Simplify results for the class " + pkgName + "." + name + " are not found"));
|
||||
for (int i = 0; i < genericGeneratorResultForAllClasses.size(); i++) {
|
||||
GenericsGeneratorResultForClass genericsGeneratorResult = genericGeneratorResultForAllClasses.get(i);
|
||||
if (genericsGeneratorResult.getClassName().equals(name)) {
|
||||
return genericsGeneratorResult;
|
||||
}
|
||||
}
|
||||
throw new NoSuchElementException("Simplify results for the class " + pkgName + "." + name + " are not found");
|
||||
|
||||
return new GenericsGeneratorResultForClass(name);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ package de.dhbwstuttgart.bytecode.simplifyRes;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
/**
|
||||
* @author fayez
|
||||
*
|
||||
@ -60,8 +62,10 @@ public class GenericsGeneratorResultForClass {
|
||||
|
||||
|
||||
public List<GenericsGeneratorResult> getMethodConstraintsByID(String id) {
|
||||
return methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id))
|
||||
.findFirst().get().getConstraints();
|
||||
java.util.Optional<MethodAndConstraints> methodAndConstraints = methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id))
|
||||
.findFirst();
|
||||
|
||||
return methodAndConstraints.isPresent() ? methodAndConstraints.get().getConstraints() : Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
|
||||
public class TypeInsert {
|
||||
@ -53,6 +54,11 @@ public class TypeInsert {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Set<TypeInsertPoint> getAdditionalPoints() {
|
||||
return this.inserts;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return point.toString();
|
||||
}
|
||||
|
@ -48,9 +48,11 @@ import javax.security.auth.kerberos.KerberosKey;
|
||||
*/
|
||||
public class TypeInsertFactory {
|
||||
|
||||
private static List<ResultSet> newResults;
|
||||
|
||||
public static Set<TypeInsert> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults){
|
||||
return new TypeInsertPlacer().getTypeInserts(forSourcefile, withResults);
|
||||
public static Set<TypeInsert> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, List<ResultSet> newResults){
|
||||
TypeInsertFactory.newResults = newResults;
|
||||
return new TypeInsertPlacer().getTypeInserts(forSourcefile, withResults);
|
||||
}
|
||||
|
||||
public static TypeInsert createInsertPoints(RefTypeOrTPHOrWildcardOrGeneric type, Token offset, ClassOrInterface cl, Method m,
|
||||
@ -60,10 +62,10 @@ public class TypeInsertFactory {
|
||||
ResolvedType resolvedType = resultSet.resolveType(type);
|
||||
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
|
||||
new TypeToInsertString(resolvedType.resolvedType).insert);
|
||||
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles(newResults);
|
||||
for (GenericGenratorResultForSourceFile simplifyResultsEntries : simplifyResults) {
|
||||
GenericsGeneratorResultForClass genericResultsForClass = simplifyResultsEntries.getSimplifyResultsByName("", cl.getClassName().toString());
|
||||
return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet), resolvedType.getResultPair());
|
||||
return new TypeInsert(insertPoint, createGenericInsert(genericResultsForClass, cl, m, resultSet, offset), resolvedType.getResultPair());
|
||||
}
|
||||
|
||||
return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
|
||||
@ -73,21 +75,21 @@ public class TypeInsertFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized Set<TypeInsertPoint> createGenericInsert(GenericsGeneratorResultForClass genericResult, ClassOrInterface cl, Method m, ResultSet resultSet){
|
||||
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));
|
||||
createMethodConstraints(method, methodConstraints);
|
||||
result.addAll(createMethodConstraints(method, methodConstraints, mOffset));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Set<TypeInsertPoint> createMethodConstraints(Method method, List<GenericsGeneratorResult> constraints) {
|
||||
private static Set<TypeInsertPoint> createMethodConstraints(Method method, List<GenericsGeneratorResult> constraints, Token mOffset) {
|
||||
Set<TypeInsertPoint> result = new HashSet<>();
|
||||
Token offset = new GenericDeclarationList(method.getGenerics(), new NullToken()).getOffset();
|
||||
Token offset = mOffset;
|
||||
|
||||
if (constraints.size() == 0) {
|
||||
result.add(new TypeInsertPoint(offset, ""));
|
||||
|
@ -1,13 +1,12 @@
|
||||
package de.dhbwstuttgart.typedeployment;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TypeInsertPlacer extends AbstractASTWalker{
|
||||
|
@ -6,6 +6,7 @@ import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TypeInsertPoint {
|
||||
@ -53,6 +54,10 @@ public class TypeInsertPoint {
|
||||
}
|
||||
}
|
||||
|
||||
public Set<TypeInsertPoint> getAdditionalPoints() {
|
||||
return this.getAdditionalPoints();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return point.toString() + " " + insertString.toString();
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class JavaTXCompilerTest {
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
|
@ -114,7 +114,7 @@ public class Meth_GenTest {
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
|
@ -140,7 +140,7 @@ public class UnifyTest {
|
||||
assert results.size()>0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for(ResultSet resultSet : results){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results);
|
||||
assert result.size()>0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for(TypeInsert tip : result){
|
||||
|
Loading…
Reference in New Issue
Block a user