Plugin: Additional generic insert points.

This commit is contained in:
Michael Uhl 2019-09-16 11:52:34 +02:00
parent 3ecb202a90
commit 25fb7a2e28
9 changed files with 38 additions and 23 deletions

View File

@ -38,14 +38,13 @@ public class GenericGenratorResultForSourceFile {
} }
public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) { public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) {
for (int i = 0; i < genericGeneratorResultForAllClasses.size(); i++) {
if (this.pkgName.equals(pkgName)) { GenericsGeneratorResultForClass genericsGeneratorResult = genericGeneratorResultForAllClasses.get(i);
return genericGeneratorResultForAllClasses.stream() if (genericsGeneratorResult.getClassName().equals(name)) {
.filter(sr -> sr.getClassName().equals(name)) return genericsGeneratorResult;
.findAny()
.orElseThrow(() -> new NoSuchElementException(
"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);
} }
} }

View File

@ -6,6 +6,8 @@ package de.dhbwstuttgart.bytecode.simplifyRes;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import com.google.common.base.Optional;
/** /**
* @author fayez * @author fayez
* *
@ -60,8 +62,10 @@ public class GenericsGeneratorResultForClass {
public List<GenericsGeneratorResult> getMethodConstraintsByID(String id) { public List<GenericsGeneratorResult> getMethodConstraintsByID(String id) {
return methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id)) java.util.Optional<MethodAndConstraints> methodAndConstraints = methodsAndTheirConstraints.getMethodsAndConstraints().stream().filter(mc -> mc.getMethodID().equals(id))
.findFirst().get().getConstraints(); .findFirst();
return methodAndConstraints.isPresent() ? methodAndConstraints.get().getConstraints() : Collections.emptyList();
} }
} }

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultPair;
public class TypeInsert { public class TypeInsert {
@ -53,6 +54,11 @@ public class TypeInsert {
} }
} }
public Set<TypeInsertPoint> getAdditionalPoints() {
return this.inserts;
}
public String toString() { public String toString() {
return point.toString(); return point.toString();
} }

View File

@ -48,8 +48,10 @@ import javax.security.auth.kerberos.KerberosKey;
*/ */
public class TypeInsertFactory { public class TypeInsertFactory {
private static List<ResultSet> newResults;
public static Set<TypeInsert> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults){ public static Set<TypeInsert> createTypeInsertPoints(SourceFile forSourcefile, ResultSet withResults, List<ResultSet> newResults){
TypeInsertFactory.newResults = newResults;
return new TypeInsertPlacer().getTypeInserts(forSourcefile, withResults); return new TypeInsertPlacer().getTypeInserts(forSourcefile, withResults);
} }
@ -60,10 +62,10 @@ public class TypeInsertFactory {
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);
List<GenericGenratorResultForSourceFile> simplifyResults = JavaTXCompiler.INSTANCE.getGeneratedGenericResultsForAllSourceFiles(); 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());
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()); 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); Set<TypeInsertPoint> result = createGenericClassInserts(genericResult, cl);
for (Method method : cl.getMethods()) { for (Method method : cl.getMethods()) {
Resolver resolver = new Resolver(resultSet); Resolver resolver = new Resolver(resultSet);
List<GenericsGeneratorResult> methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, method)); List<GenericsGeneratorResult> methodConstraints = genericResult.getMethodConstraintsByID(MethodUtility.createID(resolver, method));
createMethodConstraints(method, methodConstraints); result.addAll(createMethodConstraints(method, methodConstraints, mOffset));
} }
return result; 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<>(); Set<TypeInsertPoint> result = new HashSet<>();
Token offset = new GenericDeclarationList(method.getGenerics(), new NullToken()).getOffset(); Token offset = mOffset;
if (constraints.size() == 0) { if (constraints.size() == 0) {
result.add(new TypeInsertPoint(offset, "")); result.add(new TypeInsertPoint(offset, ""));

View File

@ -1,13 +1,12 @@
package de.dhbwstuttgart.typedeployment; package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
public class TypeInsertPlacer extends AbstractASTWalker{ public class TypeInsertPlacer extends AbstractASTWalker{

View File

@ -6,6 +6,7 @@ import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class TypeInsertPoint { public class TypeInsertPoint {
@ -53,6 +54,10 @@ public class TypeInsertPoint {
} }
} }
public Set<TypeInsertPoint> getAdditionalPoints() {
return this.getAdditionalPoints();
}
public String toString() { public String toString() {
return point.toString() + " " + insertString.toString(); return point.toString() + " " + insertString.toString();
} }

View File

@ -142,7 +142,7 @@ public class JavaTXCompilerTest {
assert results.size()>0; assert results.size()>0;
Set<String> insertedTypes = new HashSet<>(); Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){ for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results);
assert result.size()>0; assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8); String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){ for(TypeInsert tip : result){

View File

@ -114,7 +114,7 @@ public class Meth_GenTest {
assert results.size()>0; assert results.size()>0;
Set<String> insertedTypes = new HashSet<>(); Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){ for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results);
assert result.size()>0; assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8); String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){ for(TypeInsert tip : result){

View File

@ -140,7 +140,7 @@ public class UnifyTest {
assert results.size()>0; assert results.size()>0;
Set<String> insertedTypes = new HashSet<>(); Set<String> insertedTypes = new HashSet<>();
for(ResultSet resultSet : results){ for(ResultSet resultSet : results){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, results);
assert result.size()>0; assert result.size()>0;
String content = readFile(f.getPath(), StandardCharsets.UTF_8); String content = readFile(f.getPath(), StandardCharsets.UTF_8);
for(TypeInsert tip : result){ for(TypeInsert tip : result){