Use light element origin instead of getNavigationElement()
This commit is contained in:
@@ -179,9 +179,6 @@ fun JetDeclaration.isOverridable(): Boolean {
|
|||||||
hasModifier(JetTokens.ABSTRACT_KEYWORD) || hasModifier(JetTokens.OPEN_KEYWORD) || hasModifier(JetTokens.OVERRIDE_KEYWORD)
|
hasModifier(JetTokens.ABSTRACT_KEYWORD) || hasModifier(JetTokens.OPEN_KEYWORD) || hasModifier(JetTokens.OVERRIDE_KEYWORD)
|
||||||
}
|
}
|
||||||
|
|
||||||
val PsiElement.namedNavigationElement: PsiNamedElement?
|
|
||||||
get() = getNavigationElement()?.getParentByType(javaClass<PsiNamedElement>())
|
|
||||||
|
|
||||||
fun PsiElement.isExtensionDeclaration(): Boolean {
|
fun PsiElement.isExtensionDeclaration(): Boolean {
|
||||||
val callable: JetCallableDeclaration? = when (this) {
|
val callable: JetCallableDeclaration? = when (this) {
|
||||||
is JetNamedFunction, is JetProperty -> this as JetCallableDeclaration
|
is JetNamedFunction, is JetProperty -> this as JetCallableDeclaration
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ 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.JetTypeParameter;
|
||||||
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.KotlinLightElement;
|
||||||
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod;
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod;
|
||||||
@@ -52,7 +51,10 @@ public class KotlinLightTypeParameter
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JetTypeParameter getOrigin() {
|
public JetTypeParameter getOrigin() {
|
||||||
return ((JetTypeParameterListOwner) owner.getNavigationElement()).getTypeParameters().get(index);
|
JetTypeParameterListOwner jetOwner = (JetTypeParameterListOwner) AsJavaPackage.getUnwrapped(owner);
|
||||||
|
assert (jetOwner != null) : "Invalid type parameter owner: " + owner;
|
||||||
|
|
||||||
|
return jetOwner.getTypeParameters().get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ import com.intellij.psi.PsiTypeParameter
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import org.jetbrains.jet.lang.psi.JetTypeParameterList
|
import org.jetbrains.jet.lang.psi.JetTypeParameterList
|
||||||
import com.intellij.psi.PsiTypeParameterListOwner
|
import com.intellij.psi.PsiTypeParameterListOwner
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightElement
|
||||||
|
import com.intellij.psi.PsiNamedElement
|
||||||
import com.intellij.psi.PsiNamedElement
|
import com.intellij.psi.PsiNamedElement
|
||||||
import org.jetbrains.jet.lang.psi.JetCallableDeclaration
|
import org.jetbrains.jet.lang.psi.JetCallableDeclaration
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.isExtensionDeclaration
|
import org.jetbrains.jet.lang.psi.psiUtil.isExtensionDeclaration
|
||||||
@@ -104,4 +106,11 @@ fun JetTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
|
|||||||
|
|
||||||
return lightOwners?.map { lightOwner -> (lightOwner as PsiTypeParameterListOwner).getTypeParameters()[paramIndex] }
|
return lightOwners?.map { lightOwner -> (lightOwner as PsiTypeParameterListOwner).getTypeParameters()[paramIndex] }
|
||||||
?: Collections.emptyList()
|
?: Collections.emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns original declaration if given PsiElement is a Kotlin light element, and element itself otherwise
|
||||||
|
val PsiElement.unwrapped: PsiElement?
|
||||||
|
get() = if (this is KotlinLightElement<*, *>) origin else this
|
||||||
|
|
||||||
|
val PsiElement.namedUnwrappedElement: PsiNamedElement?
|
||||||
|
get() = unwrapped?.getParentByType(javaClass<PsiNamedElement>())
|
||||||
@@ -26,12 +26,13 @@ import org.jetbrains.jet.lang.psi.*
|
|||||||
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod
|
||||||
import org.jetbrains.jet.asJava.KotlinLightClass
|
import org.jetbrains.jet.asJava.KotlinLightClass
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||||
|
import org.jetbrains.jet.asJava.unwrapped
|
||||||
import org.jetbrains.jet.plugin.search.usagesSearch.descriptor
|
import org.jetbrains.jet.plugin.search.usagesSearch.descriptor
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||||
|
|
||||||
public class JetElementDescriptionProvider : ElementDescriptionProvider {
|
public class JetElementDescriptionProvider : ElementDescriptionProvider {
|
||||||
public override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
|
public override fun getElementDescription(element: PsiElement, location: ElementDescriptionLocation): String? {
|
||||||
val targetElement = element.getNavigationElement()
|
val targetElement = element.unwrapped
|
||||||
|
|
||||||
fun elementKind() = when (targetElement) {
|
fun elementKind() = when (targetElement) {
|
||||||
is JetClass -> if (targetElement.isTrait()) "trait" else "class"
|
is JetClass -> if (targetElement.isTrait()) "trait" else "class"
|
||||||
|
|||||||
+2
-1
@@ -30,6 +30,7 @@ import java.text.MessageFormat
|
|||||||
import com.intellij.psi.ElementDescriptionUtil
|
import com.intellij.psi.ElementDescriptionUtil
|
||||||
import com.intellij.refactoring.util.RefactoringDescriptionLocation
|
import com.intellij.refactoring.util.RefactoringDescriptionLocation
|
||||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||||
|
import org.jetbrains.jet.asJava.unwrapped
|
||||||
|
|
||||||
class KotlinOverrideHierarchyBrowser(
|
class KotlinOverrideHierarchyBrowser(
|
||||||
project: Project, baseElement: PsiElement
|
project: Project, baseElement: PsiElement
|
||||||
@@ -56,7 +57,7 @@ class KotlinOverrideHierarchyBrowser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getContentDisplayName(typeName: String, element: PsiElement): String? {
|
override fun getContentDisplayName(typeName: String, element: PsiElement): String? {
|
||||||
val targetElement = element.getNavigationElement()
|
val targetElement = element.unwrapped
|
||||||
if (targetElement is JetDeclaration) {
|
if (targetElement is JetDeclaration) {
|
||||||
return ElementDescriptionUtil.getElementDescription(targetElement, RefactoringDescriptionLocation.WITHOUT_PARENT)
|
return ElementDescriptionUtil.getElementDescription(targetElement, RefactoringDescriptionLocation.WITHOUT_PARENT)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -239,7 +239,9 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
|
|||||||
PsiElement usageElement = javaDeleteUsageInfo.getElement();
|
PsiElement usageElement = javaDeleteUsageInfo.getElement();
|
||||||
JetImportDirective importDirective = PsiTreeUtil.getParentOfType(usageElement, JetImportDirective.class, false);
|
JetImportDirective importDirective = PsiTreeUtil.getParentOfType(usageElement, JetImportDirective.class, false);
|
||||||
if (importDirective != null) {
|
if (importDirective != null) {
|
||||||
usageInfo = new SafeDeleteImportDirectiveUsageInfo(importDirective, (JetDeclaration) element.getNavigationElement());
|
usageInfo = new SafeDeleteImportDirectiveUsageInfo(
|
||||||
|
importDirective, (JetDeclaration) AsJavaPackage.getUnwrapped(element)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (usageInfo != null) {
|
if (usageInfo != null) {
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ import com.intellij.util.IncorrectOperationException;
|
|||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.asJava.AsJavaPackage;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||||
@@ -94,8 +93,8 @@ public abstract class JetPsiReference implements PsiPolyVariantReference {
|
|||||||
PsiElement resolvedElement = resolve();
|
PsiElement resolvedElement = resolve();
|
||||||
if (resolvedElement == null) return false;
|
if (resolvedElement == null) return false;
|
||||||
|
|
||||||
PsiNamedElement namedDeclaration = PsiUtilPackage.getNamedNavigationElement(element);
|
PsiNamedElement namedDeclaration = AsJavaPackage.getNamedUnwrappedElement(element);
|
||||||
PsiNamedElement namedResolvedDeclaration = PsiUtilPackage.getNamedNavigationElement(resolvedElement);
|
PsiNamedElement namedResolvedDeclaration = AsJavaPackage.getNamedUnwrappedElement(resolvedElement);
|
||||||
|
|
||||||
return namedDeclaration != null && namedDeclaration.equals(namedResolvedDeclaration);
|
return namedDeclaration != null && namedDeclaration.equals(namedResolvedDeclaration);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,12 +44,13 @@ import org.jetbrains.jet.lang.resolve.java.JvmAbi
|
|||||||
import org.jetbrains.jet.codegen.PropertyCodegen
|
import org.jetbrains.jet.codegen.PropertyCodegen
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod
|
import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightMethod
|
||||||
|
import org.jetbrains.jet.asJava.unwrapped
|
||||||
|
|
||||||
// Navigation element of the resolved reference
|
// Navigation element of the resolved reference
|
||||||
// For property accessor return enclosing property
|
// For property accessor return enclosing property
|
||||||
val PsiReference.navigationTarget: PsiElement?
|
val PsiReference.unwrappedTarget: PsiElement?
|
||||||
get() {
|
get() {
|
||||||
val target = resolve()?.getNavigationElement()
|
val target = resolve()?.unwrapped
|
||||||
return if (target is JetPropertyAccessor) target.getParentByType(javaClass<JetProperty>()) else target
|
return if (target is JetPropertyAccessor) target.getParentByType(javaClass<JetProperty>()) else target
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ val JetParameter.propertyDescriptor: PropertyDescriptor?
|
|||||||
get() = AnalyzerFacadeWithCache.getContextForElement(this).get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, this)
|
get() = AnalyzerFacadeWithCache.getContextForElement(this).get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, this)
|
||||||
|
|
||||||
fun PsiReference.isTargetUsage(target: PsiElement): Boolean {
|
fun PsiReference.isTargetUsage(target: PsiElement): Boolean {
|
||||||
return target.getNavigationElement() == navigationTarget
|
return target.unwrapped == unwrappedTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiReference.checkUsageVsOriginalDescriptor(
|
fun PsiReference.checkUsageVsOriginalDescriptor(
|
||||||
@@ -68,7 +69,7 @@ fun PsiReference.checkUsageVsOriginalDescriptor(
|
|||||||
declarationToDescriptor: (JetDeclaration) -> DeclarationDescriptor? = {it.descriptor},
|
declarationToDescriptor: (JetDeclaration) -> DeclarationDescriptor? = {it.descriptor},
|
||||||
checker: (usageDescriptor: DeclarationDescriptor, targetDescriptor: DeclarationDescriptor) -> Boolean
|
checker: (usageDescriptor: DeclarationDescriptor, targetDescriptor: DeclarationDescriptor) -> Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val refTarget = navigationTarget
|
val refTarget = unwrappedTarget
|
||||||
if (refTarget !is JetDeclaration) return false
|
if (refTarget !is JetDeclaration) return false
|
||||||
|
|
||||||
val usageDescriptor = declarationToDescriptor(refTarget)
|
val usageDescriptor = declarationToDescriptor(refTarget)
|
||||||
|
|||||||
Reference in New Issue
Block a user