PsiClassType (@NotNull PsiType fromType, @NotNull Project project, @NotNull PsiElement context) { JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); final PsiClass threadLocalClass = psiFacade.findClass(ThreadLocal.class.getName(), GlobalSearchScope.allScope(project)); if (threadLocalClass == null) {//show warning return null; } final Map<PsiTypeParameter, PsiType> substitutor = new HashMap<>(); final PsiTypeParameter[] typeParameters = threadLocalClass.getTypeParameters(); if (typeParameters.length == 1) { PsiType type = fromType; if (fromType instanceof PsiPrimitiveType) type = ((PsiPrimitiveType)fromType).getBoxedType(context); substitutor.put(typeParameters[0], type); } PsiElementFactory factory = psiFacade.getElementFactory(); return factory.createType(threadLocalClass, factory.createSubstitutor(substitutor)); }