mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
default Optional.empty for Optional type (IDEA-174268)
This commit is contained in:
@@ -353,7 +353,7 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
|
||||
}
|
||||
Properties properties = FileTemplateManager.getInstance(targetClass.getProject()).getDefaultProperties();
|
||||
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnType.getPresentableText());
|
||||
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType));
|
||||
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType, true));
|
||||
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(originalMethod, result));
|
||||
properties.setProperty(FileTemplate.ATTRIBUTE_PLAIN_CALL_SUPER, callSuper(originalMethod, result, false));
|
||||
JavaTemplateUtil.setClassAndMethodNameProperties(properties, targetClass, result);
|
||||
|
||||
@@ -63,6 +63,11 @@ public class PsiTypesUtil {
|
||||
|
||||
@NotNull
|
||||
public static String getDefaultValueOfType(PsiType type) {
|
||||
return getDefaultValueOfType(type, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getDefaultValueOfType(PsiType type, boolean customDefaultValues) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
int count = type.getArrayDimensions() - 1;
|
||||
PsiType componentType = type.getDeepComponentType();
|
||||
@@ -88,6 +93,12 @@ public class PsiTypesUtil {
|
||||
if (type instanceof PsiPrimitiveType) {
|
||||
return PsiType.BOOLEAN.equals(type) ? PsiKeyword.FALSE : "0";
|
||||
}
|
||||
if (customDefaultValues) {
|
||||
PsiType rawType = type instanceof PsiClassType ? ((PsiClassType)type).rawType() : null;
|
||||
if (rawType != null && rawType.equalsToText(CommonClassNames.JAVA_UTIL_OPTIONAL)) {
|
||||
return CommonClassNames.JAVA_UTIL_OPTIONAL + ".empty()";
|
||||
}
|
||||
}
|
||||
return PsiKeyword.NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Implement methods" "true"
|
||||
import java.util.Optional;
|
||||
|
||||
interface I<T> {
|
||||
Optional<T> foo();
|
||||
}
|
||||
class Impl implements I<String> {
|
||||
@Override
|
||||
public Optional<String> foo() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Implement methods" "true"
|
||||
import java.util.Optional;
|
||||
|
||||
interface I<T> {
|
||||
Optional<T> foo();
|
||||
}
|
||||
class I<caret>mpl implements I<String> {
|
||||
}
|
||||
Reference in New Issue
Block a user