org.python.indexer.ast
Class NNode
- java.lang.Object
-
- org.python.indexer.ast.NNode
-
- All Implemented Interfaces:
- java.io.Serializable
- Direct Known Subclasses:
- NAlias, NAssert, NAssign, NAttribute, NAugAssign, NBinOp, NBlock, NBoolOp, NBreak, NCall, NClassDef, NCompare, NComprehension, NContinue, NDelete, NDict, NEllipsis, NExceptHandler, NExec, NExprStmt, NFor, NFunctionDef, NGeneratorExp, NGlobal, NIf, NIfExp, NImport, NImportFrom, NIndex, NKeyword, NListComp, NModule, NName, NNum, NPass, NPlaceHolder, NPrint, NQname, NRaise, NRepr, NReturn, NSequence, NSlice, NStr, NSubscript, NTryExcept, NTryFinally, NUnaryOp, NUrl, NWhile, NWith, NYield
public abstract class NNode extends java.lang.Object implements java.io.Serializable- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description voidaddChildren(java.util.List<? extends NNode> nodes)voidaddChildren(NNode... nodes)NTypeaddType(NType newType)Adds a new type for the node, creating a union of the previous type and the new type.booleanbindsName()Returnstrueif this is a name-binding node.intend()NNodegetAstRoot()NNodegetDeepestNodeAtOffset(int sourceOffset)Searches the AST for the deepest node that overlaps the specified source offset.ScopegetEnclosingNamespace()Returns the innermost enclosing scope for doing (non-attribute) name lookups.java.lang.StringgetFile()NNodegetParent()ScopegetTable()Utility alias forgetType().getTable().NTypegetType()Returns the type for this node.booleanisCall()booleanisClassDef()booleanisFunctionDef()booleanisLambda()booleanisModule()booleanisName()intlength()NTyperesolve(Scope s)Node should set the resolved type in itstypefield and also return it.static NTyperesolveExpr(NNode n, Scope s)voidsetEnd(int end)voidsetParent(NNode parent)voidsetStart(int start)NTypesetType(NType newType)Sets the type for the node.intstart()abstract voidvisit(NNodeVisitor visitor)Visits this node and optionally its children.
-
-
-
Method Detail
-
setParent
public void setParent(NNode parent)
-
getParent
public NNode getParent()
-
getAstRoot
public NNode getAstRoot()
-
setStart
public void setStart(int start)
-
setEnd
public void setEnd(int end)
-
start
public int start()
-
end
public int end()
-
length
public int length()
-
getTable
public Scope getTable()
Utility alias forgetType().getTable().
-
getType
public NType getType()
Returns the type for this node. It is nevernull. If the node has not been resolved, the type will default toIndexer.idx.builtins.None.
-
setType
public NType setType(NType newType)
Sets the type for the node.- Parameters:
newType- the new type- Returns:
newType- Throws:
java.lang.IllegalArgumentException- ifnewTypeisnull
-
addType
public NType addType(NType newType)
Adds a new type for the node, creating a union of the previous type and the new type.- Parameters:
newType- the new type- Returns:
- the resulting type for the node
- Throws:
java.lang.IllegalArgumentException- ifnewTypeisnull
-
bindsName
public boolean bindsName()
Returnstrueif this is a name-binding node. Includes functions/lambdas, function/lambda params, classes, assignments, imports, and implicit assignment via for statements and except clauses.- See Also:
- PEP 227
-
getFile
public java.lang.String getFile()
- Returns:
- the path to the code that generated this AST
-
addChildren
public void addChildren(NNode... nodes)
-
addChildren
public void addChildren(java.util.List<? extends NNode> nodes)
-
resolve
public NType resolve(Scope s) throws java.lang.Exception
Node should set the resolved type in itstypefield and also return it.- Throws:
java.lang.Exception
-
isCall
public boolean isCall()
-
isModule
public boolean isModule()
-
isClassDef
public boolean isClassDef()
-
isFunctionDef
public boolean isFunctionDef()
-
isLambda
public boolean isLambda()
-
isName
public boolean isName()
-
visit
public abstract void visit(NNodeVisitor visitor)
Visits this node and optionally its children.- Parameters:
visitor- the object to call with this node. If the visitor returnstrue, the node also passes its children to the visitor.
-
getEnclosingNamespace
public Scope getEnclosingNamespace()
Returns the innermost enclosing scope for doing (non-attribute) name lookups. If the current node defines a scope, it returns the parent scope for name lookups.- Returns:
- the enclosing function, class, instance, module or builtin scope. If this node has not yet been resolved, returns the builtin namespace.
-
getDeepestNodeAtOffset
public NNode getDeepestNodeAtOffset(int sourceOffset)
Searches the AST for the deepest node that overlaps the specified source offset. Can be called from any node in the AST, as it traverses to the parent before beginning the search.- Parameters:
sourceOffset- the spot at which to look for a node- Returns:
- the deepest AST node whose start is greater than or equal to the offset,
and whose end is less than or equal to the offset. Returns
nullif no node overlapssourceOffset.
-
-
DMelt 3.0 © DataMelt by jWork.ORG