Class 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)
    • 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.
      • 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, use targetExpression(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.
      • 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.