From f40a04c5a22f8ca926ab1eebf108b01eb5e94135 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 29 Mar 2016 18:48:30 +0300 Subject: [PATCH] Refactor light elements KtLightElement#delegate -> clsDelegate, KtLightElement#origin -> kotlinOrigin and make them properties KtLightClassForDecompiledDeclaration stores KtClsFile KtLightField stores LightMemberOrigin --- .../FakeLightClassForFileOfPackage.java | 10 ++- .../kotlin/asJava/KtLightAnnotation.kt | 17 ++--- .../KtLightClassForExplicitDeclaration.kt | 41 ++++------ .../kotlin/asJava/KtLightClassForFacade.kt | 13 ++-- .../kotlin/asJava/KtLightElements.kt | 6 +- .../jetbrains/kotlin/asJava/KtLightField.kt | 76 +++++++++---------- .../jetbrains/kotlin/asJava/KtLightMethod.kt | 60 +++++++-------- ...tLightModifierListWithExplicitModifiers.kt | 2 +- .../kotlin/asJava/KtLightParameter.java | 23 +++--- .../kotlin/asJava/KtLightTypeParameter.java | 30 +++++--- .../kotlin/asJava/KtWrappingLightClass.java | 17 ++--- .../jetbrains/kotlin/asJava/LightClassUtil.kt | 10 +-- .../kotlin/asJava/lightClassUtils.kt | 8 +- .../asJava/KotlinLightClassCoherenceTest.java | 6 +- .../kotlin/asJava/LightClassTestCommon.kt | 4 +- .../kotlin/idea/KotlinIconProvider.kt | 4 +- .../resolve/IDELightClassGenerationSupport.kt | 6 +- .../caches/resolve/JavaResolveExtension.kt | 4 +- .../KtLightClassForDecompiledDeclaration.kt | 27 ++++--- .../idea/caches/resolve/getModuleInfo.kt | 6 +- .../KotlinReadWriteAccessDetector.kt | 4 +- .../KotlinReferencesSearcher.kt | 10 +-- .../kotlin/idea/search/usagesSearch/utils.kt | 4 +- .../idea/KotlinQuickDocumentationProvider.kt | 2 +- .../breakpoints/KotlinFieldBreakpointType.kt | 4 +- .../dialog/fieldBreakpointDialogUtil.kt | 4 +- .../evaluate/KotlinCodeFragmentFactory.kt | 4 +- .../KotlinCalleeMethodsTreeStructure.java | 4 +- .../ImplementAbstractMemberIntention.kt | 6 +- .../idea/projectView/projectViewProviders.kt | 4 +- .../refactoring/KotlinRefactoringUtil.java | 4 +- .../KotlinChangeSignatureUsageProcessor.kt | 4 +- .../MoveKotlinDeclarationsProcessor.kt | 11 ++- .../ui/MoveKotlinNestedClassesDialog.java | 6 +- .../rename/RenameKotlinClassProcessor.kt | 4 +- .../rename/RenameKotlinFunctionProcessor.kt | 6 +- .../kotlin/idea/run/JetRunConfiguration.java | 4 +- .../KotlinDefinitionsSearcher.java | 4 +- ...inOverridingMethodsWithGenericsSearcher.kt | 6 +- .../KotlinCreateTestIntention.kt | 4 +- .../idea/javaFacade/KotlinJavaFacadeTest.java | 6 +- .../lightClasses/LightClassEqualsTest.java | 6 +- .../kotlin/j2k/ExpressionConverter.kt | 8 +- .../org/jetbrains/kotlin/j2k/TypeConverter.kt | 4 +- j2k/src/org/jetbrains/kotlin/j2k/Utils.kt | 4 +- .../jetbrains/kotlin/j2k/propertyDetection.kt | 4 +- 46 files changed, 247 insertions(+), 254 deletions(-) diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/FakeLightClassForFileOfPackage.java b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/FakeLightClassForFileOfPackage.java index 63b1e864e39..cc1af5bf8a8 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/FakeLightClassForFileOfPackage.java +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/FakeLightClassForFileOfPackage.java @@ -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; } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightAnnotation.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightAnnotation.kt index 896678810eb..1da859eacee 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightAnnotation.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightAnnotation.kt @@ -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 { - override fun getDelegate() = delegate - override fun getOrigin() = originalElement - +) : PsiAnnotation by clsDelegate, KtLightElement { 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() } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt index 57143c2b1cf..4ab006d3a9d 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForExplicitDeclaration.kt @@ -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> { - 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, *>? = classOrObject.elementType override fun getStub(): KotlinClassOrObjectStub? = classOrObject.stub diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForFacade.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForFacade.kt index 5b378d159ce..e4fc3bceca5 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForFacade.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightClassForFacade.kt @@ -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() diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightElements.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightElements.kt index 423adf94230..9957db0d876 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightElements.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightElements.kt @@ -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 : PsiNamedElement { - fun getOrigin(): T? + val kotlinOrigin: T? - fun getDelegate(): D + val clsDelegate: D } interface KtLightDeclaration: KtLightElement \ No newline at end of file diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightField.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightField.kt index e74143b72cb..f97c70676ac 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightField.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightField.kt @@ -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 // 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) } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightMethod.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightMethod.kt index 46ea07d6c9e..240ff98919a 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightMethod.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightMethod.kt @@ -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 by lazy { - val cacheManager = CachedValuesManager.getManager(delegate.project) + val cacheManager = CachedValuesManager.getManager(clsDelegate.project) cacheManager.createCachedValue({ 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 by lazy { - val cacheManager = CachedValuesManager.getManager(delegate.project) + val cacheManager = CachedValuesManager.getManager(clsDelegate.project) cacheManager.createCachedValue({ + 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)) diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightModifierListWithExplicitModifiers.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightModifierListWithExplicitModifiers.kt index 08c042770a3..3eac02e85f4 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightModifierListWithExplicitModifiers.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightModifierListWithExplicitModifiers.kt @@ -69,7 +69,7 @@ internal fun computeAnnotations(lightElement: PsiModifierList, val cacheManager = CachedValuesManager.getManager(lightElement.project) return cacheManager.createCachedValue>( { - 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 diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightParameter.java b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightParameter.java index d1190ef363a..2b0105ad03d 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightParameter.java +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightParameter.java @@ -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; } } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightTypeParameter.java b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightTypeParameter.java index 8bdd0226ecb..17036e2efda 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightTypeParameter.java +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtLightTypeParameter.java @@ -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()); } } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtWrappingLightClass.java b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtWrappingLightClass.java index a95e4c17c11..0177fdf3931 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtWrappingLightClass.java +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KtWrappingLightClass.java @@ -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(); } diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.kt index 55381458176..e299b1da2b1 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/LightClassUtil.kt @@ -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() 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 diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt index f9133c018c6..3d345e05870 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/lightClassUtils.kt @@ -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 { // 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() @@ -131,5 +131,5 @@ fun FqName.defaultImplsChild() = child(DEFAULT_IMPLS_CLASS_NAME) fun KtAnnotationEntry.toLightAnnotation(): PsiAnnotation? { val ktDeclaration = getStrictParentOfType()?.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 } -} \ No newline at end of file + return lightElement.modifierList?.annotations?.firstOrNull { it is KtLightAnnotation && it.kotlinOrigin == this } +} diff --git a/compiler/tests/org/jetbrains/kotlin/asJava/KotlinLightClassCoherenceTest.java b/compiler/tests/org/jetbrains/kotlin/asJava/KotlinLightClassCoherenceTest.java index 6abe02a8d08..70c6fd512e7 100644 --- a/compiler/tests/org/jetbrains/kotlin/asJava/KotlinLightClassCoherenceTest.java +++ b/compiler/tests/org/jetbrains/kotlin/asJava/KotlinLightClassCoherenceTest.java @@ -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) { diff --git a/compiler/tests/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt b/compiler/tests/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt index be112c8eba3..b1fc5bd0868 100644 --- a/compiler/tests/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt +++ b/compiler/tests/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt @@ -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() diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinIconProvider.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinIconProvider.kt index af490f943b3..dc5d22ba11d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinIconProvider.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinIconProvider.kt @@ -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 } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.kt index 6321289e656..f0974d44412 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/IDELightClassGenerationSupport.kt @@ -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().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().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( diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt index 9e4fc28515f..a78c36bdc38 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/JavaResolveExtension.kt @@ -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) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KtLightClassForDecompiledDeclaration.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KtLightClassForDecompiledDeclaration.kt index d05c45f90e5..4e768fdfadb 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KtLightClassForDecompiledDeclaration.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KtLightClassForDecompiledDeclaration.kt @@ -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 { - val nestedClasses = origin?.declarations?.filterIsInstance() ?: emptyList() - return clsClass.ownInnerClasses.map { innerClsClass -> + val nestedClasses = kotlinOrigin?.declarations?.filterIsInstance() ?: 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() } + diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/getModuleInfo.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/getModuleInfo.kt index f73c249eff4..f54ac3c3583 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/getModuleInfo.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/getModuleInfo.kt @@ -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() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReadWriteAccessDetector.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReadWriteAccessDetector.kt index 2e31c9fc5f6..207e6da6696 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReadWriteAccessDetector.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReadWriteAccessDetector.kt @@ -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() is KtProperty, is KtParameter -> origin as KtNamedDeclaration diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt index b8dfa521ff8..02acc8ca49a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/ideaExtensions/KotlinReferencesSearcher.kt @@ -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() 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 { - 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 { - val origin = element.getOrigin() ?: return + val origin = element.kotlinOrigin ?: return runReadAction { val componentFunctionDescriptor = origin.dataClassComponentFunction() if (componentFunctionDescriptor != null) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt index 231c510f98a..39d82b9df15 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/utils.kt @@ -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 diff --git a/idea/src/org/jetbrains/kotlin/idea/KotlinQuickDocumentationProvider.kt b/idea/src/org/jetbrains/kotlin/idea/KotlinQuickDocumentationProvider.kt index 1a69acb132a..61b3e1fb998 100644 --- a/idea/src/org/jetbrains/kotlin/idea/KotlinQuickDocumentationProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/KotlinQuickDocumentationProvider.kt @@ -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) } diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt index 7912ae40d1e..d8767efc086 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/KotlinFieldBreakpointType.kt @@ -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 { - val jetClass = psiClass.getOrigin() + val jetClass = psiClass.kotlinOrigin createBreakpointIfPropertyExists(jetClass, jetClass.getContainingKtFile(), className, fieldName) } else -> null diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/fieldBreakpointDialogUtil.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/fieldBreakpointDialogUtil.kt index 11d040822ff..acb36a153a6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/fieldBreakpointDialogUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/breakpoints/dialog/fieldBreakpointDialogUtil.kt @@ -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 { return result.toTypedArray() } if (this is KtLightClass) { - val origin = this.getOrigin() + val origin = this.kotlinOrigin if (origin != null) { return origin.declarations.filterIsInstance().map { DescriptorMemberChooserObject(it, it.resolveToDescriptor()) diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt index d845c465aee..f5e125ec980 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinCodeFragmentFactory.kt @@ -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 diff --git a/idea/src/org/jetbrains/kotlin/idea/hierarchy/calls/KotlinCalleeMethodsTreeStructure.java b/idea/src/org/jetbrains/kotlin/idea/hierarchy/calls/KotlinCalleeMethodsTreeStructure.java index b128e62ab51..ff712e065fc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/hierarchy/calls/KotlinCalleeMethodsTreeStructure.java +++ b/idea/src/org/jetbrains/kotlin/idea/hierarchy/calls/KotlinCalleeMethodsTreeStructure.java @@ -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) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt index 8f5e9d0bc9c..18cf507b9ed 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt @@ -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) } diff --git a/idea/src/org/jetbrains/kotlin/idea/projectView/projectViewProviders.kt b/idea/src/org/jetbrains/kotlin/idea/projectView/projectViewProviders.kt index 3a8980a77a0..927a45b70e0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/projectView/projectViewProviders.kt +++ b/idea/src/org/jetbrains/kotlin/idea/projectView/projectViewProviders.kt @@ -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 } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/KotlinRefactoringUtil.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/KotlinRefactoringUtil.java index 061672691ce..ab8524bdbcc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/KotlinRefactoringUtil.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/KotlinRefactoringUtil.java @@ -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)); } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt index 00b92692546..f14de6c2424 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/KotlinChangeSignatureUsageProcessor.kt @@ -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() } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt index dadf5e6ce8d..101b6c7e84b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt @@ -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() } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesDialog.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesDialog.java index 7e9c925f509..37649a2cdda 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesDialog.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/ui/MoveKotlinNestedClassesDialog.java @@ -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(); } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt index 03166f9bce7..fd625094e7f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinClassProcessor.kt @@ -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) { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinFunctionProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinFunctionProcessor.kt index fbe6f611716..a8dc065eb80 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinFunctionProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/rename/RenameKotlinFunctionProcessor.kt @@ -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 } } diff --git a/idea/src/org/jetbrains/kotlin/idea/run/JetRunConfiguration.java b/idea/src/org/jetbrains/kotlin/idea/run/JetRunConfiguration.java index ad62cb7a37d..897d7a0905d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/run/JetRunConfiguration.java +++ b/idea/src/org/jetbrains/kotlin/idea/run/JetRunConfiguration.java @@ -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() == 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 } diff --git a/j2k/src/org/jetbrains/kotlin/j2k/TypeConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/TypeConverter.kt index 9f7cc82d490..f1b2d25c292 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/TypeConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/TypeConverter.kt @@ -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 diff --git a/j2k/src/org/jetbrains/kotlin/j2k/Utils.kt b/j2k/src/org/jetbrains/kotlin/j2k/Utils.kt index 27661d5b716..b931935bb70 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/Utils.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/Utils.kt @@ -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 diff --git a/j2k/src/org/jetbrains/kotlin/j2k/propertyDetection.kt b/j2k/src/org/jetbrains/kotlin/j2k/propertyDetection.kt index d0f3a1c591f..63e5cb0c14f 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/propertyDetection.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/propertyDetection.kt @@ -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 {