Class GosuClassTransformer


public class GosuClassTransformer extends AbstractElementTransformer<ClassStatement>
  • Field Details

    • ENUM_VALUES_FIELD

      public static final String ENUM_VALUES_FIELD
      See Also:
    • ENHANCED_TYPE_FIELD

      public static final String ENHANCED_TYPE_FIELD
      See Also:
    • _gsClass

      private IGosuClassInternal _gsClass
    • _enumCounter

    • _irClass

      private IRClass _irClass
    • _context

    • _bHasAsserts

      private boolean _bHasAsserts
    • bridges

      Set<String> bridges
      Generates a synthetic method if: - method overrides with covariant return type - for each in ancestry e.g., Square f() -> Rectangle f() -> Shape f(). - method overrides and specifies a concrete type for a parameter that is a type variable in the super e.g., B extends A where B#foo( o: String ) -> A#foo( o: T )
  • Constructor Details

  • Method Details

    • compile

      public static IRClass compile(IGosuClassInternal gsClass)
    • compile

      private IRClass compile()
    • addAnnotations

      private void addAnnotations()
    • addGosuMarker

      private void addGosuMarker(List<IRAnnotation> annotations)
    • getIRAnnotations

      private List<IRAnnotation> getIRAnnotations(List<? extends IAnnotationInfo> gosuAnnotations)
    • hasRetentionPolicy

      private boolean hasRetentionPolicy(IAnnotationInfo annotation, RetentionPolicy policy)
    • compileInnerClasses

      private void compileInnerClasses()
    • visitInnerClass

      private void visitInnerClass(IGosuClass innerClass)
    • compileStaticInitializer

      private void compileStaticInitializer()
    • compileFields

      private void compileFields()
    • addInstanceFields

      private void addInstanceFields()
    • maybeAddEnhancedTypeMarkerField

      private void maybeAddEnhancedTypeMarkerField()
      If this is an enhancement, add a (hacky) marker field to indicate the enhanced type for tooling. E.g., private static final <enhanced-type> ENHNANCED$TYPE;
    • addStaticFields

      private void addStaticFields()
    • addOuterThisField

      private void addOuterThisField()
    • addCapturedSymbolFields

      private void addCapturedSymbolFields()
    • addTypeParamFields

      private void addTypeParamFields()
    • isNonStaticInnerClass

      public boolean isNonStaticInnerClass()
    • getOuterThisFieldName

      public String getOuterThisFieldName()
    • compileConstructors

      private void compileConstructors()
    • compileJavaInteropBridgeConstructor

      private void compileJavaInteropBridgeConstructor(DynamicFunctionSymbol dfs)
      Add constructor so Java can use the Gosu generic class without explicitly passing in type arguments. Note this constructor forwards to the given constructor with default type arguments.
    • makeParamSymbol

      IRSymbol makeParamSymbol(DynamicFunctionSymbol dfs, ISymbol param)
    • maybeGetTypeVarSymbolTypesForConstructor

      private void maybeGetTypeVarSymbolTypesForConstructor(List<IRSymbol> parameters)
    • maybeGetEnumSuperConstructorSymbols

      private void maybeGetEnumSuperConstructorSymbols(List<IRSymbol> parameters)
    • maybeAddImplicitEnhancementParameters

      private void maybeAddImplicitEnhancementParameters(DynamicFunctionSymbol dfs, List<IRSymbol> parameters)
    • maybeAddImplicitExternalSymbolsParameter

      private void maybeAddImplicitExternalSymbolsParameter(DynamicFunctionSymbol dfs, List<IRSymbol> parameters)
    • isOverrideForSuperClass

      private boolean isOverrideForSuperClass(DynamicFunctionSymbol dfs)
    • maybeGetTypeVarSymbolTypes

      private void maybeGetTypeVarSymbolTypes(DynamicFunctionSymbol dfs, List<IRSymbol> parameters)
    • addTypeParamDescriptor

      private void addTypeParamDescriptor(List<IRSymbol> parameters, List<IGenericTypeVariable> genTypeVars)
    • appendTypeVarsFromEnclosingFunctions

      private void appendTypeVarsFromEnclosingFunctions(List<IRSymbol> parameters, IGosuClassInternal gsClass)
    • maybeGetCapturedSymbolTypes

      private void maybeGetCapturedSymbolTypes(List<IRSymbol> parameters)
    • maybeGetOuterThisParamType

      private void maybeGetOuterThisParamType(List<IRSymbol> parameters)
    • compileDefaultCtorBody

      private IRStatement compileDefaultCtorBody()
    • maybeAssignOuterRef

      public void maybeAssignOuterRef(List<IRStatement> statements)
    • maybePushSupersEnclosingThisRef

      public void maybePushSupersEnclosingThisRef(List<IRExpression> arguments)
    • compileMethods

      private void compileMethods()
    • compileBridgeMethods

      private void compileBridgeMethods(DynamicFunctionSymbol dfs)
    • maybeGetSuperDfs

      private List<DynamicFunctionSymbol> maybeGetSuperDfs(DynamicFunctionSymbol dfs)
    • getSuperDfs

      private DynamicFunctionSymbol getSuperDfs(DynamicFunctionSymbol dfs, IType gsClass, IType superType)
    • makeModifiersForBridgeMethod

      private int makeModifiersForBridgeMethod(int modifiers)
    • addCovarientProxyBridgeMethods

      private boolean addCovarientProxyBridgeMethods(DynamicFunctionSymbol dfs)
      Add a bridge method for a Java interface method that is not only implemented by a method in this Gosu class, but is also itself a covariant "override" of its super interface E.g.,
       interface JavaBase {
        public CharSequence makeText();
       }
      
       interface JavaSub extends JavaBase {
         public String makeText();
       }
      
       class GosuSub extends JavaSub {
         function makeText() : String ...
       }
       
      Here we need for this class to define a bridge method implementing JavaBase#makeText() : CharSequence
    • getMethodOverridableFromDfs

      private IJavaClassMethod getMethodOverridableFromDfs(DynamicFunctionSymbol dfs, IJavaClassInfo declaringClass)
    • genInterfaceProxyBridgeMethod

      private boolean genInterfaceProxyBridgeMethod(IJavaClassMethod m, IJavaClassInfo iJavaClassInfo)
    • genBridgeMethod

      private boolean genBridgeMethod(IJavaClassMethod bridge, IJavaClassMethod m)
    • genProxyCovariantBridgeMethod

      private boolean genProxyCovariantBridgeMethod(DynamicFunctionSymbol dfs, DynamicFunctionSymbol superDfs)
      ##hack: Potentially generates a bridge method for an overridden method where the super method is in a proxy and the proxy is for a Java interface having param types that are transformed to non-bytecode types in the type system. E.g., A guidewire platform plugin interface may declare UserBase or the like as a parameter type, which is always represented as the corresponding app derivative: UserBase -> CC's User. Essentially, we need to generate a bridge method to make the otherwise unsavory covariant parameter types work in method overrides.
    • makeCovariantParamBridgeMethod

      private void makeCovariantParamBridgeMethod(DynamicFunctionSymbol dfs, DynamicFunctionSymbol superDfs, IJavaClassMethod method)
    • getParamsIncludingTypeParams

      private IType[] getParamsIncludingTypeParams(DynamicFunctionSymbol dfs)
    • maybePassTypeParams

      private void maybePassTypeParams(DynamicFunctionSymbol dfs, List<IRExpression> args)
    • compileOuterAccessMethod

      private void compileOuterAccessMethod()
    • compileMethod

      private void compileMethod(DynamicFunctionSymbol dfs)
    • maybeWrapProgramEvaluateForManangedProgram

      private IRStatement maybeWrapProgramEvaluateForManangedProgram(DynamicFunctionSymbol dfs, IRStatement methodBody)
      If this is:
      • a Gosu program and
      • it has a superclass that implements IManagedProgramInstance and
      • this method is evaluate( IExternalSymbolMap )
      Generate the evaluate() method like so:
         function evaluate( map: IExternalSymbolMap ) : Object {
           var $failure : Throwable
           if( this.beforeExecution() ) {
             try {
               [method-body] // returns result
             }
             catch( $catchFailure: Throwable ) {
               $failure = $catchFailure
             }
             finally {
               this.afterExecution( $failure )
             }
           }
           return null // only get here if exception not rethrown in afterExecution()
         }
       
    • isStaticEnumMethod

      private boolean isStaticEnumMethod(DynamicFunctionSymbol dfs)
    • isGosuObjectMethod

      private boolean isGosuObjectMethod(DynamicFunctionSymbol dfs)
    • getGosuObjectInterface

      private IGosuClassInternal getGosuObjectInterface()
    • compileIntrinsicTypePropertyGetter

      private void compileIntrinsicTypePropertyGetter()
    • compileMainMethod

      private void compileMainMethod()
    • compileEnumValuesMethod

      private void compileEnumValuesMethod()
    • compileEnumAllValuesPropertyGetter

      private void compileEnumAllValuesPropertyGetter()
    • compileEnumValueOfMethod

      private void compileEnumValueOfMethod()
    • compileEnumValuePropertyGetter

      private void compileEnumValuePropertyGetter()
    • compileEnumCodePropertyGetter

      private void compileEnumCodePropertyGetter()
    • compileEnumOrdinalPropertyGetter

      private void compileEnumOrdinalPropertyGetter()
    • compileEnumNamePropertyGetter

      private void compileEnumNamePropertyGetter()
    • compileEnumDisplayNamePropertyGetter

      private void compileEnumDisplayNamePropertyGetter()
    • makeArrayOfTypeParameters

      private IRExpression makeArrayOfTypeParameters()
    • initializeInstanceFields

      public void initializeInstanceFields(List<IRStatement> statements)
    • initTypeVarFields

      public void initTypeVarFields(List<IRStatement> statements)
    • initCapturedSymbolFields

      public void initCapturedSymbolFields(List<IRStatement> statements)
    • initializeStaticFields

      public void initializeStaticFields(List<IRStatement> statements)
    • initializeAssertionsDisabledField

      private IRStatement initializeAssertionsDisabledField()
    • compileEnumValuesFieldInitializer

      private void compileEnumValuesFieldInitializer(List<IRStatement> statements)
    • getOrderedFields

      private List<IVarStatement> getOrderedFields()
    • getDescriptorNoStructures

      private IRType getDescriptorNoStructures(IType type)
    • getParameterDescriptors

      private String getParameterDescriptors(IType[] types)
    • getParameterDescriptors

      private String getParameterDescriptors(IJavaClassInfo[] iJavaClassInfos)
    • compileClassHeader

      private void compileClassHeader()
    • getSuperSlashName

      private IRType getSuperSlashName()
    • addSourceFileRef

      private void addSourceFileRef()
    • getClassModifiers

      private int getClassModifiers()
    • getClassModifiers

      private int getClassModifiers(IGosuClass gsClass, boolean bForInnerClass)
    • getInterfaceNames

      private IRType[] getInterfaceNames()
    • getGosuEnhancement

      public IGosuEnhancementInternal getGosuEnhancement()
    • pushEnumNameAndOrdinal

      public void pushEnumNameAndOrdinal(IType type, List<IRExpression> args)
    • setHasAsserts

      public void setHasAsserts()
    • isBlockInvoke

      public boolean isBlockInvoke(DynamicFunctionSymbol dfs)
    • setUpFunctionContext

      private void setUpFunctionContext(boolean instanceMethod, List<IRSymbol> params)
    • setUpFunctionContext

      private void setUpFunctionContext(DynamicFunctionSymbol dfs, boolean instanceMethod, List<IRSymbol> params)
    • toString

      public String toString()
      Overrides:
      toString in class Object