Remove visitors for the Oracle AST approche

This commit is contained in:
Till Schnell 2021-04-06 18:24:47 +02:00
parent 7dfe546999
commit ce8b19acae
2 changed files with 0 additions and 174 deletions

View File

@ -1,79 +0,0 @@
package de.dhbwstuttgart.inferWildcards;
import java.util.HashMap;
import java.util.Map;
import com.sun.source.tree.ExpressionStatementTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreeScanner;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
public class InferWildcardsVisitor
extends TreeScanner<Void, Void>
{
@SuppressWarnings("rawtypes")
private final ConstraintSet constraintsSet;
private final Map<TypePlaceholder, Tree> placeholderMapping;
public InferWildcardsVisitor () {
super();
this.constraintsSet = new ConstraintSet<>();
this.placeholderMapping = new HashMap<>();
}
@Override
public Void visitOther (Tree node, Void p) {
// System.out.println("Other: " + node.toString());
return super.visitOther(node, p);
}
@Override
public Void visitExpressionStatement (ExpressionStatementTree node, Void p) {
System.out.println("Expression: " + node.toString());
return super.visitExpressionStatement(node, p);
}
@Override
public Void visitVariable (VariableTree node, Void p) {
System.out.println("Variable: " + node.toString());
// Get Type
System.out.println("Type: ============");
// generate visitor
TypeParamVisitor typeParamVisitor = new TypeParamVisitor();
// visit the nodes
node.getType().accept(typeParamVisitor, null);
// consolidate results
constraintsSet.addAll(typeParamVisitor.getConstraintsSet());
placeholderMapping.putAll(typeParamVisitor.getPlaceholderMapping());
System.out.println("==================");
// Initializer of the variable
ExpressionTree initializer = node.getInitializer();
if (initializer != null) {
System.out.println("VariableInitializer: " + initializer.toString());
}
return super.visitVariable(node, p);
}
@SuppressWarnings("rawtypes")
public ConstraintSet getConstraintSet() {
return constraintsSet;
}
public Map<TypePlaceholder, Tree> getPlaceholderMapping () {
return placeholderMapping;
}
}

View File

@ -1,95 +0,0 @@
package de.dhbwstuttgart.inferWildcards;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.Tree;
import com.sun.source.util.TreeScanner;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
public class TypeParamVisitor
extends TreeScanner<List<JavaClassName>, Void>
{
//1. List erstellen, welche Methoden gibt es alles.
//2. die Expressions auflösen und Typen aus 1. heraus abfragen.
//Vistor für Expressions anlegen.
@SuppressWarnings("rawtypes")
private final ConstraintSet constraintsSet;
private final Map<TypePlaceholder, Tree> placeholderMapping;
public TypeParamVisitor () {
this.constraintsSet = new ConstraintSet<>();
this.placeholderMapping = new HashMap<>();
}
private TypePlaceholder generateTypePlaceholder (Tree t) {
TypePlaceholder tph = TypePlaceholder.fresh(new NullToken());
placeholderMapping.put(tph, t);
return tph;
}
@SuppressWarnings("rawtypes")
@Override
public List<JavaClassName> visitParameterizedType (ParameterizedTypeTree node, Void p) {
System.out.println("ParameterizedType: " + node.toString());
List<JavaClassName> list = new ArrayList<>();
node.getTypeArguments().forEach(t -> {
System.out.println("Parameters: ---");
// generate Type Placeholder
TypePlaceholder tph = generateTypePlaceholder(t);
// Search for the type parameter
List<JavaClassName> foundClassNames = t.accept(this, null);
foundClassNames.forEach(name -> {
ConstraintSet constraints = ConstraintsGenerationUtils.generateConstraints(name, tph);
constraintsSet.addAll(constraints);
});
// consolidate results
list.addAll(foundClassNames);
System.out.println("---------------");
});
return list;
}
@Override
public List<JavaClassName> visitIdentifier (IdentifierTree node, Void p) {
System.out.println("Identifier: " + node.toString());
List<JavaClassName> list = new ArrayList<>();
list.add(new JavaClassName(node.getName().toString()));
return list;
}
@Override
public List<JavaClassName> reduce (List<JavaClassName> r1, List<JavaClassName> r2) {
r1.addAll(r2);
return r1;
}
@SuppressWarnings("rawtypes")
public ConstraintSet getConstraintsSet () {
return constraintsSet;
}
public Map<TypePlaceholder, Tree> getPlaceholderMapping () {
return placeholderMapping;
}
}