mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java folding: use unicode right arrow for closures
This commit is contained in:
+11
-2
@@ -26,6 +26,8 @@ import com.intellij.lang.folding.NamedFoldingDescriptor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.FoldingGroup;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorFontType;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
@@ -41,7 +43,11 @@ import com.intellij.psi.impl.source.tree.JavaDocElementType;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.FontUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
@@ -49,6 +55,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -830,7 +837,9 @@ public abstract class JavaFoldingBuilderBase extends CustomFoldingBuilder implem
|
||||
return psiParameter.getName();
|
||||
}
|
||||
}, ", ");
|
||||
@NonNls final String lambdas = type + methodName + "(" + params + ") -> {";
|
||||
Font font = EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN);
|
||||
String arrow = FontUtil.rightArrow(font);
|
||||
@NonNls final String lambdas = type + methodName + "(" + params + ") " + arrow + " {";
|
||||
|
||||
final int closureStart = expression.getTextRange().getStartOffset();
|
||||
final int closureEnd = expression.getTextRange().getEndOffset();
|
||||
|
||||
@@ -279,12 +279,12 @@ class Test {
|
||||
configure text
|
||||
def foldingModel = myFixture.editor.foldingModel as FoldingModelImpl
|
||||
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable(")).placeholderText == '() -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable2(")).placeholderText == '(Runnable2) () -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable3(")).placeholderText == '(Runnable3) () -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable4(")).placeholderText == '() -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("MyAction(")).placeholderText == '(MyAction) () -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("MyAction2(")).placeholderText == '(MyAction2) () -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable(")).placeholderText == '() → { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable2(")).placeholderText == '(Runnable2) () → { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable3(")).placeholderText == '(Runnable3) () → { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable4(")).placeholderText == '() → { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("MyAction(")).placeholderText == '(MyAction) () → { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("MyAction2(")).placeholderText == '(MyAction2) () → { '
|
||||
}
|
||||
|
||||
public void "test closure folding after paste"() {
|
||||
@@ -306,7 +306,7 @@ class Test {
|
||||
|
||||
def foldingModel = myFixture.editor.foldingModel as FoldingModelImpl
|
||||
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable(")).placeholderText == '() -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable(")).placeholderText == '() → { '
|
||||
}
|
||||
|
||||
public void "test closure folding when overriding one method of many"() {
|
||||
@@ -333,8 +333,8 @@ class Test {
|
||||
configure text
|
||||
def foldingModel = myFixture.editor.foldingModel as FoldingModelImpl
|
||||
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable("))?.placeholderText == 'run() -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable2("))?.placeholderText == '(Runnable2) run2() -> { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable("))?.placeholderText == 'run() → { '
|
||||
assert foldingModel.getCollapsedRegionAtOffset(text.indexOf("Runnable2("))?.placeholderText == '(Runnable2) run2() → { '
|
||||
}
|
||||
|
||||
public void "test no closure folding when the method throws an unresolved exception"() {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.
|
||||
*/
|
||||
package com.intellij.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class FontUtil {
|
||||
@NotNull
|
||||
public static String rightArrow(@NotNull Font font) {
|
||||
char rightArrow = '\u2192';
|
||||
return font.canDisplay(rightArrow) ? String.valueOf(rightArrow) : "->";
|
||||
}
|
||||
}
|
||||
@@ -2973,8 +2973,7 @@ public class UIUtil {
|
||||
|
||||
@NotNull
|
||||
public static String rightArrow() {
|
||||
char rightArrow = '\u2192';
|
||||
return getLabelFont().canDisplay(rightArrow) ? String.valueOf(rightArrow) : "->";
|
||||
return FontUtil.rightArrow(getLabelFont());
|
||||
}
|
||||
|
||||
public static EmptyBorder getTextAlignBorder(@NotNull JToggleButton alignSource) {
|
||||
|
||||
Reference in New Issue
Block a user