system/src/sc/lang/java/ClassType.java
public void initType(LayeredSystem sys, Object it, JavaSemanticNode node, ITypeParamContext ctx, boolean displayError, boolean isLayer, Object typeParam) {
      if (chained)
         return; // Don't need to init if we are just part of someone else's type

      String fullTypeName = getFullBaseTypeName();

      type = FAILED_TO_INIT_SENTINEL; // prevent recursive calls

      if (fullTypeName == null)
         return; // Invalid fragment

      if (isLayer) {
         if (sys != null){
            // If this is a reference from an annotated layer model we need to annotate the type so we cna make the layer
            // references work like normal types.
            if (it instanceof TypeDeclaration) {
               JavaModel curModel = ((TypeDeclaration) it).getJavaModel();
               if (curModel != null && curModel.getLayer() != null) {
                  String layerRelPath = CTypeUtil.getPackageName(curModel.getLayer().getLayerName());
                  if (curModel.getUserData() != null) {
                     JavaModel layerModel = sys.getAnnotatedLayerModel(fullTypeName, layerRelPath);
                     if (layerModel != null)
                        type = layerModel.getModelTypeDeclaration();
                  }
                  else {
                     Layer layer = curModel.layer.activated ? sys.findLayerByName(layerRelPath, fullTypeName) : sys.getInactiveLayer(fullTypeName, false, false, true, false);
                     // Relative paths for inactive layers are done separately here.
                     if (layer == null && !curModel.layer.activated) {
                        layer = sys.getInactiveLayer(CTypeUtil.prefixPath(layerRelPath, fullTypeName), false, false, true, false);
                     }
                     if (layer != null && layer.model != null)
                        type = layer.model.getModelTypeDeclaration();
                     //else
                     //  this may be an activated layer that's not part of this layered system - e.g. a server specific layer for the client runtime.

                  }
               }
            }
         }
         return;
      }

      if (typeArguments != null && chainedTypes != null) {
         int chainedSz;
         if ((chainedSz = chainedTypes.size()) != 0)
            chainedTypes.get(chainedSz-1).typeArguments = typeArguments;
      }

      // The refLayer must be set so we retrieve the type from the right active/inactive layer set
      Layer refLayer = ctx == null ? (it instanceof TypeDeclaration ? ((TypeDeclaration) it).getLayer() : null) : ctx.getRefLayer();

      boolean userType = false;
      // Looking up type parameters by name is not good here
      if (typeParam != null && ModelUtil.isTypeVariable(typeParam))
         type = typeParam;
      else if (node != null)
         type = node.findType(fullTypeName);
      // In the parametrized type info we create ClassTypes which are defined as part of a compiled method - so no relative type info is available.
      // fortunately imports and local references are always made absolute at this level
      else if (it != null) {
         type = ModelUtil.findTypeDeclaration(sys, it, fullTypeName, refLayer, true);
      }
      else if (sys != null) {
         type = sys.getTypeDeclaration(fullTypeName, srcOnly, refLayer, false);
      }
      else if (typeParam != null) {
         type = typeParam;
         userType = true;
      }

      List<Object> typeParamTypes = null;
      // When looking up type parameters, typically the it is the ParamTypeDeclaration but if it's a param method, it won't be so we need to
      // look up the type parameter for the method explicitly here.
      if (type == null && it == null && ctx != null) {
         type = ctx.getTypeDeclarationForParam(fullTypeName, null, false);
         // An unresolvable type parameter which we've manually created.  Just use the type parameter
         // as the type so we know it's essentially an unbound type.
         if (type == null && typeParam != null) {
            type = typeParam;
            userType = true;
         }
      }

      if (type == null) { // not a relative name
         if (it != null)
            type = ModelUtil.findTypeDeclaration(sys, it, fullTypeName, refLayer, true);
      }

      if (type == null) {
         if (typeParam != null) {
            type = typeParam;
            userType = true;
         }
         else {
            type = FAILED_TO_INIT_SENTINEL;
            if (displayError) {
               displayTypeError("No type: ", getFullTypeName(), " for ");
               if (it != null) {
                  Object dummy = ModelUtil.findTypeDeclaration(sys, it, fullTypeName, refLayer, true);
                  if (node != null)
                     dummy = node.findType(fullTypeName);
               }
            }
         }
      }
      // We do not just use typeParam here, but instead at least try to resolve type by name, then resolve the
      // type arguments because sometimes those type arguments resolve to more specific values in this context.
      // But in some cases we do not have the info to resolve the type and type arguments - in those cases we
      // will just use typeParam as it is.  In any case, we are careful to use the type arguments from type
      // param and pass those into initType as the typeParam argument so we follow this pattern for the type-arguments
      // (and possibly their type-arguments).

      // Since there is a class reference to this type, we cannot optimize away that class for inner objects
      if (type instanceof BodyTypeDeclaration) {
         BodyTypeDeclaration btype = (BodyTypeDeclaration) type;
         if (sys == null)
            sys = btype.getLayeredSystem();

         // Once we start transforming things, it seems we pull in type references to object types which we do not count to decide if we need the class
         if (sys != null && !sys.allTypesProcessed) {
            btype.needsOwnClass = true;
         }
      }

      // Before we return the type, check and see if this definition adds any bound type parameters -
      // i.e. concrete types instead of parameter names.  If so, we need to wrap the returned type with
      // an object which knows how to resolve type parameters to do the proper type matching when generics are used.
      List<Object> typeDefs = getTypeArgumentDeclarations(sys, it, node, ctx, typeParamTypes, type);
      if (typeDefs != null && type != FAILED_TO_INIT_SENTINEL && anyBoundParameters(typeDefs)) {
         List<?> typeParams = ModelUtil.getTypeParameters(type);
         if (typeParams == null || typeParams.size() != typeDefs.size())
            displayError("Wrong number of type arguments for type: ", ModelUtil.getTypeName(type)," for ");
         else {
            if (it != null)
               type = new ParamTypeDeclaration(sys, it, typeParams, typeDefs, type);
            else {
               if (ctx != null && ctx.getDefinedInType() != null)
                  type = new ParamTypeDeclaration(sys, ctx.getDefinedInType(), typeParams, typeDefs, type);
               else
                  type = new ParamTypeDeclaration(sys, typeParams, typeDefs, type);
            }
         }
      }

      // Sometimes when we are called, typeParam supplies the component type and others the actual array generic type so be careful not to re-wrap it or leave it unwrapped
      if ((!userType || !ModelUtil.isArray(type)) && arrayDimensions != null && type != FAILED_TO_INIT_SENTINEL) {
         type = new ArrayTypeDeclaration(sys, it, type, arrayDimensions);
      }
   }
/**
    * Initializes this type from the model and node specified.  The ClassDeclaration needs to resolve the type
    * name using itself, so that it will not recursively check the type that is being initialized.
    * This can optionally be called with a 'typeParam' parameter.  This is used when rebuilding the ClassType from
    * an existing TypeDeclaration.  The typeParam is the existing type declaration.  It would be fastest to just
    * set type = typeParam here but there are cases where we resolve type-parameters to more specific types than
    * are found in the typeParam.   There are other cases though where the type or type argument for this ClassType cannot
    * be resolved - in these cases we need to use typeParam or the type parameter values in typeParam to make the ClassType
    * properly initialized.
    */
Initializes this type from the model and node specified.  The ClassDeclaration needs to resolve the type
name using itself, so that it will not recursively check the type that is being initialized.
This can optionally be called with a 'typeParam' parameter.  This is used when rebuilding the ClassType from
an existing TypeDeclaration.  The typeParam is the existing type declaration.  It would be fastest to just
set type = typeParam here but there are cases where we resolve type-parameters to more specific types than
are found in the typeParam.   There are other cases though where the type or type argument for this ClassType cannot
be resolved - in these cases we need to use typeParam or the type parameter values in typeParam to make the ClassType
properly initialized.
Initializes this type from the model and node specified . The ClassDeclaration needs to resolve the type name using itself so that it will not recursively check the type that is being initialized . This can optionally be called with a ' typeParam ' parameter . This is used when rebuilding the ClassType from an existing TypeDeclaration . The typeParam is the existing type declaration . It would be fastest to just set type = typeParam here but there are cases where we resolve type - parameters to more specific types than are found in the typeParam . There are other cases though where the type or type argument for this ClassType cannot be resolved - in these cases we need to use typeParam or the type parameter values in typeParam to make the ClassType properly initialized .
public void initType(LayeredSystem sys, Object it, JavaSemanticNode node, ITypeParamContext ctx, boolean displayError, boolean isLayer, Object typeParam) {
      if (chained)
         return; 
      String fullTypeName = getFullBaseTypeName();
      type = FAILED_TO_INIT_SENTINEL; 
      if (fullTypeName == null)
         return; 
      if (isLayer) {
         if (sys != null){
            if (it instanceof TypeDeclaration) {
               JavaModel curModel = ((TypeDeclaration) it).getJavaModel();
               if (curModel != null && curModel.getLayer() != null) {
                  String layerRelPath = CTypeUtil.getPackageName(curModel.getLayer().getLayerName());
                  if (curModel.getUserData() != null) {
                     JavaModel layerModel = sys.getAnnotatedLayerModel(fullTypeName, layerRelPath);
                     if (layerModel != null)
                        type = layerModel.getModelTypeDeclaration();
                  }
                  else {
                     Layer layer = curModel.layer.activated ? sys.findLayerByName(layerRelPath, fullTypeName) : sys.getInactiveLayer(fullTypeName, false, false, true, false);
                     if (layer == null && !curModel.layer.activated) {
                        layer = sys.getInactiveLayer(CTypeUtil.prefixPath(layerRelPath, fullTypeName), false, false, true, false);
                     }
                     if (layer != null && layer.model != null)
                        type = layer.model.getModelTypeDeclaration();
                  }
               }
            }
         }
         return;
      }
      if (typeArguments != null && chainedTypes != null) {
         int chainedSz;
         if ((chainedSz = chainedTypes.size()) != 0)
            chainedTypes.get(chainedSz-1).typeArguments = typeArguments;
      }
      Layer refLayer = ctx == null ? (it instanceof TypeDeclaration ? ((TypeDeclaration) it).getLayer() : null) : ctx.getRefLayer();
      boolean userType = false;
      if (typeParam != null && ModelUtil.isTypeVariable(typeParam))
         type = typeParam;
      else if (node != null)
         type = node.findType(fullTypeName);
      else if (it != null) {
         type = ModelUtil.findTypeDeclaration(sys, it, fullTypeName, refLayer, true);
      }
      else if (sys != null) {
         type = sys.getTypeDeclaration(fullTypeName, srcOnly, refLayer, false);
      }
      else if (typeParam != null) {
         type = typeParam;
         userType = true;
      }
      List<Object> typeParamTypes = null;
      if (type == null && it == null && ctx != null) {
         type = ctx.getTypeDeclarationForParam(fullTypeName, null, false);
         if (type == null && typeParam != null) {
            type = typeParam;
            userType = true;
         }
      }
      if (type == null) { 
         if (it != null)
            type = ModelUtil.findTypeDeclaration(sys, it, fullTypeName, refLayer, true);
      }
      if (type == null) {
         if (typeParam != null) {
            type = typeParam;
            userType = true;
         }
         else {
            type = FAILED_TO_INIT_SENTINEL;
            if (displayError) {
               displayTypeError("No type: ", getFullTypeName(), " for ");
               if (it != null) {
                  Object dummy = ModelUtil.findTypeDeclaration(sys, it, fullTypeName, refLayer, true);
                  if (node != null)
                     dummy = node.findType(fullTypeName);
               }
            }
         }
      }
      if (type instanceof BodyTypeDeclaration) {
         BodyTypeDeclaration btype = (BodyTypeDeclaration) type;
         if (sys == null)
            sys = btype.getLayeredSystem();
         if (sys != null && !sys.allTypesProcessed) {
            btype.needsOwnClass = true;
         }
      }
      List<Object> typeDefs = getTypeArgumentDeclarations(sys, it, node, ctx, typeParamTypes, type);
      if (typeDefs != null && type != FAILED_TO_INIT_SENTINEL && anyBoundParameters(typeDefs)) {
         List<?> typeParams = ModelUtil.getTypeParameters(type);
         if (typeParams == null || typeParams.size() != typeDefs.size())
            displayError("Wrong number of type arguments for type: ", ModelUtil.getTypeName(type)," for ");
         else {
            if (it != null)
               type = new ParamTypeDeclaration(sys, it, typeParams, typeDefs, type);
            else {
               if (ctx != null && ctx.getDefinedInType() != null)
                  type = new ParamTypeDeclaration(sys, ctx.getDefinedInType(), typeParams, typeDefs, type);
               else
                  type = new ParamTypeDeclaration(sys, typeParams, typeDefs, type);
            }
         }
      }
      if ((!userType || !ModelUtil.isArray(type)) && arrayDimensions != null && type != FAILED_TO_INIT_SENTINEL) {
         type = new ArrayTypeDeclaration(sys, it, type, arrayDimensions);
      }
   }
public void initType ( LayeredSystem sys , Object it , JavaSemanticNode node , ITypeParamContext ctx , boolean displayError , boolean isLayer , Object typeParam ) { if ( chained ) return ; String fullTypeName = getFullBaseTypeName ( ) ; type = FAILED_TO_INIT_SENTINEL ; if ( fullTypeName == null ) return ; if ( isLayer ) { if ( sys != null ) { if ( it instanceof TypeDeclaration ) { JavaModel curModel = ( ( TypeDeclaration ) it ) . getJavaModel ( ) ; if ( curModel != null && curModel . getLayer ( ) != null ) { String layerRelPath = CTypeUtil . getPackageName ( curModel . getLayer ( ) . getLayerName ( ) ) ; if ( curModel . getUserData ( ) != null ) { JavaModel layerModel = sys . getAnnotatedLayerModel ( fullTypeName , layerRelPath ) ; if ( layerModel != null ) type = layerModel . getModelTypeDeclaration ( ) ; } else { Layer layer = curModel . layer . activated ? sys . findLayerByName ( layerRelPath , fullTypeName ) : sys . getInactiveLayer ( fullTypeName , false , false , true , false ) ; if ( layer == null && ! curModel . layer . activated ) { layer = sys . getInactiveLayer ( CTypeUtil . prefixPath ( layerRelPath , fullTypeName ) , false , false , true , false ) ; } if ( layer != null && layer . model != null ) type = layer . model . getModelTypeDeclaration ( ) ; } } } } return ; } if ( typeArguments != null && chainedTypes != null ) { int chainedSz ; if ( ( chainedSz = chainedTypes . size ( ) ) != 0 ) chainedTypes . get ( chainedSz - 1 ) . typeArguments = typeArguments ; } Layer refLayer = ctx == null ? ( it instanceof TypeDeclaration ? ( ( TypeDeclaration ) it ) . getLayer ( ) : null ) : ctx . getRefLayer ( ) ; boolean userType = false ; if ( typeParam != null && ModelUtil . isTypeVariable ( typeParam ) ) type = typeParam ; else if ( node != null ) type = node . findType ( fullTypeName ) ; else if ( it != null ) { type = ModelUtil . findTypeDeclaration ( sys , it , fullTypeName , refLayer , true ) ; } else if ( sys != null ) { type = sys . getTypeDeclaration ( fullTypeName , srcOnly , refLayer , false ) ; } else if ( typeParam != null ) { type = typeParam ; userType = true ; } List < Object > typeParamTypes = null ; if ( type == null && it == null && ctx != null ) { type = ctx . getTypeDeclarationForParam ( fullTypeName , null , false ) ; if ( type == null && typeParam != null ) { type = typeParam ; userType = true ; } } if ( type == null ) { if ( it != null ) type = ModelUtil . findTypeDeclaration ( sys , it , fullTypeName , refLayer , true ) ; } if ( type == null ) { if ( typeParam != null ) { type = typeParam ; userType = true ; } else { type = FAILED_TO_INIT_SENTINEL ; if ( displayError ) { displayTypeError ( "No type: " , getFullTypeName ( ) , " for " ) ; if ( it != null ) { Object dummy = ModelUtil . findTypeDeclaration ( sys , it , fullTypeName , refLayer , true ) ; if ( node != null ) dummy = node . findType ( fullTypeName ) ; } } } } if ( type instanceof BodyTypeDeclaration ) { BodyTypeDeclaration btype = ( BodyTypeDeclaration ) type ; if ( sys == null ) sys = btype . getLayeredSystem ( ) ; if ( sys != null && ! sys . allTypesProcessed ) { btype . needsOwnClass = true ; } } List < Object > typeDefs = getTypeArgumentDeclarations ( sys , it , node , ctx , typeParamTypes , type ) ; if ( typeDefs != null && type != FAILED_TO_INIT_SENTINEL && anyBoundParameters ( typeDefs ) ) { List < ? > typeParams = ModelUtil . getTypeParameters ( type ) ; if ( typeParams == null || typeParams . size ( ) != typeDefs . size ( ) ) displayError ( "Wrong number of type arguments for type: " , ModelUtil . getTypeName ( type ) , " for " ) ; else { if ( it != null ) type = new ParamTypeDeclaration ( sys , it , typeParams , typeDefs , type ) ; else { if ( ctx != null && ctx . getDefinedInType ( ) != null ) type = new ParamTypeDeclaration ( sys , ctx . getDefinedInType ( ) , typeParams , typeDefs , type ) ; else type = new ParamTypeDeclaration ( sys , typeParams , typeDefs , type ) ; } } } if ( ( ! userType || ! ModelUtil . isArray ( type ) ) && arrayDimensions != null && type != FAILED_TO_INIT_SENTINEL ) { type = new ArrayTypeDeclaration ( sys , it , type , arrayDimensions ) ; } }
Initializes this type from the model and node specified.
Initializes this type from the model and node specified .
// Don't need to init if we are just part of someone else's type // prevent recursive calls // Invalid fragment // If this is a reference from an annotated layer model we need to annotate the type so we cna make the layer // references work like normal types. // Relative paths for inactive layers are done separately here. //else //  this may be an activated layer that's not part of this layered system - e.g. a server specific layer for the client runtime. // The refLayer must be set so we retrieve the type from the right active/inactive layer set // Looking up type parameters by name is not good here // In the parametrized type info we create ClassTypes which are defined as part of a compiled method - so no relative type info is available. // fortunately imports and local references are always made absolute at this level // When looking up type parameters, typically the it is the ParamTypeDeclaration but if it's a param method, it won't be so we need to // look up the type parameter for the method explicitly here. // An unresolvable type parameter which we've manually created.  Just use the type parameter // as the type so we know it's essentially an unbound type. // not a relative name // We do not just use typeParam here, but instead at least try to resolve type by name, then resolve the // type arguments because sometimes those type arguments resolve to more specific values in this context. // But in some cases we do not have the info to resolve the type and type arguments - in those cases we // will just use typeParam as it is.  In any case, we are careful to use the type arguments from type // param and pass those into initType as the typeParam argument so we follow this pattern for the type-arguments // (and possibly their type-arguments). // Since there is a class reference to this type, we cannot optimize away that class for inner objects // Once we start transforming things, it seems we pull in type references to object types which we do not count to decide if we need the class // Before we return the type, check and see if this definition adds any bound type parameters - // i.e. concrete types instead of parameter names.  If so, we need to wrap the returned type with // an object which knows how to resolve type parameters to do the proper type matching when generics are used. // Sometimes when we are called, typeParam supplies the component type and others the actual array generic type so be careful not to re-wrap it or leave it unwrapped