Search constructor-declared properties together with class declarations
This commit is contained in:
@@ -19,6 +19,10 @@ package org.jetbrains.jet.lang.psi.psiUtil
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
|
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
|
||||||
|
|
||||||
fun PsiElement.getParentByTypeAndPredicate<T: PsiElement>(
|
fun PsiElement.getParentByTypeAndPredicate<T: PsiElement>(
|
||||||
parentClass : Class<T>, strict : Boolean = false, predicate: (T) -> Boolean
|
parentClass : Class<T>, strict : Boolean = false, predicate: (T) -> Boolean
|
||||||
@@ -55,3 +59,11 @@ fun PsiElement.getParentByTypeAndBranch<T: PsiElement>(
|
|||||||
parentClass : Class<T>, strict : Boolean = false, branch: T.() -> PsiElement?) : T? {
|
parentClass : Class<T>, strict : Boolean = false, branch: T.() -> PsiElement?) : T? {
|
||||||
return getParentByType(parentClass, strict)?.getIfChildIsInBranch(this, branch)
|
return getParentByType(parentClass, strict)?.getIfChildIsInBranch(this, branch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun JetClassOrObject.effectiveDeclarations(): List<JetDeclaration> =
|
||||||
|
when(this) {
|
||||||
|
is JetClass ->
|
||||||
|
getDeclarations() + getPrimaryConstructorParameters().filter { p -> p.getValOrVarNode() != null }
|
||||||
|
else ->
|
||||||
|
getDeclarations()
|
||||||
|
}
|
||||||
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.psi.JetParameter
|
|||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.*
|
import org.jetbrains.jet.lang.psi.psiUtil.*
|
||||||
import org.jetbrains.jet.asJava.LightClassUtil.PropertyAccessorsPsiMethods
|
import org.jetbrains.jet.asJava.LightClassUtil.PropertyAccessorsPsiMethods
|
||||||
|
import org.jetbrains.jet.lang.psi.psiUtil.*
|
||||||
|
|
||||||
val isTargetUsage = (PsiReference::isTargetUsage).searchFilter
|
val isTargetUsage = (PsiReference::isTargetUsage).searchFilter
|
||||||
|
|
||||||
@@ -136,8 +137,8 @@ class ClassDeclarationsUsagesSearchHelper(
|
|||||||
val items = ArrayList<UsagesSearchRequestItem>()
|
val items = ArrayList<UsagesSearchRequestItem>()
|
||||||
val declHelper = DefaultSearchHelper<JetNamedDeclaration>(skipImports)
|
val declHelper = DefaultSearchHelper<JetNamedDeclaration>(skipImports)
|
||||||
|
|
||||||
for (decl in target.element.getDeclarations()) {
|
for (decl in target.element.effectiveDeclarations()) {
|
||||||
if ((decl is JetNamedFunction && functionUsages) || (decl is JetProperty && propertyUsages)) {
|
if ((decl is JetNamedFunction && functionUsages) || ((decl is JetProperty || decl is JetParameter) && propertyUsages)) {
|
||||||
items.add(declHelper.newItem(target.retarget(decl as JetNamedDeclaration)))
|
items.add(declHelper.newItem(target.retarget(decl as JetNamedDeclaration)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ trait X {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class <caret>A: X {
|
open class <caret>A(val t: String, var u: String): X {
|
||||||
override val a: String
|
override val a: String
|
||||||
get() {
|
get() {
|
||||||
return "?"
|
return "?"
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ class Usages {
|
|||||||
fun foo(a: A) {
|
fun foo(a: A) {
|
||||||
a.foo("")
|
a.foo("")
|
||||||
println("${a.a} ${a.b}")
|
println("${a.a} ${a.b}")
|
||||||
|
println("${a.t} ${a.u}")
|
||||||
a.b = 12
|
a.b = 12
|
||||||
|
a.u = 13
|
||||||
}
|
}
|
||||||
|
|
||||||
fun foo(x: X) {
|
fun foo(x: X) {
|
||||||
|
|||||||
+4
-1
@@ -1,3 +1,6 @@
|
|||||||
Value read (4: 22) println("${a.a} ${a.b}")
|
Value read (4: 22) println("${a.a} ${a.b}")
|
||||||
Value read (4: 29) println("${a.a} ${a.b}")
|
Value read (4: 29) println("${a.a} ${a.b}")
|
||||||
Value write (5: 11) a.b = 12
|
Value read (5: 22) println("${a.t} ${a.u}")
|
||||||
|
Value read (5: 29) println("${a.t} ${a.u}")
|
||||||
|
Value write (6: 11) a.b = 12
|
||||||
|
Value write (7: 11) a.u = 13
|
||||||
Reference in New Issue
Block a user