KT-2723 Overridden/Implemented gutter icon for class and trait
This commit is contained in:
committed by
Nikolay Krasko
parent
95f84459c9
commit
99aee736d1
@@ -63,6 +63,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
public static final Icon OVERRIDING_MARK = IconLoader.getIcon("/gutter/overridingMethod.png");
|
||||
public static final Icon IMPLEMENTING_MARK = IconLoader.getIcon("/gutter/implementingMethod.png");
|
||||
protected static final Icon OVERRIDDEN_MARK = IconLoader.getIcon("/gutter/overridenMethod.png");
|
||||
protected static final Icon IMPLEMENTED_MARK = IconLoader.getIcon("/gutter/implementedMethod.png");
|
||||
|
||||
private static final Function<PsiElement, String> SUBCLASSED_CLASS_TOOLTIP_ADAPTER = new Function<PsiElement, String>() {
|
||||
@Override
|
||||
@@ -100,8 +101,6 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
|
||||
@Override
|
||||
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
|
||||
// TODO this is a workaround for CME in external annotations code, should be removed after updating to IDEA 122.145+ (KT-2666)
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return null;
|
||||
|
||||
JetFile file = (JetFile)element.getContainingFile();
|
||||
if (file == null) return null;
|
||||
@@ -235,8 +234,6 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
|
||||
@Override
|
||||
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
|
||||
// TODO this is a workaround for CME in external annotations code, should be removed after updating to IDEA 122.145+ (KT-2666)
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
|
||||
if (elements.isEmpty() || DumbService.getInstance(elements.get(0).getProject()).isDumb()) {
|
||||
return;
|
||||
@@ -249,7 +246,10 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
}
|
||||
|
||||
private static void collectInheritingClasses(JetClass element, Collection<LineMarkerInfo> result) {
|
||||
if (!element.hasModifier(JetTokens.OPEN_KEYWORD)) {
|
||||
boolean isTrait = element.isTrait();
|
||||
if (!(isTrait ||
|
||||
element.hasModifier(JetTokens.OPEN_KEYWORD) ||
|
||||
element.hasModifier(JetTokens.ABSTRACT_KEYWORD))) {
|
||||
return;
|
||||
}
|
||||
PsiClass lightClass = LightClassUtil.createLightClass(element);
|
||||
@@ -260,7 +260,8 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
if (inheritor != null) {
|
||||
final PsiElement nameIdentifier = element.getNameIdentifier();
|
||||
PsiElement anchor = nameIdentifier != null ? nameIdentifier : element;
|
||||
result.add(new LineMarkerInfo<PsiElement>(anchor, anchor.getTextOffset(), OVERRIDDEN_MARK, Pass.UPDATE_OVERRIDEN_MARKERS,
|
||||
Icon mark = isTrait ? IMPLEMENTED_MARK : OVERRIDDEN_MARK;
|
||||
result.add(new LineMarkerInfo<PsiElement>(anchor, anchor.getTextOffset(), mark, Pass.UPDATE_OVERRIDEN_MARKERS,
|
||||
SUBCLASSED_CLASS_TOOLTIP_ADAPTER, SUBCLASSED_CLASS_NAVIGATION_HANDLER));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
open class A {
|
||||
open fun a(){
|
||||
}
|
||||
}
|
||||
|
||||
class B:A(){
|
||||
override fun a(){
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
trait A {
|
||||
fun a(){
|
||||
}
|
||||
}
|
||||
|
||||
class B :A {
|
||||
override fun a(){
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,14 @@ import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations;
|
||||
|
||||
public class PluginTestCaseBase {
|
||||
|
||||
public static final String TEST_DATA_PROJECT_RELATIVE = "/idea/testData";
|
||||
|
||||
private PluginTestCaseBase() {
|
||||
}
|
||||
|
||||
public static String getTestDataPathBase() {
|
||||
return JetTestCaseBuilder.getHomeDirectory() + "/idea/testData";
|
||||
return JetTestCaseBuilder.getHomeDirectory() + TEST_DATA_PROJECT_RELATIVE;
|
||||
}
|
||||
|
||||
public static Sdk jdkFromIdeaHome() {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 org.jetbrains.jet.plugin.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OverrideImplementLineMarkerTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/lineMarker";
|
||||
}
|
||||
|
||||
public void testTrait() throws Throwable {
|
||||
doSimpleTest(2);
|
||||
}
|
||||
|
||||
public void testClass() throws Throwable {
|
||||
doSimpleTest(2);
|
||||
}
|
||||
|
||||
private void doSimpleTest(int count) throws Throwable {
|
||||
myFixture.configureByFile(getTestName(false) + ".kt");
|
||||
doTest(count);
|
||||
}
|
||||
|
||||
private void doTest(int count) {
|
||||
final Editor editor = myFixture.getEditor();
|
||||
final Project project = myFixture.getProject();
|
||||
|
||||
myFixture.doHighlighting();
|
||||
|
||||
final List<LineMarkerInfo> infoList = DaemonCodeAnalyzerImpl.getLineMarkers(editor.getDocument(), project);
|
||||
assertNotNull(infoList);
|
||||
assertEquals(count, infoList.size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user