add comments
This commit is contained in:
parent
3e57a64f9c
commit
c96c56e882
@ -1,19 +1,14 @@
|
||||
package de.dhbwstuttgart.inferWildcards;
|
||||
|
||||
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.PrimitiveTypeTree;
|
||||
import com.sun.source.tree.ExpressionStatementTree;
|
||||
import com.sun.source.tree.ExpressionTree;
|
||||
import com.sun.source.tree.Tree;
|
||||
import com.sun.source.tree.TypeParameterTree;
|
||||
import com.sun.source.tree.VariableTree;
|
||||
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;
|
||||
|
||||
@ -31,64 +26,49 @@ public class InferWildcardsVisitor
|
||||
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 Void visitParameterizedType (ParameterizedTypeTree node, Void p) {
|
||||
System.out.println("ParameterizedType: " + node.toString());
|
||||
|
||||
List<? extends Tree> typeArguments = node.getTypeArguments();
|
||||
typeArguments.forEach(t -> {
|
||||
// generate Type Placeholder
|
||||
TypePlaceholder tph = generateTypePlaceholder(t);
|
||||
|
||||
// Search for the type parameter
|
||||
List<JavaClassName> foundClassNames = t.accept(new TypeParamVisitor(), null);
|
||||
foundClassNames.forEach(name -> {
|
||||
ConstraintSet constraints = ConstraintsGenerationUtils.generateConstraints(name, tph);
|
||||
constraintsSet.addAll(constraints);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
return super.visitParameterizedType(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPrimitiveType (PrimitiveTypeTree node, Void p) {
|
||||
System.out.println("PrimitiveType: " + node.toString());
|
||||
return super.visitPrimitiveType(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitIdentifier (IdentifierTree node, Void p) {
|
||||
System.out.println("Identifier: " + node.toString());
|
||||
return super.visitIdentifier(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitTypeParameter (TypeParameterTree node, Void p) {
|
||||
System.out.println("TypeParameter: " + node.toString());
|
||||
return super.visitTypeParameter(node, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitOther (Tree node, Void p) {
|
||||
System.out.println("Other: " + node.toString());
|
||||
// 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;
|
||||
}
|
||||
|
@ -1,25 +1,80 @@
|
||||
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) {
|
||||
ArrayList<JavaClassName> list = new ArrayList<>();
|
||||
System.out.println("Identifier: " + node.toString());
|
||||
|
||||
List<JavaClassName> list = new ArrayList<>();
|
||||
list.add(new JavaClassName(node.getName().toString()));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -28,4 +83,13 @@ public class TypeParamVisitor
|
||||
r1.addAll(r2);
|
||||
return r1;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public ConstraintSet getConstraintsSet () {
|
||||
return constraintsSet;
|
||||
}
|
||||
|
||||
public Map<TypePlaceholder, Tree> getPlaceholderMapping () {
|
||||
return placeholderMapping;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user