Resolution: Resolve primary constructor references to primary constructor
itself if it's explicitly present in PSI
This commit is contained in:
@@ -440,7 +440,8 @@ public class DescriptorResolver {
|
||||
ConstructorDescriptorImpl constructorDescriptor =
|
||||
DescriptorFactory.createPrimaryConstructorForObject(classDescriptor, toSourceElement(object));
|
||||
if (object != null) {
|
||||
trace.record(CONSTRUCTOR, object, constructorDescriptor);
|
||||
JetPrimaryConstructor primaryConstructor = object.getPrimaryConstructor();
|
||||
trace.record(CONSTRUCTOR, primaryConstructor != null ? primaryConstructor : object, constructorDescriptor);
|
||||
}
|
||||
return constructorDescriptor;
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ class FunctionDescriptorResolver(
|
||||
classDescriptor,
|
||||
true,
|
||||
classElement.getPrimaryConstructorModifierList(),
|
||||
classElement,
|
||||
classElement.getPrimaryConstructor() ?: classElement,
|
||||
classDescriptor.getTypeConstructor().getParameters(),
|
||||
classElement.getPrimaryConstructorParameters(),
|
||||
trace
|
||||
|
||||
+2
-3
@@ -184,9 +184,8 @@ public class LazyDeclarationResolver {
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor visitPrimaryConstructor(@NotNull JetPrimaryConstructor constructor, Void data) {
|
||||
JetClassOrObject klass = constructor.getContainingClassOrObject();
|
||||
getClassDescriptor(klass).getConstructors();
|
||||
return getBindingContext().get(BindingContext.CONSTRUCTOR, klass);
|
||||
getClassDescriptor(constructor.getContainingClassOrObject()).getConstructors();
|
||||
return getBindingContext().get(BindingContext.CONSTRUCTOR, constructor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
~A~class A {
|
||||
~B~class B() {
|
||||
~B()~constructor(i: Int) {}
|
||||
~B~class B~B()~() {
|
||||
~B(int)~constructor(i: Int) {}
|
||||
}
|
||||
|
||||
~foo~fun foo(~foo.a~a : `kotlin::Char`Char) = `foo.a`a`:kotlin::Char`
|
||||
~fooB~fun fooB() = `foo`foo('1')`:kotlin::Char`
|
||||
~foo.1~fun foo() : Int = (1.`kotlin::Int.plus(Int)`plus(1))`:kotlin::Int`
|
||||
~foo91~fun foo1() : `B`B = `B`B()`:B`
|
||||
~foo91~fun foo1() : `B`B = `B()`B()`:B`
|
||||
~A.a~val a : `kotlin::Int`Int
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// FILE: base.kt
|
||||
class java {
|
||||
class lang {
|
||||
class ~Fake~Fake()
|
||||
class ~Fake~Fake~Fake()~()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ class java {
|
||||
import java.lang.* // will import Fake
|
||||
|
||||
fun foo() {
|
||||
`Fake`Fake()
|
||||
`Fake()`Fake()
|
||||
}
|
||||
|
||||
// FILE: root2.kt
|
||||
fun foo() {
|
||||
`!`Fake() // not imported within "java.lang.*" default import
|
||||
java.lang.`Fake`Fake() // we all are in same (root) package, so it works
|
||||
java.lang.`Fake()`Fake() // we all are in same (root) package, so it works
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,6 @@ package nonRoot
|
||||
import java.lang.* // will import Fake
|
||||
|
||||
fun foo() {
|
||||
`Fake`Fake()
|
||||
`Fake()`Fake()
|
||||
java.lang.`!`Fake() // qualified access to root package's class does not work
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ fun foo(~a~a : `kotlin::Array`Array<`kotlin::Int`Int>) : `java::java.util.ArrayL
|
||||
|
||||
fun foo(o : `java::java.lang.Object`Object, l : `java::java.util`util.`java::java.util.ArrayList`ArrayList) : `java::java.util.ArrayList`ArrayList {}
|
||||
|
||||
~A~class A() {
|
||||
~A~class A~A()~() {
|
||||
fun f(a : `java::java.util`util.`java::java.util.ArrayList`ArrayList) {}
|
||||
fun f(a : `java::java.util.ArrayList`ArrayList) {}
|
||||
|
||||
@@ -29,7 +29,7 @@ class B : `java::java.lang.Object`Object {
|
||||
}
|
||||
|
||||
fun barrr() : `kotlin::Int`Int {
|
||||
`foo`foo(`A`A())
|
||||
`foo`foo(`A()`A())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
var xxxx = 1
|
||||
|
||||
~SimpleClass~class SimpleClass(x : Int) {
|
||||
~SimpleClass~class SimpleClass~SimpleClass()~(x : Int) {
|
||||
fun foo() = x
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
`SimpleClass`SimpleClass(1).`!`xxxx
|
||||
`SimpleClass()`SimpleClass(1).`!`xxxx
|
||||
}
|
||||
@@ -21,11 +21,13 @@ import com.intellij.psi.FileViewProvider
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.descriptorToKey
|
||||
import org.jetbrains.kotlin.psi.JetCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.utils.concurrent.block.LockedClearableLazyValue
|
||||
@@ -42,6 +44,11 @@ public abstract class KotlinClsFileBase(provider: FileViewProvider) : JetFile(pr
|
||||
return callableDeclaration.getValueParameters()[original.getIndex()]
|
||||
}
|
||||
|
||||
if (original is ConstructorDescriptor && original.isPrimary()) {
|
||||
val classOrObject = getDeclarationForDescriptor(original.getContainingDeclaration()) as? JetClassOrObject
|
||||
return classOrObject?.getPrimaryConstructor() ?: classOrObject
|
||||
}
|
||||
|
||||
val key = descriptorToKey(original)
|
||||
|
||||
val range = decompiledText.get().renderedDescriptorsToRange[key]
|
||||
|
||||
@@ -21,13 +21,19 @@ import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
|
||||
object KDocFinder {
|
||||
fun findKDoc(declaration: DeclarationDescriptor): KDocTag? {
|
||||
if (declaration is DeclarationDescriptorWithSource) {
|
||||
val psiDeclaration = (declaration.getSource() as? PsiSourceElement)?.psi?.getNavigationElement()
|
||||
var psiDeclaration = (declaration.getSource() as? PsiSourceElement)?.psi?.getNavigationElement()
|
||||
// KDoc for primary constructor is located inside of its class KDoc
|
||||
if (psiDeclaration is JetPrimaryConstructor) {
|
||||
psiDeclaration = psiDeclaration.getClassOrObject()
|
||||
}
|
||||
|
||||
if (psiDeclaration is JetDeclaration) {
|
||||
val kdoc = psiDeclaration.getDocComment()
|
||||
if (kdoc != null) {
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
Following declarations are used outside of selected code fragment: local final class A value-parameter val n: Int = ...
|
||||
Following declarations are used outside of selected code fragment: public constructor A(n: Int = ...) value-parameter val n: Int = ...
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
|
||||
package foo
|
||||
|
||||
// REF: (kotlin).deprecated
|
||||
// REF: (in kotlin.deprecated).deprecated(kotlin.String,kotlin.ReplaceWith)
|
||||
|
||||
@@ -4,4 +4,4 @@ package foo
|
||||
|
||||
import kotlin.deprecated as D
|
||||
|
||||
// REF: (kotlin).deprecated
|
||||
// REF: (in kotlin.deprecated).deprecated(kotlin.String,kotlin.ReplaceWith)
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ fun main(args : Array<String>) {
|
||||
var a = <caret>IntArray(array(1, 2, 3))
|
||||
}
|
||||
|
||||
// REF: (kotlin).IntArray
|
||||
// REF: (in kotlin.IntArray).IntArray(Int)
|
||||
+1
-1
@@ -4,4 +4,4 @@ fun foo() {
|
||||
<caret>Fake()
|
||||
}
|
||||
|
||||
//REF: (java.lang).Fake
|
||||
//REF: (in java.lang.Fake).Fake()
|
||||
+1
-1
@@ -5,4 +5,4 @@ fun foo() {
|
||||
<caret>Fake()
|
||||
}
|
||||
|
||||
//REF: (java.lang).Fake
|
||||
//REF: (in java.lang.Fake).Fake()
|
||||
Reference in New Issue
Block a user