Implement custom TargetElementEvaluator KT-4190 #Fixed
This commit is contained in:
@@ -23,6 +23,7 @@ import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
import org.jetbrains.jet.lang.psi.JetClass
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
|
||||
fun PsiElement.getParentByTypeAndPredicate<T: PsiElement>(
|
||||
parentClass : Class<T>, strict : Boolean = false, predicate: (T) -> Boolean
|
||||
@@ -66,4 +67,6 @@ fun JetClassOrObject.effectiveDeclarations(): List<JetDeclaration> =
|
||||
getDeclarations() + getPrimaryConstructorParameters().filter { p -> p.getValOrVarNode() != null }
|
||||
else ->
|
||||
getDeclarations()
|
||||
}
|
||||
}
|
||||
|
||||
fun JetClass.isAbstract() = isTrait() || hasModifier(JetTokens.ABSTRACT_KEYWORD)
|
||||
|
||||
@@ -350,6 +350,10 @@
|
||||
|
||||
<joinLinesHandler implementation="org.jetbrains.jet.plugin.intentions.declarations.JetDeclarationJoinLinesHandler"/>
|
||||
|
||||
<targetElementEvaluator
|
||||
language="jet"
|
||||
implementationClass="org.jetbrains.jet.plugin.search.JetTargetElementEvaluator" />
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction</className>
|
||||
<category>Kotlin</category>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.search
|
||||
|
||||
import com.intellij.codeInsight.TargetElementEvaluator
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isAbstract
|
||||
import com.intellij.psi.PsiReference
|
||||
import org.jetbrains.jet.lang.psi.JetClass
|
||||
|
||||
public class JetTargetElementEvaluator : TargetElementEvaluator {
|
||||
override fun includeSelfInGotoImplementation(element: PsiElement): Boolean =
|
||||
!(element is JetClass && element.isAbstract())
|
||||
|
||||
override fun getElementByReference(ref: PsiReference?, flags: Int): PsiElement? = null
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package testing
|
||||
|
||||
abstract class Test
|
||||
|
||||
open class TestOther : <caret>Test()
|
||||
|
||||
class TestOtherMore : TestOther()
|
||||
|
||||
// REF: (testing).TestOther
|
||||
// REF: (testing).TestOtherMore
|
||||
@@ -0,0 +1,16 @@
|
||||
package testing
|
||||
|
||||
trait Test
|
||||
|
||||
trait TestMore: <caret>Test
|
||||
|
||||
open class TestClass1: Test
|
||||
|
||||
class TestClass2: TestClass1()
|
||||
|
||||
class TestClass3: TestMore
|
||||
|
||||
// REF: (testing).TestMore
|
||||
// REF: (testing).TestClass1
|
||||
// REF: (testing).TestClass2
|
||||
// REF: (testing).TestClass3
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
public abstract class JavaBase {
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package testing.kt
|
||||
|
||||
class KotlinImpl : <caret>JavaBase()
|
||||
|
||||
// REF: (testing.kt).KotlinImpl
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
public interface JavaBase {
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package testing.kt
|
||||
|
||||
trait KotlinTrait: <caret>JavaBase
|
||||
|
||||
class KotlinClass : JavaBase
|
||||
|
||||
// REF: (testing.kt).KotlinClass
|
||||
// REF: (testing.kt).KotlinTrait
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package testing.jj;
|
||||
|
||||
class JavaImplementation extends testing.kt.Base {
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package testing.kt
|
||||
|
||||
abstract class <caret>Base
|
||||
|
||||
// REF: (testing.jj).JavaImplementation
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package testing.jj;
|
||||
|
||||
class JavaClass implements testing.kt.Base {
|
||||
}
|
||||
|
||||
interface JavaInterface extends testing.kt.Base {
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package testing.kt
|
||||
|
||||
trait Base
|
||||
|
||||
trait Derived: <caret>Base
|
||||
|
||||
// REF: (testing.jj).JavaClass
|
||||
// REF: (testing.jj).JavaInterface
|
||||
// REF: (testing.kt).Derived
|
||||
+16
@@ -31,10 +31,26 @@ public class JetGotoImplementationMultifileTest extends CodeInsightTestCase {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementKotlinAbstractClassInJava() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementKotlinTraitInJava() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaClassInKotlin() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaAbstractClassInKotlin() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementJavaInterfaceInKotlin() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
public void testImplementMethodInKotlin() throws Exception {
|
||||
doKotlinJavaTest();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,15 @@ public class JetGotoImplementationTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassImplementatorsWithDeclaration() {
|
||||
public void testClassImplementorsWithDeclaration() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAbstractClassImplementorsWithDeclaration() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTraitImplementorsWithDeclaration() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user