Package eu.clarin.sru.fcs.qlparser
Class AbstractQueryNode<Q extends AbstractQueryNode<Q,T,V>,T extends AbstractQueryNode.AbstractQueryNodeType,V extends AbstractQueryNode.AbstractQueryVisitor>
- java.lang.Object
-
- eu.clarin.sru.fcs.qlparser.AbstractQueryNode<Q,T,V>
-
public abstract class AbstractQueryNode<Q extends AbstractQueryNode<Q,T,V>,T extends AbstractQueryNode.AbstractQueryNodeType,V extends AbstractQueryNode.AbstractQueryVisitor> extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AbstractQueryNode.AbstractQueryNodeType
Interface for node types of query expression tree nodes.static interface
AbstractQueryNode.AbstractQueryVisitor
Interface implementing a Visitor pattern for query expression trees.static class
AbstractQueryNode.SourceLocation
Source information wrapping start and stop offsets in the query text for a query node.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractQueryNode(T nodeType)
Constructor.protected
AbstractQueryNode(T nodeType, List<Q> children)
Constructor.protected
AbstractQueryNode(T nodeType, Q child)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
accept(V visitor)
Q
getChild(int idx)
Get a child node by index.<X extends Q>
XgetChild(Class<X> clazz, int idx)
Get a child node of specified type by index.int
getChildCount()
Get the number of children of this node.List<Q>
getChildren()
The children of this node.Q
getFirstChild()
Get this first child node.<X extends Q>
XgetFirstChild(Class<X> clazz)
Get a first child node of specified type.Q
getLastChild()
Get this last child node.AbstractQueryNode.SourceLocation
getLocation()
Get source location information about start/stop offsets for this query node in the query text content.T
getNodeType()
Get the node type of this node.Q
getParent()
Get the parent node of this node.boolean
hasNodeType(T nodeType)
Check, if node if of given type.void
setLocation(AbstractQueryNode.SourceLocation location)
Set source location information.protected void
setParent(Q parent)
String
toString()
-
-
-
Field Detail
-
nodeType
protected final T extends AbstractQueryNode.AbstractQueryNodeType nodeType
-
parent
protected Q extends AbstractQueryNode<Q,T,V> parent
-
location
protected AbstractQueryNode.SourceLocation location
-
-
Constructor Detail
-
AbstractQueryNode
protected AbstractQueryNode(T nodeType, List<Q> children)
Constructor.- Parameters:
nodeType
- the type of the nodechildren
- the children of this node ornull
if none
-
AbstractQueryNode
protected AbstractQueryNode(T nodeType, Q child)
Constructor.- Parameters:
nodeType
- the type of the nodechild
- the child of this node ornull
if none
-
AbstractQueryNode
protected AbstractQueryNode(T nodeType)
Constructor.- Parameters:
nodeType
- the type of the node
-
-
Method Detail
-
getNodeType
public T getNodeType()
Get the node type of this node.- Returns:
- the node type
-
hasNodeType
public boolean hasNodeType(T nodeType)
Check, if node if of given type.- Parameters:
nodeType
- type to check against- Returns:
true
if node is of given type,false
otherwise
-
getParent
public Q getParent()
Get the parent node of this node.- Returns:
- the parent node or
null
if this is the root node
-
setParent
protected final void setParent(Q parent)
-
getChildren
public List<Q> getChildren()
The children of this node.- Returns:
- the list of children of this node
-
getChildCount
public int getChildCount()
Get the number of children of this node.- Returns:
- the number of children of this node
-
getChild
public Q getChild(int idx)
Get a child node by index.- Parameters:
idx
- the index of the child node- Returns:
- the child node of this node or
null
if index is out of bounds
-
getFirstChild
public Q getFirstChild()
Get this first child node.- Returns:
- the first child node of this node or
null
if none
-
getLastChild
public Q getLastChild()
Get this last child node.- Returns:
- the last child node of this node or
null
if none
-
getChild
public <X extends Q> X getChild(Class<X> clazz, int idx)
Get a child node of specified type by index. Only child nodes of the requested type are counted.- Type Parameters:
X
- the class of the nodes to be considered- Parameters:
clazz
- the type to nodes to be consideredidx
- the index of the child node- Returns:
- the child node of this node or
null
if no child was found
-
getFirstChild
public <X extends Q> X getFirstChild(Class<X> clazz)
Get a first child node of specified type.- Type Parameters:
X
- the class of the nodes to be considered- Parameters:
clazz
- the type to nodes to be considered- Returns:
- the child node of this node or
null
if no child was found
-
getLocation
public AbstractQueryNode.SourceLocation getLocation()
Get source location information about start/stop offsets for this query node in the query text content.- Returns:
- the location information with the span convering the query node in the query
-
setLocation
public final void setLocation(AbstractQueryNode.SourceLocation location)
Set source location information.- Parameters:
location
- the location information with the span convering the query node in the query
-
accept
public abstract void accept(V visitor)
-
-