org.sonar.sslr.internal.ast.select
Class SingleAstSelect

java.lang.Object
  extended by org.sonar.sslr.internal.ast.select.SingleAstSelect
All Implemented Interfaces:
Iterable<AstNode>, AstSelect

public class SingleAstSelect
extends Object
implements AstSelect

AstSelect which contains exactly one element.


Constructor Summary
SingleAstSelect(AstNode node)
           
 
Method Summary
 AstSelect children()
          Returns new selection, which contains children of this selection.
 AstSelect children(AstNodeType... types)
          Returns new selection, which contains children of a given types of this selection.
 AstSelect children(AstNodeType type)
          Returns new selection, which contains children of a given type of this selection.
 AstSelect descendants(AstNodeType... types)
          Returns new selection, which contains descendants of a given types of this selection.
 AstSelect descendants(AstNodeType type)
          Returns new selection, which contains descendants of a given type of this selection.
 AstSelect filter(AstNodeType... types)
          Returns new selection, which contains elements of this selection that have any one of the given types.
 AstSelect filter(AstNodeType type)
          Returns new selection, which contains elements of this selection that have given type.
 AstSelect filter(com.google.common.base.Predicate<AstNode> predicate)
          Returns new selection, which contains elements of this selection that satisfy a predicate.
 AstSelect firstAncestor(AstNodeType... types)
          Returns new selection, which contains first ancestor of one of the given types for each node from this selection.
 AstSelect firstAncestor(AstNodeType type)
          Returns new selection, which contains first ancestor of a given type for each node from this selection.
 AstNode get(int index)
          Returns the element at the specified position in this selection.
 boolean isEmpty()
          Returns true if this selection contains no elements.
 boolean isNotEmpty()
          Returns true if this selection contains elements.
 Iterator<AstNode> iterator()
          Returns an iterator over the elements in this selection.
 AstSelect nextSibling()
          Returns new selection, which contains next sibling for each node from this selection.
 AstSelect parent()
          Returns new selection, which contains parent for each node from this selection.
 AstSelect previousSibling()
          Returns new selection, which contains previous sibling for each node from this selection.
 int size()
          Returns the number of elements in this selection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleAstSelect

public SingleAstSelect(AstNode node)
Method Detail

children

public AstSelect children()
Description copied from interface: AstSelect
Returns new selection, which contains children of this selection.

Specified by:
children in interface AstSelect

children

public AstSelect children(AstNodeType type)
Description copied from interface: AstSelect
Returns new selection, which contains children of a given type of this selection.

In the following case, children("B") would return "B2" and "B3":

 A1
  |__ C1
  |    |__ B1
  |__ B2
  |__ B3
 

Specified by:
children in interface AstSelect

children

public AstSelect children(AstNodeType... types)
Description copied from interface: AstSelect
Returns new selection, which contains children of a given types of this selection.

Specified by:
children in interface AstSelect
See Also:
AstSelect.children(AstNodeType)

nextSibling

public AstSelect nextSibling()
Description copied from interface: AstSelect
Returns new selection, which contains next sibling for each node from this selection.

In the following case, for selection "B1" nextSibling() would return "B2":

 A1
  |__ B1
  |    |__ C1
  |__ B2
 

Specified by:
nextSibling in interface AstSelect

previousSibling

public AstSelect previousSibling()
Description copied from interface: AstSelect
Returns new selection, which contains previous sibling for each node from this selection.

In the following case, for selection "B2" previousSibling() would return "B1":

 A1
  |__ B1
  |    |__ C1
  |__ B2
 

Specified by:
previousSibling in interface AstSelect

parent

public AstSelect parent()
Description copied from interface: AstSelect
Returns new selection, which contains parent for each node from this selection.

Specified by:
parent in interface AstSelect

firstAncestor

public AstSelect firstAncestor(AstNodeType type)
Description copied from interface: AstSelect
Returns new selection, which contains first ancestor of a given type for each node from this selection.

In the following case, for selection "B2" firstAncestor("A") would return "A2":

 A1
  |__ A2
       |__ B1
       |__ B2
 

Specified by:
firstAncestor in interface AstSelect

firstAncestor

public AstSelect firstAncestor(AstNodeType... types)
Description copied from interface: AstSelect
Returns new selection, which contains first ancestor of one of the given types for each node from this selection.

Specified by:
firstAncestor in interface AstSelect
See Also:
AstSelect.firstAncestor(AstNodeType)

descendants

public AstSelect descendants(AstNodeType type)
Description copied from interface: AstSelect
Returns new selection, which contains descendants of a given type of this selection. Be careful, this method searches among all descendants whatever is their depth, so favor AstSelect.children(AstNodeType) when possible.

In the following case, getDescendants("B") would return "B1", "B2" and "B3":

 A1
  |__ C1
  |    |__ B1
  |__ B2
  |__ D1
  |__ B3
 

Specified by:
descendants in interface AstSelect

descendants

public AstSelect descendants(AstNodeType... types)
Description copied from interface: AstSelect
Returns new selection, which contains descendants of a given types of this selection.

Specified by:
descendants in interface AstSelect
See Also:
AstSelect.descendants(AstNodeType)

isEmpty

public boolean isEmpty()
Description copied from interface: AstSelect
Returns true if this selection contains no elements.

Specified by:
isEmpty in interface AstSelect
Returns:
true if this selection contains no elements

isNotEmpty

public boolean isNotEmpty()
Description copied from interface: AstSelect
Returns true if this selection contains elements.

Specified by:
isNotEmpty in interface AstSelect
Returns:
true if this selection contains elements

filter

public AstSelect filter(AstNodeType type)
Description copied from interface: AstSelect
Returns new selection, which contains elements of this selection that have given type.

Specified by:
filter in interface AstSelect

filter

public AstSelect filter(AstNodeType... types)
Description copied from interface: AstSelect
Returns new selection, which contains elements of this selection that have any one of the given types.

Specified by:
filter in interface AstSelect

filter

public AstSelect filter(com.google.common.base.Predicate<AstNode> predicate)
Description copied from interface: AstSelect
Returns new selection, which contains elements of this selection that satisfy a predicate.

Specified by:
filter in interface AstSelect

size

public int size()
Description copied from interface: AstSelect
Returns the number of elements in this selection.

Specified by:
size in interface AstSelect
Returns:
the number of elements in this selection

get

public AstNode get(int index)
Description copied from interface: AstSelect
Returns the element at the specified position in this selection.

Specified by:
get in interface AstSelect
Parameters:
index - index of the element to return
Returns:
the element at the specified position in this selection

iterator

public Iterator<AstNode> iterator()
Description copied from interface: AstSelect
Returns an iterator over the elements in this selection.

Specified by:
iterator in interface Iterable<AstNode>
Specified by:
iterator in interface AstSelect
Returns:
an iterator over the elements in this selection


Copyright © 2009-2014 SonarSource. All Rights Reserved.