Class Template

    • Field Detail

      • templateDeclarations

        public SemanticNodeList<java.lang.Object> templateDeclarations
      • templateModifiers

        public SemanticNodeList<java.lang.Object> templateModifiers
      • rootType

        public transient java.lang.Object rootType
      • implicitRoot

        public transient boolean implicitRoot
      • createInstance

        public transient boolean createInstance
      • outputRuntimeMethod

        public transient java.lang.Object outputRuntimeMethod
      • defaultExtendsTypeName

        public transient java.lang.String defaultExtendsTypeName
        The template may define an optional extends type
      • defaultExtendsType

        public transient java.lang.Object defaultExtendsType
      • generateOutputMethod

        public transient boolean generateOutputMethod
      • dynamicType

        public transient boolean dynamicType
      • statefulPage

        public transient boolean statefulPage
      • singleElementType

        public transient boolean singleElementType
      • preTagContent

        public transient java.lang.StringBuilder preTagContent
      • execMode

        public int execMode
        When the processTemplate operation is running we override the template's execMode - setting it to "server" to avoid the client-only parts. This defaults to 0 which means automatically determine the execMode.
    • Constructor Detail

      • Template

        public Template()
    • Method Detail

      • getFullTypeName

        public java.lang.String getFullTypeName​(boolean includeDims,
                                                boolean includeTypeParams)
        Specified by:
        getFullTypeName in interface ITypeDeclaration
      • definesMethod

        public java.lang.Object definesMethod​(java.lang.String name,
                                              java.util.List<?> types,
                                              ITypeParamContext ctx,
                                              java.lang.Object refType,
                                              boolean isTransformed,
                                              boolean staticOnly,
                                              java.lang.Object inferredType,
                                              java.util.List<JavaType> methodTypeArgs)
        Specified by:
        definesMethod in interface ITypeDeclaration
        Overrides:
        definesMethod in class JavaModel
      • implementsType

        public boolean implementsType​(java.lang.String otherTypeName,
                                      boolean assignment,
                                      boolean allowUnbound)
        Specified by:
        implementsType in interface ITypeDeclaration
      • getInheritedAnnotation

        public java.lang.Object getInheritedAnnotation​(java.lang.String annotationName,
                                                       boolean skipCompiled,
                                                       Layer refLayer,
                                                       boolean layerResolve)
        Description copied from interface: ITypeDeclaration
        Returns the first occurrence of the specified annotation on the types in the type hierarchy
        Specified by:
        getInheritedAnnotation in interface ITypeDeclaration
      • getAllInheritedAnnotations

        public java.util.ArrayList<java.lang.Object> getAllInheritedAnnotations​(java.lang.String annotationName,
                                                                                boolean skipCompiled,
                                                                                Layer refLayer,
                                                                                boolean layerResolve)
        Description copied from interface: ITypeDeclaration
        Returns all occurrences of the specified annotation on the types in the type hierarchy ordered so the first type encountered during the traversal is first.
        Specified by:
        getAllInheritedAnnotations in interface ITypeDeclaration
      • getDerivedTypeDeclaration

        public java.lang.Object getDerivedTypeDeclaration()
        Description copied from interface: ITypeDeclaration
        Used to retrieve the type which either a class or modify type is derived from. For a class it's the extends type. For a modify type, it's the modified type
        Specified by:
        getDerivedTypeDeclaration in interface ITypeDeclaration
      • getExtendsType

        public java.lang.Object getExtendsType()
        Description copied from interface: ITypeDeclaration
        The declaration for the extends type for a class - includes type parameters but may not be resolved
        Specified by:
        getExtendsType in interface ITypeDeclaration
      • getAllMethods

        public java.util.List<java.lang.Object> getAllMethods​(java.lang.String modifier,
                                                              boolean hasModifier,
                                                              boolean isDyn,
                                                              boolean overridesComp)
        Specified by:
        getAllMethods in interface ITypeDeclaration
      • getMethods

        public java.util.List<java.lang.Object> getMethods​(java.lang.String methodName,
                                                           java.lang.String modifier,
                                                           boolean includeExtends)
        Specified by:
        getMethods in interface ITypeDeclaration
      • getMethodFromSignature

        public java.lang.Object getMethodFromSignature​(java.lang.String methodName,
                                                       java.lang.String signature,
                                                       boolean resolveLayer)
        Specified by:
        getMethodFromSignature in interface ITypeDeclaration
      • getAllProperties

        public java.util.List<java.lang.Object> getAllProperties​(java.lang.String modifier,
                                                                 boolean includeAssigns)
        Specified by:
        getAllProperties in interface ITypeDeclaration
      • getDeclaredProperties

        public java.util.List<java.lang.Object> getDeclaredProperties​(java.lang.String modifier,
                                                                      boolean includeAssigns,
                                                                      boolean includeModified,
                                                                      boolean editorProperties)
        Specified by:
        getDeclaredProperties in interface ITypeDeclaration
      • getAllFields

        public java.util.List<java.lang.Object> getAllFields​(java.lang.String modifier,
                                                             boolean hasModifier,
                                                             boolean dynamicOnly,
                                                             boolean includeObjs,
                                                             boolean includeAssigns,
                                                             boolean includeModified)
        Description copied from interface: ITypeDeclaration
        Returns all of the fields based on the flags. If modifier is not null then we only return those with have or don't have the modifier based on hasModifier. If dynamicOnly is true, we only return dynamic fields. If includeObjs is true, we return inner objects which have instance fields in this type. If includeAssigns is true, we return any property assignments we find along the way. If includeModified is true, when we resolve objects we'll return the most specific type for each inner type even if this is called on a type which is modified.
        Specified by:
        getAllFields in interface ITypeDeclaration
      • getAllInnerTypes

        public java.util.List<java.lang.Object> getAllInnerTypes​(java.lang.String modifier,
                                                                 boolean thisClassOnly,
                                                                 boolean includeInherited)
        Specified by:
        getAllInnerTypes in interface ITypeDeclaration
      • isCompiledProperty

        public boolean isCompiledProperty​(java.lang.String name,
                                          boolean fieldMode,
                                          boolean interfaceMode)
        Specified by:
        isCompiledProperty in interface ITypeDeclaration
      • getCompiledTypeArgs

        public java.util.List<JavaType> getCompiledTypeArgs​(java.util.List<JavaType> typeArgs)
        Description copied from interface: ITypeDeclaration
        Maps the supplied type arguments to those in the actual compiled class. Used to propagate type params across in the dynamic/compiled stub
        Specified by:
        getCompiledTypeArgs in interface ITypeDeclaration
      • needsOwnClass

        public boolean needsOwnClass​(boolean checkComponents)
        Description copied from interface: ITypeDeclaration
        Returns false for object types which
        Specified by:
        needsOwnClass in interface ITypeDeclaration
      • isRealType

        public boolean isRealType()
        Description copied from interface: ITypeDeclaration
        Return false for any types, such as lambda expressions, or intermediate template fragments which are not included in the type hierarchy (name and enclosing type)
        Specified by:
        isRealType in interface ITypeDeclaration
      • getArrayComponentType

        public java.lang.Object getArrayComponentType()
        Description copied from interface: ITypeDeclaration
        If this type extends for example ArrayList return the value of the first type parameter so we get the accurate component type.
        Specified by:
        getArrayComponentType in interface ITypeDeclaration
      • resolve

        public ITypeDeclaration resolve​(boolean modified)
        Description copied from interface: ITypeDeclaration
        This method is used to be sure the ITypeDeclaration we are referring to is the latest one. If not, a replacement value is returned. There are two modes it's used. When you pass in 'modified=true' it returns the modifying type of this type. When you pass in modified=false it just returns a new type if the old one has been replaced in the current type system. Perhaps a dependent type has been updated or changed on the file system and refreshed.
        Specified by:
        resolve in interface ITypeDeclaration
      • setAccessTimeForRefs

        public void setAccessTimeForRefs​(long time)
        Description copied from interface: ITypeDeclaration
        For source representations of a type, mark any references contains in this type as 'in use' with the specified access time so only unused types in the cache are removed
        Specified by:
        setAccessTimeForRefs in interface ITypeDeclaration
      • setAccessTime

        public void setAccessTime​(long time)
        Description copied from interface: ITypeDeclaration
        Mark the lastAccessTime for all of the models that define this type only (not the code inside of the type like the ForRefs version)
        Specified by:
        setAccessTime in interface ITypeDeclaration
      • getClassTypeParameters

        public java.util.List<?> getClassTypeParameters()
        Description copied from interface: ITypeDeclaration
        This returns the normal typeParameters for the type. It used to be called getTypeParameters but that conflicts with the semantic 'typeParameters' property on TypeDeclaration This one needs to be distinct for ModifyTypes which can either set or inherit their type parameters.
        Specified by:
        getClassTypeParameters in interface ITypeDeclaration
      • getConstructors

        public java.lang.Object[] getConstructors​(java.lang.Object refType,
                                                  boolean includeHidden)
        Specified by:
        getConstructors in interface ITypeDeclaration
      • stop

        public void stop​(boolean stopModified)
        Overrides:
        stop in class JavaModel
      • reinitialize

        public void reinitialize()
        Description copied from interface: ILanguageModel
        Called when dependent files for this type have changed and this type needs to re-evaluate itself from it's original AST. It might happen if the subclass depends on the code in the base class or if the subclass failed to compile and we need to retry things again.
        Specified by:
        reinitialize in interface ILanguageModel
        Overrides:
        reinitialize in class JavaModel
      • getSingleFileElement

        public Element getSingleFileElement​(java.lang.StringBuilder preTagContent)
        For HTML/XML files, this returns the main tag which defines the body of the document. If there is more than one top-level tag, null is returned. Any control tags which precedes the tag can be returned in the supplied StringBuilder (or pass in null and that content is discarded).
      • addBodyStatementsFromChildren

        public void addBodyStatementsFromChildren​(TypeDeclaration parentType,
                                                  java.util.List<java.lang.Object> children,
                                                  Element parentTag,
                                                  boolean elementsOnly)
      • getOutputMethodTemplate

        public java.lang.String getOutputMethodTemplate()
      • generateOutputMethod

        public void generateOutputMethod()
      • addTemplateDeclToOutputMethod

        public int addTemplateDeclToOutputMethod​(TypeDeclaration parentType,
                                                 BlockStatement block,
                                                 java.lang.Object decl,
                                                 boolean copy,
                                                 java.lang.String methSuffix,
                                                 int ct,
                                                 Element parentElement,
                                                 ISrcStatement lastSrcSt,
                                                 boolean statefulContext,
                                                 boolean escape)
      • getGenerateExecFlags

        public int getGenerateExecFlags()
      • getDefaultOutputParameters

        public Parameter getDefaultOutputParameters()
      • getIdentStringOutputStatement

        public static Statement getIdentStringOutputStatement​(java.lang.String exprStr)
      • getExprStringOutputStatement

        public static Statement getExprStringOutputStatement​(java.lang.String exprStr)
      • getConstStringOutputStatement

        public static Statement getConstStringOutputStatement​(java.lang.String stringConstant)
      • getChildTagsWithName

        public Element[] getChildTagsWithName​(java.lang.String rawObjName)
      • isConcreteTemplate

        public boolean isConcreteTemplate()
      • isSimpleTemplate

        public boolean isSimpleTemplate()
      • eval

        public java.lang.Object eval​(java.lang.Class expectedType,
                                     ExecutionContext ctx)
        Overrides the value node eval method where expectedType should be String.class. The current object used for the body of the template code is either set with ctx.pushCurrentObject or created by setting Template.createInstance = true. In that case, rootType is used as the class. It is created with a zero-arg constructor.
        Specified by:
        eval in interface IValueNode
      • getCompiledProcessedFiles

        public java.util.List<SrcEntry> getCompiledProcessedFiles​(Layer buildLayer,
                                                                  java.lang.String buildSrcDir,
                                                                  boolean generate)
      • getProcessedFiles

        public java.util.List<SrcEntry> getProcessedFiles​(Layer buildLayer,
                                                          java.lang.String buildSrcDir,
                                                          boolean generate)
        Description copied from class: JavaModel
        Returns the set of files generated by this model. This includes the pass through or transformed Java file, any dynamic stubs for the main type or inner types, and any extra files added by extra features defined on this model (e.g. the GWT module file)
        Specified by:
        getProcessedFiles in interface IFileProcessorResult
        Overrides:
        getProcessedFiles in class JavaModel
      • getTransformedResult

        public java.lang.String getTransformedResult()
        The Template extends JavaModel but uses different top-level properties for its state. During transform, we convert update the JavaModel properties so it is a valid JavaModel. To output the Java source for this template then, we just generate a new description using the JavaModel parselet as the base against this object.
        Overrides:
        getTransformedResult in class JavaModel
      • getPostBuildFileId

        public java.lang.String getPostBuildFileId()
        Description copied from interface: IFileProcessorResult
        Returns the unique name of the file this type generates in the post-build process so we only generate that file once in a given system. This is different than the processedFileId for files which are both types and files, e.g. schtml files. It allows you to override an schtml template in a different layer package. At the type level, we'll maintain two unique types but the generated files will replace each other to make it easier to merge web roots with layers that are in different packages.
        Specified by:
        getPostBuildFileId in interface IFileProcessorResult
        Overrides:
        getPostBuildFileId in class JavaModel
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class JavaModel
      • getLanguage

        public TemplateLanguage getLanguage()
        Overrides:
        getLanguage in class sc.lang.sc.SCModel
      • isSemanticChildValue

        public boolean isSemanticChildValue​(ISemanticNode child)
        Description copied from interface: ISemanticNode
        Sometimes in a semantic node, you need to add children which are semantic nodes but which are not part of the semantic node tree. For example, in type declaration, we have "hiddenBody" which stores body elements that behave as though they are added to the type but are not saved to the transformed file.

        For these cases, you should override this method and return false when child == hiddenBody. That way, we do not propagate up refresh events and things when nodes in that tree change.

        Specified by:
        isSemanticChildValue in interface ISemanticNode
        Overrides:
        isSemanticChildValue in class SemanticNode
      • replaceChild

        public int replaceChild​(java.lang.Object toReplace,
                                java.lang.Object other)
        The rootType stores the Template as its direct parent so when we replace it, we need to update it both in the types list and in the rootType variable
        Specified by:
        replaceChild in interface ISemanticNode
        Overrides:
        replaceChild in class SemanticNode
      • getModelType

        public java.lang.Object getModelType()
        Description copied from interface: ILanguageModel
        Same as getModelTypeDeclaration but if you have a template where the root type is a compiled class this method returns the class
        Specified by:
        getModelType in interface ILanguageModel
        Overrides:
        getModelType in class JavaModel
      • deepCopy

        public Template deepCopy​(int options,
                                 java.util.IdentityHashMap<java.lang.Object,​java.lang.Object> oldNewMap)
        Description copied from interface: ISemanticNode
        Performs a deep copy of the semantic node tree. Subclasses should do their own copy implementation to decide what else to copy. Uses the copy options flags above. The default, with 0, just copies the semantic node information so you get a new tree like's it parsed but without parse node info. Use that mode only if you want to throw away the original source and regenerate it all from scratch. Otherwise, you can copy the parse tree as well. If you want to copy the semantic node's initial resolved state - including it's init/start, etc. and whatever the subclass adds to that copy, use CopyState or CopyNormal - for both parse nodes and state.
        Specified by:
        deepCopy in interface ISemanticNode
        Overrides:
        deepCopy in class JavaModel
      • getGeneratedSCCode

        public java.lang.String getGeneratedSCCode()
        For debugging, this lets you print out the generated code for a template in SC, before it's transformed to Java
      • getDependenciesChanged

        public boolean getDependenciesChanged​(Layer genLayer,
                                              java.util.Set<java.lang.String> changedTypes,
                                              boolean processJava)
        Overrides:
        getDependenciesChanged in class JavaModel
      • isLayerType

        public boolean isLayerType()
        Hook to reinitiaze any state after one of your base types gets modified after this type has been processed.
        Specified by:
        isLayerType in interface ITypeDeclaration
      • isLayerComponent

        public boolean isLayerComponent()
        Description copied from interface: ITypeDeclaration
        Returns true if this is a component defined as part of a layer definition
        Specified by:
        isLayerComponent in interface ITypeDeclaration