PsiType (PsiExpression expression, boolean box) { if (expression == null) return null; PsiClassType type = ObjectUtils.tryCast(expression.getType(), PsiClassType.class); if (type == null) return null; String rawName = type.rawType().getCanonicalText(); if (rawName.equals(OPTIONAL_INT)) { return box ? PsiTypes.intType().getBoxedType(expression) : PsiTypes.intType(); } if (rawName.equals(OPTIONAL_LONG)) { return box ? PsiTypes.longType().getBoxedType(expression) : PsiTypes.longType(); } if (rawName.equals(OPTIONAL_DOUBLE)) { return box ? PsiTypes.doubleType().getBoxedType(expression) : PsiTypes.doubleType(); } if (!rawName.equals(JAVA_UTIL_OPTIONAL) && !rawName.equals(GUAVA_OPTIONAL)) return null; PsiType[] parameters = type.getParameters(); if (parameters.length != 1) return null; return parameters[0]; }