Top Inners Fields Constructors Methods
org.python.indexer.ast

public abstract Class NNode

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.python.indexer.ast.NNum, org.python.indexer.ast.NPass, org.python.indexer.ast.NPlaceHolder, org.python.indexer.ast.NPrint, org.python.indexer.ast.NQname, org.python.indexer.ast.NRaise, org.python.indexer.ast.NRepr, org.python.indexer.ast.NReturn, org.python.indexer.ast.NSequence, org.python.indexer.ast.NSlice, org.python.indexer.ast.NStr, org.python.indexer.ast.NSubscript, org.python.indexer.ast.NTryExcept, org.python.indexer.ast.NTryFinally, org.python.indexer.ast.NUnaryOp, org.python.indexer.ast.NUrl, org.python.indexer.ast.NWhile, org.python.indexer.ast.NWith, org.python.indexer.ast.NYield, org.python.indexer.ast.NDelete, org.python.indexer.ast.NModule, org.python.indexer.ast.NAlias, org.python.indexer.ast.NAssert, org.python.indexer.ast.NAssign, org.python.indexer.ast.NAttribute, org.python.indexer.ast.NAugAssign, org.python.indexer.ast.NBinOp, org.python.indexer.ast.NBlock, org.python.indexer.ast.NBoolOp, org.python.indexer.ast.NBreak, org.python.indexer.ast.NCall, org.python.indexer.ast.NClassDef, org.python.indexer.ast.NCompare, org.python.indexer.ast.NComprehension, org.python.indexer.ast.NContinue, org.python.indexer.ast.NDict, org.python.indexer.ast.NEllipsis, org.python.indexer.ast.NExceptHandler, org.python.indexer.ast.NExec, org.python.indexer.ast.NExprStmt, org.python.indexer.ast.NFor, org.python.indexer.ast.NFunctionDef, org.python.indexer.ast.NGeneratorExp, org.python.indexer.ast.NGlobal, org.python.indexer.ast.NIf, org.python.indexer.ast.NIfExp, org.python.indexer.ast.NImport, org.python.indexer.ast.NImportFrom, org.python.indexer.ast.NIndex, org.python.indexer.ast.NKeyword, org.python.indexer.ast.NListComp, org.python.indexer.ast.NName
Imports
org.python.indexer.Indexer, .IndexingException, .NBinding, .Scope, org.python.indexer.types.NClassType, .NFuncType, .NType, .NUnionType, .NUnknownType, java.util.List

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
NNode.DeepestOverlappingNodeFinder

Assumes nodes are always traversed in increasing order of their start positions.

Field Summary

Modifier and TypeField and Description
private int
protected NNode
pack-priv static final long
private int
private transient NType
type

This is marked transient to prevent serialization.

Constructor Summary

AccessConstructor and Description
public
public
NNode(int start, int end)

Method Summary

Modifier and TypeMethod and Description
public void
addChildren(NNode... nodes)

public void
addChildren(List<? extends NNode> nodes)

protected void
protected void
addError(NNode loc, String msg)

public NType

Returns:

the resulting type for the node
addType
(NType
the new type
newType
)

Adds a new type for the node, creating a union of the previous type and the new type.

protected void
protected void
protected void
bindNames(Scope s)

Called by resolver to bind names into the passed scope.

public boolean
bindsName()

Returns true if this is a name-binding node.

public int
end()

public NNode
public NNode

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 null if no node overlaps sourceOffset.
getDeepestNodeAtOffset
(int
the spot at which to look for a node
sourceOffset
)

Searches the AST for the deepest node that overlaps the specified source offset.

public Scope

Returns:

the enclosing function, class, instance, module or builtin scope. If this node has not yet been resolved, returns the builtin namespace.
getEnclosingNamespace
()

Returns the innermost enclosing scope for doing (non-attribute) name lookups.

public String

Returns:

the path to the code that generated this AST
getFile
()

public NNode
public Scope
getTable()

Utility alias for getType().getTable().

public NType
getType()

Returns the type for this node.

private static NType
public boolean
public boolean
public boolean
public boolean
public boolean
public boolean
public int
public NType
resolve(Scope s)

Node should set the resolved type in its type field and also return it.

public static NType
protected void
resolveList(List<? extends NNode> nodes, Scope s)

Resolves each element of a node list in the passed scope.

protected NType
resolveListAsUnion(List<? extends NNode> nodes, Scope s)

Utility method to resolve every node in nodes and return the union of their types.

public void
setEnd(int end)

public void
setParent(NNode parent)

public void
setStart(int start)

public NType

Returns:

newType
setType
(NType
the new type
newType
)

Sets the type for the node.

public int
public abstract void
visit(NNodeVisitor
the object to call with this node. If the visitor returns true, the node also passes its children to the visitor.
visitor
)

Visits this node and optionally its children.

protected void
protected void
visitNodeList(List<? extends NNode> nodes, NNodeVisitor v)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

endback to summary
private int end
parentback to summary
protected NNode parent
serialVersionUIDback to summary
pack-priv static final long serialVersionUID
startback to summary
private int start
typeback to summary
private transient NType type

This is marked transient to prevent serialization. We re-resolve ASTs after deserializing them. It is private to ensure that the type is never null, as much code in the indexer assumes this precondition.

Constructor Detail

NNodeback to summary
public NNode()
NNodeback to summary
public NNode(int start, int end)

Method Detail

addChildrenback to summary
public void addChildren(NNode... nodes)
addChildrenback to summary
public void addChildren(List<? extends NNode> nodes)
addErrorback to summary
protected void addError(String msg)
addErrorback to summary
protected void addError(NNode loc, String msg)
addTypeback to summary
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:NType

the new type

Returns:NType

the resulting type for the node

Exceptions
IllegalArgumentException:
if newType is null

addWarningback to summary
protected void addWarning(String msg)
addWarningback to summary
protected void addWarning(NNode loc, String msg)
bindNamesback to summary
protected void bindNames(Scope s) throws Exception

Called by resolver to bind names into the passed scope.

bindsNameback to summary
public boolean bindsName()

Returns true if 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
endback to summary
public int end()
getAstRootback to summary
public NNode getAstRoot()
getDeepestNodeAtOffsetback to summary
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:int

the spot at which to look for a node

Returns:NNode

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 null if no node overlaps sourceOffset.

getEnclosingNamespaceback to summary
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:Scope

the enclosing function, class, instance, module or builtin scope. If this node has not yet been resolved, returns the builtin namespace.

getFileback to summary
public String getFile()
Returns:String

the path to the code that generated this AST

getParentback to summary
public NNode getParent()
getTableback to summary
public Scope getTable()

Utility alias for getType().getTable().

getTypeback to summary
public NType getType()

Returns the type for this node. It is never null. If the node has not been resolved, the type will default to Indexer.idx.builtins.None.

handleExceptionInResolveback to summary
private static NType handleExceptionInResolve(NNode n, Throwable t)
isCallback to summary
public boolean isCall()
isClassDefback to summary
public boolean isClassDef()
isFunctionDefback to summary
public boolean isFunctionDef()
isLambdaback to summary
public boolean isLambda()
isModuleback to summary
public boolean isModule()
isNameback to summary
public boolean isName()
lengthback to summary
public int length()
resolveback to summary
public NType resolve(Scope s) throws Exception

Node should set the resolved type in its type field and also return it.

resolveExprback to summary
public static NType resolveExpr(NNode n, Scope s)
resolveListback to summary
protected void resolveList(List<? extends NNode> nodes, Scope s)

Resolves each element of a node list in the passed scope. Node list may be empty or null.

resolveListAsUnionback to summary
protected NType resolveListAsUnion(List<? extends NNode> nodes, Scope s)

Utility method to resolve every node in nodes and return the union of their types. If nodes is empty or null, returns a new NUnknownType.

setEndback to summary
public void setEnd(int end)
setParentback to summary
public void setParent(NNode parent)
setStartback to summary
public void setStart(int start)
setTypeback to summary
public NType setType(NType newType)

Sets the type for the node.

Parameters
newType:NType

the new type

Returns:NType

newType

Exceptions
IllegalArgumentException:
if newType is null

startback to summary
public int start()
visitback to summary
public abstract void visit(NNodeVisitor visitor)

Visits this node and optionally its children.

Parameters
visitor:NNodeVisitor

the object to call with this node. If the visitor returns true, the node also passes its children to the visitor.

visitNodeback to summary
protected void visitNode(NNode n, NNodeVisitor v)
visitNodeListback to summary
protected void visitNodeList(List<? extends NNode> nodes, NNodeVisitor v)
org.python.indexer.ast back to summary

pack-priv Class NNode.DeepestOverlappingNodeFinder

extends GenericNodeVisitor
Class Inheritance

Assumes nodes are always traversed in increasing order of their start positions.

Field Summary

Modifier and TypeField and Description
private NNode
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
dispatch(NNode node)

Overrides org.python.indexer.ast.GenericNodeVisitor.dispatch.

Every visited node is passed to this method.

public NNode

Returns:

the node, or null if no node overlaps the offset
getNode
()

Returns the deepest node overlapping the desired source offset.

Inherited from org.python.indexer.ast.GenericNodeVisitor:
visitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisit

Field Detail

deepestback to summary
private NNode deepest
offsetback to summary
private int offset

Constructor Detail

DeepestOverlappingNodeFinderback to summary
public DeepestOverlappingNodeFinder(int offset)

Method Detail

dispatchback to summary
public boolean dispatch(NNode node)

Overrides org.python.indexer.ast.GenericNodeVisitor.dispatch.

Doc from org.python.indexer.ast.GenericNodeVisitor.dispatch.

Every visited node is passed to this method. The semantics for halting traversal are the same as for DefaultNodeVisitor.

Returns:boolean

true to traverse this node's children

Annotations
@Override

getNodeback to summary
public NNode getNode()

Returns the deepest node overlapping the desired source offset.

Returns:NNode

the node, or null if no node overlaps the offset