diff --git a/python/src/com/jetbrains/python/codeInsight/PyLineMarkerProvider.java b/python/src/com/jetbrains/python/codeInsight/PyLineMarkerProvider.java index e1f20056880c..b1b9f9562466 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyLineMarkerProvider.java +++ b/python/src/com/jetbrains/python/codeInsight/PyLineMarkerProvider.java @@ -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; } diff --git a/python/src/com/jetbrains/python/codeInsight/PyLineSeparatorUtil.java b/python/src/com/jetbrains/python/codeInsight/PyLineSeparatorUtil.java index ddc0d02f1fa8..a03ea5dc51e6 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyLineSeparatorUtil.java +++ b/python/src/com/jetbrains/python/codeInsight/PyLineSeparatorUtil.java @@ -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 info = new Ref(null); + public static LineMarkerInfo addLineSeparatorIfNeeded(@NotNull Provider provider, @NotNull PsiElement element) { + final Ref 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 createLineSeparatorByElement(final PsiElement element) { - final LineMarkerInfo info = new LineMarkerInfo(element, element.getTextRange().getStartOffset(), null, Pass.LINE_MARKERS, null, null); + @NotNull + private static LineMarkerInfo createLineSeparatorByElement(@NotNull PsiElement element) { + final PsiElement anchor = PsiTreeUtil.getDeepestFirst(element); + + final LineMarkerInfo 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; } - }