Extract base interface for Kotlin light elements
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.jet.lang.resolve.java.jetAsJava
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||||
|
|
||||||
|
trait KotlinLightElement<T: JetDeclaration, D: PsiElement> {
|
||||||
|
val origin: T?
|
||||||
|
val delegate: D
|
||||||
|
}
|
||||||
+2
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,7 +20,4 @@ import com.intellij.psi.PsiMethod;
|
|||||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||||
|
|
||||||
/** Java method created for Kotlin declaration to make it resolvable in Java */
|
/** Java method created for Kotlin declaration to make it resolvable in Java */
|
||||||
public interface KotlinLightMethod extends PsiMethod {
|
public trait KotlinLightMethod: PsiMethod, KotlinLightElement<JetDeclaration, PsiMethod>
|
||||||
JetDeclaration getOrigin();
|
|
||||||
PsiMethod getDelegate();
|
|
||||||
}
|
|
||||||
+8
@@ -22,6 +22,8 @@ import com.intellij.psi.PsiFile;
|
|||||||
import com.intellij.psi.PsiManager;
|
import com.intellij.psi.PsiManager;
|
||||||
import com.intellij.psi.impl.light.AbstractLightClass;
|
import com.intellij.psi.impl.light.AbstractLightClass;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetJavaMirrorMarker;
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetJavaMirrorMarker;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
@@ -46,6 +48,12 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public JetClassOrObject getOrigin() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiFile getContainingFile() {
|
public PsiFile getContainingFile() {
|
||||||
return file;
|
return file;
|
||||||
|
|||||||
+4
-6
@@ -19,11 +19,9 @@ package org.jetbrains.jet.asJava;
|
|||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightElement
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||||
|
|
||||||
public interface KotlinLightClass extends PsiClass {
|
public trait KotlinLightClass: PsiClass, KotlinLightElement<JetClassOrObject, PsiClass> {
|
||||||
@NotNull
|
val fqName: FqName
|
||||||
FqName getFqName();
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
PsiClass getDelegate();
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -198,8 +198,9 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
|||||||
this.classOrObject = classOrObject;
|
this.classOrObject = classOrObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetClassOrObject getJetClassOrObject() {
|
public JetClassOrObject getOrigin() {
|
||||||
return classOrObject;
|
return classOrObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.intellij.psi.util.CachedValuesManager;
|
|||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetJavaMirrorMarker;
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetJavaMirrorMarker;
|
||||||
@@ -91,6 +92,12 @@ public class KotlinLightClassForPackage extends KotlinWrappingLightClass impleme
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public JetClassOrObject getOrigin() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public PsiModifierList getModifierList() {
|
public PsiModifierList getModifierList() {
|
||||||
|
|||||||
+15
-17
@@ -39,15 +39,16 @@ import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
|||||||
import org.jetbrains.jet.lang.psi.JetProperty
|
import org.jetbrains.jet.lang.psi.JetProperty
|
||||||
import com.intellij.psi.PsiTypeParameter
|
import com.intellij.psi.PsiTypeParameter
|
||||||
|
|
||||||
public class KotlinLightMethodForDeclaration(manager: PsiManager, val method: PsiMethod, val jetDeclaration: JetDeclaration, containingClass: PsiClass):
|
public class KotlinLightMethodForDeclaration(
|
||||||
LightMethod(manager, method, containingClass), KotlinLightMethod {
|
manager: PsiManager, override val delegate: PsiMethod, override val origin: JetDeclaration, containingClass: PsiClass
|
||||||
|
): LightMethod(manager, delegate, containingClass), KotlinLightMethod {
|
||||||
|
|
||||||
private val paramsList: CachedValue<PsiParameterList> by Delegates.blockingLazy {
|
private val paramsList: CachedValue<PsiParameterList> by Delegates.blockingLazy {
|
||||||
val cacheManager = CachedValuesManager.getManager(method.getProject())
|
val cacheManager = CachedValuesManager.getManager(delegate.getProject())
|
||||||
cacheManager.createCachedValue<PsiParameterList>({
|
cacheManager.createCachedValue<PsiParameterList>({
|
||||||
val parameterBuilder = LightParameterListBuilder(getManager(), JetLanguage.INSTANCE)
|
val parameterBuilder = LightParameterListBuilder(getManager(), JetLanguage.INSTANCE)
|
||||||
|
|
||||||
for ((index, parameter) in method.getParameterList().getParameters().withIndices()) {
|
for ((index, parameter) in delegate.getParameterList().getParameters().withIndices()) {
|
||||||
val lightParameter = LightParameter(parameter.getName() ?: "p$index", parameter.getType(), this, JetLanguage.INSTANCE)
|
val lightParameter = LightParameter(parameter.getName() ?: "p$index", parameter.getType(), this, JetLanguage.INSTANCE)
|
||||||
parameterBuilder.addParameter(lightParameter)
|
parameterBuilder.addParameter(lightParameter)
|
||||||
}
|
}
|
||||||
@@ -57,36 +58,33 @@ public class KotlinLightMethodForDeclaration(manager: PsiManager, val method: Ps
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val typeParamsList: CachedValue<PsiTypeParameterList> by Delegates.blockingLazy {
|
private val typeParamsList: CachedValue<PsiTypeParameterList> by Delegates.blockingLazy {
|
||||||
val cacheManager = CachedValuesManager.getManager(method.getProject())
|
val cacheManager = CachedValuesManager.getManager(delegate.getProject())
|
||||||
cacheManager.createCachedValue<PsiTypeParameterList>({
|
cacheManager.createCachedValue<PsiTypeParameterList>({
|
||||||
val declaration =
|
val declaration =
|
||||||
if (jetDeclaration is JetPropertyAccessor) jetDeclaration.getParentByType(javaClass<JetProperty>()) else jetDeclaration
|
if (origin is JetPropertyAccessor) origin.getParentByType(javaClass<JetProperty>()) else origin
|
||||||
val list = LightClassUtil.buildLightTypeParameterList(this@KotlinLightMethodForDeclaration, jetDeclaration)
|
val list = LightClassUtil.buildLightTypeParameterList(this@KotlinLightMethodForDeclaration, origin)
|
||||||
CachedValueProvider.Result.create(list, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
|
CachedValueProvider.Result.create(list, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT)
|
||||||
}, false)
|
}, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDelegate(): PsiMethod = method
|
override fun getNavigationElement() : PsiElement = origin
|
||||||
|
override fun getOriginalElement() : PsiElement = origin
|
||||||
override fun getNavigationElement() : PsiElement = jetDeclaration
|
|
||||||
override fun getOriginalElement() : PsiElement = jetDeclaration
|
|
||||||
override fun getOrigin(): JetDeclaration? = jetDeclaration
|
|
||||||
|
|
||||||
override fun getParent(): PsiElement? = getContainingClass()
|
override fun getParent(): PsiElement? = getContainingClass()
|
||||||
|
|
||||||
override fun setName(name: String): PsiElement? {
|
override fun setName(name: String): PsiElement? {
|
||||||
(jetDeclaration as PsiNamedElement).setName(name)
|
(origin as PsiNamedElement).setName(name)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun delete() {
|
public override fun delete() {
|
||||||
if (jetDeclaration.isValid()) {
|
if (origin.isValid()) {
|
||||||
jetDeclaration.delete()
|
origin.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
||||||
if (another is KotlinLightMethod && getOrigin() == another.getOrigin()) {
|
if (another is KotlinLightMethod && origin == another.origin) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +98,6 @@ public class KotlinLightMethodForDeclaration(manager: PsiManager, val method: Ps
|
|||||||
getTypeParameterList()?.let { it.getTypeParameters() } ?: PsiTypeParameter.EMPTY_ARRAY
|
getTypeParameterList()?.let { it.getTypeParameters() } ?: PsiTypeParameter.EMPTY_ARRAY
|
||||||
|
|
||||||
override fun copy(): PsiElement {
|
override fun copy(): PsiElement {
|
||||||
return KotlinLightMethodForDeclaration(getManager()!!, method, jetDeclaration.copy() as JetDeclaration, getContainingClass()!!)
|
return KotlinLightMethodForDeclaration(getManager()!!, delegate, origin.copy() as JetDeclaration, getContainingClass()!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-2
@@ -20,12 +20,15 @@ import com.intellij.psi.*;
|
|||||||
import com.intellij.psi.impl.light.AbstractLightClass;
|
import com.intellij.psi.impl.light.AbstractLightClass;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetTypeParameter;
|
||||||
import org.jetbrains.jet.lang.psi.JetClass;
|
import org.jetbrains.jet.lang.psi.JetClass;
|
||||||
import org.jetbrains.jet.lang.psi.JetTypeParameterListOwner;
|
import org.jetbrains.jet.lang.psi.JetTypeParameterListOwner;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightElement;
|
||||||
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod;
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod;
|
||||||
import org.jetbrains.jet.plugin.JetLanguage;
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
public class KotlinLightTypeParameter extends AbstractLightClass implements PsiTypeParameter {
|
public class KotlinLightTypeParameter
|
||||||
|
extends AbstractLightClass implements PsiTypeParameter, KotlinLightElement<JetTypeParameter, PsiTypeParameter> {
|
||||||
private final PsiTypeParameterListOwner owner;
|
private final PsiTypeParameterListOwner owner;
|
||||||
private final int index;
|
private final int index;
|
||||||
private final String name;
|
private final String name;
|
||||||
@@ -46,6 +49,12 @@ public class KotlinLightTypeParameter extends AbstractLightClass implements PsiT
|
|||||||
return getOwnerDelegate().getTypeParameters()[index];
|
return getOwnerDelegate().getTypeParameters()[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public JetTypeParameter getOrigin() {
|
||||||
|
return ((JetTypeParameterListOwner) owner.getNavigationElement()).getTypeParameters().get(index);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private PsiTypeParameterListOwner getOwnerDelegate() {
|
private PsiTypeParameterListOwner getOwnerDelegate() {
|
||||||
if (owner instanceof KotlinLightClass) return ((KotlinLightClass) owner).getDelegate();
|
if (owner instanceof KotlinLightClass) return ((KotlinLightClass) owner).getDelegate();
|
||||||
@@ -116,6 +125,6 @@ public class KotlinLightTypeParameter extends AbstractLightClass implements PsiT
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiElement getNavigationElement() {
|
public PsiElement getNavigationElement() {
|
||||||
return ((JetTypeParameterListOwner) owner.getNavigationElement()).getTypeParameters().get(index);
|
return getOrigin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -84,7 +84,7 @@ public class KotlinFindClassUsagesDialog extends FindClassUsagesDialog {
|
|||||||
public void configureLabelComponent(@NotNull SimpleColoredComponent coloredComponent) {
|
public void configureLabelComponent(@NotNull SimpleColoredComponent coloredComponent) {
|
||||||
PsiClass klass = (PsiClass) getPsiElement();
|
PsiClass klass = (PsiClass) getPsiElement();
|
||||||
if (klass instanceof KotlinLightClassForExplicitDeclaration) {
|
if (klass instanceof KotlinLightClassForExplicitDeclaration) {
|
||||||
coloredComponent.append(JetRefactoringUtil.formatClass(((KotlinLightClassForExplicitDeclaration) klass).getJetClassOrObject()));
|
coloredComponent.append(JetRefactoringUtil.formatClass(((KotlinLightClassForExplicitDeclaration) klass).getOrigin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.asJava.KotlinLightClass;
|
import org.jetbrains.jet.asJava.KotlinLightClass;
|
||||||
import org.jetbrains.jet.asJava.KotlinLightClassForExplicitDeclaration;
|
import org.jetbrains.jet.asJava.KotlinLightClassForExplicitDeclaration;
|
||||||
import org.jetbrains.jet.asJava.KotlinLightClassForPackage;
|
import org.jetbrains.jet.asJava.KotlinLightClassForPackage;
|
||||||
import org.jetbrains.jet.lang.psi.JetClass;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.plugin.JetBundle;
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
@@ -67,7 +66,7 @@ public class RenameJetClassProcessor extends RenamePsiElementProcessor {
|
|||||||
private static JetClassOrObject getJetClassOrObject(@Nullable PsiElement element, boolean showErrors, @Nullable Editor editor) {
|
private static JetClassOrObject getJetClassOrObject(@Nullable PsiElement element, boolean showErrors, @Nullable Editor editor) {
|
||||||
if (element instanceof KotlinLightClass) {
|
if (element instanceof KotlinLightClass) {
|
||||||
if (element instanceof KotlinLightClassForExplicitDeclaration) {
|
if (element instanceof KotlinLightClassForExplicitDeclaration) {
|
||||||
return ((KotlinLightClassForExplicitDeclaration) element).getJetClassOrObject();
|
return ((KotlinLightClassForExplicitDeclaration) element).getOrigin();
|
||||||
}
|
}
|
||||||
else if (element instanceof KotlinLightClassForPackage) {
|
else if (element instanceof KotlinLightClassForPackage) {
|
||||||
if (showErrors) {
|
if (showErrors) {
|
||||||
|
|||||||
+2
-2
@@ -45,7 +45,7 @@ public class RenameKotlinFunctionProcessor : RenamePsiElementProcessor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun canProcessElement(element: PsiElement): Boolean {
|
override fun canProcessElement(element: PsiElement): Boolean {
|
||||||
return element is JetNamedFunction || (element is KotlinLightMethod && element.getOrigin() is JetNamedFunction)
|
return element is JetNamedFunction || (element is KotlinLightMethod && element.origin is JetNamedFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun substituteElementToRename(element: PsiElement?, editor: Editor?): PsiElement? {
|
override fun substituteElementToRename(element: PsiElement?, editor: Editor?): PsiElement? {
|
||||||
@@ -59,7 +59,7 @@ public class RenameKotlinFunctionProcessor : RenamePsiElementProcessor() {
|
|||||||
val subtitudedJavaElement = javaMethodProcessorInstance.substituteElementToRename(wrappedMethod, editor)
|
val subtitudedJavaElement = javaMethodProcessorInstance.substituteElementToRename(wrappedMethod, editor)
|
||||||
|
|
||||||
return when (subtitudedJavaElement) {
|
return when (subtitudedJavaElement) {
|
||||||
is KotlinLightMethod -> subtitudedJavaElement.getOrigin() as? JetNamedFunction
|
is KotlinLightMethod -> subtitudedJavaElement.origin as? JetNamedFunction
|
||||||
else -> subtitudedJavaElement
|
else -> subtitudedJavaElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ fun PsiReference.isPropertyReadOnlyUsage(): Boolean {
|
|||||||
|
|
||||||
val refTarget = resolve()
|
val refTarget = resolve()
|
||||||
if (refTarget is KotlinLightMethod) {
|
if (refTarget is KotlinLightMethod) {
|
||||||
val origin = refTarget.getOrigin()
|
val origin = refTarget.origin
|
||||||
val declaration: JetNamedDeclaration? = when (origin) {
|
val declaration: JetNamedDeclaration? = when (origin) {
|
||||||
is JetPropertyAccessor -> origin.getParentByType(javaClass<JetProperty>())
|
is JetPropertyAccessor -> origin.getParentByType(javaClass<JetProperty>())
|
||||||
is JetProperty, is JetParameter -> origin as JetNamedDeclaration
|
is JetProperty, is JetParameter -> origin as JetNamedDeclaration
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class JetPsiHeuristicsUtil {
|
|||||||
KotlinLightClassForExplicitDeclaration lightClass = (KotlinLightClassForExplicitDeclaration) member;
|
KotlinLightClassForExplicitDeclaration lightClass = (KotlinLightClassForExplicitDeclaration) member;
|
||||||
|
|
||||||
// It is a Kotlin class already, we need to properly check visibility?
|
// It is a Kotlin class already, we need to properly check visibility?
|
||||||
JetClassOrObject classOrObject = lightClass.getJetClassOrObject();
|
JetClassOrObject classOrObject = lightClass.getOrigin();
|
||||||
|
|
||||||
if (isTopLevelDeclaration(classOrObject) && classOrObject.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
|
if (isTopLevelDeclaration(classOrObject) && classOrObject.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
|
||||||
// The class is declared private in the targetPackage
|
// The class is declared private in the targetPackage
|
||||||
|
|||||||
Reference in New Issue
Block a user