From 1c050eb2b66c62f93199338b95eb1901e81cea5f Mon Sep 17 00:00:00 2001 From: "Roman.Ivanov" Date: Wed, 4 Dec 2019 13:40:06 +0700 Subject: [PATCH] Add folding for record header GitOrigin-RevId: b33bba12bc7e9bffddff6e8c613bfd507aad4cd8 --- .../folding/impl/JavaFoldingBuilderBase.java | 19 +++---------- .../codeInsight/folding/JavaFolding14Test.kt | 28 +++++++++++++++++++ .../LightJavaCodeInsightFixtureTestCase.java | 1 + 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 java/java-tests/testSrc/com/intellij/java/codeInsight/folding/JavaFolding14Test.kt 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 43b5de50c6ff..a9a828490e2d 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 @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.folding.impl; import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil; @@ -503,6 +489,9 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem else if (child instanceof PsiComment) { addCommentToFold(list, (PsiComment)child, document, processedComments); } + else if (child instanceof PsiRecordHeader) { + addToFold(list, child, document, false, "(...)", child.getTextRange(), false); + } } } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/folding/JavaFolding14Test.kt b/java/java-tests/testSrc/com/intellij/java/codeInsight/folding/JavaFolding14Test.kt new file mode 100644 index 000000000000..61cf9f966d96 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/folding/JavaFolding14Test.kt @@ -0,0 +1,28 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.java.codeInsight.folding + +import com.intellij.testFramework.LightProjectDescriptor +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase + +class JavaFolding14Test : JavaFoldingTestCase() { + override fun getProjectDescriptor(): LightProjectDescriptor = LightJavaCodeInsightFixtureTestCase.JAVA_14 + + fun testRecord() { + val text = """ + class B {} + + record A( + String s, + int a + ) { + void f() {} + }""".trimIndent() + configure(text) + + val regions = myFixture.editor.foldingModel.allFoldRegions + assertEquals(""" + FoldRegion -(20:44), placeholder='(...)' + FoldRegion -(45:62), placeholder='{...}' + """.trimIndent(), regions.joinToString("\n")) + } +} \ No newline at end of file diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java b/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java index 33a5ff9943c6..8f392ba3c160 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java @@ -72,6 +72,7 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase public static final @NotNull LightProjectDescriptor JAVA_11 = new ProjectDescriptor(LanguageLevel.JDK_11); public static final @NotNull LightProjectDescriptor JAVA_12 = new ProjectDescriptor(LanguageLevel.JDK_12); public static final @NotNull LightProjectDescriptor JAVA_13 = new ProjectDescriptor(LanguageLevel.JDK_13_PREVIEW); + public static final @NotNull LightProjectDescriptor JAVA_14 = new ProjectDescriptor(LanguageLevel.JDK_14); public static final @NotNull LightProjectDescriptor JAVA_X = new ProjectDescriptor(LanguageLevel.JDK_X); public static final @NotNull LightProjectDescriptor JAVA_LATEST = new ProjectDescriptor(LanguageLevel.HIGHEST) {