Refactor light elements
KtLightElement#delegate -> clsDelegate, KtLightElement#origin -> kotlinOrigin and make them properties KtLightClassForDecompiledDeclaration stores KtClsFile KtLightField stores LightMemberOrigin
This commit is contained in:
+8
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -46,9 +46,15 @@ public class FakeLightClassForFileOfPackage extends AbstractLightClass implement
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiClass getClsDelegate() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public KtClassOrObject getOrigin() {
|
public KtClassOrObject getKotlinOrigin() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,20 +24,17 @@ import com.intellij.util.IncorrectOperationException
|
|||||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||||
|
|
||||||
class KtLightAnnotation(
|
class KtLightAnnotation(
|
||||||
private val delegate: PsiAnnotation,
|
override val clsDelegate: PsiAnnotation,
|
||||||
private val originalElement: KtAnnotationEntry,
|
override val kotlinOrigin: KtAnnotationEntry,
|
||||||
private val owner: PsiAnnotationOwner
|
private val owner: PsiAnnotationOwner
|
||||||
) : PsiAnnotation by delegate, KtLightElement<KtAnnotationEntry, PsiAnnotation> {
|
) : PsiAnnotation by clsDelegate, KtLightElement<KtAnnotationEntry, PsiAnnotation> {
|
||||||
override fun getDelegate() = delegate
|
|
||||||
override fun getOrigin() = originalElement
|
|
||||||
|
|
||||||
override fun getName() = null
|
override fun getName() = null
|
||||||
override fun setName(newName: String) = throw IncorrectOperationException()
|
override fun setName(newName: String) = throw IncorrectOperationException()
|
||||||
|
|
||||||
override fun getOwner() = owner
|
override fun getOwner() = owner
|
||||||
|
|
||||||
override fun getText() = originalElement.text ?: ""
|
override fun getText() = kotlinOrigin.text ?: ""
|
||||||
override fun getTextRange() = originalElement.textRange ?: TextRange.EMPTY_RANGE
|
override fun getTextRange() = kotlinOrigin.textRange ?: TextRange.EMPTY_RANGE
|
||||||
|
|
||||||
override fun getParent() = owner as? PsiElement
|
override fun getParent() = owner as? PsiElement
|
||||||
|
|
||||||
@@ -46,8 +43,8 @@ class KtLightAnnotation(
|
|||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other?.javaClass != javaClass) return false
|
if (other?.javaClass != javaClass) return false
|
||||||
return originalElement == (other as KtLightAnnotation).originalElement
|
return kotlinOrigin == (other as KtLightAnnotation).kotlinOrigin
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode() = originalElement.hashCode()
|
override fun hashCode() = kotlinOrigin.hashCode()
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-25
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -56,8 +56,6 @@ open class KtLightClassForExplicitDeclaration(
|
|||||||
protected val classFqName: FqName, // FqName of (possibly inner) class
|
protected val classFqName: FqName, // FqName of (possibly inner) class
|
||||||
protected val classOrObject: KtClassOrObject)
|
protected val classOrObject: KtClassOrObject)
|
||||||
: KtWrappingLightClass(classOrObject.manager), KtJavaMirrorMarker, StubBasedPsiElement<KotlinClassOrObjectStub<out KtClassOrObject>> {
|
: KtWrappingLightClass(classOrObject.manager), KtJavaMirrorMarker, StubBasedPsiElement<KotlinClassOrObjectStub<out KtClassOrObject>> {
|
||||||
private var delegate: PsiClass? = null
|
|
||||||
|
|
||||||
private val lightIdentifier = KtLightIdentifier(this, classOrObject)
|
private val lightIdentifier = KtLightIdentifier(this, classOrObject)
|
||||||
|
|
||||||
private fun getLocalClassParent(): PsiElement? {
|
private fun getLocalClassParent(): PsiElement? {
|
||||||
@@ -139,7 +137,7 @@ open class KtLightClassForExplicitDeclaration(
|
|||||||
containingClass
|
containingClass
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOrigin(): KtClassOrObject = classOrObject
|
override val kotlinOrigin: KtClassOrObject = classOrObject
|
||||||
|
|
||||||
override fun getFqName(): FqName = classFqName
|
override fun getFqName(): FqName = classFqName
|
||||||
|
|
||||||
@@ -147,28 +145,21 @@ open class KtLightClassForExplicitDeclaration(
|
|||||||
return KtLightClassForExplicitDeclaration(classFqName, classOrObject.copy() as KtClassOrObject)
|
return KtLightClassForExplicitDeclaration(classFqName, classOrObject.copy() as KtClassOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDelegate(): PsiClass {
|
override val clsDelegate: PsiClass by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
if (delegate == null) {
|
val javaFileStub = getJavaFileStub()
|
||||||
val javaFileStub = getJavaFileStub()
|
|
||||||
|
|
||||||
val psiClass = LightClassUtil.findClass(classFqName, javaFileStub)
|
LightClassUtil.findClass(classFqName, javaFileStub) ?: run {
|
||||||
if (psiClass == null) {
|
val outermostClassOrObject = getOutermostClassOrObject(classOrObject)
|
||||||
val outermostClassOrObject = getOutermostClassOrObject(classOrObject)
|
val ktFileText: String? = try {
|
||||||
val ktFileText: String? = try {
|
outermostClassOrObject.containingFile.text
|
||||||
outermostClassOrObject.containingFile.text
|
}
|
||||||
}
|
catch (e: Exception) {
|
||||||
catch (e: Exception) {
|
"Can't get text for outermost class"
|
||||||
"Can't get text for outermost class"
|
|
||||||
}
|
|
||||||
|
|
||||||
val stubFileText = DebugUtil.stubTreeToString(javaFileStub)
|
|
||||||
|
|
||||||
throw IllegalStateException("Class was not found $classFqName\nin $ktFileText\nstub: \n$stubFileText")
|
|
||||||
}
|
}
|
||||||
delegate = psiClass
|
|
||||||
}
|
|
||||||
|
|
||||||
return delegate!!
|
val stubFileText = DebugUtil.stubTreeToString(javaFileStub)
|
||||||
|
throw IllegalStateException("Class was not found $classFqName\nin $ktFileText\nstub: \n$stubFileText")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getJavaFileStub(): PsiJavaFileStub = getLightClassData().javaFileStub
|
private fun getJavaFileStub(): PsiJavaFileStub = getLightClassData().javaFileStub
|
||||||
@@ -380,7 +371,7 @@ open class KtLightClassForExplicitDeclaration(
|
|||||||
|
|
||||||
@Throws(IncorrectOperationException::class)
|
@Throws(IncorrectOperationException::class)
|
||||||
override fun setName(@NonNls name: String): PsiElement {
|
override fun setName(@NonNls name: String): PsiElement {
|
||||||
getOrigin().setName(name)
|
kotlinOrigin.setName(name)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,7 +387,7 @@ open class KtLightClassForExplicitDeclaration(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUseScope(): SearchScope = getOrigin().useScope
|
override fun getUseScope(): SearchScope = kotlinOrigin.useScope
|
||||||
|
|
||||||
override fun getElementType(): IStubElementType<out StubElement<*>, *>? = classOrObject.elementType
|
override fun getElementType(): IStubElementType<out StubElement<*>, *>? = classOrObject.elementType
|
||||||
override fun getStub(): KotlinClassOrObjectStub<out KtClassOrObject>? = classOrObject.stub
|
override fun getStub(): KotlinClassOrObjectStub<out KtClassOrObject>? = classOrObject.stub
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class KtLightClassForFacade private constructor(
|
|||||||
stub = { lightClassDataCache.value.javaFileStub }
|
stub = { lightClassDataCache.value.javaFileStub }
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun getOrigin(): KtClassOrObject? = null
|
override val kotlinOrigin: KtClassOrObject? get() = null
|
||||||
|
|
||||||
override fun getFqName(): FqName = facadeClassFqName
|
override fun getFqName(): FqName = facadeClassFqName
|
||||||
|
|
||||||
@@ -146,11 +146,12 @@ class KtLightClassForFacade private constructor(
|
|||||||
|
|
||||||
override fun copy() = KtLightClassForFacade(getManager(), facadeClassFqName, lightClassDataCache, files)
|
override fun copy() = KtLightClassForFacade(getManager(), facadeClassFqName, lightClassDataCache, files)
|
||||||
|
|
||||||
override fun getDelegate(): PsiClass {
|
override val clsDelegate: PsiClass
|
||||||
val psiClass = LightClassUtil.findClass(facadeClassFqName, lightClassDataCache.value.javaFileStub)
|
get() {
|
||||||
?: throw IllegalStateException("Facade class $facadeClassFqName not found")
|
val psiClass = LightClassUtil.findClass(facadeClassFqName, lightClassDataCache.value.javaFileStub)
|
||||||
return psiClass
|
?: throw IllegalStateException("Facade class $facadeClassFqName not found")
|
||||||
}
|
return psiClass
|
||||||
|
}
|
||||||
|
|
||||||
override fun getNavigationElement() = files.iterator().next()
|
override fun getNavigationElement() = files.iterator().next()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -22,9 +22,9 @@ import org.jetbrains.kotlin.psi.KtDeclaration
|
|||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
|
||||||
interface KtLightElement<T : KtElement, D : PsiElement> : PsiNamedElement {
|
interface KtLightElement<T : KtElement, D : PsiElement> : PsiNamedElement {
|
||||||
fun getOrigin(): T?
|
val kotlinOrigin: T?
|
||||||
|
|
||||||
fun getDelegate(): D
|
val clsDelegate: D
|
||||||
}
|
}
|
||||||
|
|
||||||
interface KtLightDeclaration<T: KtDeclaration, D: PsiElement>: KtLightElement<T, D>
|
interface KtLightDeclaration<T: KtDeclaration, D: PsiElement>: KtLightElement<T, D>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -31,109 +31,105 @@ interface KtLightField : PsiField, KtLightDeclaration<KtDeclaration, PsiField>
|
|||||||
|
|
||||||
// Copied from com.intellij.psi.impl.light.LightField
|
// Copied from com.intellij.psi.impl.light.LightField
|
||||||
sealed class KtLightFieldImpl(
|
sealed class KtLightFieldImpl(
|
||||||
private val origin: KtDeclaration?,
|
private val lightMemberOrigin: LightMemberOrigin?,
|
||||||
private val delegate: PsiField,
|
override val clsDelegate: PsiField,
|
||||||
private val containingClass: KtLightClass
|
private val containingClass: KtLightClass
|
||||||
) : LightElement(delegate.manager, KotlinLanguage.INSTANCE), KtLightField {
|
) : LightElement(clsDelegate.manager, KotlinLanguage.INSTANCE), KtLightField {
|
||||||
private val lightIdentifier = KtLightIdentifier(this, origin as? KtNamedDeclaration)
|
private val lightIdentifier by lazy { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
|
||||||
|
|
||||||
@Throws(IncorrectOperationException::class)
|
@Throws(IncorrectOperationException::class)
|
||||||
override fun setInitializer(initializer: PsiExpression?) = throw IncorrectOperationException("Not supported")
|
override fun setInitializer(initializer: PsiExpression?) = throw IncorrectOperationException("Not supported")
|
||||||
|
|
||||||
override fun getUseScope() = origin?.useScope ?: super.getUseScope()
|
override fun getUseScope() = kotlinOrigin?.useScope ?: super.getUseScope()
|
||||||
|
|
||||||
override fun getName() = delegate.name
|
override fun getName() = clsDelegate.name
|
||||||
|
|
||||||
override fun getNameIdentifier() = lightIdentifier
|
override fun getNameIdentifier() = lightIdentifier
|
||||||
|
|
||||||
override fun getDocComment() = delegate.docComment
|
override fun getDocComment() = clsDelegate.docComment
|
||||||
|
|
||||||
override fun isDeprecated() = delegate.isDeprecated
|
override fun isDeprecated() = clsDelegate.isDeprecated
|
||||||
|
|
||||||
override fun getContainingClass() = containingClass
|
override fun getContainingClass() = containingClass
|
||||||
|
|
||||||
override fun getType() = delegate.type
|
override fun getType() = clsDelegate.type
|
||||||
|
|
||||||
override fun getTypeElement() = delegate.typeElement
|
override fun getTypeElement() = clsDelegate.typeElement
|
||||||
|
|
||||||
override fun getInitializer() = delegate.initializer
|
override fun getInitializer() = clsDelegate.initializer
|
||||||
|
|
||||||
override fun hasInitializer() = delegate.hasInitializer()
|
override fun hasInitializer() = clsDelegate.hasInitializer()
|
||||||
|
|
||||||
@Throws(IncorrectOperationException::class)
|
@Throws(IncorrectOperationException::class)
|
||||||
override fun normalizeDeclaration() = throw IncorrectOperationException("Not supported")
|
override fun normalizeDeclaration() = throw IncorrectOperationException("Not supported")
|
||||||
|
|
||||||
override fun computeConstantValue() = delegate.computeConstantValue()
|
override fun computeConstantValue() = clsDelegate.computeConstantValue()
|
||||||
|
|
||||||
@Throws(IncorrectOperationException::class)
|
@Throws(IncorrectOperationException::class)
|
||||||
override fun setName(@NonNls name: String) = throw IncorrectOperationException("Not supported")
|
override fun setName(@NonNls name: String) = throw IncorrectOperationException("Not supported")
|
||||||
|
|
||||||
private val _modifierList by lazy { delegate.modifierList?.let { KtLightModifierList(it, this) } }
|
private val _modifierList by lazy { clsDelegate.modifierList?.let { KtLightModifierList(it, this) } }
|
||||||
|
|
||||||
override fun getModifierList() = _modifierList
|
override fun getModifierList() = _modifierList
|
||||||
|
|
||||||
override fun hasModifierProperty(@NonNls name: String) = delegate.hasModifierProperty(name)
|
override fun hasModifierProperty(@NonNls name: String) = clsDelegate.hasModifierProperty(name)
|
||||||
|
|
||||||
override fun getText() = origin?.text ?: ""
|
override fun getText() = kotlinOrigin?.text ?: ""
|
||||||
|
|
||||||
override fun getTextRange() = origin?.textRange ?: TextRange.EMPTY_RANGE
|
override fun getTextRange() = kotlinOrigin?.textRange ?: TextRange.EMPTY_RANGE
|
||||||
|
|
||||||
override fun isValid() = containingClass.isValid
|
override fun isValid() = containingClass.isValid
|
||||||
|
|
||||||
override fun toString(): String = "${this.javaClass.simpleName}:$name"
|
override fun toString(): String = "${this.javaClass.simpleName}:$name"
|
||||||
|
|
||||||
override fun getOrigin() = origin
|
override val kotlinOrigin: KtDeclaration? get() = lightMemberOrigin?.originalElement
|
||||||
|
|
||||||
override fun getDelegate() = delegate
|
override fun getNavigationElement() = kotlinOrigin ?: super.getNavigationElement()
|
||||||
|
|
||||||
override fun getNavigationElement() = origin ?: super.getNavigationElement()
|
|
||||||
|
|
||||||
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
||||||
if (another is KtLightField && origin == another.getOrigin() && delegate == another.getDelegate()) {
|
if (another is KtLightField && kotlinOrigin == another.kotlinOrigin && clsDelegate == another.clsDelegate) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return super.isEquivalentTo(another)
|
return super.isEquivalentTo(another)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isWritable() = getOrigin()?.isWritable ?: false
|
override fun isWritable() = kotlinOrigin?.isWritable ?: false
|
||||||
|
|
||||||
override fun copy() = Factory.create(origin?.copy() as? KtDeclaration, delegate, containingClass)
|
override fun copy() = Factory.create(lightMemberOrigin?.copy(), clsDelegate, containingClass)
|
||||||
|
|
||||||
class KtLightEnumConstant(
|
class KtLightEnumConstant(
|
||||||
origin: KtEnumEntry?,
|
origin: LightMemberOrigin?,
|
||||||
enumConstant: PsiEnumConstant,
|
override val clsDelegate: PsiEnumConstant,
|
||||||
containingClass: KtLightClass,
|
containingClass: KtLightClass,
|
||||||
private val initializingClass: PsiEnumConstantInitializer?
|
private val initializingClass: PsiEnumConstantInitializer?
|
||||||
) : KtLightFieldImpl(origin, enumConstant, containingClass), PsiEnumConstant {
|
) : KtLightFieldImpl(origin, clsDelegate, containingClass), PsiEnumConstant {
|
||||||
override fun getDelegate() = super.getDelegate() as PsiEnumConstant
|
|
||||||
|
|
||||||
// NOTE: we don't use "delegation by" because the compiler would generate method calls to ALL of PsiEnumConstant members,
|
// NOTE: we don't use "delegation by" because the compiler would generate method calls to ALL of PsiEnumConstant members,
|
||||||
// but we need only members whose implementations are not present in KotlinLightField
|
// but we need only members whose implementations are not present in KotlinLightField
|
||||||
override fun getArgumentList() = getDelegate().argumentList
|
override fun getArgumentList() = clsDelegate.argumentList
|
||||||
|
|
||||||
override fun getInitializingClass(): PsiEnumConstantInitializer? = initializingClass
|
override fun getInitializingClass(): PsiEnumConstantInitializer? = initializingClass
|
||||||
override fun getOrCreateInitializingClass(): PsiEnumConstantInitializer =
|
override fun getOrCreateInitializingClass(): PsiEnumConstantInitializer =
|
||||||
initializingClass ?: throw UnsupportedOperationException("Can't create enum constant body: ${getDelegate().name}")
|
initializingClass ?: throw UnsupportedOperationException("Can't create enum constant body: ${clsDelegate.name}")
|
||||||
|
|
||||||
override fun resolveConstructor() = getDelegate().resolveConstructor()
|
override fun resolveConstructor() = clsDelegate.resolveConstructor()
|
||||||
override fun resolveMethod() = getDelegate().resolveMethod()
|
override fun resolveMethod() = clsDelegate.resolveMethod()
|
||||||
override fun resolveMethodGenerics() = getDelegate().resolveMethodGenerics()
|
override fun resolveMethodGenerics() = clsDelegate.resolveMethodGenerics()
|
||||||
}
|
}
|
||||||
|
|
||||||
class KtLightFieldForDeclaration(origin: KtDeclaration?, delegate: PsiField, containingClass: KtLightClass)
|
class KtLightFieldForDeclaration(origin: LightMemberOrigin?, delegate: PsiField, containingClass: KtLightClass) :
|
||||||
: KtLightFieldImpl(origin, delegate, containingClass)
|
KtLightFieldImpl(origin, delegate, containingClass)
|
||||||
|
|
||||||
companion object Factory {
|
companion object Factory {
|
||||||
fun create(origin: KtDeclaration?, delegate: PsiField, containingClass: KtLightClass): KtLightField {
|
fun create(origin: LightMemberOrigin?, delegate: PsiField, containingClass: KtLightClass): KtLightField {
|
||||||
when (delegate) {
|
when (delegate) {
|
||||||
is PsiEnumConstant -> {
|
is PsiEnumConstant -> {
|
||||||
val kotlinEnumEntry = origin as? KtEnumEntry
|
val kotlinEnumEntry = origin?.originalElement as? KtEnumEntry
|
||||||
val initializingClass = if (kotlinEnumEntry != null && kotlinEnumEntry.declarations.isNotEmpty()) {
|
val initializingClass = if (kotlinEnumEntry != null && kotlinEnumEntry.declarations.isNotEmpty()) {
|
||||||
val enumConstantFqName = FqName(containingClass.getFqName().asString() + "." + kotlinEnumEntry.name)
|
val enumConstantFqName = FqName(containingClass.getFqName().asString() + "." + kotlinEnumEntry.name)
|
||||||
KtLightClassForEnumEntry(enumConstantFqName, kotlinEnumEntry, delegate)
|
KtLightClassForEnumEntry(enumConstantFqName, kotlinEnumEntry, delegate)
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
return KtLightEnumConstant(kotlinEnumEntry, delegate, containingClass, initializingClass)
|
return KtLightEnumConstant(origin, delegate, containingClass, initializingClass)
|
||||||
}
|
}
|
||||||
else -> return KtLightFieldForDeclaration(origin, delegate, containingClass)
|
else -> return KtLightFieldForDeclaration(origin, delegate, containingClass)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -32,22 +32,22 @@ interface KtLightMethod : PsiMethod, KtLightDeclaration<KtDeclaration, PsiMethod
|
|||||||
}
|
}
|
||||||
|
|
||||||
sealed class KtLightMethodImpl(
|
sealed class KtLightMethodImpl(
|
||||||
private val delegate: PsiMethod,
|
override val clsDelegate: PsiMethod,
|
||||||
private val lightMethodOrigin: LightMemberOrigin?,
|
private val lightMethodOrigin: LightMemberOrigin?,
|
||||||
containingClass: KtLightClass
|
containingClass: KtLightClass
|
||||||
) : LightMethod(delegate.manager, delegate, containingClass), KtLightMethod {
|
) : LightMethod(clsDelegate.manager, clsDelegate, containingClass), KtLightMethod {
|
||||||
private val origin = lightMethodOrigin?.originalElement as? KtDeclaration
|
override val kotlinOrigin: KtDeclaration? = lightMethodOrigin?.originalElement as? KtDeclaration
|
||||||
|
|
||||||
private val lightIdentifier = KtLightIdentifier(this, origin as? KtNamedDeclaration)
|
private val lightIdentifier by lazy { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
|
||||||
|
|
||||||
override fun getContainingClass(): KtLightClass = super.getContainingClass() as KtLightClass
|
override fun getContainingClass(): KtLightClass = super.getContainingClass() as KtLightClass
|
||||||
|
|
||||||
private val paramsList: CachedValue<PsiParameterList> by lazy {
|
private val paramsList: CachedValue<PsiParameterList> by lazy {
|
||||||
val cacheManager = CachedValuesManager.getManager(delegate.project)
|
val cacheManager = CachedValuesManager.getManager(clsDelegate.project)
|
||||||
cacheManager.createCachedValue<PsiParameterList>({
|
cacheManager.createCachedValue<PsiParameterList>({
|
||||||
val parameterBuilder = LightParameterListBuilder(manager, KotlinLanguage.INSTANCE, this)
|
val parameterBuilder = LightParameterListBuilder(manager, KotlinLanguage.INSTANCE, this)
|
||||||
|
|
||||||
for ((index, parameter) in delegate.parameterList.parameters.withIndex()) {
|
for ((index, parameter) in clsDelegate.parameterList.parameters.withIndex()) {
|
||||||
parameterBuilder.addParameter(KtLightParameter(parameter, index, this))
|
parameterBuilder.addParameter(KtLightParameter(parameter, index, this))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,13 +56,14 @@ sealed class KtLightMethodImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val typeParamsList: CachedValue<PsiTypeParameterList> by lazy {
|
private val typeParamsList: CachedValue<PsiTypeParameterList> by lazy {
|
||||||
val cacheManager = CachedValuesManager.getManager(delegate.project)
|
val cacheManager = CachedValuesManager.getManager(clsDelegate.project)
|
||||||
cacheManager.createCachedValue<PsiTypeParameterList>({
|
cacheManager.createCachedValue<PsiTypeParameterList>({
|
||||||
|
val origin = kotlinOrigin
|
||||||
val list = if (origin is KtClassOrObject) {
|
val list = if (origin is KtClassOrObject) {
|
||||||
KotlinLightTypeParameterListBuilder(manager)
|
KotlinLightTypeParameterListBuilder(manager)
|
||||||
}
|
}
|
||||||
else if (origin == null) {
|
else if (origin == null) {
|
||||||
delegate.typeParameterList
|
clsDelegate.typeParameterList
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LightClassUtil.buildLightTypeParameterList(this@KtLightMethodImpl, origin)
|
LightClassUtil.buildLightTypeParameterList(this@KtLightMethodImpl, origin)
|
||||||
@@ -71,13 +72,11 @@ sealed class KtLightMethodImpl(
|
|||||||
}, false)
|
}, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNavigationElement(): PsiElement = origin ?: super.getNavigationElement()
|
override fun getNavigationElement(): PsiElement = kotlinOrigin?.navigationElement ?: super.getNavigationElement()
|
||||||
override fun getOriginalElement(): PsiElement = origin ?: super.getOriginalElement()
|
override fun getOriginalElement(): PsiElement = kotlinOrigin ?: super.getOriginalElement()
|
||||||
override fun getDelegate() = delegate
|
|
||||||
override fun getOrigin() = origin
|
|
||||||
override fun getParent(): PsiElement? = containingClass
|
override fun getParent(): PsiElement? = containingClass
|
||||||
override fun getText() = origin?.text ?: ""
|
override fun getText() = kotlinOrigin?.text ?: ""
|
||||||
override fun getTextRange() = origin?.textRange ?: TextRange.EMPTY_RANGE
|
override fun getTextRange() = kotlinOrigin?.textRange ?: TextRange.EMPTY_RANGE
|
||||||
|
|
||||||
override val isDelegated: Boolean
|
override val isDelegated: Boolean
|
||||||
get() = lightMethodOrigin?.originKind == JvmDeclarationOriginKind.DELEGATION
|
get() = lightMethodOrigin?.originKind == JvmDeclarationOriginKind.DELEGATION
|
||||||
@@ -93,13 +92,13 @@ sealed class KtLightMethodImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun setName(name: String): PsiElement? {
|
override fun setName(name: String): PsiElement? {
|
||||||
val toRename = origin as? PsiNamedElement ?: throwCanNotModify()
|
val toRename = kotlinOrigin as? PsiNamedElement ?: throwCanNotModify()
|
||||||
toRename.setName(name)
|
toRename.setName(name)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun delete() {
|
override fun delete() {
|
||||||
origin?.let {
|
kotlinOrigin?.let {
|
||||||
if (it.isValid) {
|
if (it.isValid) {
|
||||||
it.delete()
|
it.delete()
|
||||||
}
|
}
|
||||||
@@ -110,7 +109,7 @@ sealed class KtLightMethodImpl(
|
|||||||
throw IncorrectOperationException(JavaCoreBundle.message("psi.error.attempt.to.edit.class.file"))
|
throw IncorrectOperationException(JavaCoreBundle.message("psi.error.attempt.to.edit.class.file"))
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _modifierList by lazy { KtLightModifierList(delegate.modifierList, this) }
|
private val _modifierList by lazy { KtLightModifierList(clsDelegate.modifierList, this) }
|
||||||
|
|
||||||
override fun getModifierList() = _modifierList
|
override fun getModifierList() = _modifierList
|
||||||
|
|
||||||
@@ -125,16 +124,16 @@ sealed class KtLightMethodImpl(
|
|||||||
|
|
||||||
override fun getSignature(substitutor: PsiSubstitutor): MethodSignature {
|
override fun getSignature(substitutor: PsiSubstitutor): MethodSignature {
|
||||||
if (substitutor == PsiSubstitutor.EMPTY) {
|
if (substitutor == PsiSubstitutor.EMPTY) {
|
||||||
return delegate.getSignature(substitutor)
|
return clsDelegate.getSignature(substitutor)
|
||||||
}
|
}
|
||||||
return MethodSignatureBackedByPsiMethod.create(this, substitutor)
|
return MethodSignatureBackedByPsiMethod.create(this, substitutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun copy(): PsiElement {
|
override fun copy(): PsiElement {
|
||||||
return Factory.create(delegate, lightMethodOrigin?.copy(), containingClass)
|
return Factory.create(clsDelegate, lightMethodOrigin?.copy(), containingClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUseScope() = origin?.useScope ?: super.getUseScope()
|
override fun getUseScope() = kotlinOrigin?.useScope ?: super.getUseScope()
|
||||||
|
|
||||||
override fun getLanguage() = KotlinLanguage.INSTANCE
|
override fun getLanguage() = KotlinLanguage.INSTANCE
|
||||||
|
|
||||||
@@ -143,7 +142,7 @@ sealed class KtLightMethodImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
||||||
if (another is KtLightMethod && origin == another.getOrigin() && delegate == another.getDelegate()) {
|
if (another is KtLightMethod && kotlinOrigin == another.kotlinOrigin && clsDelegate == another.clsDelegate) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,11 +152,11 @@ sealed class KtLightMethodImpl(
|
|||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean =
|
||||||
other is KtLightMethod &&
|
other is KtLightMethod &&
|
||||||
name == other.name &&
|
name == other.name &&
|
||||||
origin == other.getOrigin() &&
|
kotlinOrigin == other.kotlinOrigin &&
|
||||||
containingClass == other.containingClass &&
|
containingClass == other.containingClass &&
|
||||||
delegate == other.getDelegate()
|
clsDelegate == other.clsDelegate
|
||||||
|
|
||||||
override fun hashCode(): Int = ((name.hashCode() * 31 + (origin?.hashCode() ?: 0)) * 31 + containingClass.hashCode()) * 31 + delegate.hashCode()
|
override fun hashCode(): Int = ((name.hashCode() * 31 + (kotlinOrigin?.hashCode() ?: 0)) * 31 + containingClass.hashCode()) * 31 + clsDelegate.hashCode()
|
||||||
|
|
||||||
override fun toString(): String = "${this.javaClass.simpleName}:$name"
|
override fun toString(): String = "${this.javaClass.simpleName}:$name"
|
||||||
|
|
||||||
@@ -166,12 +165,11 @@ sealed class KtLightMethodImpl(
|
|||||||
) : KtLightMethodImpl(delegate, origin, containingClass)
|
) : KtLightMethodImpl(delegate, origin, containingClass)
|
||||||
|
|
||||||
private class KtLightAnnotationMethod(
|
private class KtLightAnnotationMethod(
|
||||||
delegate: PsiAnnotationMethod,
|
override val clsDelegate: PsiAnnotationMethod,
|
||||||
origin: LightMemberOrigin?,
|
origin: LightMemberOrigin?,
|
||||||
containingClass: KtLightClass
|
containingClass: KtLightClass
|
||||||
) : KtLightMethodImpl(delegate, origin, containingClass), PsiAnnotationMethod {
|
) : KtLightMethodImpl(clsDelegate, origin, containingClass), PsiAnnotationMethod {
|
||||||
override fun getDefaultValue() = getDelegate().defaultValue
|
override fun getDefaultValue() = clsDelegate.defaultValue
|
||||||
override fun getDelegate() = super.getDelegate() as PsiAnnotationMethod
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object Factory {
|
companion object Factory {
|
||||||
@@ -187,13 +185,13 @@ sealed class KtLightMethodImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun KtLightMethod.isTraitFakeOverride(): Boolean {
|
fun KtLightMethod.isTraitFakeOverride(): Boolean {
|
||||||
val methodOrigin = this.getOrigin()
|
val methodOrigin = this.kotlinOrigin
|
||||||
if (!(methodOrigin is KtNamedFunction || methodOrigin is KtPropertyAccessor || methodOrigin is KtProperty)) {
|
if (!(methodOrigin is KtNamedFunction || methodOrigin is KtPropertyAccessor || methodOrigin is KtProperty)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val parentOfMethodOrigin = PsiTreeUtil.getParentOfType(methodOrigin, KtClassOrObject::class.java)
|
val parentOfMethodOrigin = PsiTreeUtil.getParentOfType(methodOrigin, KtClassOrObject::class.java)
|
||||||
val thisClassDeclaration = (this.containingClass as KtLightClass).getOrigin()
|
val thisClassDeclaration = (this.containingClass as KtLightClass).kotlinOrigin
|
||||||
|
|
||||||
// Method was generated from declaration in some other trait
|
// Method was generated from declaration in some other trait
|
||||||
return (parentOfMethodOrigin != null && thisClassDeclaration !== parentOfMethodOrigin && KtPsiUtil.isTrait(parentOfMethodOrigin))
|
return (parentOfMethodOrigin != null && thisClassDeclaration !== parentOfMethodOrigin && KtPsiUtil.isTrait(parentOfMethodOrigin))
|
||||||
|
|||||||
+1
-1
@@ -69,7 +69,7 @@ internal fun computeAnnotations(lightElement: PsiModifierList,
|
|||||||
val cacheManager = CachedValuesManager.getManager(lightElement.project)
|
val cacheManager = CachedValuesManager.getManager(lightElement.project)
|
||||||
return cacheManager.createCachedValue<Array<out PsiAnnotation>>(
|
return cacheManager.createCachedValue<Array<out PsiAnnotation>>(
|
||||||
{
|
{
|
||||||
val declaration = (lightElement.parent as? KtLightElement<*, *>)?.getOrigin() as? KtDeclaration
|
val declaration = (lightElement.parent as? KtLightElement<*, *>)?.kotlinOrigin as? KtDeclaration
|
||||||
val descriptor = declaration?.let { LightClassGenerationSupport.getInstance(lightElement.project).resolveToDescriptor(it) }
|
val descriptor = declaration?.let { LightClassGenerationSupport.getInstance(lightElement.project).resolveToDescriptor(it) }
|
||||||
val ktAnnotations = descriptor?.annotations?.getAllAnnotations() ?: emptyList()
|
val ktAnnotations = descriptor?.annotations?.getAllAnnotations() ?: emptyList()
|
||||||
var nextIndex = 0
|
var nextIndex = 0
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -41,7 +41,7 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
private final PsiParameter delegate;
|
private final PsiParameter delegate;
|
||||||
private final int index;
|
private final int index;
|
||||||
private final KtLightMethod method;
|
private final KtLightMethod method;
|
||||||
private final KtLightIdentifier lightIdentifier;
|
private KtLightIdentifier lightIdentifier = null;
|
||||||
|
|
||||||
public KtLightParameter(final PsiParameter delegate, int index, KtLightMethod method) {
|
public KtLightParameter(final PsiParameter delegate, int index, KtLightMethod method) {
|
||||||
super(getName(delegate, index), delegate.getType(), method, KotlinLanguage.INSTANCE);
|
super(getName(delegate, index), delegate.getType(), method, KotlinLanguage.INSTANCE);
|
||||||
@@ -56,8 +56,6 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
return delegate.getModifierList();
|
return delegate.getModifierList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
lightIdentifier = new KtLightIdentifier(this, getOrigin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -68,14 +66,14 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiParameter getDelegate() {
|
public PsiParameter getClsDelegate() {
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public KtParameter getOrigin() {
|
public KtParameter getKotlinOrigin() {
|
||||||
KtDeclaration declaration = method.getOrigin();
|
KtDeclaration declaration = method.getKotlinOrigin();
|
||||||
if (declaration == null) return null;
|
if (declaration == null) return null;
|
||||||
|
|
||||||
int jetIndex = KtPsiUtilKt.isExtensionDeclaration(declaration) ? index - 1 : index;
|
int jetIndex = KtPsiUtilKt.isExtensionDeclaration(declaration) ? index - 1 : index;
|
||||||
@@ -103,13 +101,13 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiElement getNavigationElement() {
|
public PsiElement getNavigationElement() {
|
||||||
KtParameter origin = getOrigin();
|
KtParameter origin = getKotlinOrigin();
|
||||||
return origin != null ? origin : super.getNavigationElement();
|
return origin != null ? origin : super.getNavigationElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||||
KtParameter origin = getOrigin();
|
KtParameter origin = getKotlinOrigin();
|
||||||
if (origin != null) {
|
if (origin != null) {
|
||||||
origin.setName(name);
|
origin.setName(name);
|
||||||
}
|
}
|
||||||
@@ -118,7 +116,7 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiFile getContainingFile() {
|
public PsiFile getContainingFile() {
|
||||||
KtDeclaration declaration = method.getOrigin();
|
KtDeclaration declaration = method.getKotlinOrigin();
|
||||||
return declaration != null ? declaration.getContainingFile() : super.getContainingFile();
|
return declaration != null ? declaration.getContainingFile() : super.getContainingFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +129,7 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public SearchScope getUseScope() {
|
public SearchScope getUseScope() {
|
||||||
KtParameter origin = getOrigin();
|
KtParameter origin = getKotlinOrigin();
|
||||||
return origin != null ? origin.getUseScope() : GlobalSearchScope.EMPTY_SCOPE;
|
return origin != null ? origin.getUseScope() : GlobalSearchScope.EMPTY_SCOPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +144,9 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiIdentifier getNameIdentifier() {
|
public PsiIdentifier getNameIdentifier() {
|
||||||
|
if (lightIdentifier == null) {
|
||||||
|
lightIdentifier = new KtLightIdentifier(this, getKotlinOrigin());
|
||||||
|
}
|
||||||
return lightIdentifier;
|
return lightIdentifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -44,13 +44,19 @@ public class KtLightTypeParameter
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiTypeParameter getDelegate() {
|
public PsiTypeParameter getClsDelegate() {
|
||||||
return getOwnerDelegate().getTypeParameters()[index];
|
return getOwnerDelegate().getTypeParameters()[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public KtTypeParameter getOrigin() {
|
public PsiClass getDelegate() {
|
||||||
|
return getClsDelegate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public KtTypeParameter getKotlinOrigin() {
|
||||||
KtTypeParameterListOwner jetOwner = (KtTypeParameterListOwner) LightClassUtilsKt.getUnwrapped(owner);
|
KtTypeParameterListOwner jetOwner = (KtTypeParameterListOwner) LightClassUtilsKt.getUnwrapped(owner);
|
||||||
assert (jetOwner != null) : "Invalid type parameter owner: " + owner;
|
assert (jetOwner != null) : "Invalid type parameter owner: " + owner;
|
||||||
|
|
||||||
@@ -59,8 +65,8 @@ public class KtLightTypeParameter
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private PsiTypeParameterListOwner getOwnerDelegate() {
|
private PsiTypeParameterListOwner getOwnerDelegate() {
|
||||||
if (owner instanceof KtLightClass) return ((KtLightClass) owner).getDelegate();
|
if (owner instanceof KtLightClass) return ((KtLightClass) owner).getClsDelegate();
|
||||||
if (owner instanceof KtLightMethod) return ((KtLightMethod) owner).getDelegate();
|
if (owner instanceof KtLightMethod) return ((KtLightMethod) owner).getClsDelegate();
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,24 +110,24 @@ public class KtLightTypeParameter
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiAnnotation[] getAnnotations() {
|
public PsiAnnotation[] getAnnotations() {
|
||||||
return getDelegate().getAnnotations();
|
return getClsDelegate().getAnnotations();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiAnnotation[] getApplicableAnnotations() {
|
public PsiAnnotation[] getApplicableAnnotations() {
|
||||||
return getDelegate().getApplicableAnnotations();
|
return getClsDelegate().getApplicableAnnotations();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiAnnotation findAnnotation(@NotNull String qualifiedName) {
|
public PsiAnnotation findAnnotation(@NotNull String qualifiedName) {
|
||||||
return getDelegate().findAnnotation(qualifiedName);
|
return getClsDelegate().findAnnotation(qualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiAnnotation addAnnotation(@NotNull String qualifiedName) {
|
public PsiAnnotation addAnnotation(@NotNull String qualifiedName) {
|
||||||
return getDelegate().addAnnotation(qualifiedName);
|
return getClsDelegate().addAnnotation(qualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -132,7 +138,7 @@ public class KtLightTypeParameter
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiElement getNavigationElement() {
|
public PsiElement getNavigationElement() {
|
||||||
return getOrigin();
|
return getKotlinOrigin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -144,12 +150,12 @@ public class KtLightTypeParameter
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public SearchScope getUseScope() {
|
public SearchScope getUseScope() {
|
||||||
return getOrigin().getUseScope();
|
return getKotlinOrigin().getUseScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj == this) return true;
|
if (obj == this) return true;
|
||||||
return obj instanceof KtLightTypeParameter && getOrigin().equals(((KtLightTypeParameter) obj).getOrigin());
|
return obj instanceof KtLightTypeParameter && getKotlinOrigin().equals(((KtLightTypeParameter) obj).getKotlinOrigin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -31,7 +31,6 @@ import com.intellij.util.containers.ContainerUtil;
|
|||||||
import kotlin.collections.ArraysKt;
|
import kotlin.collections.ArraysKt;
|
||||||
import kotlin.jvm.functions.Function1;
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||||
@@ -47,13 +46,11 @@ public abstract class KtWrappingLightClass extends AbstractLightClass implements
|
|||||||
super(manager, KotlinLanguage.INSTANCE);
|
super(manager, KotlinLanguage.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public abstract KtClassOrObject getOrigin();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public abstract PsiClass getDelegate();
|
public PsiClass getDelegate() {
|
||||||
|
return getClsDelegate();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -123,9 +120,7 @@ public abstract class KtWrappingLightClass extends AbstractLightClass implements
|
|||||||
@Override
|
@Override
|
||||||
public PsiField fun(PsiField field) {
|
public PsiField fun(PsiField field) {
|
||||||
LightMemberOrigin origin = ClsWrapperStubPsiFactory.getMemberOrigin(field);
|
LightMemberOrigin origin = ClsWrapperStubPsiFactory.getMemberOrigin(field);
|
||||||
return KtLightFieldImpl.Factory.create(origin != null ? origin.getOriginalElement() : null,
|
return KtLightFieldImpl.Factory.create(origin, field, KtWrappingLightClass.this);
|
||||||
field,
|
|
||||||
KtWrappingLightClass.this);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -161,7 +156,7 @@ public abstract class KtWrappingLightClass extends AbstractLightClass implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getText() {
|
public String getText() {
|
||||||
KtClassOrObject origin = getOrigin();
|
KtClassOrObject origin = getKotlinOrigin();
|
||||||
return origin == null ? "" : origin.getText();
|
return origin == null ? "" : origin.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -62,7 +62,7 @@ object LightClassUtil {
|
|||||||
val outerPsiClass = getWrappingClass(companionObject)
|
val outerPsiClass = getWrappingClass(companionObject)
|
||||||
if (outerPsiClass != null) {
|
if (outerPsiClass != null) {
|
||||||
for (fieldOfParent in outerPsiClass.fields) {
|
for (fieldOfParent in outerPsiClass.fields) {
|
||||||
if ((fieldOfParent is KtLightElement<*, *>) && fieldOfParent.getOrigin() === companionObject) {
|
if ((fieldOfParent is KtLightElement<*, *>) && fieldOfParent.kotlinOrigin === companionObject) {
|
||||||
return fieldOfParent
|
return fieldOfParent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ object LightClassUtil {
|
|||||||
var psiClass: PsiClass = getWrappingClass(declaration) ?: return null
|
var psiClass: PsiClass = getWrappingClass(declaration) ?: return null
|
||||||
|
|
||||||
if (psiClass is KtLightClass) {
|
if (psiClass is KtLightClass) {
|
||||||
val origin = psiClass.getOrigin()
|
val origin = psiClass.kotlinOrigin
|
||||||
if (origin is KtObjectDeclaration && origin.isCompanion()) {
|
if (origin is KtObjectDeclaration && origin.isCompanion()) {
|
||||||
val containingClass = PsiTreeUtil.getParentOfType(origin, KtClass::class.java)
|
val containingClass = PsiTreeUtil.getParentOfType(origin, KtClass::class.java)
|
||||||
if (containingClass != null) {
|
if (containingClass != null) {
|
||||||
@@ -97,7 +97,7 @@ object LightClassUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (field in psiClass.fields) {
|
for (field in psiClass.fields) {
|
||||||
if (field is KtLightField && field.getOrigin() === declaration) {
|
if (field is KtLightField && field.kotlinOrigin === declaration) {
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ object LightClassUtil {
|
|||||||
val methods = SmartList<PsiMethod>()
|
val methods = SmartList<PsiMethod>()
|
||||||
for (method in psiClass.methods.asList()) {
|
for (method in psiClass.methods.asList()) {
|
||||||
try {
|
try {
|
||||||
if (method is KtLightMethod && method.getOrigin() === declaration) {
|
if (method is KtLightMethod && method.kotlinOrigin === declaration) {
|
||||||
methods.add(method)
|
methods.add(method)
|
||||||
if (!collectAll) {
|
if (!collectAll) {
|
||||||
return methods
|
return methods
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -105,7 +105,7 @@ fun KtTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
|
|||||||
|
|
||||||
// Returns original declaration if given PsiElement is a Kotlin light element, and element itself otherwise
|
// Returns original declaration if given PsiElement is a Kotlin light element, and element itself otherwise
|
||||||
val PsiElement.unwrapped: PsiElement?
|
val PsiElement.unwrapped: PsiElement?
|
||||||
get() = if (this is KtLightElement<*, *>) getOrigin() else this
|
get() = if (this is KtLightElement<*, *>) kotlinOrigin else this
|
||||||
|
|
||||||
val PsiElement.namedUnwrappedElement: PsiNamedElement?
|
val PsiElement.namedUnwrappedElement: PsiNamedElement?
|
||||||
get() = unwrapped?.getNonStrictParentOfType<PsiNamedElement>()
|
get() = unwrapped?.getNonStrictParentOfType<PsiNamedElement>()
|
||||||
@@ -131,5 +131,5 @@ fun FqName.defaultImplsChild() = child(DEFAULT_IMPLS_CLASS_NAME)
|
|||||||
fun KtAnnotationEntry.toLightAnnotation(): PsiAnnotation? {
|
fun KtAnnotationEntry.toLightAnnotation(): PsiAnnotation? {
|
||||||
val ktDeclaration = getStrictParentOfType<KtModifierList>()?.parent as? KtDeclaration ?: return null
|
val ktDeclaration = getStrictParentOfType<KtModifierList>()?.parent as? KtDeclaration ?: return null
|
||||||
val lightElement = ktDeclaration.toLightElements().firstOrNull() as? PsiModifierListOwner ?: return null
|
val lightElement = ktDeclaration.toLightElements().firstOrNull() as? PsiModifierListOwner ?: return null
|
||||||
return lightElement.modifierList?.annotations?.firstOrNull { it is KtLightAnnotation && it.getOrigin() == this }
|
return lightElement.modifierList?.annotations?.firstOrNull { it is KtLightAnnotation && it.kotlinOrigin == this }
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -77,7 +77,7 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void assertModifiersCoherent(KtLightClass lightClass) {
|
public void assertModifiersCoherent(KtLightClass lightClass) {
|
||||||
PsiClass delegate = lightClass.getDelegate();
|
PsiClass delegate = lightClass.getClsDelegate();
|
||||||
for (String modifier : PsiModifier.MODIFIERS) {
|
for (String modifier : PsiModifier.MODIFIERS) {
|
||||||
assertEquals("Incoherent modifier: " + modifier,
|
assertEquals("Incoherent modifier: " + modifier,
|
||||||
delegate.hasModifierProperty(modifier),
|
delegate.hasModifierProperty(modifier),
|
||||||
@@ -90,7 +90,7 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
|||||||
try {
|
try {
|
||||||
Method method = reflect.getMethod(methodName);
|
Method method = reflect.getMethod(methodName);
|
||||||
Object lightResult = method.invoke(lightClass);
|
Object lightResult = method.invoke(lightClass);
|
||||||
Object delegateResult = method.invoke(lightClass.getDelegate());
|
Object delegateResult = method.invoke(lightClass.getClsDelegate());
|
||||||
assertEquals("Result of method " + methodName + "() differs in light class and its delegate", delegateResult, lightResult);
|
assertEquals("Result of method " + methodName + "() differs in light class and its delegate", delegateResult, lightResult);
|
||||||
}
|
}
|
||||||
catch (NoSuchMethodException e) {
|
catch (NoSuchMethodException e) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -50,7 +50,7 @@ object LightClassTestCommon {
|
|||||||
}
|
}
|
||||||
TestCase.assertTrue("Not a light class: $lightClass ($fqName)", lightClass is KtLightClass)
|
TestCase.assertTrue("Not a light class: $lightClass ($fqName)", lightClass is KtLightClass)
|
||||||
|
|
||||||
val delegate = (lightClass as KtLightClass).getDelegate()
|
val delegate = (lightClass as KtLightClass).clsDelegate
|
||||||
TestCase.assertTrue("Not a CLS element: $delegate", delegate is ClsElementImpl)
|
TestCase.assertTrue("Not a CLS element: $delegate", delegate is ClsElementImpl)
|
||||||
|
|
||||||
val buffer = StringBuilder()
|
val buffer = StringBuilder()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -86,7 +86,7 @@ class KotlinIconProvider : IconProvider(), DumbAware {
|
|||||||
is KtPackageDirective -> PlatformIcons.PACKAGE_ICON
|
is KtPackageDirective -> PlatformIcons.PACKAGE_ICON
|
||||||
is KtLightClassForFacade -> KotlinIcons.FILE
|
is KtLightClassForFacade -> KotlinIcons.FILE
|
||||||
is KtLightClassForDecompiledDeclaration -> {
|
is KtLightClassForDecompiledDeclaration -> {
|
||||||
val origin = getOrigin()
|
val origin = kotlinOrigin
|
||||||
//TODO (light classes for decompiled files): correct presentation
|
//TODO (light classes for decompiled files): correct presentation
|
||||||
if (origin != null) origin.getBaseIcon() else KotlinIcons.CLASS
|
if (origin != null) origin.getBaseIcon() else KotlinIcons.CLASS
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -185,7 +185,7 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
|||||||
return withFakeLightClasses(lightClassForFacade, facadeFiles)
|
return withFakeLightClasses(lightClassForFacade, facadeFiles)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return facadeFiles.filter { it.isCompiled }.mapNotNull { createLightClassForDecompiledKotlinFile(it) }
|
return facadeFiles.filterIsInstance<KtClsFile>().mapNotNull { createLightClassForDecompiledKotlinFile(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
|||||||
return getClassRelativeName(parent).child(name)
|
return getClassRelativeName(parent).child(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createLightClassForDecompiledKotlinFile(file: KtFile): KtLightClassForDecompiledDeclaration? {
|
fun createLightClassForDecompiledKotlinFile(file: KtClsFile): KtLightClassForDecompiledDeclaration? {
|
||||||
val virtualFile = file.virtualFile ?: return null
|
val virtualFile = file.virtualFile ?: return null
|
||||||
|
|
||||||
val classOrObject = file.declarations.filterIsInstance<KtClassOrObject>().singleOrNull()
|
val classOrObject = file.declarations.filterIsInstance<KtClassOrObject>().singleOrNull()
|
||||||
@@ -313,7 +313,7 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
|||||||
correspondingClassOrObject = classOrObject
|
correspondingClassOrObject = classOrObject
|
||||||
) ?: return null
|
) ?: return null
|
||||||
|
|
||||||
return KtLightClassForDecompiledDeclaration(javaClsClass, classOrObject)
|
return KtLightClassForDecompiledDeclaration(javaClsClass, classOrObject, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createClsJavaClassFromVirtualFile(
|
private fun createClsJavaClassFromVirtualFile(
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -87,7 +87,7 @@ fun PsiClass.resolveToDescriptor(
|
|||||||
declarationTranslator: (KtClassOrObject) -> KtClassOrObject? = { it }
|
declarationTranslator: (KtClassOrObject) -> KtClassOrObject? = { it }
|
||||||
): ClassDescriptor? {
|
): ClassDescriptor? {
|
||||||
return if (this is KtLightClass && this !is KtLightClassForDecompiledDeclaration) {
|
return if (this is KtLightClass && this !is KtLightClassForDecompiledDeclaration) {
|
||||||
val origin = this.getOrigin() ?: return null
|
val origin = this.kotlinOrigin ?: return null
|
||||||
val declaration = declarationTranslator(origin) ?: return null
|
val declaration = declarationTranslator(origin) ?: return null
|
||||||
resolutionFacade.resolveToDescriptor(declaration)
|
resolutionFacade.resolveToDescriptor(declaration)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-14
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,34 +19,32 @@ package org.jetbrains.kotlin.idea.caches.resolve
|
|||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
import com.intellij.psi.impl.compiled.ClsClassImpl
|
import com.intellij.psi.impl.compiled.ClsClassImpl
|
||||||
import org.jetbrains.kotlin.asJava.KtWrappingLightClass
|
import org.jetbrains.kotlin.asJava.KtWrappingLightClass
|
||||||
|
import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
|
||||||
class KtLightClassForDecompiledDeclaration(
|
class KtLightClassForDecompiledDeclaration(
|
||||||
private val clsClass: ClsClassImpl,
|
override val clsDelegate: ClsClassImpl,
|
||||||
private val origin: KtClassOrObject?
|
override val kotlinOrigin: KtClassOrObject?,
|
||||||
) : KtWrappingLightClass(clsClass.manager) {
|
private val file: KtClsFile
|
||||||
private val fqName = origin?.fqName ?: FqName(clsClass.qualifiedName)
|
) : KtWrappingLightClass(clsDelegate.manager) {
|
||||||
|
private val fqName = kotlinOrigin?.fqName ?: FqName(clsDelegate.qualifiedName)
|
||||||
|
|
||||||
override fun copy() = this
|
override fun copy() = this
|
||||||
|
|
||||||
override fun getOwnInnerClasses(): List<PsiClass> {
|
override fun getOwnInnerClasses(): List<PsiClass> {
|
||||||
val nestedClasses = origin?.declarations?.filterIsInstance<KtClassOrObject>() ?: emptyList()
|
val nestedClasses = kotlinOrigin?.declarations?.filterIsInstance<KtClassOrObject>() ?: emptyList()
|
||||||
return clsClass.ownInnerClasses.map { innerClsClass ->
|
return clsDelegate.ownInnerClasses.map { innerClsClass ->
|
||||||
KtLightClassForDecompiledDeclaration(innerClsClass as ClsClassImpl,
|
KtLightClassForDecompiledDeclaration(innerClsClass as ClsClassImpl,
|
||||||
nestedClasses.firstOrNull { innerClsClass.name == it.name })
|
nestedClasses.firstOrNull { innerClsClass.name == it.name }, file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNavigationElement() = origin?.navigationElement ?: super.getNavigationElement()
|
override fun getNavigationElement() = kotlinOrigin?.navigationElement ?: file
|
||||||
|
|
||||||
override fun getDelegate() = clsClass
|
|
||||||
|
|
||||||
override fun getOrigin() = origin
|
|
||||||
|
|
||||||
override fun getFqName() = fqName
|
override fun getFqName() = fqName
|
||||||
|
|
||||||
override fun getParent() = clsClass.parent
|
override fun getParent() = clsDelegate.parent
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean =
|
override fun equals(other: Any?): Boolean =
|
||||||
other is KtLightClassForDecompiledDeclaration &&
|
other is KtLightClassForDecompiledDeclaration &&
|
||||||
@@ -55,3 +53,4 @@ class KtLightClassForDecompiledDeclaration(
|
|||||||
override fun hashCode(): Int =
|
override fun hashCode(): Int =
|
||||||
getFqName().hashCode()
|
getFqName().hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -130,10 +130,10 @@ private fun KtLightElement<*, *>.getModuleInfoForLightElement(onFailure: (String
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val element = getOrigin() ?: when (this) {
|
val element = kotlinOrigin ?: when (this) {
|
||||||
is FakeLightClassForFileOfPackage -> this.getContainingFile()!!
|
is FakeLightClassForFileOfPackage -> this.getContainingFile()!!
|
||||||
is KtLightClassForFacade -> this.files.first()
|
is KtLightClassForFacade -> this.files.first()
|
||||||
else -> return onFailure("Light element without origin is referenced by resolve:\n$this\n${this.getDelegate().text}")
|
else -> return onFailure("Light element without origin is referenced by resolve:\n$this\n${this.clsDelegate.text}")
|
||||||
}
|
}
|
||||||
return element.getModuleInfo()
|
return element.getModuleInfo()
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -39,7 +39,7 @@ class KotlinReadWriteAccessDetector : ReadWriteAccessDetector() {
|
|||||||
|
|
||||||
val refTarget = reference.resolve()
|
val refTarget = reference.resolve()
|
||||||
if (refTarget is KtLightMethod) {
|
if (refTarget is KtLightMethod) {
|
||||||
val origin = refTarget.getOrigin()
|
val origin = refTarget.kotlinOrigin
|
||||||
val declaration: KtNamedDeclaration = when (origin) {
|
val declaration: KtNamedDeclaration = when (origin) {
|
||||||
is KtPropertyAccessor -> origin.getNonStrictParentOfType<KtProperty>()
|
is KtPropertyAccessor -> origin.getNonStrictParentOfType<KtProperty>()
|
||||||
is KtProperty, is KtParameter -> origin as KtNamedDeclaration
|
is KtProperty, is KtParameter -> origin as KtNamedDeclaration
|
||||||
|
|||||||
+5
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -197,7 +197,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
|||||||
originLightClass.fields.map { it as? KtLightField }
|
originLightClass.fields.map { it as? KtLightField }
|
||||||
|
|
||||||
for (declaration in element.declarations) {
|
for (declaration in element.declarations) {
|
||||||
val lightDeclaration = lightDeclarations.find { it?.getOrigin() == declaration }
|
val lightDeclaration = lightDeclarations.find { it?.kotlinOrigin == declaration }
|
||||||
if (lightDeclaration != null) {
|
if (lightDeclaration != null) {
|
||||||
searchNamedElement(queryParameters, lightDeclaration)
|
searchNamedElement(queryParameters, lightDeclaration)
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
|||||||
val originClass = originObject.getStrictParentOfType<KtClass>()
|
val originClass = originObject.getStrictParentOfType<KtClass>()
|
||||||
val originLightClass = originClass?.toLightClass()
|
val originLightClass = originClass?.toLightClass()
|
||||||
val allMethods = originLightClass?.allMethods
|
val allMethods = originLightClass?.allMethods
|
||||||
return allMethods?.find { it is KtLightMethod && it.getOrigin() == function }
|
return allMethods?.find { it is KtLightMethod && it.kotlinOrigin == function }
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
|||||||
}
|
}
|
||||||
|
|
||||||
is KtLightMethod -> {
|
is KtLightMethod -> {
|
||||||
val declaration = element.getOrigin()
|
val declaration = element.kotlinOrigin
|
||||||
if (declaration is KtProperty || (declaration is KtParameter && declaration.hasValOrVar())) {
|
if (declaration is KtProperty || (declaration is KtParameter && declaration.hasValOrVar())) {
|
||||||
searchNamedElement(queryParameters, declaration as PsiNamedElement)
|
searchNamedElement(queryParameters, declaration as PsiNamedElement)
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
|||||||
}
|
}
|
||||||
|
|
||||||
is KtLightParameter -> {
|
is KtLightParameter -> {
|
||||||
val origin = element.getOrigin() ?: return
|
val origin = element.kotlinOrigin ?: return
|
||||||
runReadAction {
|
runReadAction {
|
||||||
val componentFunctionDescriptor = origin.dataClassComponentFunction()
|
val componentFunctionDescriptor = origin.dataClassComponentFunction()
|
||||||
if (componentFunctionDescriptor != null) {
|
if (componentFunctionDescriptor != null) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -134,7 +134,7 @@ private fun PsiElement.processDelegationCallKotlinConstructorUsages(scope: Searc
|
|||||||
private fun PsiElement.processDelegationCallJavaConstructorUsages(scope: SearchScope, process: (KtCallElement) -> Boolean): Boolean {
|
private fun PsiElement.processDelegationCallJavaConstructorUsages(scope: SearchScope, process: (KtCallElement) -> Boolean): Boolean {
|
||||||
if (this is KtLightElement<*, *>) return true
|
if (this is KtLightElement<*, *>) return true
|
||||||
// TODO: Temporary hack to avoid NPE while KotlinNoOriginLightMethod is around
|
// TODO: Temporary hack to avoid NPE while KotlinNoOriginLightMethod is around
|
||||||
if (this is KtLightMethod && this.getOrigin() == null) return true
|
if (this is KtLightMethod && this.kotlinOrigin == null) return true
|
||||||
if (!(this is PsiMethod && isConstructor)) return true
|
if (!(this is PsiMethod && isConstructor)) return true
|
||||||
val klass = containingClass ?: return true
|
val klass = containingClass ?: return true
|
||||||
val descriptor = getJavaMethodDescriptor() as? ConstructorDescriptor ?: return true
|
val descriptor = getJavaMethodDescriptor() as? ConstructorDescriptor ?: return true
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
|||||||
return renderKotlinDeclaration(element, quickNavigation)
|
return renderKotlinDeclaration(element, quickNavigation)
|
||||||
}
|
}
|
||||||
else if (element is KtLightDeclaration<*, *>) {
|
else if (element is KtLightDeclaration<*, *>) {
|
||||||
val origin = element.getOrigin() ?: return null
|
val origin = element.kotlinOrigin ?: return null
|
||||||
return renderKotlinDeclaration(origin, quickNavigation)
|
return renderKotlinDeclaration(origin, quickNavigation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -89,7 +89,7 @@ class KotlinFieldBreakpointType : JavaBreakpointType<KotlinPropertyBreakpointPro
|
|||||||
psiClass.files.asSequence().mapNotNull { createBreakpointIfPropertyExists(it, it, className, fieldName) }.firstOrNull()
|
psiClass.files.asSequence().mapNotNull { createBreakpointIfPropertyExists(it, it, className, fieldName) }.firstOrNull()
|
||||||
}
|
}
|
||||||
is KtLightClassForExplicitDeclaration -> {
|
is KtLightClassForExplicitDeclaration -> {
|
||||||
val jetClass = psiClass.getOrigin()
|
val jetClass = psiClass.kotlinOrigin
|
||||||
createBreakpointIfPropertyExists(jetClass, jetClass.getContainingKtFile(), className, fieldName)
|
createBreakpointIfPropertyExists(jetClass, jetClass.getContainingKtFile(), className, fieldName)
|
||||||
}
|
}
|
||||||
else -> null
|
else -> null
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,7 +34,7 @@ fun PsiClass.collectProperties(): Array<DescriptorMemberChooserObject> {
|
|||||||
return result.toTypedArray()
|
return result.toTypedArray()
|
||||||
}
|
}
|
||||||
if (this is KtLightClass) {
|
if (this is KtLightClass) {
|
||||||
val origin = this.getOrigin()
|
val origin = this.kotlinOrigin
|
||||||
if (origin != null) {
|
if (origin != null) {
|
||||||
return origin.declarations.filterIsInstance<KtProperty>().map {
|
return origin.declarations.filterIsInstance<KtProperty>().map {
|
||||||
DescriptorMemberChooserObject(it, it.resolveToDescriptor())
|
DescriptorMemberChooserObject(it, it.resolveToDescriptor())
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -145,7 +145,7 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (elementAt is KtLightClass) {
|
if (elementAt is KtLightClass) {
|
||||||
return getContextElement(elementAt.getOrigin())
|
return getContextElement(elementAt.kotlinOrigin)
|
||||||
}
|
}
|
||||||
|
|
||||||
val containingFile = elementAt.containingFile
|
val containingFile = elementAt.containingFile
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -120,7 +120,7 @@ public class KotlinCalleeMethodsTreeStructure extends KotlinCallTreeStructure {
|
|||||||
|
|
||||||
// Kotlin function or property invoked from Java code
|
// Kotlin function or property invoked from Java code
|
||||||
if (targetElement instanceof KtLightMethod) {
|
if (targetElement instanceof KtLightMethod) {
|
||||||
return buildChildrenByKotlinTarget(descriptor, ((KtLightMethod) targetElement).getOrigin());
|
return buildChildrenByKotlinTarget(descriptor, ((KtLightMethod) targetElement).getKotlinOrigin());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetElement instanceof KtElement) {
|
if (targetElement instanceof KtElement) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -91,7 +91,7 @@ abstract class ImplementAbstractMemberIntentionBase :
|
|||||||
|
|
||||||
fun acceptSubClass(subClass: PsiElement): Boolean {
|
fun acceptSubClass(subClass: PsiElement): Boolean {
|
||||||
val classDescriptor = when (subClass) {
|
val classDescriptor = when (subClass) {
|
||||||
is KtLightClass -> subClass.getOrigin()?.resolveToDescriptorIfAny()
|
is KtLightClass -> subClass.kotlinOrigin?.resolveToDescriptorIfAny()
|
||||||
is KtEnumEntry -> subClass.resolveToDescriptorIfAny()
|
is KtEnumEntry -> subClass.resolveToDescriptorIfAny()
|
||||||
is PsiClass -> subClass.getJavaClassDescriptor()
|
is PsiClass -> subClass.getJavaClassDescriptor()
|
||||||
else -> null
|
else -> null
|
||||||
@@ -153,7 +153,7 @@ abstract class ImplementAbstractMemberIntentionBase :
|
|||||||
for (targetClass in targetClasses) {
|
for (targetClass in targetClasses) {
|
||||||
try {
|
try {
|
||||||
when (targetClass) {
|
when (targetClass) {
|
||||||
is KtLightClass -> targetClass.getOrigin()?.let { implementInKotlinClass(member, it) }
|
is KtLightClass -> targetClass.kotlinOrigin?.let { implementInKotlinClass(member, it) }
|
||||||
is KtEnumEntry -> implementInKotlinClass(member, targetClass)
|
is KtEnumEntry -> implementInKotlinClass(member, targetClass)
|
||||||
is PsiClass -> implementInJavaClass(member, targetClass)
|
is PsiClass -> implementInJavaClass(member, targetClass)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -69,7 +69,7 @@ class KotlinExpandNodeProjectViewProvider : TreeStructureProvider, DumbAware {
|
|||||||
|
|
||||||
private fun Any.asKtFile(): KtFile? = when (this) {
|
private fun Any.asKtFile(): KtFile? = when (this) {
|
||||||
is KtFile -> this
|
is KtFile -> this
|
||||||
is KtLightClass -> getOrigin()?.containingFile as? KtFile
|
is KtLightClass -> kotlinOrigin?.containingFile as? KtFile
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -315,7 +315,7 @@ public class KotlinRefactoringUtil {
|
|||||||
int parameterIndex = KtPsiUtilKt.parameterIndex(LightClassUtilsKt.getUnwrapped(parameter));
|
int parameterIndex = KtPsiUtilKt.parameterIndex(LightClassUtilsKt.getUnwrapped(parameter));
|
||||||
|
|
||||||
if (method instanceof KtLightMethod) {
|
if (method instanceof KtLightMethod) {
|
||||||
KtDeclaration declaration = ((KtLightMethod) method).getOrigin();
|
KtDeclaration declaration = ((KtLightMethod) method).getKotlinOrigin();
|
||||||
if (declaration instanceof KtFunction) {
|
if (declaration instanceof KtFunction) {
|
||||||
result.add(((KtFunction) declaration).getValueParameters().get(parameterIndex));
|
result.add(((KtFunction) declaration).getValueParameters().get(parameterIndex));
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -910,7 +910,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
|
|||||||
is KotlinChangeInfo -> changeInfo
|
is KotlinChangeInfo -> changeInfo
|
||||||
is JavaChangeInfo -> {
|
is JavaChangeInfo -> {
|
||||||
val method = changeInfo.method as? KtLightMethod ?: return false
|
val method = changeInfo.method as? KtLightMethod ?: return false
|
||||||
var baseFunction = method.getOrigin() ?: return false
|
var baseFunction = method.kotlinOrigin ?: return false
|
||||||
if (baseFunction is KtClass) {
|
if (baseFunction is KtClass) {
|
||||||
baseFunction = baseFunction.createPrimaryConstructorIfAbsent()
|
baseFunction = baseFunction.createPrimaryConstructorIfAbsent()
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -64,7 +64,10 @@ import org.jetbrains.kotlin.idea.refactoring.move.postProcessMoveUsages
|
|||||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference.ShorteningMode
|
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference.ShorteningMode
|
||||||
import org.jetbrains.kotlin.idea.search.projectScope
|
import org.jetbrains.kotlin.idea.search.projectScope
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.isInsideOf
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||||
@@ -359,7 +362,7 @@ class MoveKotlinDeclarationsProcessor(
|
|||||||
if (e1 === e2) return true
|
if (e1 === e2) return true
|
||||||
// Name should be enough to distinguish different light elements based on the same original declaration
|
// Name should be enough to distinguish different light elements based on the same original declaration
|
||||||
if (e1 is KtLightElement<*, *> && e2 is KtLightElement<*, *>) {
|
if (e1 is KtLightElement<*, *> && e2 is KtLightElement<*, *>) {
|
||||||
return e1.getOrigin() == e2.getOrigin() && e1.name == e2.name
|
return e1.kotlinOrigin == e2.kotlinOrigin && e1.name == e2.name
|
||||||
}
|
}
|
||||||
return e1 == e2
|
return e1 == e2
|
||||||
}
|
}
|
||||||
@@ -367,7 +370,7 @@ class MoveKotlinDeclarationsProcessor(
|
|||||||
override fun computeHashCode(e: PsiElement?): Int {
|
override fun computeHashCode(e: PsiElement?): Int {
|
||||||
return when (e) {
|
return when (e) {
|
||||||
null -> 0
|
null -> 0
|
||||||
is KtLightElement<*, *> -> (e.getOrigin()?.hashCode() ?: 0) * 31 + (e.name?.hashCode() ?: 0)
|
is KtLightElement<*, *> -> (e.kotlinOrigin?.hashCode() ?: 0) * 31 + (e.name?.hashCode() ?: 0)
|
||||||
else -> e.hashCode()
|
else -> e.hashCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -115,7 +115,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isAccepted(PsiClass aClass) {
|
public boolean isAccepted(PsiClass aClass) {
|
||||||
if (!(aClass instanceof KtLightClassForExplicitDeclaration)) return false;
|
if (!(aClass instanceof KtLightClassForExplicitDeclaration)) return false;
|
||||||
KtClassOrObject classOrObject = ((KtLightClassForExplicitDeclaration) aClass).getOrigin();
|
KtClassOrObject classOrObject = ((KtLightClassForExplicitDeclaration) aClass).getKotlinOrigin();
|
||||||
|
|
||||||
if (classOrObject instanceof KtObjectDeclaration) {
|
if (classOrObject instanceof KtObjectDeclaration) {
|
||||||
return !((KtObjectDeclaration) classOrObject).isObjectLiteral();
|
return !((KtObjectDeclaration) classOrObject).isObjectLiteral();
|
||||||
@@ -149,7 +149,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog {
|
|||||||
|
|
||||||
PsiClass aClass = chooser.getSelected();
|
PsiClass aClass = chooser.getSelected();
|
||||||
if (aClass instanceof KtLightClassForExplicitDeclaration) {
|
if (aClass instanceof KtLightClassForExplicitDeclaration) {
|
||||||
targetClass = ((KtLightClassForExplicitDeclaration) aClass).getOrigin();
|
targetClass = ((KtLightClassForExplicitDeclaration) aClass).getKotlinOrigin();
|
||||||
targetClassChooser.setText(aClass.getQualifiedName());
|
targetClassChooser.setText(aClass.getQualifiedName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog {
|
|||||||
.getInstance(myProject)
|
.getInstance(myProject)
|
||||||
.findClass(targetClassChooser.getText(), GlobalSearchScope.projectScope(myProject));
|
.findClass(targetClassChooser.getText(), GlobalSearchScope.projectScope(myProject));
|
||||||
targetClass = aClass instanceof KtLightClassForExplicitDeclaration
|
targetClass = aClass instanceof KtLightClassForExplicitDeclaration
|
||||||
? ((KtLightClassForExplicitDeclaration) aClass).getOrigin()
|
? ((KtLightClassForExplicitDeclaration) aClass).getKotlinOrigin()
|
||||||
: null;
|
: null;
|
||||||
validateButtons();
|
validateButtons();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -74,7 +74,7 @@ class RenameKotlinClassProcessor : RenameKotlinPsiProcessor() {
|
|||||||
private fun getKtClassOrObject(element: PsiElement?, showErrors: Boolean, editor: Editor?): KtClassOrObject? = when (element) {
|
private fun getKtClassOrObject(element: PsiElement?, showErrors: Boolean, editor: Editor?): KtClassOrObject? = when (element) {
|
||||||
is KtLightClass ->
|
is KtLightClass ->
|
||||||
if (element is KtLightClassForExplicitDeclaration) {
|
if (element is KtLightClassForExplicitDeclaration) {
|
||||||
element.getOrigin()
|
element.kotlinOrigin
|
||||||
}
|
}
|
||||||
else if (element is KtLightClassForFacade) {
|
else if (element is KtLightClassForFacade) {
|
||||||
if (showErrors) {
|
if (showErrors) {
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -37,7 +37,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
|||||||
private val javaMethodProcessorInstance = RenameJavaMethodProcessor()
|
private val javaMethodProcessorInstance = RenameJavaMethodProcessor()
|
||||||
|
|
||||||
override fun canProcessElement(element: PsiElement): Boolean {
|
override fun canProcessElement(element: PsiElement): Boolean {
|
||||||
return element is KtNamedFunction || (element is KtLightMethod && element.getOrigin() is KtNamedFunction)
|
return element is KtNamedFunction || (element is KtLightMethod && element.kotlinOrigin is KtNamedFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun substituteElementToRename(element: PsiElement?, editor: Editor?): PsiElement? {
|
override fun substituteElementToRename(element: PsiElement?, editor: Editor?): PsiElement? {
|
||||||
@@ -47,7 +47,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
|||||||
val substitutedJavaElement = javaMethodProcessorInstance.substituteElementToRename(wrappedMethod, editor)
|
val substitutedJavaElement = javaMethodProcessorInstance.substituteElementToRename(wrappedMethod, editor)
|
||||||
|
|
||||||
return when (substitutedJavaElement) {
|
return when (substitutedJavaElement) {
|
||||||
is KtLightMethod -> substitutedJavaElement.getOrigin() as? KtNamedFunction
|
is KtLightMethod -> substitutedJavaElement.kotlinOrigin as? KtNamedFunction
|
||||||
else -> substitutedJavaElement
|
else -> substitutedJavaElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -314,7 +314,7 @@ public class JetRunConfiguration extends ModuleBasedConfiguration<RunConfigurati
|
|||||||
public KtNamedFunction invoke(PsiMethod method) {
|
public KtNamedFunction invoke(PsiMethod method) {
|
||||||
if (!(method instanceof KtLightMethod)) return null;
|
if (!(method instanceof KtLightMethod)) return null;
|
||||||
|
|
||||||
KtDeclaration declaration = ((KtLightMethod) method).getOrigin();
|
KtDeclaration declaration = ((KtLightMethod) method).getKotlinOrigin();
|
||||||
return declaration instanceof KtNamedFunction ? (KtNamedFunction) declaration : null;
|
return declaration instanceof KtNamedFunction ? (KtNamedFunction) declaration : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -145,7 +145,7 @@ public class KotlinDefinitionsSearcher implements QueryExecutor<PsiElement, Defi
|
|||||||
if (isDelegated(implementation)) continue;
|
if (isDelegated(implementation)) continue;
|
||||||
|
|
||||||
PsiElement mirrorElement = implementation instanceof KtLightMethod
|
PsiElement mirrorElement = implementation instanceof KtLightMethod
|
||||||
? ((KtLightMethod) implementation).getOrigin() : null;
|
? ((KtLightMethod) implementation).getKotlinOrigin() : null;
|
||||||
if (mirrorElement instanceof KtProperty || mirrorElement instanceof KtParameter) {
|
if (mirrorElement instanceof KtProperty || mirrorElement instanceof KtParameter) {
|
||||||
if (!consumer.process(mirrorElement)) {
|
if (!consumer.process(mirrorElement)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -38,7 +38,7 @@ class KotlinOverridingMethodsWithGenericsSearcher : QueryExecutor<PsiMethod, Ove
|
|||||||
val method = p.method
|
val method = p.method
|
||||||
if (method !is KtLightMethod) return true
|
if (method !is KtLightMethod) return true
|
||||||
|
|
||||||
val declaration = method.getOrigin() as? KtCallableDeclaration
|
val declaration = method.kotlinOrigin as? KtCallableDeclaration
|
||||||
if (declaration == null) return true
|
if (declaration == null) return true
|
||||||
|
|
||||||
val callDescriptor = runReadAction { declaration.resolveToDescriptor() }
|
val callDescriptor = runReadAction { declaration.resolveToDescriptor() }
|
||||||
@@ -67,7 +67,7 @@ class KotlinOverridingMethodsWithGenericsSearcher : QueryExecutor<PsiMethod, Ove
|
|||||||
val methodsByName = inheritor.findMethodsByName(name, false)
|
val methodsByName = inheritor.findMethodsByName(name, false)
|
||||||
|
|
||||||
for (lightMethodCandidate in methodsByName) {
|
for (lightMethodCandidate in methodsByName) {
|
||||||
val candidateDescriptor = (lightMethodCandidate as? KtLightMethod)?.getOrigin()?.resolveToDescriptor() ?: continue
|
val candidateDescriptor = (lightMethodCandidate as? KtLightMethod)?.kotlinOrigin?.resolveToDescriptor() ?: continue
|
||||||
if (candidateDescriptor !is CallableMemberDescriptor) continue
|
if (candidateDescriptor !is CallableMemberDescriptor) continue
|
||||||
|
|
||||||
val overriddenDescriptors = OverrideResolver.getDirectlyOverriddenDeclarations(candidateDescriptor)
|
val overriddenDescriptors = OverrideResolver.getDirectlyOverriddenDeclarations(candidateDescriptor)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -132,7 +132,7 @@ class KotlinCreateTestIntention : SelfTargetingRangeIntention<KtNamedDeclaration
|
|||||||
val dialog = KotlinCreateTestDialog(project, text, srcClass, srcPackage, srcModule)
|
val dialog = KotlinCreateTestDialog(project, text, srcClass, srcPackage, srcModule)
|
||||||
if (!dialog.showAndGet()) return
|
if (!dialog.showAndGet()) return
|
||||||
|
|
||||||
val existingClass = (findTestClass(dialog.targetDirectory, dialog.className) as? KtLightClass)?.getOrigin()
|
val existingClass = (findTestClass(dialog.targetDirectory, dialog.className) as? KtLightClass)?.kotlinOrigin
|
||||||
if (existingClass != null) {
|
if (existingClass != null) {
|
||||||
// TODO: Override dialog method when it becomes protected
|
// TODO: Override dialog method when it becomes protected
|
||||||
val answer = Messages.showYesNoDialog(
|
val answer = Messages.showYesNoDialog(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -279,7 +279,7 @@ public class KotlinJavaFacadeTest extends KotlinLightCodeInsightFixtureTestCase
|
|||||||
if (shouldBeWrapped) {
|
if (shouldBeWrapped) {
|
||||||
assertNotNull(String.format("Failed to wrap declaration '%s' to method", declaration.getText()), psiMethod);
|
assertNotNull(String.format("Failed to wrap declaration '%s' to method", declaration.getText()), psiMethod);
|
||||||
assertInstanceOf(psiMethod, KtLightMethod.class);
|
assertInstanceOf(psiMethod, KtLightMethod.class);
|
||||||
assertEquals("Invalid original element for generated method", ((KtLightMethod) psiMethod).getOrigin(), declaration);
|
assertEquals("Invalid original element for generated method", ((KtLightMethod) psiMethod).getKotlinOrigin(), declaration);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assertNull("There should be no wrapper for given method", psiMethod);
|
assertNull("There should be no wrapper for given method", psiMethod);
|
||||||
@@ -304,7 +304,7 @@ public class KotlinJavaFacadeTest extends KotlinLightCodeInsightFixtureTestCase
|
|||||||
|
|
||||||
// This invokes codegen with ClassBuilderMode = LIGHT_CLASSES
|
// This invokes codegen with ClassBuilderMode = LIGHT_CLASSES
|
||||||
// No exception/error should happen here
|
// No exception/error should happen here
|
||||||
lightClass.getDelegate();
|
lightClass.getClsDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -43,7 +43,7 @@ public class LightClassEqualsTest extends KotlinLightCodeInsightFixtureTestCase
|
|||||||
assertNotNull(theClass);
|
assertNotNull(theClass);
|
||||||
assertInstanceOf(theClass, KtLightClassForExplicitDeclaration.class);
|
assertInstanceOf(theClass, KtLightClassForExplicitDeclaration.class);
|
||||||
|
|
||||||
doTestEquals(((KtLightClass) theClass).getOrigin());
|
doTestEquals(((KtLightClass) theClass).getKotlinOrigin());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEqualsForDecompiledClass() throws Exception {
|
public void testEqualsForDecompiledClass() throws Exception {
|
||||||
@@ -53,7 +53,7 @@ public class LightClassEqualsTest extends KotlinLightCodeInsightFixtureTestCase
|
|||||||
assertNotNull(theClass);
|
assertNotNull(theClass);
|
||||||
assertInstanceOf(theClass, KtLightClassForDecompiledDeclaration.class);
|
assertInstanceOf(theClass, KtLightClassForDecompiledDeclaration.class);
|
||||||
|
|
||||||
doTestEquals(((KtLightClass) theClass).getOrigin());
|
doTestEquals(((KtLightClass) theClass).getKotlinOrigin());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doTestEquals(@Nullable KtClassOrObject origin) {
|
private static void doTestEquals(@Nullable KtClassOrObject origin) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -326,7 +326,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
|||||||
val typeArguments = convertTypeArguments(expression)
|
val typeArguments = convertTypeArguments(expression)
|
||||||
|
|
||||||
if (target is KtLightMethod) {
|
if (target is KtLightMethod) {
|
||||||
val origin = target.getOrigin()
|
val origin = target.kotlinOrigin
|
||||||
val isTopLevel = origin?.getStrictParentOfType<KtClassOrObject>() == null
|
val isTopLevel = origin?.getStrictParentOfType<KtClassOrObject>() == null
|
||||||
if (origin is KtProperty || origin is KtPropertyAccessor || origin is KtParameter) {
|
if (origin is KtProperty || origin is KtPropertyAccessor || origin is KtParameter) {
|
||||||
val property = if (origin is KtPropertyAccessor)
|
val property = if (origin is KtPropertyAccessor)
|
||||||
@@ -429,7 +429,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun KtLightMethod.isKotlinExtensionFunction(): Boolean {
|
private fun KtLightMethod.isKotlinExtensionFunction(): Boolean {
|
||||||
val origin = this.getOrigin()
|
val origin = this.kotlinOrigin
|
||||||
if (origin != null) return origin.isExtensionDeclaration()
|
if (origin != null) return origin.isExtensionDeclaration()
|
||||||
|
|
||||||
val parameters = parameterList.parameters
|
val parameters = parameterList.parameters
|
||||||
@@ -539,7 +539,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
|||||||
identifier = Identifier("size", isNullable).assignNoPrototype()
|
identifier = Identifier("size", isNullable).assignNoPrototype()
|
||||||
}
|
}
|
||||||
else if (qualifier != null) {
|
else if (qualifier != null) {
|
||||||
if (target is KtLightField && target.getOrigin() is KtObjectDeclaration) {
|
if (target is KtLightField && target.kotlinOrigin is KtObjectDeclaration) {
|
||||||
result = codeConverter.convertExpression(qualifier)
|
result = codeConverter.convertExpression(qualifier)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -380,7 +380,7 @@ class TypeConverter(val converter: Converter) {
|
|||||||
|
|
||||||
override fun fromAnnotations(owner: PsiModifierListOwner): Mutability {
|
override fun fromAnnotations(owner: PsiModifierListOwner): Mutability {
|
||||||
if (owner is KtLightElement<*, *>) {
|
if (owner is KtLightElement<*, *>) {
|
||||||
val jetDeclaration = owner.getOrigin() as? KtCallableDeclaration ?: return Mutability.Default
|
val jetDeclaration = owner.kotlinOrigin as? KtCallableDeclaration ?: return Mutability.Default
|
||||||
val descriptor = converter.services.resolverForConverter.resolveToDescriptor(jetDeclaration) as? CallableDescriptor ?: return Mutability.Default
|
val descriptor = converter.services.resolverForConverter.resolveToDescriptor(jetDeclaration) as? CallableDescriptor ?: return Mutability.Default
|
||||||
val type = descriptor.returnType ?: return Mutability.Default
|
val type = descriptor.returnType ?: return Mutability.Default
|
||||||
val classDescriptor = TypeUtils.getClassDescriptor(type) ?: return Mutability.Default
|
val classDescriptor = TypeUtils.getClassDescriptor(type) ?: return Mutability.Default
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -128,4 +128,4 @@ fun PsiMember.isImported(file: PsiJavaFile): Boolean {
|
|||||||
fun PsiExpression.isNullLiteral() = this is PsiLiteralExpression && type == PsiType.NULL
|
fun PsiExpression.isNullLiteral() = this is PsiLiteralExpression && type == PsiType.NULL
|
||||||
|
|
||||||
// TODO: set origin for facade classes in library
|
// TODO: set origin for facade classes in library
|
||||||
fun isFacadeClassFromLibrary(element: PsiElement?) = element is KtLightClass && element.getOrigin() == null
|
fun isFacadeClassFromLibrary(element: PsiElement?) = element is KtLightClass && element.kotlinOrigin == null
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -367,7 +367,7 @@ private class PropertyDetector(
|
|||||||
return if (propertyInfo != null) SuperInfo.Property(propertyInfo.isVar, propertyInfo.name) else SuperInfo.Function
|
return if (propertyInfo != null) SuperInfo.Property(propertyInfo.isVar, propertyInfo.name) else SuperInfo.Function
|
||||||
}
|
}
|
||||||
else if (superMethod is KtLightMethod) {
|
else if (superMethod is KtLightMethod) {
|
||||||
val origin = superMethod.getOrigin()
|
val origin = superMethod.kotlinOrigin
|
||||||
return if (origin is KtProperty) SuperInfo.Property(origin.isVar, origin.name ?: "") else SuperInfo.Function
|
return if (origin is KtProperty) SuperInfo.Property(origin.isVar, origin.name ?: "") else SuperInfo.Function
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user