Strongly typed AST: dictionary and set literal#294
Strongly typed AST: dictionary and set literal#294andrea-guarino-sonarsource merged 3 commits intomasterfrom
Conversation
889a8f4 to
348769f
Compare
348769f to
011e975
Compare
011e975 to
914b91b
Compare
| import java.util.Set; | ||
|
|
||
| public interface PySetLiteralTree extends PyDictOrSetLiteralTree { | ||
| Set<PyExpressionTree> elements(); |
|
|
||
| @Override | ||
| public void visitSetLiteral(PySetLiteralTree pySetLiteralTree) { | ||
| scan(new ArrayList<>(pySetLiteralTree.elements())); |
There was a problem hiding this comment.
There's no need to instantiate a new list if you are not using a set in the interface.
| } | ||
|
|
||
| @Override | ||
| public Set<PyKeyValuePairTree> elements() { |
There was a problem hiding this comment.
A set seems to be a not so good choice in terms of API : order is not guaranteed for API user whereas in the case of an AST order of elements matters.
| import com.sonar.sslr.api.Token; | ||
| import java.util.List; | ||
|
|
||
| public interface PyDictOrSetLiteralTree extends PyExpressionTree { |
There was a problem hiding this comment.
Given this interface is just a way to factorize code (and btw, factorization by inheritance is not necessarily a good pattern) I believe you could push things one step further with a type parameter :
class PyDictOrSetLiteralTree<T ? extends ExpressionTree>... {
List<T> elements();
}
and specialize this in the inheritance.
There was a problem hiding this comment.
Not really sure this is worth it though... I would eventually be more in favor of not complexifying the type hierarchy and I would strongly suggest to avoid this intermediate level in the API as it is not meaningful in the interfaces (those don't share a common thing in term of language construction). (fine in the implementation though, even if it is factorization through inheritance).
e4978fb to
fcffbe3
Compare
|
|
||
| @Override | ||
| public List<Tree> children() { | ||
| return elements.stream().map(element -> (Tree) element).collect(Collectors.toList()); |
There was a problem hiding this comment.
Why Collections.unmodifiableList would not work like in PyStatementListTreeImpl ?
|
|
||
| @Override | ||
| public List<Tree> children() { | ||
| return elements.stream().map(element -> (Tree) element).collect(Collectors.toList()); |
There was a problem hiding this comment.
Why Collections.unmodifiableList would not work like in PyStatementListTreeImpl ?
GitOrigin-RevId: aa295aedc41cb4da318c6a4d9e21ede340222a1c
No description provided.