diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaCodeFoldingSettingsBase.java b/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaCodeFoldingSettingsBase.java index 629ce522d8dc..b20fdf5a5fa8 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaCodeFoldingSettingsBase.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaCodeFoldingSettingsBase.java @@ -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() { diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilderBase.java b/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilderBase.java index 5039ba4250be..8e42d9bb3c3c 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilderBase.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/folding/impl/JavaFoldingBuilderBase.java @@ -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 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 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 foldElements, - final @NotNull Set processedComments, final Document document, final boolean quick) { + private void addCodeBlockFolds(@NotNull PsiElement scope, + @NotNull final List foldElements, + @NotNull final Set processedComments, + @NotNull final Document document, + final boolean quick) { final boolean dumb = DumbService.isDumb(scope.getProject()); scope.accept(new JavaRecursiveElementWalkingVisitor() { @Override