Get first parent of a syntactic item matching the given kind. If no item was found, then null is returned. @param child @param kind @return
(Item child, Class<T> kind)
| 102 | * @return |
| 103 | */ |
| 104 | @Override |
| 105 | public <T extends Item> T getParent(Item child, Class<T> kind) { |
| 106 | // FIXME: this could be optimised a *lot* |
| 107 | for (int i = 0; i != syntacticItems.size(); ++i) { |
| 108 | Item parent = syntacticItems.get(i); |
| 109 | if(kind.isInstance(parent)) { |
| 110 | for(int j=0;j!=parent.size();++j) { |
| 111 | if(parent.get(j) == child) { |
| 112 | return (T) parent; |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | // no match |
| 118 | return null; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public <T extends Item> List<T> getParents(Item child, Class<T> kind) { |