Class CodeConnector<D extends CodeDelegate>

    • Constructor Detail

      • CodeConnector

        public CodeConnector​(CodeFactory.Task<D> task,
                             D delegate)
        Create a CodeConnector for the provided delegate.
        Parameters:
        task - CodeFactory.Task factory task creating context
        delegate - delegate instance
    • Method Detail

      • process

        protected void process()
        Process will be called by the CodeContext. Subclasses may override to extend, but should ensure to call the superclass method.
      • getDelegate

        public D getDelegate()
        Access the delegate instance.
        Returns:
        delegate
      • getLog

        public LogBuilder getLog()
        Get the LogBuilder for logging messages during processing.
        Returns:
        log builder
      • extractControls

        protected Map<String,​ControlDescriptor> extractControls()
        Called by the CodeContext to access all processed control descriptors. Subclasses may override to extend, but should ensure to call the superclass method.
        Returns:
        map of control descriptors by ID
      • extractPorts

        protected Map<String,​PortDescriptor> extractPorts()
        Called by the CodeContext to access all processed port descriptors. Subclasses may override to extend, but should ensure to call the superclass method.
        Returns:
        map of port descriptors by ID
      • extractRefs

        protected Map<String,​ReferenceDescriptor> extractRefs()
        Called by the CodeContext to access all processed reference descriptors. Subclasses may override to extend, but should ensure to call the superclass method.
        Returns:
        map of reference descriptors by ID
      • extractInfo

        protected ComponentInfo extractInfo()
        Called by the CodeContext to access the generated ComponentInfo for the delegate.
        Returns:
        component info
      • requiresClock

        protected boolean requiresClock()
        Called by the CodeContext to control whether the context should be attached to the execution clock. This method returns true if the delegate has any fields of type Property. May be overridden.
        Returns:
        whether context should connect to clock
      • buildBaseComponentInfo

        protected void buildBaseComponentInfo​(Info.ComponentInfoBuilder cmp)
        Build base component info. Called before control and port info is added. May be overridden to configure / extend.
        Parameters:
        cmp - component info builder
      • buildControlInfo

        protected void buildControlInfo​(Info.ComponentInfoBuilder cmp,
                                        Map<String,​ControlDescriptor> controls)
        Build control info. May be overridden to configure / extend.
        Parameters:
        cmp - component info builder
        controls - map of control descriptors
      • buildPortInfo

        protected void buildPortInfo​(Info.ComponentInfoBuilder cmp,
                                     Map<String,​PortDescriptor> ports)
        Build port info. May be overridden to configure / extend.
        Parameters:
        cmp - component info builder
        ports - map of port descriptors
      • addControl

        public void addControl​(ControlDescriptor ctl)
        Add a control descriptor.
        Parameters:
        ctl - control descriptor
      • addPort

        public void addPort​(PortDescriptor port)
        Add a port descriptor.
        Parameters:
        port - port descriptor
      • addReference

        public void addReference​(ReferenceDescriptor ref)
        Add a reference descriptor.
        Parameters:
        ref - reference descriptor
      • addDefaultControls

        protected void addDefaultControls()
        Called during processing to create default controls. May be overridden to configure or extend. By default this method adds the info and code properties, and a hidden control used by logging support.
      • createInfoControl

        protected ControlDescriptor createInfoControl​(int index)
        Called to create the info property control.
        Parameters:
        index - position of control
        Returns:
        info control descriptor
      • createCodeControl

        protected ControlDescriptor createCodeControl​(int index)
        Called to create the code property control.
        Parameters:
        index - position of control
        Returns:
        code control descriptor
      • addDefaultPorts

        protected void addDefaultPorts()
        Called during processing to create default ports. May be overridden to extend. By default this method does nothing.
      • analyseFields

        protected void analyseFields​(Field[] fields)
        Called during processing to analyse all discovered fields in the delegate class. May be overridden, but usually better to override the more specific analysis methods.
        Parameters:
        fields - discovered fields
      • analyseMethods

        protected void analyseMethods​(Method[] methods)
        Called during processing to analyse all discovered methods in the delegate class. May be overridden, but usually better to override the more specific analysis methods.
        Parameters:
        methods - discovered methods
      • analyseField

        protected void analyseField​(Field field)
        Called during processing to analyse each discovered field. May be overridden to extend. The default behaviour will first pass to available plugins (see CodeConnector.Plugin), then check for property, trigger, in, aux-in, out, aux-out, inject, proxy and persist annotations, in that order. First valid match wins.
        Parameters:
        field - discovered field
      • analyseMethod

        protected void analyseMethod​(Method method)
        Called during processing to analyse each discovered method. May be overridden to extend. The default behaviour will first pass to available plugins (see CodeConnector.Plugin), then check for trigger, in, aux-in and function annotations in that order. First valid match wins.
        Parameters:
        method - discovered method
      • findID

        public String findID​(Field field)
        Find a suitable ID (control or port) for the provided field. Will first look for ID annotation, and if not found convert the field name from camelCase to dash-case.
        Parameters:
        field - field to find ID for
        Returns:
        ID
      • findID

        public String findID​(Method method)
        Find a suitable ID (control or port) for the provided method. Will first look for ID annotation, and if not found convert the method name from camelCase to dash-case.
        Parameters:
        method - method to find ID for
        Returns:
        ID
      • javaNameToID

        protected String javaNameToID​(String javaName)
        Convert a Java name in camelCase to an ID in dash-case.
        Parameters:
        javaName - Java name to convert
        Returns:
        ID for Java name
      • shouldAddPort

        public boolean shouldAddPort​(AnnotatedElement element)
        Check whether a port should be added for provided element (field or method). By default returns true unless the element is marked ReadOnly, or with Config.Port and value false.
        Parameters:
        element - annotated element to analyse
        Returns:
        whether to add a port
      • getSyntheticIndex

        public int getSyntheticIndex()
        Return next index to use for synthetic descriptors. Increments and returns an int on each call, not based on registered descriptors.
        Returns:
        next index
      • getInternalIndex

        protected int getInternalIndex()
        Return next index to use for internal descriptors. Increments and returns an int on each call, not based on registered descriptors.
        Returns:
        next index