blob: a0ddbaf10cc29888d2c002c8ae843812bdb848d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package org.checkerframework.dataflow.cfg.node;
import com.sun.source.tree.LambdaExpressionTree;
import com.sun.source.tree.MemberReferenceTree;
import com.sun.source.tree.Tree;
import java.util.Collection;
import java.util.LinkedList;
import org.checkerframework.javacutil.ErrorReporter;
import org.checkerframework.javacutil.InternalUtils;
/**
* A node for member references and lambdas.
*
* <p>The {@link Node#type} of a FunctionalInterfaceNode is determined by the assignment context the
* member reference or lambda is used in.
*
* <pre>
* <em>FunctionalInterface func = param1, param2, ... → statement</em>
* </pre>
*
* <pre>
* <em>FunctionalInterface func = param1, param2, ... → { ... }</em>
* </pre>
*
* <pre>
* <em>FunctionalInterface func = member reference</em>
* </pre>
*
* @author David
*/
public class FunctionalInterfaceNode extends Node {
protected Tree tree;
public FunctionalInterfaceNode(MemberReferenceTree tree) {
super(InternalUtils.typeOf(tree));
this.tree = tree;
}
public FunctionalInterfaceNode(LambdaExpressionTree tree) {
super(InternalUtils.typeOf(tree));
this.tree = tree;
}
@Override
public Tree getTree() {
return tree;
}
@Override
public <R, P> R accept(NodeVisitor<R, P> visitor, P p) {
return visitor.visitMemberReference(this, p);
}
@Override
public String toString() {
if (tree instanceof LambdaExpressionTree) {
return "FunctionalInterfaceNode:" + ((LambdaExpressionTree) tree).getBodyKind();
} else if (tree instanceof MemberReferenceTree) {
return "FunctionalInterfaceNode:" + ((MemberReferenceTree) tree).getName();
} else {
// This should never happen.
ErrorReporter.errorAbort("Invalid tree in FunctionalInterfaceNode");
return null; // Dead code
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FunctionalInterfaceNode that = (FunctionalInterfaceNode) o;
if (tree != null ? !tree.equals(that.tree) : that.tree != null) return false;
return true;
}
@Override
public int hashCode() {
return tree != null ? tree.hashCode() : 0;
}
@Override
public Collection<Node> getOperands() {
LinkedList<Node> list = new LinkedList<Node>();
return list;
}
}
|