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");
|
||||
* 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;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass getClsDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtClassOrObject getOrigin() {
|
||||
public KtClassOrObject getKotlinOrigin() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,20 +24,17 @@ import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
|
||||
class KtLightAnnotation(
|
||||
private val delegate: PsiAnnotation,
|
||||
private val originalElement: KtAnnotationEntry,
|
||||
override val clsDelegate: PsiAnnotation,
|
||||
override val kotlinOrigin: KtAnnotationEntry,
|
||||
private val owner: PsiAnnotationOwner
|
||||
) : PsiAnnotation by delegate, KtLightElement<KtAnnotationEntry, PsiAnnotation> {
|
||||
override fun getDelegate() = delegate
|
||||
override fun getOrigin() = originalElement
|
||||
|
||||
) : PsiAnnotation by clsDelegate, KtLightElement<KtAnnotationEntry, PsiAnnotation> {
|
||||
override fun getName() = null
|
||||
override fun setName(newName: String) = throw IncorrectOperationException()
|
||||
|
||||
override fun getOwner() = owner
|
||||
|
||||
override fun getText() = originalElement.text ?: ""
|
||||
override fun getTextRange() = originalElement.textRange ?: TextRange.EMPTY_RANGE
|
||||
override fun getText() = kotlinOrigin.text ?: ""
|
||||
override fun getTextRange() = kotlinOrigin.textRange ?: TextRange.EMPTY_RANGE
|
||||
|
||||
override fun getParent() = owner as? PsiElement
|
||||
|
||||
@@ -46,8 +43,8 @@ class KtLightAnnotation(
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
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");
|
||||
* 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 classOrObject: KtClassOrObject)
|
||||
: KtWrappingLightClass(classOrObject.manager), KtJavaMirrorMarker, StubBasedPsiElement<KotlinClassOrObjectStub<out KtClassOrObject>> {
|
||||
private var delegate: PsiClass? = null
|
||||
|
||||
private val lightIdentifier = KtLightIdentifier(this, classOrObject)
|
||||
|
||||
private fun getLocalClassParent(): PsiElement? {
|
||||
@@ -139,7 +137,7 @@ open class KtLightClassForExplicitDeclaration(
|
||||
containingClass
|
||||
}
|
||||
|
||||
override fun getOrigin(): KtClassOrObject = classOrObject
|
||||
override val kotlinOrigin: KtClassOrObject = classOrObject
|
||||
|
||||
override fun getFqName(): FqName = classFqName
|
||||
|
||||
@@ -147,28 +145,21 @@ open class KtLightClassForExplicitDeclaration(
|
||||
return KtLightClassForExplicitDeclaration(classFqName, classOrObject.copy() as KtClassOrObject)
|
||||
}
|
||||
|
||||
override fun getDelegate(): PsiClass {
|
||||
if (delegate == null) {
|
||||
val javaFileStub = getJavaFileStub()
|
||||
override val clsDelegate: PsiClass by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
val javaFileStub = getJavaFileStub()
|
||||
|
||||
val psiClass = LightClassUtil.findClass(classFqName, javaFileStub)
|
||||
if (psiClass == null) {
|
||||
val outermostClassOrObject = getOutermostClassOrObject(classOrObject)
|
||||
val ktFileText: String? = try {
|
||||
outermostClassOrObject.containingFile.text
|
||||
}
|
||||
catch (e: Exception) {
|
||||
"Can't get text for outermost class"
|
||||
}
|
||||
|
||||
val stubFileText = DebugUtil.stubTreeToString(javaFileStub)
|
||||
|
||||
throw IllegalStateException("Class was not found $classFqName\nin $ktFileText\nstub: \n$stubFileText")
|
||||
LightClassUtil.findClass(classFqName, javaFileStub) ?: run {
|
||||
val outermostClassOrObject = getOutermostClassOrObject(classOrObject)
|
||||
val ktFileText: String? = try {
|
||||
outermostClassOrObject.containingFile.text
|
||||
}
|
||||
catch (e: Exception) {
|
||||
"Can't get text for outermost class"
|
||||
}
|
||||
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
|
||||
@@ -380,7 +371,7 @@ open class KtLightClassForExplicitDeclaration(
|
||||
|
||||
@Throws(IncorrectOperationException::class)
|
||||
override fun setName(@NonNls name: String): PsiElement {
|
||||
getOrigin().setName(name)
|
||||
kotlinOrigin.setName(name)
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -396,7 +387,7 @@ open class KtLightClassForExplicitDeclaration(
|
||||
return result
|
||||
}
|
||||
|
||||
override fun getUseScope(): SearchScope = getOrigin().useScope
|
||||
override fun getUseScope(): SearchScope = kotlinOrigin.useScope
|
||||
|
||||
override fun getElementType(): IStubElementType<out StubElement<*>, *>? = classOrObject.elementType
|
||||
override fun getStub(): KotlinClassOrObjectStub<out KtClassOrObject>? = classOrObject.stub
|
||||
|
||||
@@ -92,7 +92,7 @@ class KtLightClassForFacade private constructor(
|
||||
stub = { lightClassDataCache.value.javaFileStub }
|
||||
)
|
||||
|
||||
override fun getOrigin(): KtClassOrObject? = null
|
||||
override val kotlinOrigin: KtClassOrObject? get() = null
|
||||
|
||||
override fun getFqName(): FqName = facadeClassFqName
|
||||
|
||||
@@ -146,11 +146,12 @@ class KtLightClassForFacade private constructor(
|
||||
|
||||
override fun copy() = KtLightClassForFacade(getManager(), facadeClassFqName, lightClassDataCache, files)
|
||||
|
||||
override fun getDelegate(): PsiClass {
|
||||
val psiClass = LightClassUtil.findClass(facadeClassFqName, lightClassDataCache.value.javaFileStub)
|
||||
?: throw IllegalStateException("Facade class $facadeClassFqName not found")
|
||||
return psiClass
|
||||
}
|
||||
override val clsDelegate: PsiClass
|
||||
get() {
|
||||
val psiClass = LightClassUtil.findClass(facadeClassFqName, lightClassDataCache.value.javaFileStub)
|
||||
?: throw IllegalStateException("Facade class $facadeClassFqName not found")
|
||||
return psiClass
|
||||
}
|
||||
|
||||
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");
|
||||
* 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
|
||||
|
||||
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>
|
||||
@@ -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");
|
||||
* 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
|
||||
sealed class KtLightFieldImpl(
|
||||
private val origin: KtDeclaration?,
|
||||
private val delegate: PsiField,
|
||||
private val lightMemberOrigin: LightMemberOrigin?,
|
||||
override val clsDelegate: PsiField,
|
||||
private val containingClass: KtLightClass
|
||||
) : LightElement(delegate.manager, KotlinLanguage.INSTANCE), KtLightField {
|
||||
private val lightIdentifier = KtLightIdentifier(this, origin as? KtNamedDeclaration)
|
||||
) : LightElement(clsDelegate.manager, KotlinLanguage.INSTANCE), KtLightField {
|
||||
private val lightIdentifier by lazy { KtLightIdentifier(this, kotlinOrigin as? KtNamedDeclaration) }
|
||||
|
||||
@Throws(IncorrectOperationException::class)
|
||||
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 getDocComment() = delegate.docComment
|
||||
override fun getDocComment() = clsDelegate.docComment
|
||||
|
||||
override fun isDeprecated() = delegate.isDeprecated
|
||||
override fun isDeprecated() = clsDelegate.isDeprecated
|
||||
|
||||
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)
|
||||
override fun normalizeDeclaration() = throw IncorrectOperationException("Not supported")
|
||||
|
||||
override fun computeConstantValue() = delegate.computeConstantValue()
|
||||
override fun computeConstantValue() = clsDelegate.computeConstantValue()
|
||||
|
||||
@Throws(IncorrectOperationException::class)
|
||||
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 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 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 {
|
||||
if (another is KtLightField && origin == another.getOrigin() && delegate == another.getDelegate()) {
|
||||
if (another is KtLightField && kotlinOrigin == another.kotlinOrigin && clsDelegate == another.clsDelegate) {
|
||||
return true
|
||||
}
|
||||
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(
|
||||
origin: KtEnumEntry?,
|
||||
enumConstant: PsiEnumConstant,
|
||||
origin: LightMemberOrigin?,
|
||||
override val clsDelegate: PsiEnumConstant,
|
||||
containingClass: KtLightClass,
|
||||
private val initializingClass: PsiEnumConstantInitializer?
|
||||
) : KtLightFieldImpl(origin, enumConstant, containingClass), PsiEnumConstant {
|
||||
override fun getDelegate() = super.getDelegate() as PsiEnumConstant
|
||||
|
||||
) : KtLightFieldImpl(origin, clsDelegate, containingClass), PsiEnumConstant {
|
||||
// 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
|
||||
override fun getArgumentList() = getDelegate().argumentList
|
||||
override fun getArgumentList() = clsDelegate.argumentList
|
||||
|
||||
override fun getInitializingClass(): PsiEnumConstantInitializer? = initializingClass
|
||||
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 resolveMethod() = getDelegate().resolveMethod()
|
||||
override fun resolveMethodGenerics() = getDelegate().resolveMethodGenerics()
|
||||
override fun resolveConstructor() = clsDelegate.resolveConstructor()
|
||||
override fun resolveMethod() = clsDelegate.resolveMethod()
|
||||
override fun resolveMethodGenerics() = clsDelegate.resolveMethodGenerics()
|
||||
}
|
||||
|
||||
class KtLightFieldForDeclaration(origin: KtDeclaration?, delegate: PsiField, containingClass: KtLightClass)
|
||||
: KtLightFieldImpl(origin, delegate, containingClass)
|
||||
class KtLightFieldForDeclaration(origin: LightMemberOrigin?, delegate: PsiField, containingClass: KtLightClass) :
|
||||
KtLightFieldImpl(origin, delegate, containingClass)
|
||||
|
||||
companion object Factory {
|
||||
fun create(origin: KtDeclaration?, delegate: PsiField, containingClass: KtLightClass): KtLightField {
|
||||
fun create(origin: LightMemberOrigin?, delegate: PsiField, containingClass: KtLightClass): KtLightField {
|
||||
when (delegate) {
|
||||
is PsiEnumConstant -> {
|
||||
val kotlinEnumEntry = origin as? KtEnumEntry
|
||||
val kotlinEnumEntry = origin?.originalElement as? KtEnumEntry
|
||||
val initializingClass = if (kotlinEnumEntry != null && kotlinEnumEntry.declarations.isNotEmpty()) {
|
||||
val enumConstantFqName = FqName(containingClass.getFqName().asString() + "." + kotlinEnumEntry.name)
|
||||
KtLightClassForEnumEntry(enumConstantFqName, kotlinEnumEntry, delegate)
|
||||
}
|
||||
else null
|
||||
return KtLightEnumConstant(kotlinEnumEntry, delegate, containingClass, initializingClass)
|
||||
return KtLightEnumConstant(origin, delegate, containingClass, initializingClass)
|
||||
}
|
||||
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");
|
||||
* 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(
|
||||
private val delegate: PsiMethod,
|
||||
override val clsDelegate: PsiMethod,
|
||||
private val lightMethodOrigin: LightMemberOrigin?,
|
||||
containingClass: KtLightClass
|
||||
) : LightMethod(delegate.manager, delegate, containingClass), KtLightMethod {
|
||||
private val origin = lightMethodOrigin?.originalElement as? KtDeclaration
|
||||
) : LightMethod(clsDelegate.manager, clsDelegate, containingClass), KtLightMethod {
|
||||
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
|
||||
|
||||
private val paramsList: CachedValue<PsiParameterList> by lazy {
|
||||
val cacheManager = CachedValuesManager.getManager(delegate.project)
|
||||
val cacheManager = CachedValuesManager.getManager(clsDelegate.project)
|
||||
cacheManager.createCachedValue<PsiParameterList>({
|
||||
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))
|
||||
}
|
||||
|
||||
@@ -56,13 +56,14 @@ sealed class KtLightMethodImpl(
|
||||
}
|
||||
|
||||
private val typeParamsList: CachedValue<PsiTypeParameterList> by lazy {
|
||||
val cacheManager = CachedValuesManager.getManager(delegate.project)
|
||||
val cacheManager = CachedValuesManager.getManager(clsDelegate.project)
|
||||
cacheManager.createCachedValue<PsiTypeParameterList>({
|
||||
val origin = kotlinOrigin
|
||||
val list = if (origin is KtClassOrObject) {
|
||||
KotlinLightTypeParameterListBuilder(manager)
|
||||
}
|
||||
else if (origin == null) {
|
||||
delegate.typeParameterList
|
||||
clsDelegate.typeParameterList
|
||||
}
|
||||
else {
|
||||
LightClassUtil.buildLightTypeParameterList(this@KtLightMethodImpl, origin)
|
||||
@@ -71,13 +72,11 @@ sealed class KtLightMethodImpl(
|
||||
}, false)
|
||||
}
|
||||
|
||||
override fun getNavigationElement(): PsiElement = origin ?: super.getNavigationElement()
|
||||
override fun getOriginalElement(): PsiElement = origin ?: super.getOriginalElement()
|
||||
override fun getDelegate() = delegate
|
||||
override fun getOrigin() = origin
|
||||
override fun getNavigationElement(): PsiElement = kotlinOrigin?.navigationElement ?: super.getNavigationElement()
|
||||
override fun getOriginalElement(): PsiElement = kotlinOrigin ?: super.getOriginalElement()
|
||||
override fun getParent(): PsiElement? = containingClass
|
||||
override fun getText() = origin?.text ?: ""
|
||||
override fun getTextRange() = origin?.textRange ?: TextRange.EMPTY_RANGE
|
||||
override fun getText() = kotlinOrigin?.text ?: ""
|
||||
override fun getTextRange() = kotlinOrigin?.textRange ?: TextRange.EMPTY_RANGE
|
||||
|
||||
override val isDelegated: Boolean
|
||||
get() = lightMethodOrigin?.originKind == JvmDeclarationOriginKind.DELEGATION
|
||||
@@ -93,13 +92,13 @@ sealed class KtLightMethodImpl(
|
||||
}
|
||||
|
||||
override fun setName(name: String): PsiElement? {
|
||||
val toRename = origin as? PsiNamedElement ?: throwCanNotModify()
|
||||
val toRename = kotlinOrigin as? PsiNamedElement ?: throwCanNotModify()
|
||||
toRename.setName(name)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun delete() {
|
||||
origin?.let {
|
||||
kotlinOrigin?.let {
|
||||
if (it.isValid) {
|
||||
it.delete()
|
||||
}
|
||||
@@ -110,7 +109,7 @@ sealed class KtLightMethodImpl(
|
||||
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
|
||||
|
||||
@@ -125,16 +124,16 @@ sealed class KtLightMethodImpl(
|
||||
|
||||
override fun getSignature(substitutor: PsiSubstitutor): MethodSignature {
|
||||
if (substitutor == PsiSubstitutor.EMPTY) {
|
||||
return delegate.getSignature(substitutor)
|
||||
return clsDelegate.getSignature(substitutor)
|
||||
}
|
||||
return MethodSignatureBackedByPsiMethod.create(this, substitutor)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -143,7 +142,7 @@ sealed class KtLightMethodImpl(
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -153,11 +152,11 @@ sealed class KtLightMethodImpl(
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is KtLightMethod &&
|
||||
name == other.name &&
|
||||
origin == other.getOrigin() &&
|
||||
kotlinOrigin == other.kotlinOrigin &&
|
||||
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"
|
||||
|
||||
@@ -166,12 +165,11 @@ sealed class KtLightMethodImpl(
|
||||
) : KtLightMethodImpl(delegate, origin, containingClass)
|
||||
|
||||
private class KtLightAnnotationMethod(
|
||||
delegate: PsiAnnotationMethod,
|
||||
override val clsDelegate: PsiAnnotationMethod,
|
||||
origin: LightMemberOrigin?,
|
||||
containingClass: KtLightClass
|
||||
) : KtLightMethodImpl(delegate, origin, containingClass), PsiAnnotationMethod {
|
||||
override fun getDefaultValue() = getDelegate().defaultValue
|
||||
override fun getDelegate() = super.getDelegate() as PsiAnnotationMethod
|
||||
) : KtLightMethodImpl(clsDelegate, origin, containingClass), PsiAnnotationMethod {
|
||||
override fun getDefaultValue() = clsDelegate.defaultValue
|
||||
}
|
||||
|
||||
companion object Factory {
|
||||
@@ -187,13 +185,13 @@ sealed class KtLightMethodImpl(
|
||||
}
|
||||
|
||||
fun KtLightMethod.isTraitFakeOverride(): Boolean {
|
||||
val methodOrigin = this.getOrigin()
|
||||
val methodOrigin = this.kotlinOrigin
|
||||
if (!(methodOrigin is KtNamedFunction || methodOrigin is KtPropertyAccessor || methodOrigin is KtProperty)) {
|
||||
return false
|
||||
}
|
||||
|
||||
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
|
||||
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)
|
||||
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 ktAnnotations = descriptor?.annotations?.getAllAnnotations() ?: emptyList()
|
||||
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");
|
||||
* 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 int index;
|
||||
private final KtLightMethod method;
|
||||
private final KtLightIdentifier lightIdentifier;
|
||||
private KtLightIdentifier lightIdentifier = null;
|
||||
|
||||
public KtLightParameter(final PsiParameter delegate, int index, KtLightMethod method) {
|
||||
super(getName(delegate, index), delegate.getType(), method, KotlinLanguage.INSTANCE);
|
||||
@@ -56,8 +56,6 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
||||
return delegate.getModifierList();
|
||||
}
|
||||
};
|
||||
|
||||
lightIdentifier = new KtLightIdentifier(this, getOrigin());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -68,14 +66,14 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiParameter getDelegate() {
|
||||
public PsiParameter getClsDelegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public KtParameter getOrigin() {
|
||||
KtDeclaration declaration = method.getOrigin();
|
||||
public KtParameter getKotlinOrigin() {
|
||||
KtDeclaration declaration = method.getKotlinOrigin();
|
||||
if (declaration == null) return null;
|
||||
|
||||
int jetIndex = KtPsiUtilKt.isExtensionDeclaration(declaration) ? index - 1 : index;
|
||||
@@ -103,13 +101,13 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getNavigationElement() {
|
||||
KtParameter origin = getOrigin();
|
||||
KtParameter origin = getKotlinOrigin();
|
||||
return origin != null ? origin : super.getNavigationElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||
KtParameter origin = getOrigin();
|
||||
KtParameter origin = getKotlinOrigin();
|
||||
if (origin != null) {
|
||||
origin.setName(name);
|
||||
}
|
||||
@@ -118,7 +116,7 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
||||
|
||||
@Override
|
||||
public PsiFile getContainingFile() {
|
||||
KtDeclaration declaration = method.getOrigin();
|
||||
KtDeclaration declaration = method.getKotlinOrigin();
|
||||
return declaration != null ? declaration.getContainingFile() : super.getContainingFile();
|
||||
}
|
||||
|
||||
@@ -131,7 +129,7 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
||||
@NotNull
|
||||
@Override
|
||||
public SearchScope getUseScope() {
|
||||
KtParameter origin = getOrigin();
|
||||
KtParameter origin = getKotlinOrigin();
|
||||
return origin != null ? origin.getUseScope() : GlobalSearchScope.EMPTY_SCOPE;
|
||||
}
|
||||
|
||||
@@ -146,6 +144,9 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
||||
|
||||
@Override
|
||||
public PsiIdentifier getNameIdentifier() {
|
||||
if (lightIdentifier == null) {
|
||||
lightIdentifier = new KtLightIdentifier(this, getKotlinOrigin());
|
||||
}
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,13 +44,19 @@ public class KtLightTypeParameter
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiTypeParameter getDelegate() {
|
||||
public PsiTypeParameter getClsDelegate() {
|
||||
return getOwnerDelegate().getTypeParameters()[index];
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KtTypeParameter getOrigin() {
|
||||
public PsiClass getDelegate() {
|
||||
return getClsDelegate();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public KtTypeParameter getKotlinOrigin() {
|
||||
KtTypeParameterListOwner jetOwner = (KtTypeParameterListOwner) LightClassUtilsKt.getUnwrapped(owner);
|
||||
assert (jetOwner != null) : "Invalid type parameter owner: " + owner;
|
||||
|
||||
@@ -59,8 +65,8 @@ public class KtLightTypeParameter
|
||||
|
||||
@NotNull
|
||||
private PsiTypeParameterListOwner getOwnerDelegate() {
|
||||
if (owner instanceof KtLightClass) return ((KtLightClass) owner).getDelegate();
|
||||
if (owner instanceof KtLightMethod) return ((KtLightMethod) owner).getDelegate();
|
||||
if (owner instanceof KtLightClass) return ((KtLightClass) owner).getClsDelegate();
|
||||
if (owner instanceof KtLightMethod) return ((KtLightMethod) owner).getClsDelegate();
|
||||
return owner;
|
||||
}
|
||||
|
||||
@@ -104,24 +110,24 @@ public class KtLightTypeParameter
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiAnnotation[] getAnnotations() {
|
||||
return getDelegate().getAnnotations();
|
||||
return getClsDelegate().getAnnotations();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiAnnotation[] getApplicableAnnotations() {
|
||||
return getDelegate().getApplicableAnnotations();
|
||||
return getClsDelegate().getApplicableAnnotations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiAnnotation findAnnotation(@NotNull String qualifiedName) {
|
||||
return getDelegate().findAnnotation(qualifiedName);
|
||||
return getClsDelegate().findAnnotation(qualifiedName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiAnnotation addAnnotation(@NotNull String qualifiedName) {
|
||||
return getDelegate().addAnnotation(qualifiedName);
|
||||
return getClsDelegate().addAnnotation(qualifiedName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,7 +138,7 @@ public class KtLightTypeParameter
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getNavigationElement() {
|
||||
return getOrigin();
|
||||
return getKotlinOrigin();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -144,12 +150,12 @@ public class KtLightTypeParameter
|
||||
@NotNull
|
||||
@Override
|
||||
public SearchScope getUseScope() {
|
||||
return getOrigin().getUseScope();
|
||||
return getKotlinOrigin().getUseScope();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
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");
|
||||
* 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.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage;
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||
@@ -47,13 +46,11 @@ public abstract class KtWrappingLightClass extends AbstractLightClass implements
|
||||
super(manager, KotlinLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public abstract KtClassOrObject getOrigin();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public abstract PsiClass getDelegate();
|
||||
public PsiClass getDelegate() {
|
||||
return getClsDelegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -123,9 +120,7 @@ public abstract class KtWrappingLightClass extends AbstractLightClass implements
|
||||
@Override
|
||||
public PsiField fun(PsiField field) {
|
||||
LightMemberOrigin origin = ClsWrapperStubPsiFactory.getMemberOrigin(field);
|
||||
return KtLightFieldImpl.Factory.create(origin != null ? origin.getOriginalElement() : null,
|
||||
field,
|
||||
KtWrappingLightClass.this);
|
||||
return KtLightFieldImpl.Factory.create(origin, field, KtWrappingLightClass.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -161,7 +156,7 @@ public abstract class KtWrappingLightClass extends AbstractLightClass implements
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
KtClassOrObject origin = getOrigin();
|
||||
KtClassOrObject origin = getKotlinOrigin();
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,7 +62,7 @@ object LightClassUtil {
|
||||
val outerPsiClass = getWrappingClass(companionObject)
|
||||
if (outerPsiClass != null) {
|
||||
for (fieldOfParent in outerPsiClass.fields) {
|
||||
if ((fieldOfParent is KtLightElement<*, *>) && fieldOfParent.getOrigin() === companionObject) {
|
||||
if ((fieldOfParent is KtLightElement<*, *>) && fieldOfParent.kotlinOrigin === companionObject) {
|
||||
return fieldOfParent
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ object LightClassUtil {
|
||||
var psiClass: PsiClass = getWrappingClass(declaration) ?: return null
|
||||
|
||||
if (psiClass is KtLightClass) {
|
||||
val origin = psiClass.getOrigin()
|
||||
val origin = psiClass.kotlinOrigin
|
||||
if (origin is KtObjectDeclaration && origin.isCompanion()) {
|
||||
val containingClass = PsiTreeUtil.getParentOfType(origin, KtClass::class.java)
|
||||
if (containingClass != null) {
|
||||
@@ -97,7 +97,7 @@ object LightClassUtil {
|
||||
}
|
||||
|
||||
for (field in psiClass.fields) {
|
||||
if (field is KtLightField && field.getOrigin() === declaration) {
|
||||
if (field is KtLightField && field.kotlinOrigin === declaration) {
|
||||
return field
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ object LightClassUtil {
|
||||
val methods = SmartList<PsiMethod>()
|
||||
for (method in psiClass.methods.asList()) {
|
||||
try {
|
||||
if (method is KtLightMethod && method.getOrigin() === declaration) {
|
||||
if (method is KtLightMethod && method.kotlinOrigin === declaration) {
|
||||
methods.add(method)
|
||||
if (!collectAll) {
|
||||
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");
|
||||
* 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
|
||||
val PsiElement.unwrapped: PsiElement?
|
||||
get() = if (this is KtLightElement<*, *>) getOrigin() else this
|
||||
get() = if (this is KtLightElement<*, *>) kotlinOrigin else this
|
||||
|
||||
val PsiElement.namedUnwrappedElement: PsiNamedElement?
|
||||
get() = unwrapped?.getNonStrictParentOfType<PsiNamedElement>()
|
||||
@@ -131,5 +131,5 @@ fun FqName.defaultImplsChild() = child(DEFAULT_IMPLS_CLASS_NAME)
|
||||
fun KtAnnotationEntry.toLightAnnotation(): PsiAnnotation? {
|
||||
val ktDeclaration = getStrictParentOfType<KtModifierList>()?.parent as? KtDeclaration ?: 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");
|
||||
* 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) {
|
||||
PsiClass delegate = lightClass.getDelegate();
|
||||
PsiClass delegate = lightClass.getClsDelegate();
|
||||
for (String modifier : PsiModifier.MODIFIERS) {
|
||||
assertEquals("Incoherent modifier: " + modifier,
|
||||
delegate.hasModifierProperty(modifier),
|
||||
@@ -90,7 +90,7 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
|
||||
try {
|
||||
Method method = reflect.getMethod(methodName);
|
||||
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);
|
||||
}
|
||||
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");
|
||||
* 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)
|
||||
|
||||
val delegate = (lightClass as KtLightClass).getDelegate()
|
||||
val delegate = (lightClass as KtLightClass).clsDelegate
|
||||
TestCase.assertTrue("Not a CLS element: $delegate", delegate is ClsElementImpl)
|
||||
|
||||
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");
|
||||
* 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 KtLightClassForFacade -> KotlinIcons.FILE
|
||||
is KtLightClassForDecompiledDeclaration -> {
|
||||
val origin = getOrigin()
|
||||
val origin = kotlinOrigin
|
||||
//TODO (light classes for decompiled files): correct presentation
|
||||
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)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
fun createLightClassForDecompiledKotlinFile(file: KtFile): KtLightClassForDecompiledDeclaration? {
|
||||
fun createLightClassForDecompiledKotlinFile(file: KtClsFile): KtLightClassForDecompiledDeclaration? {
|
||||
val virtualFile = file.virtualFile ?: return null
|
||||
|
||||
val classOrObject = file.declarations.filterIsInstance<KtClassOrObject>().singleOrNull()
|
||||
@@ -313,7 +313,7 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
|
||||
correspondingClassOrObject = classOrObject
|
||||
) ?: return null
|
||||
|
||||
return KtLightClassForDecompiledDeclaration(javaClsClass, classOrObject)
|
||||
return KtLightClassForDecompiledDeclaration(javaClsClass, classOrObject, file)
|
||||
}
|
||||
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -87,7 +87,7 @@ fun PsiClass.resolveToDescriptor(
|
||||
declarationTranslator: (KtClassOrObject) -> KtClassOrObject? = { it }
|
||||
): ClassDescriptor? {
|
||||
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
|
||||
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");
|
||||
* 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.impl.compiled.ClsClassImpl
|
||||
import org.jetbrains.kotlin.asJava.KtWrappingLightClass
|
||||
import org.jetbrains.kotlin.idea.decompiler.classFile.KtClsFile
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
|
||||
class KtLightClassForDecompiledDeclaration(
|
||||
private val clsClass: ClsClassImpl,
|
||||
private val origin: KtClassOrObject?
|
||||
) : KtWrappingLightClass(clsClass.manager) {
|
||||
private val fqName = origin?.fqName ?: FqName(clsClass.qualifiedName)
|
||||
override val clsDelegate: ClsClassImpl,
|
||||
override val kotlinOrigin: KtClassOrObject?,
|
||||
private val file: KtClsFile
|
||||
) : KtWrappingLightClass(clsDelegate.manager) {
|
||||
private val fqName = kotlinOrigin?.fqName ?: FqName(clsDelegate.qualifiedName)
|
||||
|
||||
override fun copy() = this
|
||||
|
||||
override fun getOwnInnerClasses(): List<PsiClass> {
|
||||
val nestedClasses = origin?.declarations?.filterIsInstance<KtClassOrObject>() ?: emptyList()
|
||||
return clsClass.ownInnerClasses.map { innerClsClass ->
|
||||
val nestedClasses = kotlinOrigin?.declarations?.filterIsInstance<KtClassOrObject>() ?: emptyList()
|
||||
return clsDelegate.ownInnerClasses.map { innerClsClass ->
|
||||
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 getDelegate() = clsClass
|
||||
|
||||
override fun getOrigin() = origin
|
||||
override fun getNavigationElement() = kotlinOrigin?.navigationElement ?: file
|
||||
|
||||
override fun getFqName() = fqName
|
||||
|
||||
override fun getParent() = clsClass.parent
|
||||
override fun getParent() = clsDelegate.parent
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is KtLightClassForDecompiledDeclaration &&
|
||||
@@ -55,3 +53,4 @@ class KtLightClassForDecompiledDeclaration(
|
||||
override fun hashCode(): Int =
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -130,10 +130,10 @@ private fun KtLightElement<*, *>.getModuleInfoForLightElement(onFailure: (String
|
||||
false
|
||||
)
|
||||
}
|
||||
val element = getOrigin() ?: when (this) {
|
||||
val element = kotlinOrigin ?: when (this) {
|
||||
is FakeLightClassForFileOfPackage -> this.getContainingFile()!!
|
||||
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()
|
||||
}
|
||||
|
||||
+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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,7 +39,7 @@ class KotlinReadWriteAccessDetector : ReadWriteAccessDetector() {
|
||||
|
||||
val refTarget = reference.resolve()
|
||||
if (refTarget is KtLightMethod) {
|
||||
val origin = refTarget.getOrigin()
|
||||
val origin = refTarget.kotlinOrigin
|
||||
val declaration: KtNamedDeclaration = when (origin) {
|
||||
is KtPropertyAccessor -> origin.getNonStrictParentOfType<KtProperty>()
|
||||
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");
|
||||
* 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 }
|
||||
|
||||
for (declaration in element.declarations) {
|
||||
val lightDeclaration = lightDeclarations.find { it?.getOrigin() == declaration }
|
||||
val lightDeclaration = lightDeclarations.find { it?.kotlinOrigin == declaration }
|
||||
if (lightDeclaration != null) {
|
||||
searchNamedElement(queryParameters, lightDeclaration)
|
||||
}
|
||||
@@ -218,7 +218,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
||||
val originClass = originObject.getStrictParentOfType<KtClass>()
|
||||
val originLightClass = originClass?.toLightClass()
|
||||
val allMethods = originLightClass?.allMethods
|
||||
return allMethods?.find { it is KtLightMethod && it.getOrigin() == function }
|
||||
return allMethods?.find { it is KtLightMethod && it.kotlinOrigin == function }
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -275,7 +275,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
||||
}
|
||||
|
||||
is KtLightMethod -> {
|
||||
val declaration = element.getOrigin()
|
||||
val declaration = element.kotlinOrigin
|
||||
if (declaration is KtProperty || (declaration is KtParameter && declaration.hasValOrVar())) {
|
||||
searchNamedElement(queryParameters, declaration as PsiNamedElement)
|
||||
}
|
||||
@@ -292,7 +292,7 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
|
||||
}
|
||||
|
||||
is KtLightParameter -> {
|
||||
val origin = element.getOrigin() ?: return
|
||||
val origin = element.kotlinOrigin ?: return
|
||||
runReadAction {
|
||||
val componentFunctionDescriptor = origin.dataClassComponentFunction()
|
||||
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");
|
||||
* 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 {
|
||||
if (this is KtLightElement<*, *>) return true
|
||||
// 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
|
||||
val klass = containingClass ?: return true
|
||||
val descriptor = getJavaMethodDescriptor() as? ConstructorDescriptor ?: return true
|
||||
|
||||
@@ -93,7 +93,7 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
|
||||
return renderKotlinDeclaration(element, quickNavigation)
|
||||
}
|
||||
else if (element is KtLightDeclaration<*, *>) {
|
||||
val origin = element.getOrigin() ?: return null
|
||||
val origin = element.kotlinOrigin ?: return null
|
||||
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");
|
||||
* 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()
|
||||
}
|
||||
is KtLightClassForExplicitDeclaration -> {
|
||||
val jetClass = psiClass.getOrigin()
|
||||
val jetClass = psiClass.kotlinOrigin
|
||||
createBreakpointIfPropertyExists(jetClass, jetClass.getContainingKtFile(), className, fieldName)
|
||||
}
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,7 +34,7 @@ fun PsiClass.collectProperties(): Array<DescriptorMemberChooserObject> {
|
||||
return result.toTypedArray()
|
||||
}
|
||||
if (this is KtLightClass) {
|
||||
val origin = this.getOrigin()
|
||||
val origin = this.kotlinOrigin
|
||||
if (origin != null) {
|
||||
return origin.declarations.filterIsInstance<KtProperty>().map {
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -145,7 +145,7 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() {
|
||||
}
|
||||
|
||||
if (elementAt is KtLightClass) {
|
||||
return getContextElement(elementAt.getOrigin())
|
||||
return getContextElement(elementAt.kotlinOrigin)
|
||||
}
|
||||
|
||||
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");
|
||||
* 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
|
||||
if (targetElement instanceof KtLightMethod) {
|
||||
return buildChildrenByKotlinTarget(descriptor, ((KtLightMethod) targetElement).getOrigin());
|
||||
return buildChildrenByKotlinTarget(descriptor, ((KtLightMethod) targetElement).getKotlinOrigin());
|
||||
}
|
||||
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -91,7 +91,7 @@ abstract class ImplementAbstractMemberIntentionBase :
|
||||
|
||||
fun acceptSubClass(subClass: PsiElement): Boolean {
|
||||
val classDescriptor = when (subClass) {
|
||||
is KtLightClass -> subClass.getOrigin()?.resolveToDescriptorIfAny()
|
||||
is KtLightClass -> subClass.kotlinOrigin?.resolveToDescriptorIfAny()
|
||||
is KtEnumEntry -> subClass.resolveToDescriptorIfAny()
|
||||
is PsiClass -> subClass.getJavaClassDescriptor()
|
||||
else -> null
|
||||
@@ -153,7 +153,7 @@ abstract class ImplementAbstractMemberIntentionBase :
|
||||
for (targetClass in targetClasses) {
|
||||
try {
|
||||
when (targetClass) {
|
||||
is KtLightClass -> targetClass.getOrigin()?.let { implementInKotlinClass(member, it) }
|
||||
is KtLightClass -> targetClass.kotlinOrigin?.let { implementInKotlinClass(member, it) }
|
||||
is KtEnumEntry -> implementInKotlinClass(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");
|
||||
* 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) {
|
||||
is KtFile -> this
|
||||
is KtLightClass -> getOrigin()?.containingFile as? KtFile
|
||||
is KtLightClass -> kotlinOrigin?.containingFile as? KtFile
|
||||
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");
|
||||
* 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));
|
||||
|
||||
if (method instanceof KtLightMethod) {
|
||||
KtDeclaration declaration = ((KtLightMethod) method).getOrigin();
|
||||
KtDeclaration declaration = ((KtLightMethod) method).getKotlinOrigin();
|
||||
if (declaration instanceof KtFunction) {
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -910,7 +910,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
|
||||
is KotlinChangeInfo -> changeInfo
|
||||
is JavaChangeInfo -> {
|
||||
val method = changeInfo.method as? KtLightMethod ?: return false
|
||||
var baseFunction = method.getOrigin() ?: return false
|
||||
var baseFunction = method.kotlinOrigin ?: return false
|
||||
if (baseFunction is KtClass) {
|
||||
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");
|
||||
* 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.search.projectScope
|
||||
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.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
@@ -359,7 +362,7 @@ class MoveKotlinDeclarationsProcessor(
|
||||
if (e1 === e2) return true
|
||||
// Name should be enough to distinguish different light elements based on the same original declaration
|
||||
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
|
||||
}
|
||||
@@ -367,7 +370,7 @@ class MoveKotlinDeclarationsProcessor(
|
||||
override fun computeHashCode(e: PsiElement?): Int {
|
||||
return when (e) {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -115,7 +115,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog {
|
||||
@Override
|
||||
public boolean isAccepted(PsiClass aClass) {
|
||||
if (!(aClass instanceof KtLightClassForExplicitDeclaration)) return false;
|
||||
KtClassOrObject classOrObject = ((KtLightClassForExplicitDeclaration) aClass).getOrigin();
|
||||
KtClassOrObject classOrObject = ((KtLightClassForExplicitDeclaration) aClass).getKotlinOrigin();
|
||||
|
||||
if (classOrObject instanceof KtObjectDeclaration) {
|
||||
return !((KtObjectDeclaration) classOrObject).isObjectLiteral();
|
||||
@@ -149,7 +149,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog {
|
||||
|
||||
PsiClass aClass = chooser.getSelected();
|
||||
if (aClass instanceof KtLightClassForExplicitDeclaration) {
|
||||
targetClass = ((KtLightClassForExplicitDeclaration) aClass).getOrigin();
|
||||
targetClass = ((KtLightClassForExplicitDeclaration) aClass).getKotlinOrigin();
|
||||
targetClassChooser.setText(aClass.getQualifiedName());
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ public class MoveKotlinNestedClassesDialog extends RefactoringDialog {
|
||||
.getInstance(myProject)
|
||||
.findClass(targetClassChooser.getText(), GlobalSearchScope.projectScope(myProject));
|
||||
targetClass = aClass instanceof KtLightClassForExplicitDeclaration
|
||||
? ((KtLightClassForExplicitDeclaration) aClass).getOrigin()
|
||||
? ((KtLightClassForExplicitDeclaration) aClass).getKotlinOrigin()
|
||||
: null;
|
||||
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");
|
||||
* 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) {
|
||||
is KtLightClass ->
|
||||
if (element is KtLightClassForExplicitDeclaration) {
|
||||
element.getOrigin()
|
||||
element.kotlinOrigin
|
||||
}
|
||||
else if (element is KtLightClassForFacade) {
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
private val javaMethodProcessorInstance = RenameJavaMethodProcessor()
|
||||
|
||||
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? {
|
||||
@@ -47,7 +47,7 @@ class RenameKotlinFunctionProcessor : RenameKotlinPsiProcessor() {
|
||||
val substitutedJavaElement = javaMethodProcessorInstance.substituteElementToRename(wrappedMethod, editor)
|
||||
|
||||
return when (substitutedJavaElement) {
|
||||
is KtLightMethod -> substitutedJavaElement.getOrigin() as? KtNamedFunction
|
||||
is KtLightMethod -> substitutedJavaElement.kotlinOrigin as? KtNamedFunction
|
||||
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");
|
||||
* 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) {
|
||||
if (!(method instanceof KtLightMethod)) return null;
|
||||
|
||||
KtDeclaration declaration = ((KtLightMethod) method).getOrigin();
|
||||
KtDeclaration declaration = ((KtLightMethod) method).getKotlinOrigin();
|
||||
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");
|
||||
* 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;
|
||||
|
||||
PsiElement mirrorElement = implementation instanceof KtLightMethod
|
||||
? ((KtLightMethod) implementation).getOrigin() : null;
|
||||
? ((KtLightMethod) implementation).getKotlinOrigin() : null;
|
||||
if (mirrorElement instanceof KtProperty || mirrorElement instanceof KtParameter) {
|
||||
if (!consumer.process(mirrorElement)) {
|
||||
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");
|
||||
* 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
|
||||
if (method !is KtLightMethod) return true
|
||||
|
||||
val declaration = method.getOrigin() as? KtCallableDeclaration
|
||||
val declaration = method.kotlinOrigin as? KtCallableDeclaration
|
||||
if (declaration == null) return true
|
||||
|
||||
val callDescriptor = runReadAction { declaration.resolveToDescriptor() }
|
||||
@@ -67,7 +67,7 @@ class KotlinOverridingMethodsWithGenericsSearcher : QueryExecutor<PsiMethod, Ove
|
||||
val methodsByName = inheritor.findMethodsByName(name, false)
|
||||
|
||||
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
|
||||
|
||||
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");
|
||||
* 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)
|
||||
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) {
|
||||
// TODO: Override dialog method when it becomes protected
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -279,7 +279,7 @@ public class KotlinJavaFacadeTest extends KotlinLightCodeInsightFixtureTestCase
|
||||
if (shouldBeWrapped) {
|
||||
assertNotNull(String.format("Failed to wrap declaration '%s' to method", declaration.getText()), psiMethod);
|
||||
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 {
|
||||
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
|
||||
// No exception/error should happen here
|
||||
lightClass.getDelegate();
|
||||
lightClass.getClsDelegate();
|
||||
}
|
||||
|
||||
@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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ public class LightClassEqualsTest extends KotlinLightCodeInsightFixtureTestCase
|
||||
assertNotNull(theClass);
|
||||
assertInstanceOf(theClass, KtLightClassForExplicitDeclaration.class);
|
||||
|
||||
doTestEquals(((KtLightClass) theClass).getOrigin());
|
||||
doTestEquals(((KtLightClass) theClass).getKotlinOrigin());
|
||||
}
|
||||
|
||||
public void testEqualsForDecompiledClass() throws Exception {
|
||||
@@ -53,7 +53,7 @@ public class LightClassEqualsTest extends KotlinLightCodeInsightFixtureTestCase
|
||||
assertNotNull(theClass);
|
||||
assertInstanceOf(theClass, KtLightClassForDecompiledDeclaration.class);
|
||||
|
||||
doTestEquals(((KtLightClass) theClass).getOrigin());
|
||||
doTestEquals(((KtLightClass) theClass).getKotlinOrigin());
|
||||
}
|
||||
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -326,7 +326,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
||||
val typeArguments = convertTypeArguments(expression)
|
||||
|
||||
if (target is KtLightMethod) {
|
||||
val origin = target.getOrigin()
|
||||
val origin = target.kotlinOrigin
|
||||
val isTopLevel = origin?.getStrictParentOfType<KtClassOrObject>() == null
|
||||
if (origin is KtProperty || origin is KtPropertyAccessor || origin is KtParameter) {
|
||||
val property = if (origin is KtPropertyAccessor)
|
||||
@@ -429,7 +429,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
||||
}
|
||||
|
||||
private fun KtLightMethod.isKotlinExtensionFunction(): Boolean {
|
||||
val origin = this.getOrigin()
|
||||
val origin = this.kotlinOrigin
|
||||
if (origin != null) return origin.isExtensionDeclaration()
|
||||
|
||||
val parameters = parameterList.parameters
|
||||
@@ -539,7 +539,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
||||
identifier = Identifier("size", isNullable).assignNoPrototype()
|
||||
}
|
||||
else if (qualifier != null) {
|
||||
if (target is KtLightField && target.getOrigin() is KtObjectDeclaration) {
|
||||
if (target is KtLightField && target.kotlinOrigin is KtObjectDeclaration) {
|
||||
result = codeConverter.convertExpression(qualifier)
|
||||
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");
|
||||
* 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 {
|
||||
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 type = descriptor.returnType ?: 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");
|
||||
* 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
|
||||
|
||||
// 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");
|
||||
* 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
|
||||
}
|
||||
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
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user