/** * Provides a collection of all the nodes in the tree * using a depth-first preorder traversal. * * @param c the closure to run for each node (a one or two parameter can be used; if one parameter is given the * closure will be passed the node, for a two param closure the second parameter will be the level). * @since 2.5.0 */ public void depthFirst(Closure c) { Map<String, Object> options = new ListHashMap<String, Object>(); options.put("preorder", true); depthFirst(options, c); }
/** * Copies all node meta data from the other node to this one * @param other - the other node */ public void copyNodeMetaData(ASTNode other) { if (other.metaDataMap == null) { return; } if (metaDataMap == null) { metaDataMap = new ListHashMap(); } metaDataMap.putAll(other.metaDataMap); }
/** * Calls the provided closure for all the nodes in the tree * using a breadth-first preorder traversal. * * @param c the closure to run for each node (a one or two parameter can be used; if one parameter is given the * closure will be passed the node, for a two param closure the second parameter will be the level). * @since 2.5.0 */ public void breadthFirst(Closure c) { Map<String, Object> options = new ListHashMap<String, Object>(); options.put("preorder", true); breadthFirst(options, c); }
/** * Sets the node meta data but allows overwriting values. * * @param key - the meta data key * @param value - the meta data value * @return the old node meta data value for this key * @throws GroovyBugError if key is null */ public Object putNodeMetaData(Object key, Object value) { if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + "."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } return metaDataMap.put(key, value); }
/** * Sets the node meta data but allows overwriting values. * * @param key - the meta data key * @param value - the meta data value * @return the old node meta data value for this key * @throws GroovyBugError if key is null */ public Object putNodeMetaData(Object key, Object value) { if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + "."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } return metaDataMap.put(key, value); }
/** * Sets the node meta data for the provided key. * * @param key - the meta data key * @param value - the meta data value * @throws GroovyBugError if key is null or there is already meta * data under that key */ public void setNodeMetaData(Object key, Object value) { if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+"."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } Object old = metaDataMap.put(key,value); if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+"."); }
/** * Sets the node meta data. * * @param key - the meta data key * @param value - the meta data value * @throws GroovyBugError if key is null or there is already meta * data under that key */ public void setNodeMetaData(Object key, Object value) { if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+"."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } Object old = metaDataMap.put(key,value); if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+"."); }
protected void saveVariableExpressionMetadata(final Set<VariableExpression> closureSharedExpressions, final Map<VariableExpression, ListHashMap> typesBeforeVisit) { for (VariableExpression ve : closureSharedExpressions) { // GROOVY-6921: We must force a call to getType in order to update closure shared variable whose // types are inferred thanks to closure parameter type inference getType(ve); ListHashMap<StaticTypesMarker, Object> metadata = new ListHashMap<StaticTypesMarker, Object>(); for (StaticTypesMarker marker : StaticTypesMarker.values()) { Object value = ve.getNodeMetaData(marker); if (value != null) { metadata.put(marker, value); } } typesBeforeVisit.put(ve, metadata); Variable accessedVariable = ve.getAccessedVariable(); if (accessedVariable != ve && accessedVariable instanceof VariableExpression) { saveVariableExpressionMetadata(Collections.singleton((VariableExpression) accessedVariable), typesBeforeVisit); } } }