mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
Folding: add replacing with inferred type for var as folding: IDEA-194935
This commit is contained in:
@@ -29,6 +29,7 @@ public class JavaCodeFoldingSettingsBase extends JavaCodeFoldingSettings {
|
||||
private boolean COLLAPSE_I18N_MESSAGES = true;
|
||||
private boolean COLLAPSE_SUPPRESS_WARNINGS = true;
|
||||
private boolean COLLAPSE_END_OF_LINE_COMMENTS;
|
||||
private boolean REPLACE_VAR_WITH_INFERRED_TYPE = false;
|
||||
|
||||
@Override
|
||||
public boolean isCollapseImports() {
|
||||
@@ -168,4 +169,14 @@ public class JavaCodeFoldingSettingsBase extends JavaCodeFoldingSettings {
|
||||
public void setCollapseEndOfLineComments(boolean value) {
|
||||
COLLAPSE_END_OF_LINE_COMMENTS = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReplaceVarWithInferredType() {
|
||||
return REPLACE_VAR_WITH_INFERRED_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReplaceVarWithInferredType(boolean value) {
|
||||
REPLACE_VAR_WITH_INFERRED_TYPE = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +269,17 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
|
||||
addTypeParametersFolding(list, document, parameterList, 3, quick);
|
||||
}
|
||||
|
||||
private static void addLocalVariableTypeFolding(@NotNull List<? super FoldingDescriptor> list,
|
||||
@NotNull PsiVariable expression,
|
||||
boolean quick) {
|
||||
if (quick) return; // presentable text may require resolve
|
||||
PsiTypeElement typeElement = expression.getTypeElement();
|
||||
if (typeElement == null) return;
|
||||
if (!typeElement.isInferredType()) return;
|
||||
String presentableText = expression.getType().getPresentableText();
|
||||
list.add(new NamedFoldingDescriptor(typeElement.getNode(), typeElement.getTextRange(), null, presentableText, true, Collections.emptySet()));
|
||||
}
|
||||
|
||||
private static boolean resolvesCorrectly(@NotNull PsiReferenceExpression expression) {
|
||||
for (final JavaResolveResult result : expression.multiResolve(true)) {
|
||||
if (!result.isValidResult()) {
|
||||
@@ -550,7 +561,7 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
|
||||
}
|
||||
|
||||
PsiCodeBlock body = method.getBody();
|
||||
if (body != null && !oneLiner) {
|
||||
if (body != null) {
|
||||
addCodeBlockFolds(list, body, processedComments, document, quick);
|
||||
}
|
||||
}
|
||||
@@ -678,6 +689,15 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLocalVariable(PsiLocalVariable variable) {
|
||||
if (!dumb && JavaCodeFoldingSettings.getInstance().isReplaceVarWithInferredType()) {
|
||||
addLocalVariableTypeFolding(list, variable, quick);
|
||||
}
|
||||
|
||||
super.visitLocalVariable(variable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
if (!dumb) {
|
||||
|
||||
Reference in New Issue
Block a user