private List<IRType> getBoundedParameterTypeDescriptors(IConstructorInfo mi) {
    if (mi.getParameters().length == 0) {
      return Collections.emptyList();
    }

    if (mi instanceof IJavaConstructorInfo) {
      return IRTypeResolver.getDescriptors(
          ((IJavaConstructorInfo) mi).getJavaConstructor().getParameterTypes());
    } else if (mi instanceof IGosuConstructorInfo) {
      IReducedDynamicFunctionSymbol dfs = ((IGosuConstructorInfo) mi).getDfs();
      while (dfs instanceof ReducedParameterizedDynamicFunctionSymbol) {
        ReducedParameterizedDynamicFunctionSymbol pdfs =
            (ReducedParameterizedDynamicFunctionSymbol) dfs;
        dfs = pdfs.getBackingDfs();
      }

      List<IRType> boundedTypes = new ArrayList<IRType>(dfs.getArgs().size());
      if (IGosuClass.ProxyUtil.isProxy(dfs.getGosuClass())) {
        return getBoundedParamTypesFromProxiedClass(dfs);
      }

      for (int i = 0; i < dfs.getArgs().size(); i++) {
        boundedTypes.add(
            IRTypeResolver.getDescriptor(
                TypeLord.getDefaultParameterizedTypeWithTypeVars(dfs.getArgs().get(i).getType())));
      }
      return boundedTypes;
    } else {
      return getTypeDescriptors(mi.getParameters());
    }
  }
  public Class defineClass(ICompilableTypeInternal gsClass, boolean useSingleServingLoader)
      throws ClassNotFoundException {
    try {
      if (gsClass instanceof IGosuClassInternal
          && ((IGosuClassInternal) gsClass).hasBackingClass()) {
        return ((IGosuClassInternal) gsClass).getBackingClass();
      }

      // there is no point in defining eval classes in a single serving class loader (it wastes
      // memory)
      if (useSingleServingLoader
          || TypeLord.isEvalProgram(gsClass)
          || isThrowawayProgram(gsClass)
          || isEnclosingTypeInSingleServingLoader(gsClass)
          || hasDiscreteNamespace(gsClass.getNamespace())) {
        // These classes are "fire and forget"; they need to be disposable after they run,
        // so we load them in a separate class loader so we can unload them -- it's the only
        // way to unload a class in java.
        return defineClassInLoader(gsClass, true);
      }

      return findOrDefineClass(gsClass);
    } catch (Exception e) {
      throw GosuExceptionUtil.forceThrow(e, gsClass.getName());
    }
  }
 @Override
 public IGenericTypeVariable[] getTypeVariables(IJavaMethodInfo javaMethodInfo) {
   IJavaClassTypeVariable[] rawTypeParams = getTypeParameters();
   IType declClass = TypeSystem.get(getEnclosingClass());
   TypeVarToTypeMap actualParamByVarName = TypeLord.mapTypeByVarName(declClass, declClass);
   FunctionType functionType = new FunctionType(javaMethodInfo, true);
   return GenericTypeVariable.convertTypeVars(functionType, rawTypeParams, actualParamByVarName);
 }
Beispiel #4
0
 private IType findCommonClass(IType t1, IType t2) {
   do {
     t1 = t1.getSupertype();
     if (t1 == null) {
       return JavaTypes.OBJECT();
     }
     t1 = TypeLord.getPureGenericType(t1);
   } while (!t1.isAssignableFrom(t2));
   return t1;
 }
 public static String getJavaName(IType type) {
   if (type != null) {
     type = TypeLord.getPureGenericType(type);
     IType outerType = type.getEnclosingType();
     if (outerType != null) {
       return getJavaName(outerType) + "$" + type.getRelativeName();
     }
     return type.getName();
   }
   return null;
 }
  private Constructor getJavaConstructorFromProxy(IReducedDynamicFunctionSymbol dfs) {
    IType proxyType = dfs.getGosuClass();
    IJavaType javaType = (IJavaType) IGosuClass.ProxyUtil.getProxiedType(proxyType);

    IType[] boundedDfsParams = new IType[dfs.getArgs().size()];
    for (int i = 0; i < boundedDfsParams.length; i++) {
      IType param = dfs.getArgs().get(i).getType();
      if (param instanceof ITypeVariableType && param.getEnclosingType() instanceof IGosuClass) {
        param = ((ITypeVariableType) param).getBoundingType();
      }
      boundedDfsParams[i] = param;
    }

    javaType = (IJavaType) TypeLord.getDefaultParameterizedType(javaType);
    IJavaConstructorInfo jmi =
        (IJavaConstructorInfo)
            ((IRelativeTypeInfo) javaType.getTypeInfo()).getConstructor(javaType, boundedDfsParams);
    return jmi.getRawConstructor();
  }
 @Override
 public IType getActualType(TypeVarToTypeMap typeMap, boolean bKeepTypeVars) {
   IType typeFromMap = typeMap.getByMatcher(this, JavaClassTypeVarMatcher.instance());
   if (typeFromMap != null && !(typeFromMap instanceof ErrorType)) {
     if (typeFromMap.getName().equals(getName())) {
       IType boundingType = ((ITypeVariableType) typeFromMap).getBoundingType();
       IType boundingTypeFromMap = TypeLord.getActualType(boundingType, typeMap, bKeepTypeVars);
       if (boundingType != boundingTypeFromMap) {
         TypeVariableDefinitionImpl tvd =
             ((TypeVariableDefinitionImpl) ((ITypeVariableType) typeFromMap).getTypeVarDef())
                 .clone(boundingTypeFromMap);
         typeFromMap =
             new TypeVariableType(
                 tvd,
                 ((ITypeVariableType) typeFromMap).getTypeVarDef().getEnclosingType()
                     instanceof IFunctionType);
         ((ITypeVariableType) typeFromMap).getTypeVarDef().setVariance(getVariance());
       }
     }
     return typeFromMap;
   } else {
     return TypeSystem.getErrorType(getName());
   }
 }