Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 18332:65a160d9d259
Truffle: add NodeInterface and require that all child fields be of this type
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Mon, 10 Nov 2014 19:29:08 +0100 |
parents | c88ab4f1f04a |
children | e3c95cbbb50c |
comparison
equal
deleted
inserted
replaced
18331:803b0b06e408 | 18332:65a160d9d259 |
---|---|
222 this.childOffsets = toLongArray(childOffsetsList); | 222 this.childOffsets = toLongArray(childOffsetsList); |
223 this.childrenOffsets = toLongArray(childrenOffsetsList); | 223 this.childrenOffsets = toLongArray(childrenOffsetsList); |
224 this.clazz = clazz; | 224 this.clazz = clazz; |
225 } | 225 } |
226 | 226 |
227 private static boolean isNodeType(Class<?> clazz) { | |
228 return Node.class.isAssignableFrom(clazz) || (clazz.isInterface() && NodeInterface.class.isAssignableFrom(clazz)); | |
229 } | |
230 | |
227 private static void checkChildField(Field field) { | 231 private static void checkChildField(Field field) { |
228 if (!(Node.class.isAssignableFrom(field.getType()) || field.getType().isInterface())) { | 232 if (!isNodeType(field.getType())) { |
229 throw new AssertionError("@Child field type must be a subclass of Node or an interface (" + field + ")"); | 233 throw new AssertionError("@Child field type must be a subclass of Node or an interface extending NodeInterface (" + field + ")"); |
230 } | 234 } |
231 if (Modifier.isFinal(field.getModifiers())) { | 235 if (Modifier.isFinal(field.getModifiers())) { |
232 throw new AssertionError("@Child field must not be final (" + field + ")"); | 236 throw new AssertionError("@Child field must not be final (" + field + ")"); |
233 } | 237 } |
234 } | 238 } |
235 | 239 |
236 private static void checkChildrenField(Field field) { | 240 private static void checkChildrenField(Field field) { |
237 if (!(field.getType().isArray() && (Node.class.isAssignableFrom(field.getType().getComponentType()) || field.getType().getComponentType().isInterface()))) { | 241 if (!(field.getType().isArray() && isNodeType(field.getType().getComponentType()))) { |
238 throw new AssertionError("@Children field type must be an array of a subclass of Node or an interface (" + field + ")"); | 242 throw new AssertionError("@Children field type must be an array of a subclass of Node or an interface extending NodeInterface (" + field + ")"); |
239 } | 243 } |
240 if (!Modifier.isFinal(field.getModifiers())) { | 244 if (!Modifier.isFinal(field.getModifiers())) { |
241 throw new AssertionError("@Children field must be final (" + field + ")"); | 245 throw new AssertionError("@Children field must be final (" + field + ")"); |
242 } | 246 } |
243 } | 247 } |