예제 #1
0
  @NotNull
  public static PsiType createSetType(@NotNull PsiElement context, @NotNull PsiType type) {
    JavaPsiFacade facade = JavaPsiFacade.getInstance(context.getProject());
    GlobalSearchScope resolveScope = context.getResolveScope();

    PsiClass setClass = facade.findClass(JAVA_UTIL_SET, resolveScope);
    if (setClass != null && setClass.getTypeParameters().length == 1) {
      return facade.getElementFactory().createType(setClass, type);
    }

    return facade.getElementFactory().createTypeByFQClassName(JAVA_UTIL_SET, resolveScope);
  }
예제 #2
0
  @Nullable
  private static PsiClassType createCollection(
      Project project, String collectionName, PsiType... item) {
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
    PsiClass collection =
        JavaPsiFacade.getInstance(project)
            .findClass(collectionName, GlobalSearchScope.allScope(project));
    if (collection == null) return null;

    PsiTypeParameter[] parameters = collection.getTypeParameters();
    if (parameters.length != 1) return null;

    return factory.createType(collection, item);
  }
예제 #3
0
 @Nullable
 public static PsiType createJavaLangClassType(
     @Nullable PsiType type, Project project, GlobalSearchScope resolveScope) {
   final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
   PsiType result = null;
   PsiClass javaLangClass = facade.findClass(JAVA_LANG_CLASS, resolveScope);
   if (javaLangClass != null) {
     PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
     final PsiTypeParameter[] typeParameters = javaLangClass.getTypeParameters();
     if (typeParameters.length == 1) {
       substitutor = substitutor.put(typeParameters[0], type);
     }
     result = facade.getElementFactory().createType(javaLangClass, substitutor);
   }
   return result;
 }