Class AccessorCodeGeneratorAdapter
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.cg.kernel.generic.CodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.accessor.AccessorCodeGeneratorAdapter
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
JavaScript
,TypedCompositeActor
public abstract class AccessorCodeGeneratorAdapter extends CodeGeneratorAdapter
Base class for an Accessor code generator adapter.Subclasses should override generateAccessor().
Subclasses should be sure to properly indent the code by either using the code block functionality in methods like _generateBlockCode(String) or by calling
CodeStream.indent(String)
, for example:StringBuffer code = new StringBuffer(); code.append(super.generateWrapupCode()); code.append("// Local wrapup code"); return processCode(CodeStream.indent(code.toString()));
- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Christopher Brooks. Based on AccessorCodeGeneratorAdapter by Bert Rodiers
- Pt.AcceptedRating:
- Yellow (rodiers)
- Pt.ProposedRating:
- Yellow (rodiers)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected GenericCodeGenerator
_codeGenerator
The code generator that contains this adapter class.protected static java.lang.String
_eol
End of line character.protected static java.lang.String
_INDENT1
Level one indent string.-
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
-
-
Constructor Summary
Constructors Constructor Description AccessorCodeGeneratorAdapter(NamedObj component)
Construct the code generator adapter associated with the given component.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.String
generateAccessor()
Generate Accessor code.GenericCodeGenerator
getCodeGenerator()
Get the code generator associated with this adapter class.NamedObj
getComponent()
Get the component associated with this adapter.void
setCodeGenerator(GenericCodeGenerator codeGenerator)
Set the code generator associated with this adapter class.java.lang.String
targetExpression(java.lang.String expression, Type ptType)
Given a Ptolemy expression, return an Accessor-compatibile expression.java.lang.String
targetExpression(Parameter parameter)
Given a Ptolemy Parameter, return an Accessor-compatibile expression.java.lang.String
targetType(Type ptType)
Get the corresponding type in the target language from the given Ptolemy type.-
Methods inherited from class ptolemy.cg.kernel.generic.CodeGeneratorAdapter
createDecoratorAttributes, generateName
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateExistence, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getContainer, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
Field Detail
-
_eol
protected static final java.lang.String _eol
End of line character. Under Unix: "\n", under Windows: "\n\r". We use a end of line character so that the files we generate have the proper end of line character for use by other native tools.
-
_INDENT1
protected static final java.lang.String _INDENT1
Level one indent string.- See Also:
- Constant Field Values
-
_codeGenerator
protected GenericCodeGenerator _codeGenerator
The code generator that contains this adapter class.
-
-
Constructor Detail
-
AccessorCodeGeneratorAdapter
public AccessorCodeGeneratorAdapter(NamedObj component)
Construct the code generator adapter associated with the given component.- Parameters:
component
- The associated component.
-
-
Method Detail
-
generateAccessor
public abstract java.lang.String generateAccessor() throws IllegalActionException
Generate Accessor code.- Returns:
- The generated Accessor
- Throws:
IllegalActionException
- If there is a problem reading data from the model while generating Accessor code.
-
getCodeGenerator
public GenericCodeGenerator getCodeGenerator()
Get the code generator associated with this adapter class.- Specified by:
getCodeGenerator
in classCodeGeneratorAdapter
- Returns:
- The code generator associated with this adapter class.
- See Also:
setCodeGenerator(GenericCodeGenerator)
-
getComponent
public NamedObj getComponent()
Get the component associated with this adapter.- Returns:
- The associated component.
-
targetExpression
public java.lang.String targetExpression(java.lang.String expression, Type ptType)
Given a Ptolemy expression, return an Accessor-compatibile expression. For example, strings are quoted, ints and doubles and JSON are not. Note that this method incorrectly double quotes JSON expressions. To avoid this, usetargetExpression(Parameter)
.- Parameters:
expression
- the Ptolemy expression.ptType
- The Ptolemy Type.- Returns:
- A JavaScript-compatible expression
-
targetExpression
public java.lang.String targetExpression(Parameter parameter) throws IllegalActionException
Given a Ptolemy Parameter, return an Accessor-compatibile expression. For example, strings are quoted, ints and doubles and JSON are not.- Parameters:
parameter
- the Ptolemy expression.- Returns:
- A JavaScript-compatible expression
- Throws:
IllegalActionException
- If thrown will getting the type or expression of the parameter.
-
setCodeGenerator
public void setCodeGenerator(GenericCodeGenerator codeGenerator)
Set the code generator associated with this adapter class.- Specified by:
setCodeGenerator
in classCodeGeneratorAdapter
- Parameters:
codeGenerator
- The code generator associated with this adapter class.- See Also:
getCodeGenerator()
-
targetType
public java.lang.String targetType(Type ptType)
Get the corresponding type in the target language from the given Ptolemy type.- Parameters:
ptType
- The given Ptolemy type.- Returns:
- The target language data type.
-
-