com.intellij.psi.PsiArrayType Java Examples

The following examples show how to use com.intellij.psi.PsiArrayType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PsiTypeUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static TypeName getTypeName(PsiType type) {
  if (type instanceof PsiPrimitiveType) {
    // float
    return getPrimitiveTypeName((PsiPrimitiveType) type);
  } else if (type instanceof PsiClassType && ((PsiClassType) type).getParameterCount() > 0) {
    // Set<Integer>
    PsiClassType classType = (PsiClassType) type;
    return ParameterizedTypeName.get(
        guessClassName(classType.rawType().getCanonicalText()),
        getTypeNameArray(classType.getParameters()));
  } else if (type instanceof PsiArrayType) {
    // int[]
    PsiType componentType = ((PsiArrayType) type).getComponentType();
    return ArrayTypeName.of(getTypeName(componentType));
  } else if (type.getCanonicalText().contains("?")) {
    // ? extends Type
    return getWildcardTypeName(type.getCanonicalText());
  } else {
    return guessClassName(type.getCanonicalText());
  }
}
 
Example #2
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 6 votes vote down vote up
@Nullable
public static PsiType safeGetValidType(@NotNull Module module, @NotNull String fqn) {
  try {
    // Intellij expects inner classes to be referred via `.` instead of `$`
    PsiType type = JavaPsiFacade.getInstance(module.getProject()).getParserFacade()
        .createTypeFromText(fqn.replaceAll("\\$", "."), null);
    boolean typeValid = isValidType(type);
    if (typeValid) {
      if (type instanceof PsiClassType) {
        return PsiClassType.class.cast(type);
      } else if (type instanceof PsiArrayType) {
        return PsiArrayType.class.cast(type);
      }
    }
    return null;
  } catch (IncorrectOperationException e) {
    debug(() -> log.debug("Unable to find class fqn " + fqn));
    return null;
  }
}
 
Example #3
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 6 votes vote down vote up
public static boolean isValidType(@NotNull PsiType type) {
  if (!type.isValid()) {
    TimeoutUtil.sleep(
        1); // to see if processing in another thread suddenly makes the type valid again (which is a bug)
    if (!type.isValid()) {
      return false;
    }
  }
  if (type instanceof PsiArrayType) {
    return isValidType(PsiArrayType.class.cast(type).getComponentType());
  } else if (type instanceof PsiWildcardType) {
    PsiType bound = ((PsiWildcardType) type).getBound();
    return bound != null && isValidType(bound);
  } else if (type instanceof PsiCapturedWildcardType) {
    PsiType lowerBound = ((PsiCapturedWildcardType) type).getLowerBound();
    type = (lowerBound != NULL ? lowerBound : ((PsiCapturedWildcardType) type).getUpperBound());
    return type != NULL && isValidType(type);
  } else if (type instanceof PsiClassType) {
    PsiClassType.ClassResolveResult classResolveResult = ((PsiClassType) type).resolveGenerics();
    return classResolveResult.isValidResult() && isValidElement(
        requireNonNull(classResolveResult.getElement())) && !hasUnresolvedComponents(type);
  }
  return true;
}
 
Example #4
Source File: ClassSuggestionNodeFactory.java    From intellij-spring-assistant with MIT License 6 votes vote down vote up
@NotNull
public static MetadataProxy newMetadataProxy(Module module, @NotNull PsiType type) {
  if (type instanceof PsiArrayType) {
    return new ArrayMetadataProxy(module, (PsiArrayType) type);
  } else if (type instanceof PsiPrimitiveType) {
    PsiPrimitiveType primitiveType = (PsiPrimitiveType) type;
    type = getBoxedTypeFromPrimitiveType(module, primitiveType);
  }

  if (type instanceof PsiClassType) {
    SuggestionNodeType suggestionNodeType = getSuggestionNodeType(type);
    if (suggestionNodeType == SuggestionNodeType.MAP) {
      return new MapClassMetadataProxy((PsiClassType) type);
    } else {
      return new ClassMetadataProxy((PsiClassType) type);
    }
  }

  throw new IllegalAccessError(
      "Supports only PsiArrayType, PsiPrimitiveType & PsiClassType types");
}
 
Example #5
Source File: PsiTypeUtils.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
public static String getResolvedResultTypeName(PsiMethod method) {
    //return method.getReturnType().getCanonicalText();
    PsiType type = method.getReturnType();
    while (type instanceof PsiArrayType) {
        type = ((PsiArrayType)type).getComponentType();
    }
    return type.getCanonicalText();
}
 
Example #6
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static Map<PsiTypeParameter, PsiType> getTypeParameters(PsiType type) {
  if (type instanceof PsiArrayType) {
    return getTypeParameters(((PsiArrayType) type).getComponentType());
  } else if (type instanceof PsiPrimitiveType) {
    return null;
  } else if (type instanceof PsiClassType) {
    PsiClassType.ClassResolveResult resolveResult =
        PsiClassType.class.cast(type).resolveGenerics();
    if (resolveResult.isValidResult()) {
      return resolveResult.getSubstitutor().getSubstitutionMap();
    }
  }
  return null;
}
 
Example #7
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static String toClassFqn(@NotNull PsiType type) {
  if (type instanceof PsiArrayType) {
    String componentLongName = toClassFqn(PsiArrayType.class.cast(type).getComponentType());
    if (componentLongName != null) {
      return componentLongName + "[]";
    }
  } else if (type instanceof PsiPrimitiveType) {
    return type.getPresentableText();
  } else if (type instanceof PsiClassType) {
    return type.getCanonicalText();
  }
  return null;
}
 
Example #8
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static String toClassNonQualifiedName(@NotNull PsiType type) {
  if (type instanceof PsiArrayType) {
    String componentLongName =
        toClassNonQualifiedName(PsiArrayType.class.cast(type).getComponentType());
    if (componentLongName != null) {
      return componentLongName + "[]";
    }
  } else if (type instanceof PsiPrimitiveType) {
    return type.getPresentableText();
  } else if (type instanceof PsiClassType) {
    return ((PsiClassType) type).getClassName();
  }
  return null;
}
 
Example #9
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static String typeToFqn(Module module, @NotNull PsiType type) {
  if (isValidType(type)) {
    if (type instanceof PsiArrayType) {
      type = PsiArrayType.class.cast(type).getComponentType();
      return type.getCanonicalText();
    } else if (type instanceof PsiPrimitiveType) {
      return getBoxedTypeFromPrimitiveType(module, (PsiPrimitiveType) type).getCanonicalText();
    } else if (type instanceof PsiClassType) {
      return type.getCanonicalText();
    }
  }
  return null;
}
 
Example #10
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static PsiType getComponentType(@NotNull PsiType type) {
  if (type instanceof PsiArrayType) {
    return ((PsiArrayType) type).getComponentType();
  }
  return extractIterableTypeParameter(type, true);
}
 
Example #11
Source File: ArrayMetadataProxy.java    From intellij-spring-assistant with MIT License 4 votes vote down vote up
ArrayMetadataProxy(Module module, @NotNull PsiArrayType type) {
  this.type = type;
  delegate = newMetadataProxy(module, type.getComponentType());
}