Fix performance warning when using method separators.

See 1d262171ae, PY-25475 and PY-26158.
This commit is contained in:
Semyon Proshev
2017-10-04 15:18:02 +03:00
parent b825a05f35
commit 7c793ce173
2 changed files with 15 additions and 38 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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-2017 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.jetbrains.python.codeInsight;
import com.intellij.codeHighlighting.Pass;
@@ -185,7 +171,7 @@ public class PyLineMarkerProvider implements LineMarkerProvider, PyLineSeparator
}
@Override
public boolean isSeparatorAllowed(PsiElement element) {
public boolean isSeparatorAllowed(@Nullable PsiElement element) {
return element instanceof PyFunction || element instanceof PyClass;
}
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2017 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.jetbrains.python.codeInsight;
import com.intellij.codeHighlighting.Pass;
@@ -20,9 +6,12 @@ import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.markup.GutterIconRenderer;
import com.intellij.openapi.editor.markup.SeparatorPlacement;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -34,13 +23,12 @@ public class PyLineSeparatorUtil {
}
public interface Provider {
boolean isSeparatorAllowed(PsiElement element);
boolean isSeparatorAllowed(@Nullable PsiElement element);
}
@Nullable
public static LineMarkerInfo addLineSeparatorIfNeeded(final Provider provider,
final PsiElement element) {
final Ref<LineMarkerInfo> info = new Ref<LineMarkerInfo>(null);
public static LineMarkerInfo addLineSeparatorIfNeeded(@NotNull Provider provider, @NotNull PsiElement element) {
final Ref<LineMarkerInfo> info = new Ref<>(null);
ApplicationManager.getApplication().runReadAction(() -> {
if (!provider.isSeparatorAllowed(element)) {
return;
@@ -67,11 +55,14 @@ public class PyLineSeparatorUtil {
return info.get();
}
private static LineMarkerInfo<PsiElement> createLineSeparatorByElement(final PsiElement element) {
final LineMarkerInfo<PsiElement> info = new LineMarkerInfo<PsiElement>(element, element.getTextRange().getStartOffset(), null, Pass.LINE_MARKERS, null, null);
@NotNull
private static LineMarkerInfo<PsiElement> createLineSeparatorByElement(@NotNull PsiElement element) {
final PsiElement anchor = PsiTreeUtil.getDeepestFirst(element);
final LineMarkerInfo<PsiElement> info =
new LineMarkerInfo<>(anchor, anchor.getTextRange(), null, Pass.LINE_MARKERS, null, null, GutterIconRenderer.Alignment.RIGHT);
info.separatorColor = EditorColorsManager.getInstance().getGlobalScheme().getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
}
}