Package ptolemy.actor.gt
Class Constraint
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,HasTypeConstraints
,Typeable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
,Settable
,ValueListener
public class Constraint extends GTParameter
Constraint used to restrict pattern matching in model transformations. A constraint contains an expression that must be evaluable into a boolean at the time the transformation rule is applied. When the expression is specified at design time, it is parsed and a syntax tree is generated. If the parsing is not successful, a design time exception occurs. If the parse is successful, the constraint is evaluated every time a match to the pattern is found. No exception will be shown at the time of pattern matching even if the constraint cannot be successfully evaluated. In that case, the constraint will only be considered false. A constraint is satisfied if and only if it can be successfully evaluated and the result is boolean true.- Since:
- Ptolemy II 7.1
- Version:
- $Id$
- Author:
- Thomas Huining Feng
- Pt.AcceptedRating:
- Red (tfeng)
- Pt.ProposedRating:
- Yellow (tfeng)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.actor.gt.GTParameter
GTParameter.Evaluator, GTParameter.Scope, GTParameter.TypeInference
-
Nested classes/interfaces inherited from class ptolemy.data.expr.Variable
Variable.CircularDependencyError, Variable.VariableScope
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
Nested classes/interfaces inherited from interface ptolemy.kernel.util.Settable
Settable.Visibility
-
-
Field Summary
Fields Modifier and Type Field Description VisibleParameterEditorFactory
editorFactory
The editor factory.-
Fields inherited from class ptolemy.data.expr.Variable
_currentExpression, _needsEvaluation, _parserScope, _parseTreeValid, _suppressVariableSubstitution, _valueListeners
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.kernel.util.Settable
EXPERT, FULL, NONE, NOT_EDITABLE
-
-
Constructor Summary
Constructors Constructor Description Constraint(NamedObj container, java.lang.String name)
Constraint a constraint.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_evaluate(Pattern pattern, MatchResult matchResult)
Evaluate the current expression to a token with the given pattern and match result usingGTParameter.Evaluator
.boolean
check(Pattern pattern, MatchResult matchResult)
Check whether this constraint is satisfied with the given match in matchResult to the given pattern.void
setContainer(NamedObj container)
Set the container of this constraint.-
Methods inherited from class ptolemy.data.expr.Parameter
addChoice, clone, exportMoML, getChoices, removeAllChoices, removeChoice
-
Methods inherited from class ptolemy.data.expr.Variable
_description, _evaluate, _getCurrentExpression, _notifyValueListeners, _parseIfNecessary, _propagate, _propagateToValueListeners, _propagateValue, _setToken, _setTokenAndNotify, addValueListener, attributeChanged, getDeclaredType, getExpression, getFreeIdentifiers, getParserScope, getScope, getScope, getToken, getType, getTypeTerm, getValueAsString, getVariable, getVisibility, invalidate, isKnown, isLazy, isStringMode, isSuppressVariableSubstitution, isTypeAcceptable, removeValueListener, reset, setExpression, setLazy, setName, setParseTreeEvaluator, setStringMode, setSuppressVariableSubstitution, setToken, setToken, setTypeAtLeast, setTypeAtLeast, setTypeAtMost, setTypeEquals, setTypeSameAs, setUnknown, setValueListenerAsWeakDependency, setVisibility, stringRepresentation, toString, typeConstraintList, typeConstraints, validate, valueChanged
-
Methods inherited from class ptolemy.kernel.util.AbstractSettableAttribute
getDefaultExpression
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getFullName, getName, getName
-
Methods inherited from interface ptolemy.kernel.util.Settable
getDisplayName
-
-
-
-
Field Detail
-
editorFactory
public VisibleParameterEditorFactory editorFactory
The editor factory.
-
-
Constructor Detail
-
Constraint
public Constraint(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Constraint a constraint.- Parameters:
container
- The container of the constraint, which is usually the pattern of aTransformationRule
.name
- The name of the constraint.- Throws:
IllegalActionException
- If the attribute is not of an acceptable class for the container, or if the name contains a period.NameDuplicationException
- If the name coincides with an attribute already in the container.
-
-
Method Detail
-
check
public boolean check(Pattern pattern, MatchResult matchResult)
Check whether this constraint is satisfied with the given match in matchResult to the given pattern. A constraint is satisfied if and only if it can be successfully evaluated and the result is boolean true.- Parameters:
pattern
- The pattern.matchResult
- The match result.- Returns:
- true if the constraint is satisfied; false if it cannot be evaluated or the evaluation result is false.
-
setContainer
public void setContainer(NamedObj container) throws IllegalActionException, NameDuplicationException
Set the container of this constraint. This method ensures that the container must be the pattern of aTransformationRule
.- Overrides:
setContainer
in classVariable
- Parameters:
container
- The new container, or null if the current container of this constraint is to be removed.- Throws:
IllegalActionException
- If this attribute is not of the expected class for the container, or it has no name, or the attribute and container are not in the same workspace, or the proposed container would result in recursive containment, or the container is not an instance ofPattern
.NameDuplicationException
- If the container already has an attribute with the name of this attribute.- See Also:
Attribute.getContainer()
-
_evaluate
protected void _evaluate(Pattern pattern, MatchResult matchResult) throws IllegalActionException
Evaluate the current expression to a token with the given pattern and match result usingGTParameter.Evaluator
. If this variable was last set directly with a token, then do nothing. In other words, the expression is evaluated only if the value of the token was most recently given by an expression. The expression is also evaluated if any of the variables it refers to have changed since the last evaluation. If the value of this variable changes due to this evaluation, then notify all value dependents and notify the container (if there is one) by calling its attributeChanged() and attributeTypeChanged() methods, as appropriate. An exception is thrown if the expression is illegal, for example if a parse error occurs or if there is a dependency loop.If evaluation results in a token that is not of the same type as the current type of the variable, then the type of the variable is changed, unless the new type is incompatible with statically specified types (setTypeEquals() and setTypeAtMost()). If the type is changed, the attributeTypeChanged() method of the container is called. The container can reject the change by throwing an exception.
This method may trigger a model error, which is delegated up the container hierarchy until an error handler is found, and is ignored if no error handler is found. A model error occurs if the expression cannot be parsed or cannot be evaluated.
Part of this method is read-synchronized on the workspace.
- Overrides:
_evaluate
in classGTParameter
- Parameters:
pattern
- The pattern.matchResult
- The match result for the match between the pattern and a host model.- Throws:
IllegalActionException
- If the expression cannot be parsed or cannot be evaluated, or if a dependency loop is found.
-
-