This commit is contained in:
Alexey Kudravtsev
2016-07-12 12:14:00 +03:00
parent 34343c165d
commit cf212616ff
2 changed files with 26 additions and 23 deletions
@@ -19,17 +19,17 @@ import com.intellij.codeInsight.folding.CodeFoldingSettings;
import com.intellij.codeInsight.folding.JavaCodeFoldingSettings;
public class JavaCodeFoldingSettingsBase extends JavaCodeFoldingSettings {
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_ACCESSORS;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_ONE_LINE_METHODS = true;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_INNER_CLASSES;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_ANONYMOUS_CLASSES;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_ANNOTATIONS;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_CLOSURES = true;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_CONSTRUCTOR_GENERIC_PARAMETERS = true;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_I18N_MESSAGES = true;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_SUPPRESS_WARNINGS = true;
@SuppressWarnings({"WeakerAccess"}) public boolean COLLAPSE_END_OF_LINE_COMMENTS;
@SuppressWarnings({"WeakerAccess"}) public boolean INLINE_PARAMETER_NAMES_FOR_LITERAL_CALL_ARGUMENTS;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_ACCESSORS;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_ONE_LINE_METHODS = true;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_INNER_CLASSES;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_ANONYMOUS_CLASSES;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_ANNOTATIONS;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_CLOSURES = true;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_CONSTRUCTOR_GENERIC_PARAMETERS = true;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_I18N_MESSAGES = true;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_SUPPRESS_WARNINGS = true;
@SuppressWarnings("WeakerAccess") public boolean COLLAPSE_END_OF_LINE_COMMENTS;
@SuppressWarnings("WeakerAccess") public boolean INLINE_PARAMETER_NAMES_FOR_LITERAL_CALL_ARGUMENTS;
@Override
public boolean isCollapseImports() {
@@ -65,22 +65,22 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
if (element instanceof PsiImportList) {
return "...";
}
else if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiClass) {
if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiClass) {
return "{...}";
}
else if (element instanceof PsiDocComment) {
if (element instanceof PsiDocComment) {
return "/**...*/";
}
else if (element instanceof PsiFile) {
if (element instanceof PsiFile) {
return "/.../";
}
else if (element instanceof PsiAnnotation) {
if (element instanceof PsiAnnotation) {
return "@{...}";
}
else if (element instanceof PsiReferenceParameterList) {
if (element instanceof PsiReferenceParameterList) {
return SMILEY;
}
else if (element instanceof PsiComment) {
if (element instanceof PsiComment) {
return "//...";
}
return "...";
@@ -201,8 +201,9 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
}
}
if (element == null) return null;
if (element.getPrevSibling() instanceof PsiWhiteSpace) element = element.getPrevSibling();
if (element == null || element.equals(first)) return null;
PsiElement prevSibling = element.getPrevSibling();
if (prevSibling instanceof PsiWhiteSpace) element = prevSibling;
if (element.equals(first)) return null;
return new UnfairTextRange(first.getTextOffset(), element.getTextOffset());
}
@@ -447,8 +448,7 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
private boolean addToFold(List<FoldingDescriptor> list, PsiElement elementToFold, Document document, boolean allowOneLiners) {
PsiUtilCore.ensureValid(elementToFold);
TextRange range = getRangeToFold(elementToFold);
if (range == null) return false;
return addFoldRegion(list, elementToFold, document, allowOneLiners, range);
return range != null && addFoldRegion(list, elementToFold, document, allowOneLiners, range);
}
private static boolean addFoldRegion(final List<FoldingDescriptor> list, final PsiElement elementToFold, final Document document,
@@ -740,8 +740,11 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
}
}
private void addCodeBlockFolds(PsiElement scope, final List<FoldingDescriptor> foldElements,
final @NotNull Set<PsiElement> processedComments, final Document document, final boolean quick) {
private void addCodeBlockFolds(@NotNull PsiElement scope,
@NotNull final List<FoldingDescriptor> foldElements,
@NotNull final Set<PsiElement> processedComments,
@NotNull final Document document,
final boolean quick) {
final boolean dumb = DumbService.isDumb(scope.getProject());
scope.accept(new JavaRecursiveElementWalkingVisitor() {
@Override