Java 类com.intellij.psi.PsiIntersectionType 实例源码

项目:manifold-ij    文件:TypeUtil.java   
public static PsiType getDefaultParameterizedType( PsiType type, PsiManager mgr )
{
  if( type.getArrayDimensions() > 0 )
  {
    PsiType defType = getDefaultParameterizedType( ((PsiArrayType)type).getComponentType(), mgr );
    if( !defType.equals( type ) )
    {
      return new PsiArrayType( defType );
    }
    return type;
  }
  if( type instanceof PsiIntersectionType )
  {
    return makeDefaultParameterizedTypeForCompoundType( (PsiIntersectionType)type, mgr );
  }
  if( type instanceof PsiDisjunctionType )
  {
    return getDefaultParameterizedType( PsiTypesUtil.getLowestUpperBoundClassType( (PsiDisjunctionType)type ), mgr );
  }
  if( !isGenericType( type ) && !isParameterizedType( type ) )
  {
    return type;
  }
  type = ((PsiClassType)type).rawType();
  return makeDefaultParameterizedType( type );
}
项目:manifold-ij    文件:TypeUtil.java   
private static PsiType makeDefaultParameterizedTypeForCompoundType( PsiIntersectionType type, PsiManager mgr )
{
  PsiType[] types = type.getConjuncts();
  PsiType[] defCompTypes = new PsiType[types.length];
  int i = 0;
  boolean bDifferent = false;
  for( PsiType compType : types )
  {
    defCompTypes[i++] = getDefaultParameterizedType( compType, mgr );
    bDifferent = bDifferent || !defCompTypes[i].equals( compType );
  }
  if( bDifferent )
  {
    return PsiIntersectionType.createIntersection( defCompTypes );
  }
  return type;
}
项目:intellij-ce-playground    文件:DFAType.java   
@Nullable
public PsiType getResultType() {
  if (mixins.isEmpty()) return primary;

  List<PsiType> types = new ArrayList<PsiType>();
  if (primary != null) {
    types.add(primary);
  }
  for (Mixin mixin : mixins) {
    if (!mixin.myNegated) {
      types.add(mixin.myType);
    }
  }
  if (types.isEmpty()) return null;
  return PsiIntersectionType.createIntersection(types.toArray(PsiType.createArray(types.size())));
}
项目:tools-idea    文件:DFAType.java   
@Nullable
public PsiType getResultType() {
  if (mixins.size() == 0) return primary;

  List<PsiType> types = new ArrayList<PsiType>();
  if (primary != null) {
    types.add(primary);
  }
  for (Mixin mixin : mixins) {
    if (!mixin.myNegated) {
      types.add(mixin.myType);
    }
  }
  if (types.size() == 0) return null;
  return PsiIntersectionType.createIntersection(types.toArray(new PsiType[types.size()]));
}
项目:intellij-ce-playground    文件:ClosureSyntheticParameter.java   
@Override
public PsiType fun(ClosureSyntheticParameter parameter) {
  PsiType typeGroovy = GrVariableEnhancer.getEnhancedType(parameter);
  if (typeGroovy instanceof PsiIntersectionType) {
    return ((PsiIntersectionType)typeGroovy).getRepresentative();
  }
  return typeGroovy;
}
项目:manifold-ij    文件:TypeUtil.java   
public static PsiType replaceTypeVariableTypeParametersWithBoundingTypes( PsiType type, PsiType enclType )
{
  if( isTypeVariable( type ) )
  {
    PsiClass boundingType = getBoundingType( (PsiTypeParameter)((PsiClassType)type).resolve() );

    if( isRecursiveType( (PsiClassType)type, type( boundingType ) ) )
    {
      // short-circuit recursive typevar
      return ((PsiClassType)type( boundingType )).rawType();
    }

    if( enclType != null && isParameterizedType( enclType ) )
    {
      TypeVarToTypeMap map = mapTypeByVarName( enclType, enclType );
      return replaceTypeVariableTypeParametersWithBoundingTypes( getActualType( type( boundingType ), map, true ) );
    }

    return replaceTypeVariableTypeParametersWithBoundingTypes( type( boundingType ), enclType );
  }

  if( type.getArrayDimensions() > 0 )
  {
    return new PsiArrayType( replaceTypeVariableTypeParametersWithBoundingTypes( ((PsiArrayType)type).getComponentType(), enclType ) );
  }

  if( type instanceof PsiIntersectionType )
  {
    PsiType[] types = ((PsiIntersectionType)type).getConjuncts();
    Set<PsiType> newTypes = new HashSet<>();
    for( PsiType t : types )
    {
      newTypes.add( replaceTypeVariableTypeParametersWithBoundingTypes( t ) );
    }
    if( newTypes.size() == 1 )
    {
      return newTypes.iterator().next();
    }
    return PsiIntersectionType.createIntersection( new ArrayList<>( newTypes ) );
  }

  if( isParameterizedType( type ) )
  {
    PsiType[] typeParams = ((PsiClassType)type).getParameters();
    PsiType[] concreteParams = new PsiType[typeParams.length];
    for( int i = 0; i < typeParams.length; i++ )
    {
      concreteParams[i] = replaceTypeVariableTypeParametersWithBoundingTypes( typeParams[i], enclType );
    }
    type = parameterizeType( (PsiClassType)type, concreteParams );
  }
  else if( type instanceof PsiClassType )
  {
    PsiClass psiClass = ((PsiClassType)type).resolve();
    PsiTypeParameter[] typeVars = psiClass.getTypeParameters();
    PsiType[] boundingTypes = new PsiType[typeVars.length];
    for( int i = 0; i < boundingTypes.length; i++ )
    {
      boundingTypes[i] = type( getBoundingType( typeVars[i] ) );

      if( isRecursiveType( (PsiClassType)type( typeVars[i] ), boundingTypes[i] ) )
      {
        return type;
      }
    }
    for( int i = 0; i < boundingTypes.length; i++ )
    {
      boundingTypes[i] = replaceTypeVariableTypeParametersWithBoundingTypes( boundingTypes[i], enclType );
    }
    type = parameterizeType( (PsiClassType)type, boundingTypes );
  }
  else if( type instanceof PsiWildcardType )
  {
    replaceTypeVariableTypeParametersWithBoundingTypes( ((PsiWildcardType)type).getExtendsBound() );
  }
  return type;
}