com.sonar.sslr.api
Class PreprocessorAction

java.lang.Object
  extended by com.sonar.sslr.api.PreprocessorAction

public class PreprocessorAction
extends java.lang.Object

This class encapsulates the actions to be performed by a preprocessor.


Field Summary
static PreprocessorAction NO_OPERATION
           Use this no operation preprocessor action for improved readability and performances.
 
Constructor Summary
PreprocessorAction(int numberOfConsumedTokens, java.util.List<Trivia> triviaToInject, java.util.List<Token> tokensToInject)
           Construct a preprocessor action.
 
Method Summary
 int getNumberOfConsumedTokens()
           
 java.util.List<Token> getTokensToInject()
           
 java.util.List<Trivia> getTriviaToInject()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_OPERATION

public static final PreprocessorAction NO_OPERATION

Use this no operation preprocessor action for improved readability and performances.

Equivalent to: new PreprocessorAction(0, new ArrayList<Trivia>(), new ArrayList<Token>());

Constructor Detail

PreprocessorAction

public PreprocessorAction(int numberOfConsumedTokens,
                          java.util.List<Trivia> triviaToInject,
                          java.util.List<Token> tokensToInject)

Construct a preprocessor action.

The actions are executed in this order:

  1. Deletions of tokens, handled by numberOfConsumedTokens
  2. Injections of trivia, handled by triviaToInject
  3. Injections of tokens, handled by tokensToInject

Preprocessor actions are executed as follows:

  1. If numberOfConsumedTokens is greater than 0, then this number of tokens are deleted. Their trivia is added to a pending list of trivia. The preprocessor will not be called on deleted tokens.
  2. All trivia from triviaToInject are added to the same pending list of trivia
  3. All tokens from tokensToInject are injected. If present, the first token of tokensToInject is augmented with the pending trivia, which is then cleared. If not present, the pending trivia is left unchanged.
  4. Finally, if numberOfConsumedTokens was 0, the current token is injected, with any pending trivia which is then cleared.

A few examples:

Parameters:
numberOfConsumedTokens - Number of tokens consumed by the preprocessor, which can be 0. Consumed tokens are deleted and will not lead to successive calls to the preprocessor.
triviaToInject - Trivia to inject.
tokensToInject - Tokens to inject. Injected tokens will not lead to successive calls to the preprocessor.
Method Detail

getNumberOfConsumedTokens

public int getNumberOfConsumedTokens()

getTriviaToInject

public java.util.List<Trivia> getTriviaToInject()

getTokensToInject

public java.util.List<Token> getTokensToInject()


Copyright © 2012 SonarSource. All Rights Reserved.