org.eclipse.ocl.parser
Class OCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>

java.lang.Object
  extended by org.eclipse.ocl.lpg.AbstractAnalyzer
      extended by org.eclipse.ocl.parser.AbstractOCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
          extended by org.eclipse.ocl.parser.OCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>

public class OCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
extends AbstractOCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>

The OCLAnalyzer performs semantic analysis on a CST produced by an OCLParser to create the OCL AST. It is necessary that syntactic parsing and semantic analysis are performed in two steps because LPG is a bottom up parser and cannot provide enough contextual information to create the AST on the first pass.


Field Summary
 
Fields inherited from class org.eclipse.ocl.parser.AbstractOCLAnalyzer
environmentFactory, oclFactory, uml
 
Constructor Summary
OCLAnalyzer(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> environment)
          Construct an OCL semantic analyzer with default syntactic and lexical parsers all operating within a given environment.
OCLAnalyzer(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> environment, String text)
          Construct an OCL semantic analyzer with default syntactic and lexical parsers all operating within a given environment.
OCLAnalyzer(OCLParser parser)
          Construct an OCL semantic analyzer that will use a given parser to perform syntactic and lexical analysis.
 
Method Summary
protected  CT createConstraint()
          Creates an Constraint instance.
protected  ExpressionInOCL<C,PM> createExpressionInOCL()
          Creates an ExpressionInOcl instance.
protected  OCLFactory createOCLFactory(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env)
          Creates/obtains the OCLFactory that I use to create OCL AST elements.
 void ERROR(List<?> problemObjects, String rule, String problemMessage)
           
 void ERROR(Object problemObject, String rule, String problemMessage)
           
 void ERROR(String problemMessage)
           
 OCLParser getParser()
           
protected  boolean isErrorNode(TypedElement<C> expr)
           Queries whether the specified expression is a placeholder that was created for an expression that failed to parse.
protected  void markAsErrorNode(TypedElement<C> expr)
           Marks the specified (sub)expression as a placeholder for an expression that could not be parsed.
 OCLExpression<C> parseAST(OCLExpressionCS cst, ConstraintKind constraintType)
          Parses the specified concrete syntax model to an abstract syntax model.
 CSTNode parseConcreteSyntax()
          Performs a concrete-syntax parser and throws ParserException if any parse errors are encountered.
 CT parseInitOrDerValueCS()
          Parses the input as an InitOrDerValueCS.
 CT parseInvOrDefCS()
          Parses the input as an InvOrDefCS.
 List<CT> parsePackageDeclarationCS(List<CT> constraints)
          Parses the input as a PackageDeclarationCS.
 CT parsePrePostOrBodyDeclCS()
          Parses the input as a PrePostOrBodyDeclCS.
 Variable<C,PM> parseVariableDeclarationCS(boolean addToEnvironment)
          Parses the input as a VariableDeclarationCS.
 
Methods inherited from class org.eclipse.ocl.parser.AbstractOCLAnalyzer
booleanLiteralExpCS, checkNotReflexive, classifierContextDeclCS, collectionLiteralExpCS, collectionLiteralPartCS, collectionTypeCS, collectionTypeIdentifierCS, contextDeclCS, createClassifierContext, createDummyInvalidLiteralExp, createImplicitCollect, createOperationContext, createPackageContext, createPropertyContext, defCS, enumLiteralExpCS, equalName, genOperationCallExp, genVariableDeclaration, getBagType, getBoolean, getCollectionKind, getCollectionSourceExpression, getCollectionType, getCommonSuperType, getElementType, getLoopBody, getOCLEnvironment, getOCLType, getOclVoid, getOperationMessageType, getOrderedSetType, getSequenceType, getSetType, getSignalMessageType, getStandardLibrary, getTupleType, getTypeType, ifExpCS, initASTMapping, initOrDerValueCS, integerLiteralExpCS, invalidLiteralExpCS, invCS, invOrDefCS, isEscaped, isIdentifierOrKeyword, iterateExpCS, iteratorExpCS, letExpCS, letExpCSRecursive, literalExpCS, lookupAssociationClassReference, lookupClassifier, lookupImplicitSourceForOperation, lookupOperation, lookupProperty, lookupSignal, lookupState, loopExpCS, messageExpCS, modelPropertyCallExpCS, nullLiteralExpCS, oclExpressionCS, operationCallExpCS, operationContextDeclCS, operationCS, operationString, packageDeclarationCS, parametersCS, prePostOrBodyDeclCS, primitiveLiteralExpCS, primitiveTypeCS, propertyCallExpCS, propertyContextCS, qualifiersCS, realLiteralExpCS, setQualifiers, simpleNameCS, stateExpCS, stringLiteralExpCS, tupleLiteralExpCS, tupleLiteralPartCS, tupleLiteralPartListCS, tupleTypeCS, typeCS, typeCS, unescape, unlimitedNaturalLiteralExpCS, variableDeclarationCS, variableDeclarationListCS, variableExpCS
 
Methods inherited from class org.eclipse.ocl.lpg.AbstractAnalyzer
computeInputString, dumpTokens, formatClass, formatEClassName, formatName, formatPath, formatPath, formatQualifiedName, formatString, formatType, getCharOffset, getEnvironment, getFormatter, getLexer, getTraceFlag, initialize, initialize, initPropertyPositions, initStartEndPositions, initTypePositions, makeName, makeString, setCharacterOffset, setFileName, setTab, setTraceFlag, TRACE, TRACE
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OCLAnalyzer

public OCLAnalyzer(OCLParser parser)
Construct an OCL semantic analyzer that will use a given parser to perform syntactic and lexical analysis.

Parameters:
parser - the syntactic (and lexical) parser

OCLAnalyzer

public OCLAnalyzer(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> environment)
Construct an OCL semantic analyzer with default syntactic and lexical parsers all operating within a given environment.

Parameters:
environment - the symbolic and problem handling environment

OCLAnalyzer

public OCLAnalyzer(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> environment,
                   String text)
Construct an OCL semantic analyzer with default syntactic and lexical parsers all operating within a given environment. Then prime the analyzer by performing keyword and lexical parsing of the given source text.

Parameters:
environment - the symbolic and problem handling environment
text - the source text for analysis
Method Detail

getParser

public OCLParser getParser()
Overrides:
getParser in class AbstractOCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>

createOCLFactory

protected OCLFactory createOCLFactory(Environment<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E> env)
Description copied from class: AbstractOCLAnalyzer
Creates/obtains the OCLFactory that I use to create OCL AST elements.

Overrides:
createOCLFactory in class AbstractOCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Parameters:
env - my OCL environment
Returns:
an appropriate factory

parseConcreteSyntax

public CSTNode parseConcreteSyntax()
Performs a concrete-syntax parser and throws ParserException if any parse errors are encountered.

Returns:
the parsed CST, or null if it could not be parsed

parseAST

public OCLExpression<C> parseAST(OCLExpressionCS cst,
                                 ConstraintKind constraintType)
Parses the specified concrete syntax model to an abstract syntax model. The result is contained by an Constraint, so care must be taken when the result is no longer needed to dispose of the entire tree rooted in the Constraint.

Parameters:
cst - the OCL concrete syntax model
constraintType - the kind of constraint to parse
Returns:
the OCL expression, if it successfully parsed

parsePackageDeclarationCS

public List<CT> parsePackageDeclarationCS(List<CT> constraints)
Parses the input as a PackageDeclarationCS.

Parameters:
constraints -
Returns:
the parsed constraints (as many as could be parsed)

parseInvOrDefCS

public CT parseInvOrDefCS()
Parses the input as an InvOrDefCS.

Returns:
the parsed OCL constraint, or null if it could not be parsed

parsePrePostOrBodyDeclCS

public CT parsePrePostOrBodyDeclCS()
Parses the input as a PrePostOrBodyDeclCS.

Returns:
the parsed OCL constraint, or null if it could not be parsed

parseInitOrDerValueCS

public CT parseInitOrDerValueCS()
Parses the input as an InitOrDerValueCS.

Returns:
the parsed OCL constraint, or null if it could not be parsed

parseVariableDeclarationCS

public Variable<C,PM> parseVariableDeclarationCS(boolean addToEnvironment)
Parses the input as a VariableDeclarationCS.

Parameters:
addToEnvironment - boolean whether or not to add the the parsed variable to the environment
Returns:
the parsed variable declaration, or null if it could not be parsed

ERROR

public void ERROR(List<?> problemObjects,
                  String rule,
                  String problemMessage)
Overrides:
ERROR in class AbstractAnalyzer

ERROR

public void ERROR(Object problemObject,
                  String rule,
                  String problemMessage)
Overrides:
ERROR in class AbstractAnalyzer

ERROR

public void ERROR(String problemMessage)
Overrides:
ERROR in class AbstractAnalyzer

createConstraint

protected CT createConstraint()
Description copied from class: AbstractOCLAnalyzer
Creates an Constraint instance. Subclasses may override.

Overrides:
createConstraint in class AbstractOCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Returns:
an new constraint

createExpressionInOCL

protected ExpressionInOCL<C,PM> createExpressionInOCL()
Description copied from class: AbstractOCLAnalyzer
Creates an ExpressionInOcl instance. Subclasses may override.

Overrides:
createExpressionInOCL in class AbstractOCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Returns:
an new expression-in-OCL

isErrorNode

protected boolean isErrorNode(TypedElement<C> expr)
Description copied from class: AbstractOCLAnalyzer

Queries whether the specified expression is a placeholder that was created for an expression that failed to parse. An example is the expression returned by AbstractOCLAnalyzer.createDummyInvalidLiteralExp().

The default implementation simply returns false; subclasses should override if necessary, in conjunction with the AbstractOCLAnalyzer.markAsErrorNode(TypedElement) method.

Overrides:
isErrorNode in class AbstractOCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Parameters:
expr - a (sub)expression
Returns:
whether the expr is a placeholder for an unparseable (sub)expression
See Also:
AbstractOCLAnalyzer.markAsErrorNode(TypedElement)

markAsErrorNode

protected void markAsErrorNode(TypedElement<C> expr)
Description copied from class: AbstractOCLAnalyzer

Marks the specified (sub)expression as a placeholder for an expression that could not be parsed. A subsequent invocation of the AbstractOCLAnalyzer.isErrorNode(TypedElement) method should recognize an expression thus marked. Subsequent attempts to mark an expression that is already marked have no effect.

The default implementation does nothing; subclasses should override if necessary, in conjunction with the isErrorPlaceholder method.

Overrides:
markAsErrorNode in class AbstractOCLAnalyzer<PK,C,O,P,EL,PM,S,COA,SSA,CT,CLS,E>
Parameters:
expr - an expression that takes the place of a (sub)expression that could not be parsed
See Also:
AbstractOCLAnalyzer.isErrorNode(TypedElement)

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.