org.eclipse.ocl.lpg
Class AbstractBasicEnvironment

java.lang.Object
  extended by org.eclipse.ocl.lpg.AbstractBasicEnvironment
All Implemented Interfaces:
BasicEnvironment, BasicEnvironment2, Customizable, Adaptable
Direct Known Subclasses:
AbstractEnvironment

public abstract class AbstractBasicEnvironment
extends java.lang.Object
implements BasicEnvironment2

Partial implementation of the BasicEnvironment interface, providing default behaviours for most features.

Since:
1.2

Constructor Summary
protected AbstractBasicEnvironment(BasicEnvironment parent)
          Initializes me with the specified parent environment, which should be of the same type as me.
 
Method Summary
 void analyzerError(java.lang.String problemMessage, java.lang.String problemContext, int startOffset, int endOffset)
          Convenience method invoking getProblemHandler().analyzerProblem with a ProblemHandler.errorSeverity.
 void analyzerError(java.lang.String problemMessage, java.lang.String problemContext, java.util.List<?> problemObjects)
          Convenience method invoking getProblemHandler().analyzerProblem with a ProblemHandler.errorSeverity.
 void analyzerError(java.lang.String problemMessage, java.lang.String problemContext, java.lang.Object problemObject)
          Convenience method invoking getProblemHandler().analyzerProblem with a ProblemHandler.errorSeverity.
 void analyzerWarning(java.lang.String problemMessage, java.lang.String problemContext, java.lang.Object problemObject)
          Convenience method invoking getProblemHandler().analyzerProblem with a ProblemHandler.warningSeverity.
protected  java.util.Map<Option<?>,java.lang.Object> basicGetOptions()
           
 java.util.Map<Option<?>,java.lang.Object> clearOptions()
          Clears all options.
protected  ProblemHandler createDefaultProblemHandler(AbstractParser parser)
           
protected  FormattingHelper createFormattingHelper()
          Obtains the new or existing formatting-helper for this environment to use.
<T> T
getAdapter(java.lang.Class<T> adapterType)
          The abstract environment implementation is adaptable.
 CSTNode getASTMapping(java.lang.Object object)
          Return the mapping of an astNode to its originating cstNode, so that AST-based analysis may report error messages exploiting the CST context, or to support incremental AST/CST update.
 java.util.Map<java.lang.Object,CSTNode> getASTNodeToCSTNodeMap()
           
 FormattingHelper getFormatter()
          Return the message formatter that may be used to format object-related contributions to problem messages.
 java.util.Map<Option<?>,java.lang.Object> getOptions()
          Obtains a copy of my map of options.
 BasicEnvironment getParent()
           
 AbstractParser getParser()
          Return the syntactic parser from which source tokens and text amy be obtained.
 ProblemHandler getProblemHandler()
          Obtains a problem handler to service lexer, parser, analyzer, validator, ...
<T> T
getValue(Option<T> option)
          Obtains the value of the specified option's setting in the my options map.
 void initASTMapping(java.lang.Object astNode, CSTNode cstNode)
          Initialize the mapping of an object (typically an astNode) to its originating cstNode, so that AST-based analysis may report error messages exploiting the CST context, or to support incremental AST/CST update.
 void initASTMapping(java.lang.Object fromAstNode, CSTNode cstNode, java.lang.Object toAstNode)
          Initialize the asymmetric mapping of an object (typically an astNode) to its originating cstNode, and of a cstNode to its consequent object (typically an astNode) so that AST-based analysis may report error messages exploiting the CST context, or to support incremental AST/CST update.
 boolean isEnabled(Option<java.lang.Boolean> option)
          Queries whether the specified boolean-valued option is enabled.
 void lexerError(int errorCode, int startOffset, int endOffset)
          Convenience method invoking getProblemHandler().lexerProblem with a ProblemHandler.errorSeverity.
 void parserError(int errorCode, int leftToken, int rightToken, java.lang.String tokenText)
          Convenience method invoking getProblemHandler().parserProblem with a ProblemHandler.errorSeverity.
 void problem(ProblemHandler.Severity severity, ProblemHandler.Phase phase, java.lang.String problemMessage, java.lang.String problemContext, java.lang.Object problemObject)
          Generically reports a problem about some object.
<T> void
putOptions(java.util.Map<? extends Option<T>,? extends T> options)
          Adds options to apply to my behaviour.
<T> T
removeOption(Option<T> option)
          Removes the specified option.
<T> java.util.Map<Option<T>,T>
removeOptions(java.util.Collection<Option<T>> options)
          Removes the specified options.
 void setASTNodeToCSTNodeMap(java.util.Map<java.lang.Object,CSTNode> astNodeToCstNodeMap)
           
<T> void
setOption(Option<T> option, T value)
          Add an option to apply to my behaviour.
protected  void setParent(BasicEnvironment parent)
          Assigns me a parent environment after construction.
 void setParser(AbstractParser parser)
          Define the syntactic parser from which source tokens and text amy be obtained.
 ProblemHandler setProblemHandler(ProblemHandler newProblemHandler)
          Define the handler for any problem reports.
 void utilityError(java.lang.String problemMessage, java.lang.String problemContext, java.lang.Object problemObject)
          Convenience method invoking getProblemHandler().utilityProblem with a ProblemHandler.errorSeverity.
 void validatorError(java.lang.String problemMessage, java.lang.String problemContext, java.lang.Object problemObject)
          Convenience method invoking getProblemHandler().validatorProblem with a ProblemHandler.errorSeverity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractBasicEnvironment

protected AbstractBasicEnvironment(BasicEnvironment parent)
Initializes me with the specified parent environment, which should be of the same type as me.

Parameters:
parent - an environment of the same type as me (or null)
Method Detail

getAdapter

public <T> T getAdapter(java.lang.Class<T> adapterType)
The abstract environment implementation is adaptable. The default implementation adapts to and interface actually implemented by the receiver in addition to the ProblemHandler interface.

Subclasses may override or extend this implementation.

Specified by:
getAdapter in interface Adaptable
Type Parameters:
T - the requested adapter interface
Parameters:
adapterType - the requested adapter interface
Returns:
an instance of the requested interface, or null if this environment does not adapt to it

analyzerError

public void analyzerError(java.lang.String problemMessage,
                          java.lang.String problemContext,
                          java.lang.Object problemObject)
Description copied from interface: BasicEnvironment
Convenience method invoking getProblemHandler().analyzerProblem with a ProblemHandler.errorSeverity.

Specified by:
analyzerError in interface BasicEnvironment
Parameters:
problemMessage - message describing the problem
problemContext - optional message describing the reporting context
problemObject - optional object associated with the problem

analyzerError

public void analyzerError(java.lang.String problemMessage,
                          java.lang.String problemContext,
                          java.util.List<?> problemObjects)
Description copied from interface: BasicEnvironment
Convenience method invoking getProblemHandler().analyzerProblem with a ProblemHandler.errorSeverity.

Specified by:
analyzerError in interface BasicEnvironment
Parameters:
problemMessage - message describing the problem
problemContext - optional message describing the reporting context
problemObjects - optional sequence of objects associated with the problem

analyzerError

public void analyzerError(java.lang.String problemMessage,
                          java.lang.String problemContext,
                          int startOffset,
                          int endOffset)
Description copied from interface: BasicEnvironment
Convenience method invoking getProblemHandler().analyzerProblem with a ProblemHandler.errorSeverity.

Specified by:
analyzerError in interface BasicEnvironment
Parameters:
problemMessage - message describing the problem
problemContext - optional message describing the reporting context
startOffset - character index at the start of the error
endOffset - character index beyond the end of the error

analyzerWarning

public void analyzerWarning(java.lang.String problemMessage,
                            java.lang.String problemContext,
                            java.lang.Object problemObject)
Description copied from interface: BasicEnvironment
Convenience method invoking getProblemHandler().analyzerProblem with a ProblemHandler.warningSeverity.

Specified by:
analyzerWarning in interface BasicEnvironment
Parameters:
problemMessage - message describing the problem
problemContext - optional message describing the reporting context
problemObject - optional object associated with the problem

createDefaultProblemHandler

protected ProblemHandler createDefaultProblemHandler(AbstractParser parser)

getParent

public BasicEnvironment getParent()

getParser

public AbstractParser getParser()
Description copied from interface: BasicEnvironment
Return the syntactic parser from which source tokens and text amy be obtained.

Specified by:
getParser in interface BasicEnvironment
Returns:
parser

getASTNodeToCSTNodeMap

public java.util.Map<java.lang.Object,CSTNode> getASTNodeToCSTNodeMap()

getASTMapping

public CSTNode getASTMapping(java.lang.Object object)
Description copied from interface: BasicEnvironment
Return the mapping of an astNode to its originating cstNode, so that AST-based analysis may report error messages exploiting the CST context, or to support incremental AST/CST update.

Specified by:
getASTMapping in interface BasicEnvironment
Returns:
cstNode

getFormatter

public FormattingHelper getFormatter()
Description copied from interface: BasicEnvironment
Return the message formatter that may be used to format object-related contributions to problem messages.

Specified by:
getFormatter in interface BasicEnvironment
Returns:
non-null message formatter

createFormattingHelper

protected FormattingHelper createFormattingHelper()
Obtains the new or existing formatting-helper for this environment to use. This default implementation returns the shared AbstractFormattingHelper; subclasses may override.

Returns:
a new formatting helper
Since:
1.3

getProblemHandler

public ProblemHandler getProblemHandler()
Description copied from interface: BasicEnvironment
Obtains a problem handler to service lexer, parser, analyzer, validator, ... errors.

Specified by:
getProblemHandler in interface BasicEnvironment
Returns:
the problem handler.

initASTMapping

public void initASTMapping(java.lang.Object astNode,
                           CSTNode cstNode)
Description copied from interface: BasicEnvironment
Initialize the mapping of an object (typically an astNode) to its originating cstNode, so that AST-based analysis may report error messages exploiting the CST context, or to support incremental AST/CST update.

Specified by:
initASTMapping in interface BasicEnvironment

initASTMapping

public void initASTMapping(java.lang.Object fromAstNode,
                           CSTNode cstNode,
                           java.lang.Object toAstNode)
Description copied from interface: BasicEnvironment2
Initialize the asymmetric mapping of an object (typically an astNode) to its originating cstNode, and of a cstNode to its consequent object (typically an astNode) so that AST-based analysis may report error messages exploiting the CST context, or to support incremental AST/CST update. Any pre-existing mapping is preserved. Each mapping involving a null object is ignored, so that for instance the toAstNode may be set null to establish only the fromAstNode to cstNode mapping.

Specified by:
initASTMapping in interface BasicEnvironment2
Parameters:
fromAstNode - source of the AST-to-CST mapping
cstNode - target of the AST-to-CST mapping and source of the CST-to-AST mapping
toAstNode - target of the CST-to-AST mapping
Since:
1.3

lexerError

public void lexerError(int errorCode,
                       int startOffset,
                       int endOffset)
Description copied from interface: BasicEnvironment
Convenience method invoking getProblemHandler().lexerProblem with a ProblemHandler.errorSeverity.

Specified by:
lexerError in interface BasicEnvironment
Parameters:
errorCode - the ParserErrorCodes value identifying the error
startOffset - character index at the start of the error
endOffset - character index beyond the end of the error

parserError

public void parserError(int errorCode,
                        int leftToken,
                        int rightToken,
                        java.lang.String tokenText)
Description copied from interface: BasicEnvironment
Convenience method invoking getProblemHandler().parserProblem with a ProblemHandler.errorSeverity.

Specified by:
parserError in interface BasicEnvironment
Parameters:
errorCode - the ParserErrorCodes value identifying the error
leftToken - the lexical token index at the left hand edge of the error
rightToken - the lexical token index at the right hand edge of the error
tokenText - additional text apprropriate to the ParserErrorCodes value.

setASTNodeToCSTNodeMap

public void setASTNodeToCSTNodeMap(java.util.Map<java.lang.Object,CSTNode> astNodeToCstNodeMap)

setParent

protected void setParent(BasicEnvironment parent)
Assigns me a parent environment after construction. It is not advisable to set the parent to null if I previously had one.

Parameters:
parent - my new parent

setParser

public void setParser(AbstractParser parser)
Description copied from interface: BasicEnvironment
Define the syntactic parser from which source tokens and text amy be obtained.

Specified by:
setParser in interface BasicEnvironment

setProblemHandler

public ProblemHandler setProblemHandler(ProblemHandler newProblemHandler)
Description copied from interface: BasicEnvironment
Define the handler for any problem reports.

Specified by:
setProblemHandler in interface BasicEnvironment
Returns:
the previous problem handler

utilityError

public void utilityError(java.lang.String problemMessage,
                         java.lang.String problemContext,
                         java.lang.Object problemObject)
Description copied from interface: BasicEnvironment
Convenience method invoking getProblemHandler().utilityProblem with a ProblemHandler.errorSeverity.

Specified by:
utilityError in interface BasicEnvironment
Parameters:
problemMessage - message describing the problem
problemContext - optional message describing the reporting context
problemObject - optional object associated with the problem

validatorError

public void validatorError(java.lang.String problemMessage,
                           java.lang.String problemContext,
                           java.lang.Object problemObject)
Description copied from interface: BasicEnvironment
Convenience method invoking getProblemHandler().validatorProblem with a ProblemHandler.errorSeverity.

Specified by:
validatorError in interface BasicEnvironment
Parameters:
problemMessage - message describing the problem
problemContext - optional message describing the reporting context
problemObject - optional object associated with the problem

problem

public void problem(ProblemHandler.Severity severity,
                    ProblemHandler.Phase phase,
                    java.lang.String problemMessage,
                    java.lang.String problemContext,
                    java.lang.Object problemObject)
Description copied from interface: BasicEnvironment
Generically reports a problem about some object.

Specified by:
problem in interface BasicEnvironment
Parameters:
severity - the severity of the problem
phase - the phase in which the problem was encountered
problemMessage - message describing the problem
problemContext - optional message describing the reporting context
problemObject - optional object associated with the problem

basicGetOptions

protected java.util.Map<Option<?>,java.lang.Object> basicGetOptions()

getOptions

public java.util.Map<Option<?>,java.lang.Object> getOptions()
Description copied from interface: Customizable
Obtains a copy of my map of options. Options not explicitly set in an environment are inherited from the parent environment, if any, otherwise they are at their default values.

Specified by:
getOptions in interface Customizable
Returns:
the map of options

setOption

public <T> void setOption(Option<T> option,
                          T value)
Description copied from interface: Customizable
Add an option to apply to my behaviour.

Specified by:
setOption in interface Customizable
Parameters:
option - the option
value - the option's value

putOptions

public <T> void putOptions(java.util.Map<? extends Option<T>,? extends T> options)
Description copied from interface: Customizable
Adds options to apply to my behaviour.

Specified by:
putOptions in interface Customizable
Parameters:
options - the options

removeOption

public <T> T removeOption(Option<T> option)
Description copied from interface: Customizable
Removes the specified option.

Specified by:
removeOption in interface Customizable
Parameters:
option - the option to remove
Returns:
the former value of the option

removeOptions

public <T> java.util.Map<Option<T>,T> removeOptions(java.util.Collection<Option<T>> options)
Description copied from interface: Customizable
Removes the specified options.

Specified by:
removeOptions in interface Customizable
Parameters:
options - the options to remove
Returns:
the former values of the options

clearOptions

public java.util.Map<Option<?>,java.lang.Object> clearOptions()
Description copied from interface: Customizable
Clears all options.

Specified by:
clearOptions in interface Customizable
Returns:
the former values of the options

isEnabled

public boolean isEnabled(Option<java.lang.Boolean> option)
Description copied from interface: Customizable
Queries whether the specified boolean-valued option is enabled. This method essentially just puts a nice "is" name on boolean options. Options not explicitly set in an environment are inherited from the parent environment, if any, otherwise they are at their default values.

Specified by:
isEnabled in interface Customizable
Parameters:
option - an option
Returns:
whether the option is enabled

getValue

public <T> T getValue(Option<T> option)
Description copied from interface: Customizable
Obtains the value of the specified option's setting in the my options map. Options not explicitly set in an environment are inherited from the parent environment, if any, otherwise they are at their default values.

Specified by:
getValue in interface Customizable
Parameters:
option - the option to query
Returns:
value of the option