MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / getAncestor

Method getAncestor

src/main/java/wycc/util/AbstractHeap.java:146–170  ·  view source on GitHub ↗

Get first ancestor 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)

Source from the content-addressed store, hash-verified

144 * @return
145 */
146 @Override
147 public <T extends Item> T getAncestor(Item child, Class<T> kind) {
148 // FIXME: this could be optimised a *lot*
149 if (kind.isInstance(child)) {
150 return (T) child;
151 } else {
152 for (int i = 0; i != syntacticItems.size(); ++i) {
153 Item parent = syntacticItems.get(i);
154 for (int j = 0; j != parent.size(); ++j) {
155 // Don't follow cross-references
156 if (parent.get(j) == child && !(parent instanceof AbstractCompilationUnit.Ref)) {
157 // FIXME: this is not specifically efficient. It would
158 // be helpful if SyntacticItems actually contained
159 // references to their parent items.
160 T tmp = getAncestor(parent, kind);
161 if (tmp != null) {
162 return tmp;
163 }
164 }
165 }
166 }
167 // no match
168 return null;
169 }
170 }
171
172 @Override
173 public <T extends Item> List<T> findAll(Class<T> kind) {

Callers

nothing calls this directly

Calls 3

getMethod · 0.95
sizeMethod · 0.95
sizeMethod · 0.65

Tested by

no test coverage detected