Light Classes: Generate light wrappers for name identifiers
This commit is contained in:
+4
-2
@@ -19,12 +19,10 @@ package org.jetbrains.kotlin.asJava
|
|||||||
import com.intellij.openapi.diagnostic.Logger
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.util.Comparing
|
import com.intellij.openapi.util.Comparing
|
||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.openapi.util.TextRange
|
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.impl.DebugUtil
|
import com.intellij.psi.impl.DebugUtil
|
||||||
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub
|
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub
|
||||||
import com.intellij.psi.impl.light.LightClass
|
import com.intellij.psi.impl.light.LightClass
|
||||||
import com.intellij.psi.impl.light.LightIdentifier
|
|
||||||
import com.intellij.psi.impl.light.LightMethod
|
import com.intellij.psi.impl.light.LightMethod
|
||||||
import com.intellij.psi.scope.PsiScopeProcessor
|
import com.intellij.psi.scope.PsiScopeProcessor
|
||||||
import com.intellij.psi.search.SearchScope
|
import com.intellij.psi.search.SearchScope
|
||||||
@@ -58,6 +56,8 @@ open class KtLightClassForExplicitDeclaration(
|
|||||||
: KtWrappingLightClass(classOrObject.manager), KtJavaMirrorMarker, StubBasedPsiElement<KotlinClassOrObjectStub<out KtClassOrObject>> {
|
: KtWrappingLightClass(classOrObject.manager), KtJavaMirrorMarker, StubBasedPsiElement<KotlinClassOrObjectStub<out KtClassOrObject>> {
|
||||||
private var delegate: PsiClass? = null
|
private var delegate: PsiClass? = null
|
||||||
|
|
||||||
|
private val lightIdentifier = KtLightIdentifier(this, classOrObject)
|
||||||
|
|
||||||
private fun getLocalClassParent(): PsiElement? {
|
private fun getLocalClassParent(): PsiElement? {
|
||||||
fun getParentByPsiMethod(method: PsiMethod?, name: String?, forceMethodWrapping: Boolean): PsiElement? {
|
fun getParentByPsiMethod(method: PsiMethod?, name: String?, forceMethodWrapping: Boolean): PsiElement? {
|
||||||
if (method == null || name == null) return null
|
if (method == null || name == null) return null
|
||||||
@@ -385,6 +385,8 @@ open class KtLightClassForExplicitDeclaration(
|
|||||||
override fun getElementType(): IStubElementType<out StubElement<*>, *>? = classOrObject.elementType
|
override fun getElementType(): IStubElementType<out StubElement<*>, *>? = classOrObject.elementType
|
||||||
override fun getStub(): KotlinClassOrObjectStub<out KtClassOrObject>? = classOrObject.stub
|
override fun getStub(): KotlinClassOrObjectStub<out KtClassOrObject>? = classOrObject.stub
|
||||||
|
|
||||||
|
override fun getNameIdentifier() = lightIdentifier
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val JAVA_API_STUB = Key.create<CachedValue<WithFileStubAndExtraDiagnostics>>("JAVA_API_STUB")
|
private val JAVA_API_STUB = Key.create<CachedValue<WithFileStubAndExtraDiagnostics>>("JAVA_API_STUB")
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.idea.KotlinLanguage
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtEnumEntry
|
import org.jetbrains.kotlin.psi.KtEnumEntry
|
||||||
|
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||||
|
|
||||||
interface KtLightField : PsiField, KtLightDeclaration<KtDeclaration, PsiField>
|
interface KtLightField : PsiField, KtLightDeclaration<KtDeclaration, PsiField>
|
||||||
|
|
||||||
@@ -34,6 +35,8 @@ sealed class KtLightFieldImpl(
|
|||||||
private val delegate: PsiField,
|
private val delegate: PsiField,
|
||||||
private val containingClass: KtLightClass
|
private val containingClass: KtLightClass
|
||||||
) : LightElement(delegate.manager, KotlinLanguage.INSTANCE), KtLightField {
|
) : LightElement(delegate.manager, KotlinLanguage.INSTANCE), KtLightField {
|
||||||
|
private val lightIdentifier = KtLightIdentifier(this, origin as? KtNamedDeclaration)
|
||||||
|
|
||||||
@Throws(IncorrectOperationException::class)
|
@Throws(IncorrectOperationException::class)
|
||||||
override fun setInitializer(initializer: PsiExpression?) = throw IncorrectOperationException("Not supported")
|
override fun setInitializer(initializer: PsiExpression?) = throw IncorrectOperationException("Not supported")
|
||||||
|
|
||||||
@@ -41,7 +44,7 @@ sealed class KtLightFieldImpl(
|
|||||||
|
|
||||||
override fun getName() = delegate.name
|
override fun getName() = delegate.name
|
||||||
|
|
||||||
override fun getNameIdentifier() = delegate.nameIdentifier
|
override fun getNameIdentifier() = lightIdentifier
|
||||||
|
|
||||||
override fun getDocComment() = delegate.docComment
|
override fun getDocComment() = delegate.docComment
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.asJava
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.TextRange
|
||||||
|
import com.intellij.psi.PsiNameIdentifierOwner
|
||||||
|
import com.intellij.psi.impl.light.LightIdentifier
|
||||||
|
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||||
|
|
||||||
|
class KtLightIdentifier(
|
||||||
|
private val lightOwner: PsiNameIdentifierOwner,
|
||||||
|
private val ktDeclaration: KtNamedDeclaration?
|
||||||
|
) : LightIdentifier(lightOwner.manager, ktDeclaration?.name ?: "") {
|
||||||
|
override fun getParent() = lightOwner
|
||||||
|
override fun getTextRange() = ktDeclaration?.nameIdentifier?.textRange ?: TextRange.EMPTY_RANGE
|
||||||
|
}
|
||||||
@@ -38,6 +38,8 @@ sealed class KtLightMethodImpl(
|
|||||||
) : LightMethod(delegate.manager, delegate, containingClass), KtLightMethod {
|
) : LightMethod(delegate.manager, delegate, containingClass), KtLightMethod {
|
||||||
private val origin = lightMethodOrigin?.originalElement as? KtDeclaration
|
private val origin = lightMethodOrigin?.originalElement as? KtDeclaration
|
||||||
|
|
||||||
|
private val lightIdentifier = KtLightIdentifier(this, origin as? KtNamedDeclaration)
|
||||||
|
|
||||||
override fun getContainingClass(): KtLightClass = super.getContainingClass() as KtLightClass
|
override fun getContainingClass(): KtLightClass = super.getContainingClass() as KtLightClass
|
||||||
|
|
||||||
private val paramsList: CachedValue<PsiParameterList> by lazy {
|
private val paramsList: CachedValue<PsiParameterList> by lazy {
|
||||||
@@ -112,6 +114,8 @@ sealed class KtLightMethodImpl(
|
|||||||
|
|
||||||
override fun getModifierList() = _modifierList
|
override fun getModifierList() = _modifierList
|
||||||
|
|
||||||
|
override fun getNameIdentifier() = lightIdentifier
|
||||||
|
|
||||||
override fun getParameterList() = paramsList.value
|
override fun getParameterList() = paramsList.value
|
||||||
|
|
||||||
override fun getTypeParameterList() = typeParamsList.value
|
override fun getTypeParameterList() = typeParamsList.value
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
private final PsiParameter delegate;
|
private final PsiParameter delegate;
|
||||||
private final int index;
|
private final int index;
|
||||||
private final KtLightMethod method;
|
private final KtLightMethod method;
|
||||||
|
private final KtLightIdentifier lightIdentifier;
|
||||||
|
|
||||||
public KtLightParameter(final PsiParameter delegate, int index, KtLightMethod method) {
|
public KtLightParameter(final PsiParameter delegate, int index, KtLightMethod method) {
|
||||||
super(getName(delegate, index), delegate.getType(), method, KotlinLanguage.INSTANCE);
|
super(getName(delegate, index), delegate.getType(), method, KotlinLanguage.INSTANCE);
|
||||||
@@ -55,6 +56,8 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
return delegate.getModifierList();
|
return delegate.getModifierList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lightIdentifier = new KtLightIdentifier(this, getOrigin());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -140,4 +143,9 @@ public class KtLightParameter extends LightParameter implements KtLightDeclarati
|
|||||||
public String getText() {
|
public String getText() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiIdentifier getNameIdentifier() {
|
||||||
|
return lightIdentifier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user