Add a child class of the compiler to implement the wildcard infer
algorithm
This commit is contained in:
parent
cb28405fe1
commit
4ca0e1e5f6
@ -0,0 +1,48 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||
|
||||
public class JavaTXCompilerWildcards
|
||||
extends JavaTXCompiler
|
||||
{
|
||||
|
||||
private final Map<TypePlaceholder, RefType> tphMap;
|
||||
|
||||
public JavaTXCompilerWildcards (File... sourceFile) throws IOException, ClassNotFoundException {
|
||||
super(sourceFile);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
|
||||
super(sourceFile, log);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (List<File> sourceFiles) throws IOException, ClassNotFoundException {
|
||||
super(sourceFiles);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
public JavaTXCompilerWildcards (List<File> sources, List<File> contextPath)
|
||||
throws IOException, ClassNotFoundException {
|
||||
super(sources, contextPath);
|
||||
this.tphMap = TypePlaceholderReplaceUtils.generateTypePlaceholder(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintSet<Pair> getConstraints () throws ClassNotFoundException, IOException {
|
||||
ConstraintSet<Pair> constraints = super.getConstraints();
|
||||
ConstraintSet<Pair> generateConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||
constraints.addAll(generateConstraints);
|
||||
return constraints;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
/**
|
||||
* Class providing utilities to generate the Type placeholder for parameter
|
||||
* types which shall be inferred.
|
||||
*
|
||||
* @author Till Schnell
|
||||
* @version 1.0
|
||||
*/
|
||||
public final class TypePlaceholderReplaceUtils
|
||||
{
|
||||
|
||||
private TypePlaceholderReplaceUtils () {
|
||||
throw new AssertionError("No TypePlaceholderReplaceUtils instance for you");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the map of the generated type placeholder for the associate parameter
|
||||
* type
|
||||
*
|
||||
* @param compiler {@link JavaTXCompiler} to get the source file from
|
||||
* @return {@link Map} over {@link TypePlaceholder} and the {@link RefType}
|
||||
* replaced
|
||||
*/
|
||||
public static Map<TypePlaceholder, RefType> generateTypePlaceholder (JavaTXCompiler compiler) {
|
||||
Map<File, SourceFile> sourceFiles = compiler.getSourceFiles();
|
||||
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
|
||||
sourceFiles.forEach( (k, v) -> v.accept(visitor));
|
||||
return visitor.getTphMap();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user