rename Jet* classes to Kt*
This commit is contained in:
+30
-30
@@ -23,10 +23,10 @@ import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetCodeFragment
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.JetTypeReference
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
|
||||
@@ -35,14 +35,14 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.util.*
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ReferenceVariantsHelper(
|
||||
) {
|
||||
@JvmOverloads
|
||||
public fun getReferenceVariants(
|
||||
expression: JetSimpleNameExpression,
|
||||
expression: KtSimpleNameExpression,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
callTypeAndReceiver: CallTypeAndReceiver<*, *> = CallTypeAndReceiver.detect(expression),
|
||||
@@ -85,7 +85,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun getReferenceVariantsNoVisibilityFilter(
|
||||
expression: JetSimpleNameExpression,
|
||||
expression: KtSimpleNameExpression,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
callTypeAndReceiver: CallTypeAndReceiver<*, *>,
|
||||
@@ -96,7 +96,7 @@ public class ReferenceVariantsHelper(
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val kindFilter = kindFilter.intersect(callType.descriptorKindFilter)
|
||||
|
||||
val receiverExpression: JetExpression?
|
||||
val receiverExpression: KtExpression?
|
||||
when (callTypeAndReceiver) {
|
||||
is CallTypeAndReceiver.IMPORT_DIRECTIVE -> {
|
||||
return getVariantsForImportOrPackageDirective(callTypeAndReceiver.receiver, kindFilter, nameFilter)
|
||||
@@ -115,7 +115,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
is CallTypeAndReceiver.CALLABLE_REFERENCE -> {
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression.parent as JetExpression] ?: return emptyList()
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression.parent as KtExpression] ?: return emptyList()
|
||||
return getVariantsForCallableReference(callTypeAndReceiver.receiver, resolutionScope, kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
@@ -168,8 +168,8 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun getVariantsForUserType(
|
||||
receiverExpression: JetExpression?,
|
||||
expression: JetSimpleNameExpression,
|
||||
receiverExpression: KtExpression?,
|
||||
expression: KtSimpleNameExpression,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
@@ -178,7 +178,7 @@ public class ReferenceVariantsHelper(
|
||||
return qualifier.scope.getDescriptorsFiltered(kindFilter, nameFilter)
|
||||
}
|
||||
else {
|
||||
val lexicalScope = expression.getParentOfType<JetTypeReference>(strict = true)?.let {
|
||||
val lexicalScope = expression.getParentOfType<KtTypeReference>(strict = true)?.let {
|
||||
context[BindingContext.LEXICAL_SCOPE, it]
|
||||
} ?: return emptyList()
|
||||
return lexicalScope.getDescriptorsFiltered(kindFilter, nameFilter)
|
||||
@@ -186,8 +186,8 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun getVariantsForCallableReference(
|
||||
qualifierTypeRef: JetTypeReference?,
|
||||
resolutionScope: JetScope,
|
||||
qualifierTypeRef: KtTypeReference?,
|
||||
resolutionScope: KtScope,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
@@ -207,7 +207,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun getVariantsForImportOrPackageDirective(
|
||||
receiverExpression: JetExpression?,
|
||||
receiverExpression: KtExpression?,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
@@ -222,9 +222,9 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.processAll(
|
||||
implicitReceiverTypes: Collection<JetType>,
|
||||
receiverTypes: Collection<JetType>,
|
||||
resolutionScope: JetScope,
|
||||
implicitReceiverTypes: Collection<KtType>,
|
||||
receiverTypes: Collection<KtType>,
|
||||
resolutionScope: KtScope,
|
||||
callType: CallType<*>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
@@ -235,8 +235,8 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.addMemberExtensions(
|
||||
dispatchReceiverTypes: Collection<JetType>,
|
||||
extensionReceiverTypes: Collection<JetType>,
|
||||
dispatchReceiverTypes: Collection<KtType>,
|
||||
extensionReceiverTypes: Collection<KtType>,
|
||||
callType: CallType<*>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
@@ -250,7 +250,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.addNonExtensionMembers(
|
||||
receiverTypes: Collection<JetType>,
|
||||
receiverTypes: Collection<KtType>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
constructorFilter: (ClassDescriptor) -> Boolean
|
||||
@@ -261,7 +261,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.addNonExtensionCallablesAndConstructors(
|
||||
scope: JetScope,
|
||||
scope: KtScope,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean,
|
||||
constructorFilter: (ClassDescriptor) -> Boolean
|
||||
@@ -286,8 +286,8 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
private fun MutableSet<DeclarationDescriptor>.addScopeAndSyntheticExtensions(
|
||||
resolutionScope: JetScope,
|
||||
receiverTypes: Collection<JetType>,
|
||||
resolutionScope: KtScope,
|
||||
receiverTypes: Collection<KtType>,
|
||||
callType: CallType<*>,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
@@ -320,10 +320,10 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getQualifierRuntimeType(receiver: JetExpression): JetType? {
|
||||
private fun getQualifierRuntimeType(receiver: KtExpression): KtType? {
|
||||
val type = context.getType(receiver)
|
||||
if (type != null && TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, type)) {
|
||||
val evaluator = receiver.getContainingFile().getCopyableUserData(JetCodeFragment.RUNTIME_TYPE_EVALUATOR)
|
||||
if (type != null && TypeUtils.canHaveSubtypes(KotlinTypeChecker.DEFAULT, type)) {
|
||||
val evaluator = receiver.getContainingFile().getCopyableUserData(KtCodeFragment.RUNTIME_TYPE_EVALUATOR)
|
||||
val runtimeType = evaluator?.invoke(receiver)
|
||||
if (runtimeType == type) return null
|
||||
return runtimeType
|
||||
@@ -332,7 +332,7 @@ public class ReferenceVariantsHelper(
|
||||
}
|
||||
|
||||
public fun getPackageReferenceVariants(
|
||||
expression: JetSimpleNameExpression,
|
||||
expression: KtSimpleNameExpression,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||
|
||||
@@ -21,19 +21,19 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
|
||||
public interface ResolutionFacade {
|
||||
public val project: Project
|
||||
|
||||
public fun analyze(element: JetElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext
|
||||
public fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext
|
||||
|
||||
public fun analyzeFullyAndGetResult(elements: Collection<JetElement>): AnalysisResult
|
||||
public fun analyzeFullyAndGetResult(elements: Collection<KtElement>): AnalysisResult
|
||||
|
||||
public fun resolveToDescriptor(declaration: JetDeclaration): DeclarationDescriptor
|
||||
public fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor
|
||||
|
||||
public val moduleDescriptor: ModuleDescriptor
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isImportDirectiveExpression
|
||||
@@ -29,31 +29,31 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
|
||||
public sealed class CallType<TReceiver : JetElement?>(val descriptorKindFilter: DescriptorKindFilter) {
|
||||
public sealed class CallType<TReceiver : KtElement?>(val descriptorKindFilter: DescriptorKindFilter) {
|
||||
object UNKNOWN : CallType<Nothing?>(DescriptorKindFilter.ALL)
|
||||
|
||||
object DEFAULT : CallType<Nothing?>(DescriptorKindFilter.ALL)
|
||||
|
||||
object DOT : CallType<JetExpression>(DescriptorKindFilter.ALL)
|
||||
object DOT : CallType<KtExpression>(DescriptorKindFilter.ALL)
|
||||
|
||||
object SAFE : CallType<JetExpression>(DescriptorKindFilter.ALL)
|
||||
object SAFE : CallType<KtExpression>(DescriptorKindFilter.ALL)
|
||||
|
||||
object INFIX : CallType<JetExpression>(DescriptorKindFilter.FUNCTIONS exclude NonInfixExclude)
|
||||
object INFIX : CallType<KtExpression>(DescriptorKindFilter.FUNCTIONS exclude NonInfixExclude)
|
||||
|
||||
object OPERATOR : CallType<JetExpression>(DescriptorKindFilter.FUNCTIONS exclude NonOperatorExclude)
|
||||
object OPERATOR : CallType<KtExpression>(DescriptorKindFilter.FUNCTIONS exclude NonOperatorExclude)
|
||||
|
||||
object CALLABLE_REFERENCE : CallType<JetTypeReference?>(DescriptorKindFilter.CALLABLES exclude CallableReferenceExclude)
|
||||
object CALLABLE_REFERENCE : CallType<KtTypeReference?>(DescriptorKindFilter.CALLABLES exclude CallableReferenceExclude)
|
||||
|
||||
object IMPORT_DIRECTIVE : CallType<JetExpression?>(DescriptorKindFilter.ALL)
|
||||
object IMPORT_DIRECTIVE : CallType<KtExpression?>(DescriptorKindFilter.ALL)
|
||||
|
||||
object PACKAGE_DIRECTIVE : CallType<JetExpression?>(DescriptorKindFilter.PACKAGES)
|
||||
object PACKAGE_DIRECTIVE : CallType<KtExpression?>(DescriptorKindFilter.PACKAGES)
|
||||
|
||||
object TYPE : CallType<JetExpression?>(DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK))
|
||||
object TYPE : CallType<KtExpression?>(DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK))
|
||||
|
||||
object ANNOTATION : CallType<JetExpression?>(DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude NonAnnotationClassifierExclude)
|
||||
object ANNOTATION : CallType<KtExpression?>(DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude NonAnnotationClassifierExclude)
|
||||
|
||||
private object NonInfixExclude : DescriptorKindExclude() {
|
||||
override fun excludes(descriptor: DeclarationDescriptor) =
|
||||
@@ -89,26 +89,26 @@ public sealed class CallType<TReceiver : JetElement?>(val descriptorKindFilter:
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CallTypeAndReceiver<TReceiver : JetElement?, TCallType : CallType<TReceiver>>(
|
||||
public sealed class CallTypeAndReceiver<TReceiver : KtElement?, TCallType : CallType<TReceiver>>(
|
||||
val callType: TCallType,
|
||||
val receiver: TReceiver
|
||||
) {
|
||||
object UNKNOWN : CallTypeAndReceiver<Nothing?, CallType.UNKNOWN>(CallType.UNKNOWN, null)
|
||||
object DEFAULT : CallTypeAndReceiver<Nothing?, CallType.DEFAULT>(CallType.DEFAULT, null)
|
||||
class DOT(receiver: JetExpression) : CallTypeAndReceiver<JetExpression, CallType.DOT>(CallType.DOT, receiver)
|
||||
class SAFE(receiver: JetExpression) : CallTypeAndReceiver<JetExpression, CallType.SAFE>(CallType.SAFE, receiver)
|
||||
class INFIX(receiver: JetExpression) : CallTypeAndReceiver<JetExpression, CallType.INFIX>(CallType.INFIX, receiver)
|
||||
class OPERATOR(receiver: JetExpression) : CallTypeAndReceiver<JetExpression, CallType.OPERATOR>(CallType.OPERATOR, receiver)
|
||||
class CALLABLE_REFERENCE(receiver: JetTypeReference?) : CallTypeAndReceiver<JetTypeReference?, CallType.CALLABLE_REFERENCE>(CallType.CALLABLE_REFERENCE, receiver)
|
||||
class IMPORT_DIRECTIVE(receiver: JetExpression?) : CallTypeAndReceiver<JetExpression?, CallType.IMPORT_DIRECTIVE>(CallType.IMPORT_DIRECTIVE, receiver)
|
||||
class PACKAGE_DIRECTIVE(receiver: JetExpression?) : CallTypeAndReceiver<JetExpression?, CallType.PACKAGE_DIRECTIVE>(CallType.PACKAGE_DIRECTIVE, receiver)
|
||||
class TYPE(receiver: JetExpression?) : CallTypeAndReceiver<JetExpression?, CallType.TYPE>(CallType.TYPE, receiver)
|
||||
class ANNOTATION(receiver: JetExpression?) : CallTypeAndReceiver<JetExpression?, CallType.ANNOTATION>(CallType.ANNOTATION, receiver)
|
||||
class DOT(receiver: KtExpression) : CallTypeAndReceiver<KtExpression, CallType.DOT>(CallType.DOT, receiver)
|
||||
class SAFE(receiver: KtExpression) : CallTypeAndReceiver<KtExpression, CallType.SAFE>(CallType.SAFE, receiver)
|
||||
class INFIX(receiver: KtExpression) : CallTypeAndReceiver<KtExpression, CallType.INFIX>(CallType.INFIX, receiver)
|
||||
class OPERATOR(receiver: KtExpression) : CallTypeAndReceiver<KtExpression, CallType.OPERATOR>(CallType.OPERATOR, receiver)
|
||||
class CALLABLE_REFERENCE(receiver: KtTypeReference?) : CallTypeAndReceiver<KtTypeReference?, CallType.CALLABLE_REFERENCE>(CallType.CALLABLE_REFERENCE, receiver)
|
||||
class IMPORT_DIRECTIVE(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.IMPORT_DIRECTIVE>(CallType.IMPORT_DIRECTIVE, receiver)
|
||||
class PACKAGE_DIRECTIVE(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.PACKAGE_DIRECTIVE>(CallType.PACKAGE_DIRECTIVE, receiver)
|
||||
class TYPE(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.TYPE>(CallType.TYPE, receiver)
|
||||
class ANNOTATION(receiver: KtExpression?) : CallTypeAndReceiver<KtExpression?, CallType.ANNOTATION>(CallType.ANNOTATION, receiver)
|
||||
|
||||
companion object {
|
||||
public fun detect(expression: JetSimpleNameExpression): CallTypeAndReceiver<*, *> {
|
||||
public fun detect(expression: KtSimpleNameExpression): CallTypeAndReceiver<*, *> {
|
||||
val parent = expression.parent
|
||||
if (parent is JetCallableReferenceExpression) {
|
||||
if (parent is KtCallableReferenceExpression) {
|
||||
return CallTypeAndReceiver.CALLABLE_REFERENCE(parent.typeReference)
|
||||
}
|
||||
|
||||
@@ -122,9 +122,9 @@ public sealed class CallTypeAndReceiver<TReceiver : JetElement?, TCallType : Cal
|
||||
return CallTypeAndReceiver.PACKAGE_DIRECTIVE(receiverExpression)
|
||||
}
|
||||
|
||||
if (parent is JetUserType) {
|
||||
val constructorCallee = (parent.parent as? JetTypeReference)?.parent as? JetConstructorCalleeExpression
|
||||
if (constructorCallee != null && constructorCallee.parent is JetAnnotationEntry) {
|
||||
if (parent is KtUserType) {
|
||||
val constructorCallee = (parent.parent as? KtTypeReference)?.parent as? KtConstructorCalleeExpression
|
||||
if (constructorCallee != null && constructorCallee.parent is KtAnnotationEntry) {
|
||||
return CallTypeAndReceiver.ANNOTATION(receiverExpression)
|
||||
}
|
||||
|
||||
@@ -132,39 +132,39 @@ public sealed class CallTypeAndReceiver<TReceiver : JetElement?, TCallType : Cal
|
||||
}
|
||||
|
||||
when (expression) {
|
||||
is JetOperationReferenceExpression -> {
|
||||
is KtOperationReferenceExpression -> {
|
||||
if (receiverExpression == null) {
|
||||
return UNKNOWN // incomplete code
|
||||
}
|
||||
return when (parent) {
|
||||
is JetBinaryExpression -> {
|
||||
if (parent.operationToken == JetTokens.IDENTIFIER)
|
||||
is KtBinaryExpression -> {
|
||||
if (parent.operationToken == KtTokens.IDENTIFIER)
|
||||
CallTypeAndReceiver.INFIX(receiverExpression)
|
||||
else
|
||||
CallTypeAndReceiver.OPERATOR(receiverExpression)
|
||||
}
|
||||
|
||||
is JetUnaryExpression -> CallTypeAndReceiver.OPERATOR(receiverExpression)
|
||||
is KtUnaryExpression -> CallTypeAndReceiver.OPERATOR(receiverExpression)
|
||||
|
||||
else -> error("Unknown parent for JetOperationReferenceExpression: $parent")
|
||||
}
|
||||
}
|
||||
|
||||
is JetNameReferenceExpression -> {
|
||||
is KtNameReferenceExpression -> {
|
||||
if (receiverExpression == null) {
|
||||
return CallTypeAndReceiver.DEFAULT
|
||||
}
|
||||
|
||||
return when (parent) {
|
||||
is JetCallExpression -> {
|
||||
if ((parent.parent as JetQualifiedExpression).operationSign == JetTokens.SAFE_ACCESS)
|
||||
is KtCallExpression -> {
|
||||
if ((parent.parent as KtQualifiedExpression).operationSign == KtTokens.SAFE_ACCESS)
|
||||
CallTypeAndReceiver.SAFE(receiverExpression)
|
||||
else
|
||||
CallTypeAndReceiver.DOT(receiverExpression)
|
||||
}
|
||||
|
||||
is JetQualifiedExpression -> {
|
||||
if (parent.operationSign == JetTokens.SAFE_ACCESS)
|
||||
is KtQualifiedExpression -> {
|
||||
if (parent.operationSign == KtTokens.SAFE_ACCESS)
|
||||
CallTypeAndReceiver.SAFE(receiverExpression)
|
||||
else
|
||||
CallTypeAndReceiver.DOT(receiverExpression)
|
||||
@@ -182,11 +182,11 @@ public sealed class CallTypeAndReceiver<TReceiver : JetElement?, TCallType : Cal
|
||||
|
||||
public fun CallTypeAndReceiver<*, *>.receiverTypes(
|
||||
bindingContext: BindingContext,
|
||||
position: JetExpression,
|
||||
position: KtExpression,
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
predictableSmartCastsOnly: Boolean
|
||||
): Collection<JetType>? {
|
||||
val receiverExpression: JetExpression?
|
||||
): Collection<KtType>? {
|
||||
val receiverExpression: KtExpression?
|
||||
when (this) {
|
||||
is CallTypeAndReceiver.CALLABLE_REFERENCE -> {
|
||||
return receiver?.let { bindingContext[BindingContext.TYPE, it] }.singletonOrEmptyList()
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.registerTypeVariables
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
@@ -51,7 +51,7 @@ fun FuzzyType.isAlmostEverything(): Boolean {
|
||||
}
|
||||
|
||||
class FuzzyType(
|
||||
val type: JetType,
|
||||
val type: KtType,
|
||||
freeParameters: Collection<TypeParameterDescriptor>
|
||||
) {
|
||||
public val freeParameters: Set<TypeParameterDescriptor>
|
||||
@@ -71,7 +71,7 @@ class FuzzyType(
|
||||
|
||||
override fun hashCode() = type.hashCode()
|
||||
|
||||
private fun MutableSet<TypeParameterDescriptor>.addUsedTypeParameters(type: JetType) {
|
||||
private fun MutableSet<TypeParameterDescriptor>.addUsedTypeParameters(type: KtType) {
|
||||
val typeParameter = type.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
if (typeParameter != null && add(typeParameter)) {
|
||||
typeParameter.getLowerBounds().forEach { addUsedTypeParameters(it) }
|
||||
@@ -91,10 +91,10 @@ class FuzzyType(
|
||||
public fun checkIsSuperTypeOf(otherType: FuzzyType): TypeSubstitutor?
|
||||
= matchedSubstitutor(otherType, MatchKind.IS_SUPERTYPE)
|
||||
|
||||
public fun checkIsSubtypeOf(otherType: JetType): TypeSubstitutor?
|
||||
public fun checkIsSubtypeOf(otherType: KtType): TypeSubstitutor?
|
||||
= checkIsSubtypeOf(FuzzyType(otherType, emptyList()))
|
||||
|
||||
public fun checkIsSuperTypeOf(otherType: JetType): TypeSubstitutor?
|
||||
public fun checkIsSuperTypeOf(otherType: KtType): TypeSubstitutor?
|
||||
= checkIsSuperTypeOf(FuzzyType(otherType, emptyList()))
|
||||
|
||||
private enum class MatchKind {
|
||||
@@ -106,7 +106,7 @@ class FuzzyType(
|
||||
if (type.isError()) return null
|
||||
if (otherType.type.isError()) return null
|
||||
|
||||
fun JetType.checkInheritance(otherType: JetType): Boolean {
|
||||
fun KtType.checkInheritance(otherType: KtType): Boolean {
|
||||
return when (matchKind) {
|
||||
MatchKind.IS_SUBTYPE -> this.isSubtypeOf(otherType)
|
||||
MatchKind.IS_SUPERTYPE -> otherType.isSubtypeOf(this)
|
||||
|
||||
@@ -20,16 +20,16 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
|
||||
import org.jetbrains.kotlin.renderer.NameShortness
|
||||
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
public object IdeDescriptorRenderers {
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES: (JetType) -> JetType = { approximateFlexibleTypes(it, true) }
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES: (KtType) -> KtType = { approximateFlexibleTypes(it, true) }
|
||||
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (JetType) -> JetType = { approximateFlexibleTypes(it, false) }
|
||||
public val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (KtType) -> KtType = { approximateFlexibleTypes(it, false) }
|
||||
|
||||
private fun unwrapAnonymousType(type: JetType): JetType {
|
||||
private fun unwrapAnonymousType(type: KtType): KtType {
|
||||
if (type.isDynamic()) return type
|
||||
|
||||
val classifier = type.constructor.declarationDescriptor
|
||||
|
||||
@@ -20,13 +20,13 @@ package org.jetbrains.kotlin.idea.imports
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getImportableDescriptor
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
public val DeclarationDescriptor.importableFqName: FqName?
|
||||
get() {
|
||||
@@ -51,13 +51,13 @@ public fun DeclarationDescriptor.canBeReferencedViaImport(): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
public fun JetType.canBeReferencedViaImport(): Boolean {
|
||||
public fun KtType.canBeReferencedViaImport(): Boolean {
|
||||
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||
return descriptor != null && descriptor.canBeReferencedViaImport()
|
||||
}
|
||||
|
||||
// for cases when class qualifier refers companion object treats it like reference to class itself
|
||||
public fun JetReferenceExpression.getImportableTargets(bindingContext: BindingContext): Collection<DeclarationDescriptor> {
|
||||
public fun KtReferenceExpression.getImportableTargets(bindingContext: BindingContext): Collection<DeclarationDescriptor> {
|
||||
val targets = bindingContext[BindingContext.SHORT_REFERENCE_TO_COMPANION_OBJECT, this]?.let { listOf(it) }
|
||||
?: getReferenceTargets(bindingContext)
|
||||
return targets.map { it.getImportableDescriptor() }.toSet()
|
||||
|
||||
@@ -40,14 +40,14 @@ import java.util.*
|
||||
public class ShadowedDeclarationsFilter private constructor(
|
||||
private val bindingContext: BindingContext,
|
||||
private val resolutionFacade: ResolutionFacade,
|
||||
private val context: JetExpression,
|
||||
private val context: KtExpression,
|
||||
private val explicitReceiverValue: ReceiverValue
|
||||
) {
|
||||
companion object {
|
||||
fun create(
|
||||
bindingContext: BindingContext,
|
||||
resolutionFacade: ResolutionFacade,
|
||||
context: JetExpression,
|
||||
context: KtExpression,
|
||||
callTypeAndReceiver: CallTypeAndReceiver<*, *>
|
||||
): ShadowedDeclarationsFilter? {
|
||||
val receiverExpression = when (callTypeAndReceiver) {
|
||||
@@ -67,7 +67,7 @@ public class ShadowedDeclarationsFilter private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private val psiFactory = JetPsiFactory(resolutionFacade.project)
|
||||
private val psiFactory = KtPsiFactory(resolutionFacade.project)
|
||||
private val dummyExpressionFactory = DummyExpressionFactory(psiFactory)
|
||||
|
||||
public fun <TDescriptor : DeclarationDescriptor> filter(declarations: Collection<TDescriptor>): Collection<TDescriptor> {
|
||||
@@ -173,7 +173,7 @@ public class ShadowedDeclarationsFilter private constructor(
|
||||
|
||||
override fun getFunctionLiteralArguments() = emptyList<FunctionLiteralArgument>()
|
||||
|
||||
override fun getTypeArguments() = emptyList<JetTypeProjection>()
|
||||
override fun getTypeArguments() = emptyList<KtTypeProjection>()
|
||||
|
||||
override fun getTypeArgumentList() = null
|
||||
|
||||
@@ -209,10 +209,10 @@ public class ShadowedDeclarationsFilter private constructor(
|
||||
return if (filtered.isNotEmpty()) filtered else descriptors /* something went wrong, none of our declarations among resolve candidates, let's not filter anything */
|
||||
}
|
||||
|
||||
private class DummyExpressionFactory(val factory: JetPsiFactory) {
|
||||
private val expressions = ArrayList<JetExpression>()
|
||||
private class DummyExpressionFactory(val factory: KtPsiFactory) {
|
||||
private val expressions = ArrayList<KtExpression>()
|
||||
|
||||
fun createDummyExpressions(count: Int): List<JetExpression> {
|
||||
fun createDummyExpressions(count: Int): List<KtExpression> {
|
||||
while (expressions.size() < count) {
|
||||
expressions.add(factory.createExpression("dummy"))
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
|
||||
public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true): JetType {
|
||||
public fun approximateFlexibleTypes(jetType: KtType, outermost: Boolean = true): KtType {
|
||||
if (jetType.isDynamic()) return jetType
|
||||
if (jetType.isFlexible()) {
|
||||
val flexible = jetType.flexibility()
|
||||
@@ -60,7 +60,7 @@ public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true)
|
||||
|
||||
return approximation
|
||||
}
|
||||
return JetTypeImpl.create(
|
||||
return KtTypeImpl.create(
|
||||
jetType.getAnnotations(),
|
||||
jetType.getConstructor(),
|
||||
jetType.isMarkedNullable(),
|
||||
@@ -69,15 +69,15 @@ public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true)
|
||||
)
|
||||
}
|
||||
|
||||
public fun JetType.isAnnotatedReadOnly(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_READONLY_ANNOTATION)
|
||||
public fun JetType.isAnnotatedNotNull(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NOT_NULL_ANNOTATION)
|
||||
public fun JetType.isAnnotatedNullable(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NULLABLE_ANNOTATION)
|
||||
public fun KtType.isAnnotatedReadOnly(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_READONLY_ANNOTATION)
|
||||
public fun KtType.isAnnotatedNotNull(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NOT_NULL_ANNOTATION)
|
||||
public fun KtType.isAnnotatedNullable(): Boolean = hasAnnotationMaybeExternal(JETBRAINS_NULLABLE_ANNOTATION)
|
||||
|
||||
private fun JetType.hasAnnotationMaybeExternal(fqName: FqName) = with (getAnnotations()) {
|
||||
private fun KtType.hasAnnotationMaybeExternal(fqName: FqName) = with (getAnnotations()) {
|
||||
findAnnotation(fqName) ?: findExternalAnnotation(fqName)
|
||||
} != null
|
||||
|
||||
fun JetType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boolean): Boolean {
|
||||
fun KtType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boolean): Boolean {
|
||||
if (canBeReferencedViaImport()) return true
|
||||
|
||||
val descriptor = getConstructor().getDeclarationDescriptor()
|
||||
@@ -87,13 +87,13 @@ fun JetType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boole
|
||||
return scope != null && scope.getClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor
|
||||
}
|
||||
|
||||
public fun JetType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): JetType {
|
||||
public fun KtType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): KtType {
|
||||
if (isError() || isResolvableInScope(scope, checkTypeParameters)) return this
|
||||
return supertypes().firstOrNull { it.isResolvableInScope(scope, checkTypeParameters) }
|
||||
?: builtIns.anyType
|
||||
}
|
||||
|
||||
public fun JetType.anonymousObjectSuperTypeOrNull(): JetType? {
|
||||
public fun KtType.anonymousObjectSuperTypeOrNull(): KtType? {
|
||||
val classDescriptor = constructor.declarationDescriptor
|
||||
if (classDescriptor != null && DescriptorUtils.isAnonymousObject(classDescriptor)) {
|
||||
return immediateSupertypes().firstOrNull() ?: classDescriptor.builtIns.anyType
|
||||
|
||||
@@ -19,23 +19,23 @@ package org.jetbrains.kotlin.idea.util
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
public fun JetFunctionLiteral.findLabelAndCall(): Pair<Name?, JetCallExpression?> {
|
||||
val literalParent = (this.getParent() as JetFunctionLiteralExpression).getParent()
|
||||
public fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
|
||||
val literalParent = (this.getParent() as KtFunctionLiteralExpression).getParent()
|
||||
|
||||
fun JetValueArgument.callExpression(): JetCallExpression? {
|
||||
fun KtValueArgument.callExpression(): KtCallExpression? {
|
||||
val parent = getParent()
|
||||
return (if (parent is JetValueArgumentList) parent else this).getParent() as? JetCallExpression
|
||||
return (if (parent is KtValueArgumentList) parent else this).getParent() as? KtCallExpression
|
||||
}
|
||||
|
||||
when (literalParent) {
|
||||
is JetLabeledExpression -> {
|
||||
val callExpression = (literalParent.getParent() as? JetValueArgument)?.callExpression()
|
||||
is KtLabeledExpression -> {
|
||||
val callExpression = (literalParent.getParent() as? KtValueArgument)?.callExpression()
|
||||
return Pair(literalParent.getLabelNameAsName(), callExpression)
|
||||
}
|
||||
|
||||
is JetValueArgument -> {
|
||||
is KtValueArgument -> {
|
||||
val callExpression = literalParent.callExpression()
|
||||
val label = (callExpression?.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedNameAsName()
|
||||
val label = (callExpression?.getCalleeExpression() as? KtSimpleNameExpression)?.getReferencedNameAsName()
|
||||
return Pair(label, callExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,16 @@ package org.jetbrains.kotlin.idea.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetPsiUtil
|
||||
import org.jetbrains.kotlin.psi.JetThisExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||
@@ -51,7 +51,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
}
|
||||
|
||||
public fun CallableDescriptor.substituteExtensionIfCallableWithImplicitReceiver(
|
||||
scope: JetScope,
|
||||
scope: KtScope,
|
||||
context: BindingContext,
|
||||
dataFlowInfo: DataFlowInfo
|
||||
): Collection<CallableDescriptor> {
|
||||
@@ -73,7 +73,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
}
|
||||
|
||||
public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
receiverTypes: Collection<JetType>,
|
||||
receiverTypes: Collection<KtType>,
|
||||
callType: CallType<*>
|
||||
): Collection<CallableDescriptor> {
|
||||
if (!callType.descriptorKindFilter.accepts(this)) return listOf()
|
||||
@@ -105,7 +105,7 @@ public fun CallableDescriptor.substituteExtensionIfCallable(
|
||||
public fun ReceiverValue.getThisReceiverOwner(bindingContext: BindingContext): DeclarationDescriptor? {
|
||||
return when (this) {
|
||||
is ExpressionReceiver -> {
|
||||
val thisRef = (JetPsiUtil.deparenthesize(this.getExpression()) as? JetThisExpression)?.getInstanceReference() ?: return null
|
||||
val thisRef = (KtPsiUtil.deparenthesize(this.getExpression()) as? KtThisExpression)?.getInstanceReference() ?: return null
|
||||
bindingContext[BindingContext.REFERENCE_TARGET, thisRef]
|
||||
}
|
||||
|
||||
|
||||
@@ -21,24 +21,24 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteral
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtFunctionLiteral
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import java.util.LinkedHashMap
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public fun JetScope.getImplicitReceiversWithInstance(): Collection<ReceiverParameterDescriptor>
|
||||
public fun KtScope.getImplicitReceiversWithInstance(): Collection<ReceiverParameterDescriptor>
|
||||
= getImplicitReceiversWithInstanceToExpression().keySet()
|
||||
|
||||
public interface ReceiverExpressionFactory {
|
||||
public fun createExpression(psiFactory: JetPsiFactory, shortThis: Boolean = true): JetExpression
|
||||
public fun createExpression(psiFactory: KtPsiFactory, shortThis: Boolean = true): KtExpression
|
||||
}
|
||||
|
||||
public fun JetScope.getImplicitReceiversWithInstanceToExpression(): Map<ReceiverParameterDescriptor, ReceiverExpressionFactory?> {
|
||||
public fun KtScope.getImplicitReceiversWithInstanceToExpression(): Map<ReceiverParameterDescriptor, ReceiverExpressionFactory?> {
|
||||
// we use a set to workaround a bug with receiver for companion object present twice in the result of getImplicitReceiversHierarchy()
|
||||
val receivers = LinkedHashSet(getImplicitReceiversHierarchy())
|
||||
|
||||
@@ -74,7 +74,7 @@ public fun JetScope.getImplicitReceiversWithInstanceToExpression(): Map<Receiver
|
||||
}
|
||||
val factory = if (expressionText != null)
|
||||
object : ReceiverExpressionFactory {
|
||||
override fun createExpression(psiFactory: JetPsiFactory, shortThis: Boolean): JetExpression {
|
||||
override fun createExpression(psiFactory: KtPsiFactory, shortThis: Boolean): KtExpression {
|
||||
return psiFactory.createExpression(if (shortThis && isImmediateThis) "this" else expressionText)
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,6 @@ private fun thisQualifierName(receiver: ReceiverParameterDescriptor): Name? {
|
||||
val name = descriptor.getName()
|
||||
if (!name.isSpecial()) return name
|
||||
|
||||
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? JetFunctionLiteral
|
||||
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? KtFunctionLiteral
|
||||
return functionLiteral?.findLabelAndCall()?.first
|
||||
}
|
||||
|
||||
@@ -22,21 +22,21 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
|
||||
|
||||
public fun JetScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor>
|
||||
public fun KtScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor>
|
||||
= getVariablesFromImplicitReceivers(name) + getProperties(name, NoLookupLocation.FROM_IDE) + listOfNotNull(getLocalVariable(name))
|
||||
|
||||
public fun JetScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor>
|
||||
public fun KtScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor>
|
||||
= getImplicitReceiversWithInstance().flatMap { it.type.memberScope.getFunctions(name, NoLookupLocation.FROM_IDE) } +
|
||||
getFunctions(name, NoLookupLocation.FROM_IDE)
|
||||
|
||||
public fun JetScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> = getImplicitReceiversWithInstance().flatMap {
|
||||
public fun KtScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> = getImplicitReceiversWithInstance().flatMap {
|
||||
it.type.memberScope.getProperties(name, NoLookupLocation.FROM_IDE)
|
||||
}
|
||||
|
||||
public fun JetScope.getVariableFromImplicitReceivers(name: Name): VariableDescriptor? {
|
||||
public fun KtScope.getVariableFromImplicitReceivers(name: Name): VariableDescriptor? {
|
||||
getImplicitReceiversWithInstance().forEach {
|
||||
it.type.memberScope.getProperties(name, NoLookupLocation.FROM_IDE).singleOrNull()?.let { return it }
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.jetbrains.kotlin.resolve.lazy
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.JetNodeTypes
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.StatementFilter
|
||||
@@ -33,8 +33,8 @@ import java.util.HashSet
|
||||
//TODO: do resolve anonymous object's body
|
||||
|
||||
class PartialBodyResolveFilter(
|
||||
elementToResolve: JetElement,
|
||||
private val declaration: JetDeclaration,
|
||||
elementToResolve: KtElement,
|
||||
private val declaration: KtDeclaration,
|
||||
probablyNothingCallableNames: ProbablyNothingCallableNames,
|
||||
forCompletion: Boolean
|
||||
) : StatementFilter() {
|
||||
@@ -44,20 +44,20 @@ class PartialBodyResolveFilter(
|
||||
private val nothingFunctionNames = HashSet(probablyNothingCallableNames.functionNames())
|
||||
private val nothingVariableNames = HashSet(probablyNothingCallableNames.propertyNames())
|
||||
|
||||
override val filter: ((JetExpression) -> Boolean)? = { statementMarks.statementMark(it) != MarkLevel.NONE }
|
||||
override val filter: ((KtExpression) -> Boolean)? = { statementMarks.statementMark(it) != MarkLevel.NONE }
|
||||
|
||||
val allStatementsToResolve: Collection<JetExpression>
|
||||
val allStatementsToResolve: Collection<KtExpression>
|
||||
get() = statementMarks.allMarkedStatements()
|
||||
|
||||
init {
|
||||
assert(declaration.isAncestor(elementToResolve))
|
||||
assert(!JetPsiUtil.isLocal(declaration)) { "Should never be invoked on local declaration otherwise we may miss some local declarations with type Nothing" }
|
||||
assert(!KtPsiUtil.isLocal(declaration)) { "Should never be invoked on local declaration otherwise we may miss some local declarations with type Nothing" }
|
||||
|
||||
declaration.forEachDescendantOfType<JetCallableDeclaration> { declaration ->
|
||||
declaration.forEachDescendantOfType<KtCallableDeclaration> { declaration ->
|
||||
if (declaration.getTypeReference().containsProbablyNothing()) {
|
||||
val name = declaration.getName()
|
||||
if (name != null) {
|
||||
if (declaration is JetNamedFunction) {
|
||||
if (declaration is KtNamedFunction) {
|
||||
nothingFunctionNames.add(name)
|
||||
}
|
||||
else {
|
||||
@@ -73,7 +73,7 @@ class PartialBodyResolveFilter(
|
||||
|
||||
//TODO: do..while is special case
|
||||
|
||||
private fun processBlock(block: JetBlockExpression): NameFilter {
|
||||
private fun processBlock(block: KtBlockExpression): NameFilter {
|
||||
if (isValueNeeded(block)) {
|
||||
block.lastStatement()?.let { statementMarks.mark(it, MarkLevel.NEED_REFERENCE_RESOLVE) }
|
||||
}
|
||||
@@ -82,15 +82,15 @@ class PartialBodyResolveFilter(
|
||||
val startStatement = statementMarks.lastMarkedStatement(block, MarkLevel.NEED_REFERENCE_RESOLVE) ?: return nameFilter
|
||||
|
||||
for (statement in startStatement.siblings(forward = false)) {
|
||||
if (statement !is JetExpression) continue
|
||||
if (statement !is KtExpression) continue
|
||||
|
||||
if (statement is JetNamedDeclaration) {
|
||||
if (statement is KtNamedDeclaration) {
|
||||
val name = statement.getName()
|
||||
if (name != null && nameFilter(name)) {
|
||||
statementMarks.mark(statement, MarkLevel.NEED_REFERENCE_RESOLVE)
|
||||
}
|
||||
}
|
||||
else if (statement is JetMultiDeclaration) {
|
||||
else if (statement is KtMultiDeclaration) {
|
||||
if (statement.getEntries().any {
|
||||
val name = it.getName()
|
||||
name != null && nameFilter(name)
|
||||
@@ -138,22 +138,22 @@ class PartialBodyResolveFilter(
|
||||
* Returns map from smart-cast expression names (variable name or qualified variable name) to places.
|
||||
*/
|
||||
private fun potentialSmartCastPlaces(
|
||||
statement: JetExpression,
|
||||
statement: KtExpression,
|
||||
filter: (SmartCastName) -> Boolean = { true }
|
||||
): Map<SmartCastName, List<JetExpression>> {
|
||||
val map = HashMap<SmartCastName, ArrayList<JetExpression>>(0)
|
||||
): Map<SmartCastName, List<KtExpression>> {
|
||||
val map = HashMap<SmartCastName, ArrayList<KtExpression>>(0)
|
||||
|
||||
fun addPlace(name: SmartCastName, place: JetExpression) {
|
||||
fun addPlace(name: SmartCastName, place: KtExpression) {
|
||||
map.getOrPut(name, { ArrayList(1) }).add(place)
|
||||
}
|
||||
|
||||
fun addPlaces(name: SmartCastName, places: Collection<JetExpression>) {
|
||||
fun addPlaces(name: SmartCastName, places: Collection<KtExpression>) {
|
||||
if (places.isNotEmpty()) {
|
||||
map.getOrPut(name, { ArrayList(places.size()) }).addAll(places)
|
||||
}
|
||||
}
|
||||
|
||||
fun addIfCanBeSmartCast(expression: JetExpression) {
|
||||
fun addIfCanBeSmartCast(expression: KtExpression) {
|
||||
val name = expression.smartCastExpressionName() ?: return
|
||||
if (filter(name)) {
|
||||
addPlace(name, expression)
|
||||
@@ -161,26 +161,26 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
statement.accept(object : ControlFlowVisitor() {
|
||||
override fun visitPostfixExpression(expression: JetPostfixExpression) {
|
||||
override fun visitPostfixExpression(expression: KtPostfixExpression) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationToken() == JetTokens.EXCLEXCL) {
|
||||
if (expression.getOperationToken() == KtTokens.EXCLEXCL) {
|
||||
addIfCanBeSmartCast(expression.getBaseExpression() ?: return)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryWithTypeRHSExpression(expression: JetBinaryExpressionWithTypeRHS) {
|
||||
override fun visitBinaryWithTypeRHSExpression(expression: KtBinaryExpressionWithTypeRHS) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationReference().getReferencedNameElementType() == JetTokens.AS_KEYWORD) {
|
||||
if (expression.getOperationReference().getReferencedNameElementType() == KtTokens.AS_KEYWORD) {
|
||||
addIfCanBeSmartCast(expression.getLeft())
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryExpression(expression: JetBinaryExpression) {
|
||||
override fun visitBinaryExpression(expression: KtBinaryExpression) {
|
||||
expression.acceptChildren(this)
|
||||
|
||||
if (expression.getOperationToken() == JetTokens.ELVIS) {
|
||||
if (expression.getOperationToken() == KtTokens.ELVIS) {
|
||||
val left = expression.getLeft()
|
||||
val right = expression.getRight()
|
||||
if (left != null && right != null) {
|
||||
@@ -193,14 +193,14 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitIfExpression(expression: JetIfExpression) {
|
||||
override fun visitIfExpression(expression: KtIfExpression) {
|
||||
val condition = expression.getCondition()
|
||||
val thenBranch = expression.getThen()
|
||||
val elseBranch = expression.getElse()
|
||||
|
||||
val (thenSmartCastNames, elseSmartCastNames) = possiblySmartCastInCondition(condition)
|
||||
|
||||
fun processBranchExits(smartCastNames: Collection<SmartCastName>, branch: JetExpression?) {
|
||||
fun processBranchExits(smartCastNames: Collection<SmartCastName>, branch: KtExpression?) {
|
||||
if (branch == null) return
|
||||
val filteredNames = smartCastNames.filter(filter)
|
||||
if (filteredNames.isNotEmpty()) {
|
||||
@@ -237,12 +237,12 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitForExpression(expression: JetForExpression) {
|
||||
override fun visitForExpression(expression: KtForExpression) {
|
||||
// analyze only the loop-range expression, do not enter the loop body
|
||||
expression.getLoopRange()?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitWhileExpression(expression: JetWhileExpression) {
|
||||
override fun visitWhileExpression(expression: KtWhileExpression) {
|
||||
val condition = expression.getCondition()
|
||||
// we need to enter the body only for "while(true)"
|
||||
if (condition.isTrueConstant()) {
|
||||
@@ -264,10 +264,10 @@ class PartialBodyResolveFilter(
|
||||
* in then (first component) and else (second component)
|
||||
* branches of an if-statement with such condition
|
||||
*/
|
||||
private fun possiblySmartCastInCondition(condition: JetExpression?): Pair<Set<SmartCastName>, Set<SmartCastName>> {
|
||||
private fun possiblySmartCastInCondition(condition: KtExpression?): Pair<Set<SmartCastName>, Set<SmartCastName>> {
|
||||
val emptyResult = Pair(setOf<SmartCastName>(), setOf<SmartCastName>())
|
||||
when (condition) {
|
||||
is JetBinaryExpression -> {
|
||||
is KtBinaryExpression -> {
|
||||
val operation = condition.getOperationToken()
|
||||
val left = condition.getLeft() ?: return emptyResult
|
||||
val right = condition.getRight() ?: return emptyResult
|
||||
@@ -288,17 +288,17 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
when (operation) {
|
||||
JetTokens.EQEQ, JetTokens.EQEQEQ -> return smartCastInEq()
|
||||
KtTokens.EQEQ, KtTokens.EQEQEQ -> return smartCastInEq()
|
||||
|
||||
JetTokens.EXCLEQ, JetTokens.EXCLEQEQEQ -> return smartCastInEq().swap()
|
||||
KtTokens.EXCLEQ, KtTokens.EXCLEQEQEQ -> return smartCastInEq().swap()
|
||||
|
||||
JetTokens.ANDAND -> {
|
||||
KtTokens.ANDAND -> {
|
||||
val casts1 = possiblySmartCastInCondition(left)
|
||||
val casts2 = possiblySmartCastInCondition(right)
|
||||
return Pair(casts1.first.union(casts2.first), casts1.second.intersect(casts2.second))
|
||||
}
|
||||
|
||||
JetTokens.OROR -> {
|
||||
KtTokens.OROR -> {
|
||||
val casts1 = possiblySmartCastInCondition(left)
|
||||
val casts2 = possiblySmartCastInCondition(right)
|
||||
return Pair(casts1.first.intersect(casts2.first), casts1.second.union(casts2.second))
|
||||
@@ -306,19 +306,19 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
is JetIsExpression -> {
|
||||
is KtIsExpression -> {
|
||||
val cast = condition.getLeftHandSide().smartCastExpressionName().singletonOrEmptySet()
|
||||
return if (condition.isNegated()) Pair(setOf(), cast) else Pair(cast, setOf())
|
||||
}
|
||||
|
||||
is JetPrefixExpression -> {
|
||||
if (condition.getOperationToken() == JetTokens.EXCL) {
|
||||
is KtPrefixExpression -> {
|
||||
if (condition.getOperationToken() == KtTokens.EXCL) {
|
||||
val operand = condition.getBaseExpression() ?: return emptyResult
|
||||
return possiblySmartCastInCondition(operand).swap()
|
||||
}
|
||||
}
|
||||
|
||||
is JetParenthesizedExpression -> {
|
||||
is KtParenthesizedExpression -> {
|
||||
val operand = condition.getExpression() ?: return emptyResult
|
||||
return possiblySmartCastInCondition(operand)
|
||||
}
|
||||
@@ -331,20 +331,20 @@ class PartialBodyResolveFilter(
|
||||
* If it's possible that the given statement never passes the execution to the next statement (that is, always exits somewhere)
|
||||
* then this function returns a collection of all places in code that are necessary to be kept to preserve this behaviour.
|
||||
*/
|
||||
private fun collectAlwaysExitPoints(statement: JetExpression?): Collection<JetExpression> {
|
||||
val result = ArrayList<JetExpression>()
|
||||
private fun collectAlwaysExitPoints(statement: KtExpression?): Collection<KtExpression> {
|
||||
val result = ArrayList<KtExpression>()
|
||||
statement?.accept(object : ControlFlowVisitor() {
|
||||
var insideLoopLevel: Int = 0
|
||||
|
||||
override fun visitReturnExpression(expression: JetReturnExpression) {
|
||||
override fun visitReturnExpression(expression: KtReturnExpression) {
|
||||
result.add(expression)
|
||||
}
|
||||
|
||||
override fun visitThrowExpression(expression: JetThrowExpression) {
|
||||
override fun visitThrowExpression(expression: KtThrowExpression) {
|
||||
result.add(expression)
|
||||
}
|
||||
|
||||
override fun visitIfExpression(expression: JetIfExpression) {
|
||||
override fun visitIfExpression(expression: KtIfExpression) {
|
||||
expression.getCondition()?.accept(this)
|
||||
|
||||
val thenBranch = expression.getThen()
|
||||
@@ -361,12 +361,12 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitForExpression(loop: JetForExpression) {
|
||||
override fun visitForExpression(loop: KtForExpression) {
|
||||
loop.getLoopRange()?.accept(this)
|
||||
// do not make sense to search exits inside for as not necessary enter it at all
|
||||
}
|
||||
|
||||
override fun visitWhileExpression(loop: JetWhileExpression) {
|
||||
override fun visitWhileExpression(loop: KtWhileExpression) {
|
||||
val condition = loop.getCondition() ?: return
|
||||
if (condition.isTrueConstant()) {
|
||||
insideLoopLevel++
|
||||
@@ -379,42 +379,42 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitDoWhileExpression(loop: JetDoWhileExpression) {
|
||||
override fun visitDoWhileExpression(loop: KtDoWhileExpression) {
|
||||
loop.getCondition()?.accept(this)
|
||||
insideLoopLevel++
|
||||
loop.getBody()?.accept(this)
|
||||
insideLoopLevel--
|
||||
}
|
||||
|
||||
override fun visitBreakExpression(expression: JetBreakExpression) {
|
||||
override fun visitBreakExpression(expression: KtBreakExpression) {
|
||||
if (insideLoopLevel == 0 || expression.getLabelName() != null) {
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitContinueExpression(expression: JetContinueExpression) {
|
||||
override fun visitContinueExpression(expression: KtContinueExpression) {
|
||||
if (insideLoopLevel == 0 || expression.getLabelName() != null) {
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitCallExpression(expression: JetCallExpression) {
|
||||
val name = (expression.getCalleeExpression() as? JetSimpleNameExpression)?.getReferencedName()
|
||||
override fun visitCallExpression(expression: KtCallExpression) {
|
||||
val name = (expression.getCalleeExpression() as? KtSimpleNameExpression)?.getReferencedName()
|
||||
if (name != null && name in nothingFunctionNames) {
|
||||
result.add(expression)
|
||||
}
|
||||
super.visitCallExpression(expression)
|
||||
}
|
||||
|
||||
override fun visitSimpleNameExpression(expression: JetSimpleNameExpression) {
|
||||
override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) {
|
||||
val name = expression.getReferencedName()
|
||||
if (name in nothingVariableNames) {
|
||||
result.add(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBinaryExpression(expression: JetBinaryExpression) {
|
||||
if (expression.getOperationToken() == JetTokens.ELVIS) {
|
||||
override fun visitBinaryExpression(expression: KtBinaryExpression) {
|
||||
if (expression.getOperationToken() == KtTokens.ELVIS) {
|
||||
// do not search exits after "?:"
|
||||
expression.getLeft()?.accept(this)
|
||||
}
|
||||
@@ -429,13 +429,13 @@ class PartialBodyResolveFilter(
|
||||
/**
|
||||
* Recursively visits code but does not enter constructs that may not affect smart casts/control flow
|
||||
*/
|
||||
private abstract class ControlFlowVisitor : JetVisitorVoid() {
|
||||
override fun visitJetElement(element: JetElement) {
|
||||
private abstract class ControlFlowVisitor : KtVisitorVoid() {
|
||||
override fun visitJetElement(element: KtElement) {
|
||||
if (element.noControlFlowInside()) return
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
|
||||
private fun JetElement.noControlFlowInside() = this is JetFunction || this is JetClass || this is JetClassBody
|
||||
private fun KtElement.noControlFlowInside() = this is KtFunction || this is KtClass || this is KtClassBody
|
||||
}
|
||||
|
||||
private data class SmartCastName(
|
||||
@@ -457,22 +457,22 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun JetExpression.smartCastExpressionName(): SmartCastName? {
|
||||
private fun KtExpression.smartCastExpressionName(): SmartCastName? {
|
||||
return when (this) {
|
||||
is JetSimpleNameExpression -> SmartCastName(null, this.getReferencedName())
|
||||
is KtSimpleNameExpression -> SmartCastName(null, this.getReferencedName())
|
||||
|
||||
is JetQualifiedExpression -> {
|
||||
val selector = getSelectorExpression() as? JetSimpleNameExpression ?: return null
|
||||
is KtQualifiedExpression -> {
|
||||
val selector = getSelectorExpression() as? KtSimpleNameExpression ?: return null
|
||||
val selectorName = selector.getReferencedName()
|
||||
val receiver = getReceiverExpression()
|
||||
if (receiver is JetThisExpression) {
|
||||
if (receiver is KtThisExpression) {
|
||||
return SmartCastName(null, selectorName)
|
||||
}
|
||||
val receiverName = receiver.smartCastExpressionName() ?: return null
|
||||
return SmartCastName(receiverName, selectorName)
|
||||
}
|
||||
|
||||
is JetThisExpression -> SmartCastName(null, null)
|
||||
is KtThisExpression -> SmartCastName(null, null)
|
||||
|
||||
else -> null
|
||||
}
|
||||
@@ -487,9 +487,9 @@ class PartialBodyResolveFilter(
|
||||
val isEmpty: Boolean
|
||||
get() = names?.isEmpty() ?: false
|
||||
|
||||
fun addUsedNames(statement: JetExpression) {
|
||||
fun addUsedNames(statement: KtExpression) {
|
||||
if (names != null) {
|
||||
statement.forEachDescendantOfType<JetSimpleNameExpression>(canGoInside = { it !is JetBlockExpression }) {
|
||||
statement.forEachDescendantOfType<KtSimpleNameExpression>(canGoInside = { it !is KtBlockExpression }) {
|
||||
names!!.add(it.getReferencedName())
|
||||
}
|
||||
}
|
||||
@@ -518,74 +518,74 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun findStatementToResolve(element: JetElement, declaration: JetDeclaration): JetExpression? {
|
||||
return element.parentsWithSelf.takeWhile { it != declaration }.firstOrNull { it.isStatement() } as JetExpression?
|
||||
public fun findStatementToResolve(element: KtElement, declaration: KtDeclaration): KtExpression? {
|
||||
return element.parentsWithSelf.takeWhile { it != declaration }.firstOrNull { it.isStatement() } as KtExpression?
|
||||
}
|
||||
|
||||
private fun JetElement.forTopLevelBlocksInside(action: (JetBlockExpression) -> Unit) {
|
||||
forEachDescendantOfType(canGoInside = { it !is JetBlockExpression }, action = action)
|
||||
private fun KtElement.forTopLevelBlocksInside(action: (KtBlockExpression) -> Unit) {
|
||||
forEachDescendantOfType(canGoInside = { it !is KtBlockExpression }, action = action)
|
||||
}
|
||||
|
||||
private fun JetExpression?.isNullLiteral() = this?.getNode()?.getElementType() == JetNodeTypes.NULL
|
||||
private fun KtExpression?.isNullLiteral() = this?.getNode()?.getElementType() == KtNodeTypes.NULL
|
||||
|
||||
private fun JetExpression?.isTrueConstant()
|
||||
= this != null && getNode()?.getElementType() == JetNodeTypes.BOOLEAN_CONSTANT && getText() == "true"
|
||||
private fun KtExpression?.isTrueConstant()
|
||||
= this != null && getNode()?.getElementType() == KtNodeTypes.BOOLEAN_CONSTANT && getText() == "true"
|
||||
|
||||
private fun <T : Any> T?.singletonOrEmptySet(): Set<T> = if (this != null) setOf(this) else setOf()
|
||||
|
||||
//TODO: review logic
|
||||
private fun isValueNeeded(expression: JetExpression): Boolean {
|
||||
private fun isValueNeeded(expression: KtExpression): Boolean {
|
||||
val parent = expression.getParent()
|
||||
return when (parent) {
|
||||
is JetBlockExpression -> expression == parent.lastStatement() && isValueNeeded(parent)
|
||||
is KtBlockExpression -> expression == parent.lastStatement() && isValueNeeded(parent)
|
||||
|
||||
is JetContainerNode -> { //TODO - not quite correct
|
||||
val pparent = parent.getParent() as? JetExpression
|
||||
is KtContainerNode -> { //TODO - not quite correct
|
||||
val pparent = parent.getParent() as? KtExpression
|
||||
pparent != null && isValueNeeded(pparent)
|
||||
}
|
||||
|
||||
is JetDeclarationWithBody -> {
|
||||
is KtDeclarationWithBody -> {
|
||||
if (expression == parent.getBodyExpression())
|
||||
!parent.hasBlockBody() && !parent.hasDeclaredReturnType()
|
||||
else
|
||||
true
|
||||
}
|
||||
|
||||
is JetClassInitializer -> false
|
||||
is KtClassInitializer -> false
|
||||
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
private fun JetBlockExpression.lastStatement(): JetExpression?
|
||||
= getLastChild()?.siblings(forward = false)?.firstIsInstanceOrNull<JetExpression>()
|
||||
private fun KtBlockExpression.lastStatement(): KtExpression?
|
||||
= getLastChild()?.siblings(forward = false)?.firstIsInstanceOrNull<KtExpression>()
|
||||
|
||||
private fun PsiElement.isStatement() = this is JetExpression && getParent() is JetBlockExpression
|
||||
private fun PsiElement.isStatement() = this is KtExpression && getParent() is KtBlockExpression
|
||||
|
||||
private fun JetTypeReference?.containsProbablyNothing()
|
||||
= this?.typeElement?.anyDescendantOfType<JetUserType> { it.isProbablyNothing() } ?: false
|
||||
private fun KtTypeReference?.containsProbablyNothing()
|
||||
= this?.typeElement?.anyDescendantOfType<KtUserType> { it.isProbablyNothing() } ?: false
|
||||
}
|
||||
|
||||
private inner class StatementMarks {
|
||||
private val statementMarks = HashMap<JetExpression, MarkLevel>()
|
||||
private val blockLevels = HashMap<JetBlockExpression, MarkLevel>()
|
||||
private val statementMarks = HashMap<KtExpression, MarkLevel>()
|
||||
private val blockLevels = HashMap<KtBlockExpression, MarkLevel>()
|
||||
|
||||
fun mark(element: PsiElement, level: MarkLevel) {
|
||||
var e = element
|
||||
while (e != declaration) {
|
||||
if (e.isStatement()) {
|
||||
markStatement(e as JetExpression, level)
|
||||
markStatement(e as KtExpression, level)
|
||||
}
|
||||
e = e.getParent()!!
|
||||
}
|
||||
}
|
||||
|
||||
private fun markStatement(statement: JetExpression, level: MarkLevel) {
|
||||
private fun markStatement(statement: KtExpression, level: MarkLevel) {
|
||||
val currentLevel = statementMark(statement)
|
||||
if (currentLevel < level) {
|
||||
statementMarks[statement] = level
|
||||
|
||||
val block = statement.getParent() as JetBlockExpression
|
||||
val block = statement.getParent() as KtBlockExpression
|
||||
val currentBlockLevel = blockLevels[block] ?: MarkLevel.NONE
|
||||
if (currentBlockLevel < level) {
|
||||
blockLevels[block] = level
|
||||
@@ -593,17 +593,17 @@ class PartialBodyResolveFilter(
|
||||
}
|
||||
}
|
||||
|
||||
fun statementMark(statement: JetExpression): MarkLevel
|
||||
fun statementMark(statement: KtExpression): MarkLevel
|
||||
= statementMarks[statement] ?: MarkLevel.NONE
|
||||
|
||||
fun allMarkedStatements(): Collection<JetExpression>
|
||||
fun allMarkedStatements(): Collection<KtExpression>
|
||||
= statementMarks.keySet()
|
||||
|
||||
fun lastMarkedStatement(block: JetBlockExpression, minLevel: MarkLevel): JetExpression? {
|
||||
fun lastMarkedStatement(block: KtBlockExpression, minLevel: MarkLevel): KtExpression? {
|
||||
val level = blockLevels[block] ?: MarkLevel.NONE
|
||||
if (level < minLevel) return null // optimization
|
||||
return block.getLastChild().siblings(forward = false)
|
||||
.filterIsInstance<JetExpression>()
|
||||
.filterIsInstance<KtExpression>()
|
||||
.first { statementMark(it) >= minLevel }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,17 @@ import com.google.common.collect.Multimap
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.psi.stubs.PsiFileStub
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetTypeReference
|
||||
import org.jetbrains.kotlin.psi.JetUserType
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
|
||||
public fun JetUserType.aliasImportMap(): Multimap<String, String> {
|
||||
public fun KtUserType.aliasImportMap(): Multimap<String, String> {
|
||||
// we need to access containing file via stub because getPsi() may return null when indexing and getContainingFile() will crash
|
||||
val file = getStub()?.getContainingFileStub()?.getPsi() ?: return HashMultimap.create()
|
||||
return (file as JetFile).aliasImportMap()
|
||||
return (file as KtFile).aliasImportMap()
|
||||
}
|
||||
|
||||
private fun JetFile.aliasImportMap(): Multimap<String, String> {
|
||||
private fun KtFile.aliasImportMap(): Multimap<String, String> {
|
||||
val cached = getUserData(ALIAS_IMPORT_DATA_KEY)
|
||||
val modificationStamp = getModificationStamp()
|
||||
if (cached != null && modificationStamp == cached.fileModificationStamp) {
|
||||
@@ -43,7 +43,7 @@ private fun JetFile.aliasImportMap(): Multimap<String, String> {
|
||||
return data.map
|
||||
}
|
||||
|
||||
private fun JetFile.buildAliasImportMap(): Multimap<String, String> {
|
||||
private fun KtFile.buildAliasImportMap(): Multimap<String, String> {
|
||||
val map = HashMultimap.create<String, String>()
|
||||
val importList = getImportList() ?: return map
|
||||
for (import in importList.getImports()) {
|
||||
@@ -58,12 +58,12 @@ private class CachedAliasImportData(val map: Multimap<String, String>, val fileM
|
||||
|
||||
private val ALIAS_IMPORT_DATA_KEY = Key<CachedAliasImportData>("ALIAS_IMPORT_MAP_KEY")
|
||||
|
||||
public fun JetTypeReference?.isProbablyNothing(): Boolean {
|
||||
val userType = this?.typeElement as? JetUserType ?: return false
|
||||
public fun KtTypeReference?.isProbablyNothing(): Boolean {
|
||||
val userType = this?.typeElement as? KtUserType ?: return false
|
||||
return userType.isProbablyNothing()
|
||||
}
|
||||
|
||||
public fun JetUserType?.isProbablyNothing(): Boolean {
|
||||
public fun KtUserType?.isProbablyNothing(): Boolean {
|
||||
if (this == null) return false
|
||||
val referencedName = getReferencedName()
|
||||
return referencedName == "Nothing" || aliasImportMap()[referencedName].contains("Nothing")
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
import org.jetbrains.kotlin.types.typeUtil.equalTypesOrNulls
|
||||
|
||||
@@ -32,7 +32,7 @@ public fun descriptorsEqualWithSubstitution(descriptor1: DeclarationDescriptor?,
|
||||
if (descriptor1 !is CallableDescriptor) return true
|
||||
descriptor2 as CallableDescriptor
|
||||
|
||||
val typeChecker = JetTypeChecker.withAxioms(object: JetTypeChecker.TypeConstructorEquality {
|
||||
val typeChecker = KotlinTypeChecker.withAxioms(object: KotlinTypeChecker.TypeConstructorEquality {
|
||||
override fun equals(a: TypeConstructor, b: TypeConstructor): Boolean {
|
||||
val typeParam1 = a.getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
val typeParam2 = b.getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
||||
import java.util.LinkedHashMap
|
||||
|
||||
public fun getTypeSubstitution(baseType: JetType, derivedType: JetType): LinkedHashMap<TypeConstructor, TypeProjection>? {
|
||||
public fun getTypeSubstitution(baseType: KtType, derivedType: KtType): LinkedHashMap<TypeConstructor, TypeProjection>? {
|
||||
val substitutedType = TypeCheckingProcedure.findCorrespondingSupertype(derivedType, baseType) ?: return null
|
||||
|
||||
val substitution = LinkedHashMap<TypeConstructor, TypeProjection>(substitutedType.getArguments().size())
|
||||
@@ -55,6 +55,6 @@ public fun getCallableSubstitutor(
|
||||
return getCallableSubstitution(baseCallable, derivedCallable)?.let { TypeSubstitutor.create(it) }
|
||||
}
|
||||
|
||||
public fun getTypeSubstitutor(baseType: JetType, derivedType: JetType): TypeSubstitutor? {
|
||||
public fun getTypeSubstitutor(baseType: KtType, derivedType: KtType): TypeSubstitutor? {
|
||||
return getTypeSubstitution(baseType, derivedType)?.let { TypeSubstitutor.create(it) }
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
||||
import org.jetbrains.kotlin.psi.JetElement;
|
||||
import org.jetbrains.kotlin.psi.KtElement;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class JetDescriptorIconProvider {
|
||||
|
||||
@NotNull
|
||||
public static Icon getIcon(@NotNull DeclarationDescriptor descriptor, @Nullable PsiElement declaration, @Iconable.IconFlags int flags) {
|
||||
if (declaration != null && !(declaration instanceof JetElement)) {
|
||||
if (declaration != null && !(declaration instanceof KtElement)) {
|
||||
return declaration.getIcon(flags);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public final class JetDescriptorIconProvider {
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
if (functionDescriptor.getExtensionReceiverParameter() != null) {
|
||||
return JetIcons.EXTENSION_FUNCTION;
|
||||
return KtIcons.EXTENSION_FUNCTION;
|
||||
}
|
||||
|
||||
if (descriptor.getContainingDeclaration() instanceof ClassDescriptor) {
|
||||
@@ -96,38 +96,38 @@ public final class JetDescriptorIconProvider {
|
||||
}
|
||||
}
|
||||
else {
|
||||
return JetIcons.FUNCTION;
|
||||
return KtIcons.FUNCTION;
|
||||
}
|
||||
}
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
switch (((ClassDescriptor) descriptor).getKind()) {
|
||||
case INTERFACE:
|
||||
return JetIcons.TRAIT;
|
||||
return KtIcons.TRAIT;
|
||||
case ENUM_CLASS:
|
||||
return JetIcons.ENUM;
|
||||
return KtIcons.ENUM;
|
||||
case ENUM_ENTRY:
|
||||
return JetIcons.ENUM;
|
||||
return KtIcons.ENUM;
|
||||
case ANNOTATION_CLASS:
|
||||
return PlatformIcons.ANNOTATION_TYPE_ICON;
|
||||
case OBJECT:
|
||||
return JetIcons.OBJECT;
|
||||
return KtIcons.OBJECT;
|
||||
case CLASS:
|
||||
return JetIcons.CLASS;
|
||||
return KtIcons.CLASS;
|
||||
default:
|
||||
LOG.warn("No icon for descriptor: " + descriptor);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (descriptor instanceof ValueParameterDescriptor) {
|
||||
return JetIcons.PARAMETER;
|
||||
return KtIcons.PARAMETER;
|
||||
}
|
||||
|
||||
if (descriptor instanceof LocalVariableDescriptor) {
|
||||
return ((VariableDescriptor) descriptor).isVar() ? JetIcons.VAR : JetIcons.VAL;
|
||||
return ((VariableDescriptor) descriptor).isVar() ? KtIcons.VAR : KtIcons.VAL;
|
||||
}
|
||||
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
return ((VariableDescriptor) descriptor).isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
|
||||
return ((VariableDescriptor) descriptor).isVar() ? KtIcons.FIELD_VAR : KtIcons.FIELD_VAL;
|
||||
}
|
||||
|
||||
if (descriptor instanceof TypeParameterDescriptor) {
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.asJava.KotlinLightClassForExplicitDeclaration;
|
||||
import org.jetbrains.kotlin.asJava.KotlinLightClassForFacade;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.KotlinLightClassForDecompiledDeclaration;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -42,16 +42,16 @@ public class JetIconProvider extends IconProvider implements DumbAware {
|
||||
public static JetIconProvider INSTANCE = new JetIconProvider();
|
||||
|
||||
@Nullable
|
||||
public static JetClassOrObject getMainClass(@NotNull JetFile file) {
|
||||
List<JetDeclaration> classes = ContainerUtil.filter(file.getDeclarations(), new Condition<JetDeclaration>() {
|
||||
public static KtClassOrObject getMainClass(@NotNull KtFile file) {
|
||||
List<KtDeclaration> classes = ContainerUtil.filter(file.getDeclarations(), new Condition<KtDeclaration>() {
|
||||
@Override
|
||||
public boolean value(JetDeclaration jetDeclaration) {
|
||||
return jetDeclaration instanceof JetClassOrObject;
|
||||
public boolean value(KtDeclaration jetDeclaration) {
|
||||
return jetDeclaration instanceof KtClassOrObject;
|
||||
}
|
||||
});
|
||||
if (classes.size() == 1) {
|
||||
if (StringUtil.getPackageName(file.getName()).equals(classes.get(0).getName())) {
|
||||
return (JetClassOrObject) classes.get(0);
|
||||
return (KtClassOrObject) classes.get(0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -59,15 +59,15 @@ public class JetIconProvider extends IconProvider implements DumbAware {
|
||||
|
||||
@Override
|
||||
public Icon getIcon(@NotNull PsiElement psiElement, int flags) {
|
||||
if (psiElement instanceof JetFile) {
|
||||
JetFile file = (JetFile) psiElement;
|
||||
JetClassOrObject mainClass = getMainClass(file);
|
||||
return mainClass != null && file.getDeclarations().size() == 1 ? getIcon(mainClass, flags) : JetIcons.FILE;
|
||||
if (psiElement instanceof KtFile) {
|
||||
KtFile file = (KtFile) psiElement;
|
||||
KtClassOrObject mainClass = getMainClass(file);
|
||||
return mainClass != null && file.getDeclarations().size() == 1 ? getIcon(mainClass, flags) : KtIcons.FILE;
|
||||
}
|
||||
|
||||
Icon result = getBaseIcon(psiElement);
|
||||
if ((flags & Iconable.ICON_FLAG_VISIBILITY) > 0 && psiElement instanceof JetModifierListOwner) {
|
||||
JetModifierList list = ((JetModifierListOwner) psiElement).getModifierList();
|
||||
if ((flags & Iconable.ICON_FLAG_VISIBILITY) > 0 && psiElement instanceof KtModifierListOwner) {
|
||||
KtModifierList list = ((KtModifierListOwner) psiElement).getModifierList();
|
||||
result = createRowIcon(result, getVisibilityIcon(list));
|
||||
}
|
||||
return result;
|
||||
@@ -80,15 +80,15 @@ public class JetIconProvider extends IconProvider implements DumbAware {
|
||||
return rowIcon;
|
||||
}
|
||||
|
||||
public static Icon getVisibilityIcon(@Nullable JetModifierList list) {
|
||||
public static Icon getVisibilityIcon(@Nullable KtModifierList list) {
|
||||
if (list != null) {
|
||||
if (list.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
|
||||
if (list.hasModifier(KtTokens.PRIVATE_KEYWORD)) {
|
||||
return PlatformIcons.PRIVATE_ICON;
|
||||
}
|
||||
if (list.hasModifier(JetTokens.PROTECTED_KEYWORD)) {
|
||||
if (list.hasModifier(KtTokens.PROTECTED_KEYWORD)) {
|
||||
return PlatformIcons.PROTECTED_ICON;
|
||||
}
|
||||
if (list.hasModifier(JetTokens.INTERNAL_KEYWORD)) {
|
||||
if (list.hasModifier(KtTokens.INTERNAL_KEYWORD)) {
|
||||
return PlatformIcons.PACKAGE_LOCAL_ICON;
|
||||
}
|
||||
}
|
||||
@@ -97,22 +97,22 @@ public class JetIconProvider extends IconProvider implements DumbAware {
|
||||
}
|
||||
|
||||
public static Icon getBaseIcon(PsiElement psiElement) {
|
||||
if (psiElement instanceof JetPackageDirective) {
|
||||
if (psiElement instanceof KtPackageDirective) {
|
||||
return PlatformIcons.PACKAGE_ICON;
|
||||
}
|
||||
|
||||
if (psiElement instanceof KotlinLightClassForFacade) {
|
||||
return JetIcons.FILE;
|
||||
return KtIcons.FILE;
|
||||
}
|
||||
|
||||
if (psiElement instanceof KotlinLightClassForDecompiledDeclaration) {
|
||||
JetClassOrObject origin = ((KotlinLightClassForDecompiledDeclaration) psiElement).getOrigin();
|
||||
KtClassOrObject origin = ((KotlinLightClassForDecompiledDeclaration) psiElement).getOrigin();
|
||||
if (origin != null) {
|
||||
psiElement = origin;
|
||||
}
|
||||
else {
|
||||
//TODO (light classes for decompiled files): correct presentation
|
||||
return JetIcons.CLASS;
|
||||
return KtIcons.CLASS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,13 +120,13 @@ public class JetIconProvider extends IconProvider implements DumbAware {
|
||||
psiElement = psiElement.getNavigationElement();
|
||||
}
|
||||
|
||||
if (psiElement instanceof JetNamedFunction) {
|
||||
if (((JetFunction) psiElement).getReceiverTypeReference() != null) {
|
||||
return JetIcons.EXTENSION_FUNCTION;
|
||||
if (psiElement instanceof KtNamedFunction) {
|
||||
if (((KtFunction) psiElement).getReceiverTypeReference() != null) {
|
||||
return KtIcons.EXTENSION_FUNCTION;
|
||||
}
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(psiElement, JetNamedDeclaration.class) instanceof JetClass) {
|
||||
if (JetPsiUtil.isAbstract((JetFunction) psiElement)) {
|
||||
if (PsiTreeUtil.getParentOfType(psiElement, KtNamedDeclaration.class) instanceof KtClass) {
|
||||
if (KtPsiUtil.isAbstract((KtFunction) psiElement)) {
|
||||
return PlatformIcons.ABSTRACT_METHOD_ICON;
|
||||
}
|
||||
else {
|
||||
@@ -134,41 +134,41 @@ public class JetIconProvider extends IconProvider implements DumbAware {
|
||||
}
|
||||
}
|
||||
else {
|
||||
return JetIcons.FUNCTION;
|
||||
return KtIcons.FUNCTION;
|
||||
}
|
||||
}
|
||||
|
||||
if (psiElement instanceof JetFunctionLiteral) return JetIcons.LAMBDA;
|
||||
if (psiElement instanceof KtFunctionLiteral) return KtIcons.LAMBDA;
|
||||
|
||||
if (psiElement instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) psiElement;
|
||||
if (jetClass.isInterface()) {
|
||||
return JetIcons.TRAIT;
|
||||
if (psiElement instanceof KtClass) {
|
||||
KtClass ktClass = (KtClass) psiElement;
|
||||
if (ktClass.isInterface()) {
|
||||
return KtIcons.TRAIT;
|
||||
}
|
||||
|
||||
Icon icon = jetClass.isEnum() ? JetIcons.ENUM : JetIcons.CLASS;
|
||||
if (jetClass instanceof JetEnumEntry) {
|
||||
JetEnumEntry enumEntry = (JetEnumEntry) jetClass;
|
||||
Icon icon = ktClass.isEnum() ? KtIcons.ENUM : KtIcons.CLASS;
|
||||
if (ktClass instanceof KtEnumEntry) {
|
||||
KtEnumEntry enumEntry = (KtEnumEntry) ktClass;
|
||||
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
||||
icon = JetIcons.ENUM;
|
||||
icon = KtIcons.ENUM;
|
||||
}
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
if (psiElement instanceof JetObjectDeclaration) {
|
||||
return JetIcons.OBJECT;
|
||||
if (psiElement instanceof KtObjectDeclaration) {
|
||||
return KtIcons.OBJECT;
|
||||
}
|
||||
if (psiElement instanceof JetParameter) {
|
||||
JetParameter parameter = (JetParameter) psiElement;
|
||||
if (JetPsiUtil.getClassIfParameterIsProperty(parameter) != null) {
|
||||
return parameter.isMutable() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
|
||||
if (psiElement instanceof KtParameter) {
|
||||
KtParameter parameter = (KtParameter) psiElement;
|
||||
if (KtPsiUtil.getClassIfParameterIsProperty(parameter) != null) {
|
||||
return parameter.isMutable() ? KtIcons.FIELD_VAR : KtIcons.FIELD_VAL;
|
||||
}
|
||||
|
||||
return JetIcons.PARAMETER;
|
||||
return KtIcons.PARAMETER;
|
||||
}
|
||||
if (psiElement instanceof JetProperty) {
|
||||
JetProperty property = (JetProperty) psiElement;
|
||||
return property.isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
|
||||
if (psiElement instanceof KtProperty) {
|
||||
KtProperty property = (KtProperty) psiElement;
|
||||
return property.isVar() ? KtIcons.FIELD_VAR : KtIcons.FIELD_VAL;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import com.intellij.util.PlatformIcons;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public interface JetIcons {
|
||||
public interface KtIcons {
|
||||
Icon SMALL_LOGO = IconLoader.getIcon("/org/jetbrains/kotlin/idea/icons/kotlin.png");
|
||||
Icon KOTLIN_LOGO_24 = IconLoader.getIcon("/org/jetbrains/kotlin/idea/icons/kotlin24.png");
|
||||
|
||||
@@ -18,26 +18,26 @@ package org.jetbrains.kotlin.idea.analysis
|
||||
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asLexicalScope
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.JetTypeInfo
|
||||
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor
|
||||
|
||||
@JvmOverloads
|
||||
public fun JetExpression.computeTypeInfoInContext(
|
||||
scope: JetScope,
|
||||
contextExpression: JetExpression = this,
|
||||
public fun KtExpression.computeTypeInfoInContext(
|
||||
scope: KtScope,
|
||||
contextExpression: KtExpression = this,
|
||||
trace: BindingTrace = BindingTraceContext(),
|
||||
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
|
||||
expectedType: KtType = TypeUtils.NO_EXPECTED_TYPE,
|
||||
isStatement: Boolean = false
|
||||
): JetTypeInfo {
|
||||
PreliminaryDeclarationVisitor.createForExpression(this, trace)
|
||||
@@ -46,12 +46,12 @@ public fun JetExpression.computeTypeInfoInContext(
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
public fun JetExpression.analyzeInContext(
|
||||
scope: JetScope,
|
||||
contextExpression: JetExpression = this,
|
||||
public fun KtExpression.analyzeInContext(
|
||||
scope: KtScope,
|
||||
contextExpression: KtExpression = this,
|
||||
trace: BindingTrace = BindingTraceContext(),
|
||||
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE,
|
||||
expectedType: KtType = TypeUtils.NO_EXPECTED_TYPE,
|
||||
isStatement: Boolean = false
|
||||
): BindingContext {
|
||||
computeTypeInfoInContext(scope, contextExpression, trace, dataFlowInfo, expectedType, isStatement)
|
||||
@@ -59,12 +59,12 @@ public fun JetExpression.analyzeInContext(
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
public fun JetExpression.computeTypeInContext(
|
||||
scope: JetScope,
|
||||
contextExpression: JetExpression = this,
|
||||
public fun KtExpression.computeTypeInContext(
|
||||
scope: KtScope,
|
||||
contextExpression: KtExpression = this,
|
||||
trace: BindingTrace = BindingTraceContext(),
|
||||
dataFlowInfo: DataFlowInfo = DataFlowInfo.EMPTY,
|
||||
expectedType: JetType = TypeUtils.NO_EXPECTED_TYPE
|
||||
): JetType? {
|
||||
expectedType: KtType = TypeUtils.NO_EXPECTED_TYPE
|
||||
): KtType? {
|
||||
return computeTypeInfoInContext(scope, contextExpression, trace, dataFlowInfo, expectedType).type
|
||||
}
|
||||
|
||||
+18
-18
@@ -48,9 +48,9 @@ public class CodeFragmentAnalyzer(
|
||||
public var resolveElementCache: ResolveElementCache? = null
|
||||
@Inject set
|
||||
|
||||
public fun analyzeCodeFragment(codeFragment: JetCodeFragment, trace: BindingTrace, bodyResolveMode: BodyResolveMode) {
|
||||
public fun analyzeCodeFragment(codeFragment: KtCodeFragment, trace: BindingTrace, bodyResolveMode: BodyResolveMode) {
|
||||
val codeFragmentExpression = codeFragment.getContentElement()
|
||||
if (codeFragmentExpression !is JetExpression) return
|
||||
if (codeFragmentExpression !is KtExpression) return
|
||||
|
||||
val (scopeForContextElement, dataFlowInfo) = getScopeAndDataFlowForAnalyzeFragment(codeFragment) {
|
||||
resolveElementCache!!.resolveToElement(it, bodyResolveMode)
|
||||
@@ -68,18 +68,18 @@ public class CodeFragmentAnalyzer(
|
||||
}
|
||||
|
||||
//TODO: this code should be moved into debugger which should set correct context for its code fragment
|
||||
private fun JetExpression.correctContextForExpression(): JetExpression {
|
||||
private fun KtExpression.correctContextForExpression(): KtExpression {
|
||||
return when (this) {
|
||||
is JetProperty -> this.getDelegateExpressionOrInitializer()
|
||||
is JetFunctionLiteral -> this.getBodyExpression()?.getStatements()?.lastOrNull()
|
||||
is JetDeclarationWithBody -> this.getBodyExpression()
|
||||
is JetBlockExpression -> this.getStatements().lastOrNull()
|
||||
is KtProperty -> this.getDelegateExpressionOrInitializer()
|
||||
is KtFunctionLiteral -> this.getBodyExpression()?.getStatements()?.lastOrNull()
|
||||
is KtDeclarationWithBody -> this.getBodyExpression()
|
||||
is KtBlockExpression -> this.getStatements().lastOrNull()
|
||||
else -> {
|
||||
val previousSibling = this.siblings(forward = false, withItself = false).firstIsInstanceOrNull<JetExpression>()
|
||||
val previousSibling = this.siblings(forward = false, withItself = false).firstIsInstanceOrNull<KtExpression>()
|
||||
if (previousSibling != null) return previousSibling
|
||||
for (parent in this.parents) {
|
||||
if (parent is JetWhenEntry || parent is JetIfExpression || parent is JetBlockExpression) return this
|
||||
if (parent is JetExpression) return parent
|
||||
if (parent is KtWhenEntry || parent is KtIfExpression || parent is KtBlockExpression) return this
|
||||
if (parent is KtExpression) return parent
|
||||
}
|
||||
null
|
||||
}
|
||||
@@ -87,23 +87,23 @@ public class CodeFragmentAnalyzer(
|
||||
}
|
||||
|
||||
private fun getScopeAndDataFlowForAnalyzeFragment(
|
||||
codeFragment: JetCodeFragment,
|
||||
resolveToElement: (JetElement) -> BindingContext
|
||||
codeFragment: KtCodeFragment,
|
||||
resolveToElement: (KtElement) -> BindingContext
|
||||
): Pair<LexicalScope, DataFlowInfo>? {
|
||||
val context = codeFragment.getContext()
|
||||
if (context !is JetExpression) return null
|
||||
if (context !is KtExpression) return null
|
||||
|
||||
val scopeForContextElement: LexicalScope?
|
||||
val dataFlowInfo: DataFlowInfo
|
||||
|
||||
when (context) {
|
||||
is JetPrimaryConstructor -> {
|
||||
is KtPrimaryConstructor -> {
|
||||
val descriptor = resolveSession.getClassDescriptor(context.getContainingClassOrObject(), NoLookupLocation.FROM_IDE) as ClassDescriptorWithResolutionScopes
|
||||
|
||||
scopeForContextElement = descriptor.getScopeForInitializerResolution()
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
}
|
||||
is JetSecondaryConstructor -> {
|
||||
is KtSecondaryConstructor -> {
|
||||
val correctedContext = context.getDelegationCall().calleeExpression!!
|
||||
|
||||
val contextForElement = resolveToElement(correctedContext)
|
||||
@@ -111,13 +111,13 @@ public class CodeFragmentAnalyzer(
|
||||
scopeForContextElement = contextForElement[BindingContext.LEXICAL_SCOPE, correctedContext]
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
}
|
||||
is JetClassOrObject -> {
|
||||
is KtClassOrObject -> {
|
||||
val descriptor = resolveSession.getClassDescriptor(context, NoLookupLocation.FROM_IDE) as ClassDescriptorWithResolutionScopes
|
||||
|
||||
scopeForContextElement = descriptor.getScopeForMemberDeclarationResolution()
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
}
|
||||
is JetExpression -> {
|
||||
is KtExpression -> {
|
||||
val correctedContext = context.correctContextForExpression()
|
||||
|
||||
val contextForElement = resolveToElement(correctedContext)
|
||||
@@ -125,7 +125,7 @@ public class CodeFragmentAnalyzer(
|
||||
scopeForContextElement = contextForElement[BindingContext.LEXICAL_SCOPE, correctedContext]
|
||||
dataFlowInfo = contextForElement.getDataFlowInfo(correctedContext)
|
||||
}
|
||||
is JetFile -> {
|
||||
is KtFile -> {
|
||||
scopeForContextElement = resolveSession.getFileScopeProvider().getFileScope(context)
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
}
|
||||
|
||||
+27
-27
@@ -47,7 +47,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
||||
import org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.util.*
|
||||
|
||||
@@ -55,13 +55,13 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
private val scopeFileComparator = JavaElementFinder.byClasspathComparator(GlobalSearchScope.allScope(project))
|
||||
private val psiManager: PsiManager = PsiManager.getInstance(project)
|
||||
|
||||
override fun getContextForPackage(files: Collection<JetFile>): LightClassConstructionContext {
|
||||
override fun getContextForPackage(files: Collection<KtFile>): LightClassConstructionContext {
|
||||
assert(!files.isEmpty()) { "No files in package" }
|
||||
|
||||
return getContextForFiles(files)
|
||||
}
|
||||
|
||||
private fun getContextForFiles(files: Collection<JetFile>): LightClassConstructionContext {
|
||||
private fun getContextForFiles(files: Collection<KtFile>): LightClassConstructionContext {
|
||||
val sortedFiles = files.sortedWith(scopeFileComparator)
|
||||
val file = sortedFiles.first()
|
||||
val resolveSession = file.getResolutionFacade().getFrontendService(ResolveSession::class.java)
|
||||
@@ -69,7 +69,7 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
return LightClassConstructionContext(resolveSession.bindingContext, resolveSession.getModuleDescriptor())
|
||||
}
|
||||
|
||||
override fun getContextForClassOrObject(classOrObject: JetClassOrObject): LightClassConstructionContext {
|
||||
override fun getContextForClassOrObject(classOrObject: KtClassOrObject): LightClassConstructionContext {
|
||||
val resolutionFacade = classOrObject.getResolutionFacade()
|
||||
|
||||
val moduleDescriptor = resolutionFacade.moduleDescriptor
|
||||
@@ -92,24 +92,24 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
return LightClassConstructionContext(bindingContext, moduleDescriptor)
|
||||
}
|
||||
|
||||
override fun getContextForFacade(files: Collection<JetFile>): LightClassConstructionContext {
|
||||
override fun getContextForFacade(files: Collection<KtFile>): LightClassConstructionContext {
|
||||
assert(!files.isEmpty()) { "No files in facade" }
|
||||
|
||||
return getContextForFiles(files)
|
||||
}
|
||||
|
||||
override fun findClassOrObjectDeclarations(fqName: FqName, searchScope: GlobalSearchScope): Collection<JetClassOrObject> {
|
||||
override fun findClassOrObjectDeclarations(fqName: FqName, searchScope: GlobalSearchScope): Collection<KtClassOrObject> {
|
||||
return JetFullClassNameIndex.getInstance().get(fqName.asString(), project, kotlinSourceAndClassFiles(searchScope, project))
|
||||
}
|
||||
|
||||
override fun findFilesForPackage(fqName: FqName, searchScope: GlobalSearchScope): Collection<JetFile> {
|
||||
override fun findFilesForPackage(fqName: FqName, searchScope: GlobalSearchScope): Collection<KtFile> {
|
||||
return PackageIndexUtil.findFilesWithExactPackage(fqName, kotlinSourceAndClassFiles(searchScope, project), project)
|
||||
}
|
||||
|
||||
override fun findClassOrObjectDeclarationsInPackage(
|
||||
packageFqName: FqName,
|
||||
searchScope: GlobalSearchScope
|
||||
): Collection<JetClassOrObject> {
|
||||
): Collection<KtClassOrObject> {
|
||||
return JetTopLevelClassByPackageIndex.getInstance().get(
|
||||
packageFqName.asString(), project, kotlinSourceAndClassFiles(searchScope, project))
|
||||
}
|
||||
@@ -119,10 +119,10 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
}
|
||||
|
||||
override fun getSubPackages(fqn: FqName, scope: GlobalSearchScope): Collection<FqName> {
|
||||
return PackageIndexUtil.getSubPackageFqNames(fqn, kotlinSourceAndClassFiles(scope, project), project, JetScope.ALL_NAME_FILTER)
|
||||
return PackageIndexUtil.getSubPackageFqNames(fqn, kotlinSourceAndClassFiles(scope, project), project, KtScope.ALL_NAME_FILTER)
|
||||
}
|
||||
|
||||
override fun getPsiClass(classOrObject: JetClassOrObject): PsiClass? {
|
||||
override fun getPsiClass(classOrObject: KtClassOrObject): PsiClass? {
|
||||
val virtualFile = classOrObject.containingFile.virtualFile
|
||||
if (virtualFile != null && LibraryUtil.findLibraryEntry(virtualFile, classOrObject.project) != null) {
|
||||
if (ProjectRootsUtil.isLibraryClassFile(project, virtualFile)) {
|
||||
@@ -135,7 +135,7 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
|
||||
private fun withFakeLightClasses(
|
||||
lightClassForFacade: KotlinLightClassForFacade?,
|
||||
facadeFiles: List<JetFile>
|
||||
facadeFiles: List<KtFile>
|
||||
): List<PsiClass> {
|
||||
if (lightClassForFacade == null) return emptyList()
|
||||
|
||||
@@ -161,7 +161,7 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
|
||||
public fun createLightClassForFileFacade(
|
||||
facadeFqName: FqName,
|
||||
facadeFiles: List<JetFile>,
|
||||
facadeFiles: List<KtFile>,
|
||||
moduleInfo: IdeaModuleInfo
|
||||
): List<PsiClass> {
|
||||
if (moduleInfo is ModuleSourceInfo) {
|
||||
@@ -174,11 +174,11 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
}
|
||||
}
|
||||
|
||||
override fun findFilesForFacade(facadeFqName: FqName, scope: GlobalSearchScope): Collection<JetFile> {
|
||||
override fun findFilesForFacade(facadeFqName: FqName, scope: GlobalSearchScope): Collection<KtFile> {
|
||||
return JetFileFacadeFqNameIndex.INSTANCE.get(facadeFqName.asString(), project, scope)
|
||||
}
|
||||
|
||||
override fun resolveClassToDescriptor(classOrObject: JetClassOrObject): ClassDescriptor? {
|
||||
override fun resolveClassToDescriptor(classOrObject: KtClassOrObject): ClassDescriptor? {
|
||||
try {
|
||||
return classOrObject.resolveToDescriptor() as ClassDescriptor
|
||||
}
|
||||
@@ -206,7 +206,7 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
}
|
||||
|
||||
|
||||
private fun forceResolvePackageDeclarations(files: Collection<JetFile>, session: ResolveSession) {
|
||||
private fun forceResolvePackageDeclarations(files: Collection<KtFile>, session: ResolveSession) {
|
||||
for (file in files) {
|
||||
// SCRIPT: not supported
|
||||
if (file.isScript) continue
|
||||
@@ -222,21 +222,21 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
}
|
||||
|
||||
for (declaration in file.declarations) {
|
||||
if (declaration is JetFunction) {
|
||||
if (declaration is KtFunction) {
|
||||
val name = declaration.nameAsSafeName
|
||||
val functions = packageDescriptor.memberScope.getFunctions(name, NoLookupLocation.FROM_IDE)
|
||||
for (descriptor in functions) {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor)
|
||||
}
|
||||
}
|
||||
else if (declaration is JetProperty) {
|
||||
else if (declaration is KtProperty) {
|
||||
val name = declaration.nameAsSafeName
|
||||
val properties = packageDescriptor.memberScope.getProperties(name, NoLookupLocation.FROM_IDE)
|
||||
for (descriptor in properties) {
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor)
|
||||
}
|
||||
}
|
||||
else if (declaration is JetClassOrObject) {
|
||||
else if (declaration is KtClassOrObject) {
|
||||
// Do nothing: we are not interested in classes
|
||||
}
|
||||
else {
|
||||
@@ -248,8 +248,8 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLightClassForDecompiledClassOrObject(decompiledClassOrObject: JetClassOrObject): PsiClass? {
|
||||
if (decompiledClassOrObject is JetEnumEntry) {
|
||||
private fun getLightClassForDecompiledClassOrObject(decompiledClassOrObject: KtClassOrObject): PsiClass? {
|
||||
if (decompiledClassOrObject is KtEnumEntry) {
|
||||
return null
|
||||
}
|
||||
val containingJetFile = decompiledClassOrObject.getContainingJetFile()
|
||||
@@ -262,7 +262,7 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
}
|
||||
|
||||
private fun findCorrespondingLightClass(
|
||||
decompiledClassOrObject: JetClassOrObject,
|
||||
decompiledClassOrObject: KtClassOrObject,
|
||||
rootLightClassForDecompiledFile: PsiClass): PsiClass {
|
||||
val relativeFqName = getClassRelativeName(decompiledClassOrObject)
|
||||
val iterator = relativeFqName.pathSegments().iterator()
|
||||
@@ -279,9 +279,9 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
return current
|
||||
}
|
||||
|
||||
private fun getClassRelativeName(decompiledClassOrObject: JetClassOrObject): FqName {
|
||||
private fun getClassRelativeName(decompiledClassOrObject: KtClassOrObject): FqName {
|
||||
val name = decompiledClassOrObject.nameAsName!!
|
||||
val parent = PsiTreeUtil.getParentOfType(decompiledClassOrObject, JetClassOrObject::class.java, true)
|
||||
val parent = PsiTreeUtil.getParentOfType(decompiledClassOrObject, KtClassOrObject::class.java, true)
|
||||
if (parent == null) {
|
||||
assert(decompiledClassOrObject.isTopLevel())
|
||||
return FqName.topLevel(name)
|
||||
@@ -289,10 +289,10 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
return getClassRelativeName(parent).child(name)
|
||||
}
|
||||
|
||||
private fun createLightClassForDecompiledKotlinFile(file: JetFile): KotlinLightClassForDecompiledDeclaration? {
|
||||
private fun createLightClassForDecompiledKotlinFile(file: KtFile): KotlinLightClassForDecompiledDeclaration? {
|
||||
val virtualFile = file.virtualFile ?: return null
|
||||
|
||||
val classOrObject = file.declarations.filterIsInstance<JetClassOrObject>().singleOrNull()
|
||||
val classOrObject = file.declarations.filterIsInstance<KtClassOrObject>().singleOrNull()
|
||||
|
||||
val javaClsClass = createClsJavaClassFromVirtualFile(
|
||||
file, virtualFile,
|
||||
@@ -303,9 +303,9 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
|
||||
}
|
||||
|
||||
private fun createClsJavaClassFromVirtualFile(
|
||||
mirrorFile: JetFile,
|
||||
mirrorFile: KtFile,
|
||||
classFile: VirtualFile,
|
||||
correspondingClassOrObject: JetClassOrObject?
|
||||
correspondingClassOrObject: KtClassOrObject?
|
||||
): ClsClassImpl? {
|
||||
val javaFileStub = ClsJavaStubByVirtualFileCache.getInstance(project).get(classFile) ?: return null
|
||||
val manager = PsiManager.getInstance(mirrorFile.project)
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.load.java.structure.impl.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
|
||||
private fun PsiElement.getJavaDescriptorResolver(): JavaDescriptorResolver? {
|
||||
if (!ProjectRootsUtil.isInProjectOrLibraryClassFile(this)) return null
|
||||
@@ -78,7 +78,7 @@ public fun JavaDescriptorResolver.resolveField(field: JavaField): PropertyDescri
|
||||
return getContainingScope(field)?.getProperties(field.name, NoLookupLocation.FROM_IDE)?.findByJavaElement(field) as? PropertyDescriptor
|
||||
}
|
||||
|
||||
private fun JavaDescriptorResolver.getContainingScope(member: JavaMember): JetScope? {
|
||||
private fun JavaDescriptorResolver.getContainingScope(member: JavaMember): KtScope? {
|
||||
val containingClass = resolveClass(member.getContainingClass())
|
||||
return if (member.isStatic())
|
||||
containingClass?.getStaticScope()
|
||||
|
||||
+15
-15
@@ -31,9 +31,9 @@ import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.psi.JetCodeFragment
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
@@ -46,7 +46,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
public fun getInstance(project: Project): KotlinCacheService = ServiceManager.getService(project, javaClass<KotlinCacheService>())!!
|
||||
}
|
||||
|
||||
public fun getResolutionFacade(elements: List<JetElement>): ResolutionFacade {
|
||||
public fun getResolutionFacade(elements: List<KtElement>): ResolutionFacade {
|
||||
return getFacadeToAnalyzeFiles(elements.map { it.getContainingJetFile() })
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
|
||||
private fun librariesFacade(platform: TargetPlatform) = globalFacadesPerPlatform[platform]!!.facadeForLibraries
|
||||
|
||||
private fun createFacadeForSyntheticFiles(files: Set<JetFile>): ProjectResolutionFacade {
|
||||
private fun createFacadeForSyntheticFiles(files: Set<KtFile>): ProjectResolutionFacade {
|
||||
// we assume that all files come from the same module
|
||||
val targetPlatform = files.map { TargetPlatformDetector.getPlatform(it) }.toSet().single()
|
||||
val syntheticFileModule = files.map { it.getModuleInfo() }.toSet().single()
|
||||
@@ -150,14 +150,14 @@ public class KotlinCacheService(val project: Project) {
|
||||
private val syntheticFileCachesLock = Any()
|
||||
|
||||
private val slruCacheProvider = CachedValueProvider {
|
||||
CachedValueProvider.Result(object : SLRUCache<Set<JetFile>, ProjectResolutionFacade>(2, 3) {
|
||||
override fun createValue(files: Set<JetFile>): ProjectResolutionFacade {
|
||||
CachedValueProvider.Result(object : SLRUCache<Set<KtFile>, ProjectResolutionFacade>(2, 3) {
|
||||
override fun createValue(files: Set<KtFile>): ProjectResolutionFacade {
|
||||
return createFacadeForSyntheticFiles(files)
|
||||
}
|
||||
}, LibraryModificationTracker.getInstance(project), ProjectRootModificationTracker.getInstance(project))
|
||||
}
|
||||
|
||||
private fun getFacadeForSyntheticFiles(files: Set<JetFile>): ProjectResolutionFacade {
|
||||
private fun getFacadeForSyntheticFiles(files: Set<KtFile>): ProjectResolutionFacade {
|
||||
return synchronized(syntheticFileCachesLock) {
|
||||
//NOTE: computations inside createCacheForSyntheticFiles depend on project root structure
|
||||
// so we additionally drop the whole slru cache on change
|
||||
@@ -165,7 +165,7 @@ public class KotlinCacheService(val project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFacadeToAnalyzeFiles(files: Collection<JetFile>): ResolutionFacade {
|
||||
private fun getFacadeToAnalyzeFiles(files: Collection<KtFile>): ResolutionFacade {
|
||||
val syntheticFiles = findSyntheticFiles(files)
|
||||
val file = files.first()
|
||||
val projectFacade = if (syntheticFiles.isNotEmpty()) {
|
||||
@@ -177,17 +177,17 @@ public class KotlinCacheService(val project: Project) {
|
||||
return ResolutionFacadeImpl(projectFacade, file.getModuleInfo())
|
||||
}
|
||||
|
||||
private fun findSyntheticFiles(files: Collection<JetFile>) = files.map {
|
||||
if (it is JetCodeFragment) it.getContextFile() else it
|
||||
private fun findSyntheticFiles(files: Collection<KtFile>) = files.map {
|
||||
if (it is KtCodeFragment) it.getContextFile() else it
|
||||
}.filterNotNull().filter {
|
||||
!ProjectRootsUtil.isInProjectSource(it)
|
||||
}.toSet()
|
||||
|
||||
private fun JetCodeFragment.getContextFile(): JetFile? {
|
||||
private fun KtCodeFragment.getContextFile(): KtFile? {
|
||||
val contextElement = getContext() ?: return null
|
||||
val contextFile = (contextElement as? JetElement)?.getContainingJetFile()
|
||||
val contextFile = (contextElement as? KtElement)?.getContainingJetFile()
|
||||
?: throw AssertionError("Analyzing kotlin code fragment of type $javaClass with java context of type ${contextElement.javaClass}")
|
||||
return if (contextFile is JetCodeFragment) contextFile.getContextFile() else contextFile
|
||||
return if (contextFile is KtCodeFragment) contextFile.getContextFile() else contextFile
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ private fun globalResolveSessionProvider(
|
||||
dependencies: Collection<Any>,
|
||||
moduleFilter: (IdeaModuleInfo) -> Boolean,
|
||||
reuseDataFrom: ProjectResolutionFacade? = null,
|
||||
syntheticFiles: Collection<JetFile> = listOf(),
|
||||
syntheticFiles: Collection<KtFile> = listOf(),
|
||||
logProcessCanceled: Boolean = false
|
||||
): CachedValueProvider.Result<ModuleResolverProvider> {
|
||||
val delegateResolverProvider = reuseDataFrom?.moduleResolverProvider
|
||||
|
||||
+3
-3
@@ -20,18 +20,18 @@ import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.impl.compiled.ClsClassImpl
|
||||
import org.jetbrains.kotlin.asJava.KotlinWrappingLightClass
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
|
||||
class KotlinLightClassForDecompiledDeclaration(
|
||||
private val clsClass: ClsClassImpl,
|
||||
private val origin: JetClassOrObject?
|
||||
private val origin: KtClassOrObject?
|
||||
) : KotlinWrappingLightClass(clsClass.getManager()) {
|
||||
private val fqName = origin?.getFqName() ?: FqName(clsClass.getQualifiedName())
|
||||
|
||||
override fun copy() = this
|
||||
|
||||
override fun getOwnInnerClasses(): List<PsiClass> {
|
||||
val nestedClasses = origin?.getDeclarations()?.filterIsInstance<JetClassOrObject>() ?: emptyList()
|
||||
val nestedClasses = origin?.getDeclarations()?.filterIsInstance<KtClassOrObject>() ?: emptyList()
|
||||
return clsClass.getOwnInnerClasses().map { innerClsClass ->
|
||||
KotlinLightClassForDecompiledDeclaration(innerClsClass as ClsClassImpl,
|
||||
nestedClasses.firstOrNull { innerClsClass.getName() == it.getName() })
|
||||
|
||||
+27
-27
@@ -40,10 +40,10 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import java.util.*
|
||||
|
||||
internal class PerFileAnalysisCache(val file: JetFile, val componentProvider: ComponentProvider) {
|
||||
internal class PerFileAnalysisCache(val file: KtFile, val componentProvider: ComponentProvider) {
|
||||
private val cache = HashMap<PsiElement, AnalysisResult>()
|
||||
|
||||
private fun lookUp(analyzableElement: JetElement): AnalysisResult? {
|
||||
private fun lookUp(analyzableElement: KtElement): AnalysisResult? {
|
||||
// Looking for parent elements that are already analyzed
|
||||
// Also removing all elements whose parents are already analyzed, to guarantee consistency
|
||||
val descendantsOfCurrent = arrayListOf<PsiElement>()
|
||||
@@ -66,7 +66,7 @@ internal class PerFileAnalysisCache(val file: JetFile, val componentProvider: Co
|
||||
return result
|
||||
}
|
||||
|
||||
fun getAnalysisResults(element: JetElement): AnalysisResult {
|
||||
fun getAnalysisResults(element: KtElement): AnalysisResult {
|
||||
assert (element.getContainingJetFile() == file) { "Wrong file. Expected $file, but was ${element.getContainingJetFile()}" }
|
||||
|
||||
val analyzableParent = KotlinResolveDataProvider.findAnalyzableParent(element)
|
||||
@@ -84,7 +84,7 @@ internal class PerFileAnalysisCache(val file: JetFile, val componentProvider: Co
|
||||
}
|
||||
}
|
||||
|
||||
private fun analyze(analyzableElement: JetElement): AnalysisResult {
|
||||
private fun analyze(analyzableElement: KtElement): AnalysisResult {
|
||||
val project = analyzableElement.getProject()
|
||||
if (DumbService.isDumb(project)) {
|
||||
return AnalysisResult.EMPTY
|
||||
@@ -110,45 +110,45 @@ internal class PerFileAnalysisCache(val file: JetFile, val componentProvider: Co
|
||||
|
||||
private object KotlinResolveDataProvider {
|
||||
private val topmostElementTypes = arrayOf<Class<out PsiElement?>?>(
|
||||
javaClass<JetNamedFunction>(),
|
||||
javaClass<JetClassInitializer>(),
|
||||
javaClass<JetProperty>(),
|
||||
javaClass<JetImportDirective>(),
|
||||
javaClass<JetPackageDirective>(),
|
||||
javaClass<JetCodeFragment>(),
|
||||
javaClass<KtNamedFunction>(),
|
||||
javaClass<KtClassInitializer>(),
|
||||
javaClass<KtProperty>(),
|
||||
javaClass<KtImportDirective>(),
|
||||
javaClass<KtPackageDirective>(),
|
||||
javaClass<KtCodeFragment>(),
|
||||
// TODO: Non-analyzable so far, add more granular analysis
|
||||
javaClass<JetAnnotationEntry>(),
|
||||
javaClass<JetTypeConstraint>(),
|
||||
javaClass<JetDelegationSpecifierList>(),
|
||||
javaClass<JetTypeParameter>(),
|
||||
javaClass<JetParameter>()
|
||||
javaClass<KtAnnotationEntry>(),
|
||||
javaClass<KtTypeConstraint>(),
|
||||
javaClass<KtDelegationSpecifierList>(),
|
||||
javaClass<KtTypeParameter>(),
|
||||
javaClass<KtParameter>()
|
||||
)
|
||||
|
||||
fun findAnalyzableParent(element: JetElement): JetElement {
|
||||
if (element is JetFile) return element
|
||||
fun findAnalyzableParent(element: KtElement): KtElement {
|
||||
if (element is KtFile) return element
|
||||
|
||||
val topmostElement = JetPsiUtil.getTopmostParentOfTypes(element, *topmostElementTypes) as JetElement?
|
||||
val topmostElement = KtPsiUtil.getTopmostParentOfTypes(element, *topmostElementTypes) as KtElement?
|
||||
// parameters and supertype lists are not analyzable by themselves, but if we don't count them as topmost, we'll stop inside, say,
|
||||
// object expressions inside arguments of super constructors of classes (note that classes themselves are not topmost elements)
|
||||
val analyzableElement = when (topmostElement) {
|
||||
is JetAnnotationEntry,
|
||||
is JetTypeConstraint,
|
||||
is JetDelegationSpecifierList,
|
||||
is JetTypeParameter,
|
||||
is JetParameter -> PsiTreeUtil.getParentOfType(topmostElement, javaClass<JetClassOrObject>(), javaClass<JetCallableDeclaration>())
|
||||
is KtAnnotationEntry,
|
||||
is KtTypeConstraint,
|
||||
is KtDelegationSpecifierList,
|
||||
is KtTypeParameter,
|
||||
is KtParameter -> PsiTreeUtil.getParentOfType(topmostElement, javaClass<KtClassOrObject>(), javaClass<KtCallableDeclaration>())
|
||||
else -> topmostElement
|
||||
}
|
||||
return analyzableElement
|
||||
// if none of the above worked, take the outermost declaration
|
||||
?: PsiTreeUtil.getTopmostParentOfType(element, javaClass<JetDeclaration>())
|
||||
?: PsiTreeUtil.getTopmostParentOfType(element, javaClass<KtDeclaration>())
|
||||
// if even that didn't work, take the whole file
|
||||
?: element.getContainingJetFile()
|
||||
}
|
||||
|
||||
fun analyze(project: Project, componentProvider: ComponentProvider, analyzableElement: JetElement): AnalysisResult {
|
||||
fun analyze(project: Project, componentProvider: ComponentProvider, analyzableElement: KtElement): AnalysisResult {
|
||||
try {
|
||||
val module = componentProvider.get<ModuleDescriptor>()
|
||||
if (analyzableElement is JetCodeFragment) {
|
||||
if (analyzableElement is KtCodeFragment) {
|
||||
return AnalysisResult.success(analyzeExpressionCodeFragment(componentProvider, analyzableElement), module)
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ private object KotlinResolveDataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private fun analyzeExpressionCodeFragment(componentProvider: ComponentProvider, codeFragment: JetCodeFragment): BindingContext {
|
||||
private fun analyzeExpressionCodeFragment(componentProvider: ComponentProvider, codeFragment: KtCodeFragment): BindingContext {
|
||||
val trace = BindingTraceContext()
|
||||
componentProvider.get<CodeFragmentAnalyzer>().analyzeCodeFragment(
|
||||
codeFragment,
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.context.withProject
|
||||
import org.jetbrains.kotlin.idea.project.IdeaEnvironment
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
|
||||
import org.jetbrains.kotlin.storage.ExceptionTracker
|
||||
|
||||
@@ -38,7 +38,7 @@ fun createModuleResolverProvider(
|
||||
project: Project,
|
||||
globalContext: GlobalContextImpl,
|
||||
analyzerFacade: AnalyzerFacade<JvmPlatformParameters>,
|
||||
syntheticFiles: Collection<JetFile>,
|
||||
syntheticFiles: Collection<KtFile>,
|
||||
delegateResolver: ResolverForProject<IdeaModuleInfo>,
|
||||
moduleFilter: (IdeaModuleInfo) -> Boolean
|
||||
): ModuleResolverProvider {
|
||||
|
||||
+9
-9
@@ -29,9 +29,9 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.idea.project.ResolveElementCache
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.CompositeBindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
@@ -56,15 +56,15 @@ internal class ProjectResolutionFacade(
|
||||
private val analysisResults = CachedValuesManager.getManager(project).createCachedValue(
|
||||
{
|
||||
val resolverProvider = moduleResolverProvider
|
||||
val results = object : SLRUCache<JetFile, PerFileAnalysisCache>(2, 3) {
|
||||
override fun createValue(file: JetFile?): PerFileAnalysisCache {
|
||||
val results = object : SLRUCache<KtFile, PerFileAnalysisCache>(2, 3) {
|
||||
override fun createValue(file: KtFile?): PerFileAnalysisCache {
|
||||
return PerFileAnalysisCache(file!!, resolverProvider.resolverForProject.resolverForModule(file.getModuleInfo()).componentProvider)
|
||||
}
|
||||
}
|
||||
CachedValueProvider.Result(results, PsiModificationTracker.MODIFICATION_COUNT, resolverProvider.exceptionTracker)
|
||||
}, false)
|
||||
|
||||
fun getAnalysisResultsForElements(elements: Collection<JetElement>): AnalysisResult {
|
||||
fun getAnalysisResultsForElements(elements: Collection<KtElement>): AnalysisResult {
|
||||
assert(elements.isNotEmpty()) { "elements collection should not be empty" }
|
||||
val slruCache = synchronized(analysisResults) {
|
||||
analysisResults.getValue()!!
|
||||
@@ -97,15 +97,15 @@ internal class ResolutionFacadeImpl(
|
||||
override val moduleDescriptor: ModuleDescriptor
|
||||
get() = projectFacade.findModuleDescriptor(moduleInfo)
|
||||
|
||||
override fun analyze(element: JetElement, bodyResolveMode: BodyResolveMode): BindingContext {
|
||||
override fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode): BindingContext {
|
||||
val resolveElementCache = getFrontendService(element, javaClass<ResolveElementCache>())
|
||||
return resolveElementCache.resolveToElement(element, bodyResolveMode)
|
||||
}
|
||||
|
||||
override fun analyzeFullyAndGetResult(elements: Collection<JetElement>): AnalysisResult
|
||||
override fun analyzeFullyAndGetResult(elements: Collection<KtElement>): AnalysisResult
|
||||
= projectFacade.getAnalysisResultsForElements(elements)
|
||||
|
||||
override fun resolveToDescriptor(declaration: JetDeclaration): DeclarationDescriptor {
|
||||
override fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor {
|
||||
val resolveSession = projectFacade.resolverForModuleInfo(declaration.getModuleInfo()).componentProvider.get<ResolveSession>()
|
||||
return resolveSession.resolveToDescriptor(declaration)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ fun PsiElement.getModuleInfo(): IdeaModuleInfo {
|
||||
|
||||
if (this is KotlinLightElement<*, *>) return this.getModuleInfoForLightElement()
|
||||
|
||||
val containingJetFile = (this as? JetElement)?.getContainingFile() as? JetFile
|
||||
val containingJetFile = (this as? KtElement)?.getContainingFile() as? KtFile
|
||||
val context = containingJetFile?.analysisContext
|
||||
if (context != null) return context.getModuleInfo()
|
||||
|
||||
@@ -48,10 +48,10 @@ fun PsiElement.getModuleInfo(): IdeaModuleInfo {
|
||||
)
|
||||
}
|
||||
|
||||
val explicitModuleInfo = containingJetFile?.moduleInfo ?: (containingJetFile?.originalFile as? JetFile)?.moduleInfo
|
||||
val explicitModuleInfo = containingJetFile?.moduleInfo ?: (containingJetFile?.originalFile as? KtFile)?.moduleInfo
|
||||
if (explicitModuleInfo is IdeaModuleInfo) return explicitModuleInfo
|
||||
|
||||
if (containingJetFile is JetCodeFragment) {
|
||||
if (containingJetFile is KtCodeFragment) {
|
||||
return containingJetFile.getContext()?.getModuleInfo()
|
||||
?: logAndReturnDefault("Analyzing code fragment of type ${containingJetFile.javaClass} with no context element\nText:\n${containingJetFile.getText()}")
|
||||
}
|
||||
@@ -66,7 +66,7 @@ fun PsiElement.getModuleInfo(): IdeaModuleInfo {
|
||||
return getModuleInfoByVirtualFile(
|
||||
project,
|
||||
virtualFile,
|
||||
isDecompiledFile = (containingFile as? JetFile)?.isCompiled() ?: false
|
||||
isDecompiledFile = (containingFile as? KtFile)?.isCompiled() ?: false
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
@@ -37,19 +37,19 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyFileScope
|
||||
|
||||
public fun JetElement.getResolutionFacade(): ResolutionFacade {
|
||||
public fun KtElement.getResolutionFacade(): ResolutionFacade {
|
||||
return KotlinCacheService.getInstance(getProject()).getResolutionFacade(listOf(this))
|
||||
}
|
||||
|
||||
public fun JetDeclaration.resolveToDescriptor(): DeclarationDescriptor {
|
||||
public fun KtDeclaration.resolveToDescriptor(): DeclarationDescriptor {
|
||||
return getResolutionFacade().resolveToDescriptor(this)
|
||||
}
|
||||
|
||||
public fun JetDeclaration.resolveToDescriptorIfAny(): DeclarationDescriptor? {
|
||||
public fun KtDeclaration.resolveToDescriptorIfAny(): DeclarationDescriptor? {
|
||||
return analyze(BodyResolveMode.PARTIAL).get(BindingContext.DECLARATION_TO_DESCRIPTOR, this)
|
||||
}
|
||||
|
||||
public fun JetFile.resolveImportReference(fqName: FqName): Collection<DeclarationDescriptor> {
|
||||
public fun KtFile.resolveImportReference(fqName: FqName): Collection<DeclarationDescriptor> {
|
||||
val facade = getResolutionFacade()
|
||||
return facade.resolveImportReference(facade.moduleDescriptor, fqName)
|
||||
}
|
||||
@@ -60,24 +60,24 @@ public fun JetFile.resolveImportReference(fqName: FqName): Collection<Declaratio
|
||||
// analyzeFully - see KotlinResolveCache, KotlinResolveDataProvider
|
||||
// In the future these two approaches should be unified
|
||||
@JvmOverloads
|
||||
public fun JetElement.analyze(bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext {
|
||||
public fun KtElement.analyze(bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext {
|
||||
return getResolutionFacade().analyze(this, bodyResolveMode)
|
||||
}
|
||||
|
||||
public fun JetElement.analyzeAndGetResult(): AnalysisResult {
|
||||
public fun KtElement.analyzeAndGetResult(): AnalysisResult {
|
||||
val resolutionFacade = getResolutionFacade()
|
||||
return AnalysisResult.success(resolutionFacade.analyze(this), resolutionFacade.moduleDescriptor)
|
||||
}
|
||||
|
||||
public fun JetElement.findModuleDescriptor(): ModuleDescriptor {
|
||||
public fun KtElement.findModuleDescriptor(): ModuleDescriptor {
|
||||
return getResolutionFacade().moduleDescriptor
|
||||
}
|
||||
|
||||
public fun JetElement.analyzeFully(): BindingContext {
|
||||
public fun KtElement.analyzeFully(): BindingContext {
|
||||
return analyzeFullyAndGetResult().bindingContext
|
||||
}
|
||||
|
||||
public fun JetElement.analyzeFullyAndGetResult(vararg extraFiles: JetFile): AnalysisResult {
|
||||
public fun KtElement.analyzeFullyAndGetResult(vararg extraFiles: KtFile): AnalysisResult {
|
||||
return KotlinCacheService.getInstance(getProject()).getResolutionFacade(listOf(this) + extraFiles.toList()).analyzeFullyAndGetResult(listOf(this))
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public fun ResolutionFacade.resolveImportReference(
|
||||
moduleDescriptor: ModuleDescriptor,
|
||||
fqName: FqName
|
||||
): Collection<DeclarationDescriptor> {
|
||||
val importDirective = JetPsiFactory(project).createImportDirective(ImportPath(fqName, false))
|
||||
val importDirective = KtPsiFactory(project).createImportDirective(ImportPath(fqName, false))
|
||||
val qualifiedExpressionResolver = this.getFrontendService(moduleDescriptor, QualifiedExpressionResolver::class.java)
|
||||
return qualifiedExpressionResolver.processImportReference(
|
||||
importDirective, moduleDescriptor, BindingTraceContext(), packageFragmentForVisibilityCheck = null)?.getAllDescriptors() ?: emptyList()
|
||||
@@ -95,13 +95,13 @@ public fun ResolutionFacade.resolveImportReference(
|
||||
//NOTE: idea default API returns module search scope for file under module but not in source or production source (for example, test data )
|
||||
// this scope can't be used to search for kotlin declarations in index in order to resolve in that case
|
||||
// see com.intellij.psi.impl.file.impl.ResolveScopeManagerImpl.getInherentResolveScope
|
||||
public fun getResolveScope(file: JetFile): GlobalSearchScope {
|
||||
public fun getResolveScope(file: KtFile): GlobalSearchScope {
|
||||
return when (file.getModuleInfo()) {
|
||||
is ModuleSourceInfo -> file.getResolveScope()
|
||||
else -> GlobalSearchScope.EMPTY_SCOPE
|
||||
}
|
||||
}
|
||||
|
||||
public fun ResolutionFacade.getFileTopLevelScope(file: JetFile): LazyFileScope {
|
||||
public fun ResolutionFacade.getFileTopLevelScope(file: KtFile): LazyFileScope {
|
||||
return frontendService<FileScopeProvider>().getFileScope(file)
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.codeInsight
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.idea.decompiler.navigation.DecompiledNavigationUtils
|
||||
import org.jetbrains.kotlin.idea.references.BuiltInsReferenceResolver
|
||||
|
||||
+23
-23
@@ -16,37 +16,37 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.codeInsight
|
||||
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetTreeVisitorVoid
|
||||
import org.jetbrains.kotlin.psi.JetUserType
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetCallExpression
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.psi.JetQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtQualifiedExpression
|
||||
import java.util.LinkedHashMap
|
||||
|
||||
object JetFileReferencesResolver {
|
||||
fun resolve(
|
||||
element: JetElement,
|
||||
element: KtElement,
|
||||
resolveQualifiers: Boolean = true,
|
||||
resolveShortNames: Boolean = true
|
||||
): Map<JetReferenceExpression, BindingContext> {
|
||||
return (element.getContainingFile() as? JetFile)?.let { file ->
|
||||
): Map<KtReferenceExpression, BindingContext> {
|
||||
return (element.getContainingFile() as? KtFile)?.let { file ->
|
||||
resolve(file, listOf(element), resolveQualifiers, resolveShortNames)
|
||||
} ?: Collections.emptyMap()
|
||||
}
|
||||
|
||||
fun resolve(
|
||||
file: JetFile,
|
||||
elements: Iterable<JetElement>? = null,
|
||||
file: KtFile,
|
||||
elements: Iterable<KtElement>? = null,
|
||||
resolveQualifiers: Boolean = true,
|
||||
resolveShortNames: Boolean = true
|
||||
): Map<JetReferenceExpression, BindingContext> {
|
||||
): Map<KtReferenceExpression, BindingContext> {
|
||||
val visitor = ResolveAllReferencesVisitor(file, resolveQualifiers, resolveShortNames)
|
||||
if (elements != null) {
|
||||
elements.forEach { it.accept(visitor) }
|
||||
@@ -57,13 +57,13 @@ object JetFileReferencesResolver {
|
||||
return visitor.result
|
||||
}
|
||||
|
||||
private class ResolveAllReferencesVisitor(file: JetFile, val resolveQualifiers: Boolean, val resolveShortNames: Boolean) : JetTreeVisitorVoid() {
|
||||
private class ResolveAllReferencesVisitor(file: KtFile, val resolveQualifiers: Boolean, val resolveShortNames: Boolean) : KtTreeVisitorVoid() {
|
||||
private val resolutionFacade = file.getResolutionFacade()
|
||||
private val resolveMap = LinkedHashMap<JetReferenceExpression, BindingContext>()
|
||||
private val resolveMap = LinkedHashMap<KtReferenceExpression, BindingContext>()
|
||||
|
||||
public val result: Map<JetReferenceExpression, BindingContext> = resolveMap
|
||||
public val result: Map<KtReferenceExpression, BindingContext> = resolveMap
|
||||
|
||||
override fun visitUserType(userType: JetUserType) {
|
||||
override fun visitUserType(userType: KtUserType) {
|
||||
if (resolveQualifiers) {
|
||||
userType.acceptChildren(this)
|
||||
}
|
||||
@@ -76,7 +76,7 @@ object JetFileReferencesResolver {
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitQualifiedExpression(expression: JetQualifiedExpression) {
|
||||
override fun visitQualifiedExpression(expression: KtQualifiedExpression) {
|
||||
val receiverExpression = expression.getReceiverExpression()
|
||||
if (resolveQualifiers || resolutionFacade.analyze(expression)[BindingContext.QUALIFIER, receiverExpression] == null) {
|
||||
receiverExpression.accept(this)
|
||||
@@ -89,7 +89,7 @@ object JetFileReferencesResolver {
|
||||
expression.getSelectorExpression()?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitSimpleNameExpression(expression: JetSimpleNameExpression) {
|
||||
override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) {
|
||||
if (resolveShortNames) {
|
||||
resolveMap[expression] = resolutionFacade.analyze(expression)
|
||||
}
|
||||
@@ -97,5 +97,5 @@ object JetFileReferencesResolver {
|
||||
}
|
||||
}
|
||||
|
||||
fun JetExpression.referenceExpression(): JetReferenceExpression? =
|
||||
(if (this is JetCallExpression) getCalleeExpression() else this) as? JetReferenceExpression
|
||||
fun KtExpression.referenceExpression(): KtReferenceExpression? =
|
||||
(if (this is KtCallExpression) getCalleeExpression() else this) as? KtReferenceExpression
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.codeInsight.shorten
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.SmartPsiElementPointer
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.UserDataProperty
|
||||
import com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.idea.util.ShortenReferences.Options
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences
|
||||
import java.util.*
|
||||
|
||||
class ShorteningRequest(val pointer: SmartPsiElementPointer<JetElement>, val options: Options)
|
||||
class ShorteningRequest(val pointer: SmartPsiElementPointer<KtElement>, val options: Options)
|
||||
|
||||
private var Project.elementsToShorten: MutableSet<ShorteningRequest>?
|
||||
by UserDataProperty(Key.create("ELEMENTS_TO_SHORTEN_KEY"))
|
||||
@@ -62,7 +62,7 @@ private fun Project.getOrCreateElementsToShorten(): MutableSet<ShorteningRequest
|
||||
return elements
|
||||
}
|
||||
|
||||
public fun JetElement.addToShorteningWaitSet(options: Options = Options.DEFAULT) {
|
||||
public fun KtElement.addToShorteningWaitSet(options: Options = Options.DEFAULT) {
|
||||
assert(ApplicationManager.getApplication()!!.isWriteAccessAllowed()) { "Write access needed" }
|
||||
val project = getProject()
|
||||
val elementPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(this)
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.serialization.deserialization.AnnotationAndConstantL
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer
|
||||
import org.jetbrains.kotlin.serialization.js.JsProtoBuf
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndConstantLoader<ClassId, Unit, ClassIdWithTarget> {
|
||||
|
||||
@@ -79,6 +79,6 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon
|
||||
override fun loadPropertyConstant(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: JetType
|
||||
expectedType: KtType
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -24,26 +24,26 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.descriptorToKey
|
||||
import org.jetbrains.kotlin.psi.JetCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.utils.concurrent.block.LockedClearableLazyValue
|
||||
|
||||
public abstract class KotlinClsFileBase(val provider: KotlinClassFileViewProvider) : JetFile(provider, true) {
|
||||
public abstract class KotlinClsFileBase(val provider: KotlinClassFileViewProvider) : KtFile(provider, true) {
|
||||
protected abstract val decompiledText: LockedClearableLazyValue<DecompiledText>
|
||||
|
||||
public fun getDeclarationForDescriptor(descriptor: DeclarationDescriptor): JetDeclaration? {
|
||||
public fun getDeclarationForDescriptor(descriptor: DeclarationDescriptor): KtDeclaration? {
|
||||
val original = descriptor.getOriginal()
|
||||
|
||||
if (original is ValueParameterDescriptor) {
|
||||
val callable = original.getContainingDeclaration()
|
||||
val callableDeclaration = getDeclarationForDescriptor(callable) as? JetCallableDeclaration ?: return null
|
||||
val callableDeclaration = getDeclarationForDescriptor(callable) as? KtCallableDeclaration ?: return null
|
||||
return callableDeclaration.getValueParameters()[original.getIndex()]
|
||||
}
|
||||
|
||||
if (original is ConstructorDescriptor && original.isPrimary()) {
|
||||
val classOrObject = getDeclarationForDescriptor(original.getContainingDeclaration()) as? JetClassOrObject
|
||||
val classOrObject = getDeclarationForDescriptor(original.getContainingDeclaration()) as? KtClassOrObject
|
||||
return classOrObject?.getPrimaryConstructor() ?: classOrObject
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class KotlinClsFileBase(val provider: KotlinClassFileViewProvide
|
||||
|
||||
val range = decompiledText.get().renderedDescriptorsToRange[key]
|
||||
return if (range != null) {
|
||||
PsiTreeUtil.findElementOfClassAtRange(this, range.getStartOffset(), range.getEndOffset(), javaClass<JetDeclaration>())
|
||||
PsiTreeUtil.findElementOfClassAtRange(this, range.getStartOffset(), range.getEndOffset(), javaClass<KtDeclaration>())
|
||||
}
|
||||
else {
|
||||
null
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.SingleRootFileViewProvider
|
||||
import com.intellij.psi.impl.source.PsiFileImpl
|
||||
import org.jetbrains.kotlin.idea.JetFileType
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.utils.concurrent.block.LockedClearableLazyValue
|
||||
|
||||
@@ -34,7 +34,7 @@ abstract class KotlinClassFileViewProvider(
|
||||
file: VirtualFile,
|
||||
physical: Boolean) : SingleRootFileViewProvider(manager, file, physical, KotlinLanguage.INSTANCE) {
|
||||
val content : LockedClearableLazyValue<String> = LockedClearableLazyValue(Any()) {
|
||||
val psiFile = createFile(manager.getProject(), file, JetFileType.INSTANCE)
|
||||
val psiFile = createFile(manager.getProject(), file, KotlinFileType.INSTANCE)
|
||||
val text = psiFile?.getText() ?: ""
|
||||
|
||||
(psiFile as? PsiFileImpl)?.markInvalidated()
|
||||
|
||||
+5
-5
@@ -35,8 +35,8 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileFinderFactory;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor;
|
||||
@@ -51,7 +51,7 @@ import static org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClass
|
||||
public final class DecompiledNavigationUtils {
|
||||
|
||||
@Nullable
|
||||
public static JetDeclaration getDeclarationFromDecompiledClassFile(
|
||||
public static KtDeclaration getDeclarationFromDecompiledClassFile(
|
||||
@NotNull Project project,
|
||||
@NotNull DeclarationDescriptor referencedDescriptor
|
||||
) {
|
||||
@@ -130,13 +130,13 @@ public final class DecompiledNavigationUtils {
|
||||
Name partClassName = JvmFileClassUtil.getImplClassName((DeserializedCallableMemberDescriptor) referencedDescriptor);
|
||||
if (partClassName != null) {
|
||||
FqName partFQN = packageFQN.child(partClassName);
|
||||
Collection<JetFile> multifileFacadeJetFiles =
|
||||
Collection<KtFile> multifileFacadeJetFiles =
|
||||
StaticFacadeIndexUtil.getMultifileClassForPart(partFQN, GlobalSearchScope.allScope(project), project);
|
||||
if (multifileFacadeJetFiles.isEmpty()) {
|
||||
return new ClassId(packageFQN, partClassName);
|
||||
}
|
||||
else {
|
||||
JetFile multifileFacade = multifileFacadeJetFiles.iterator().next();
|
||||
KtFile multifileFacade = multifileFacadeJetFiles.iterator().next();
|
||||
String multifileFacadeName = multifileFacade.getVirtualFile().getNameWithoutExtension();
|
||||
return new ClassId(packageFQN, Name.identifier(multifileFacadeName));
|
||||
}
|
||||
|
||||
+82
-82
@@ -52,7 +52,7 @@ import org.jetbrains.kotlin.idea.stubindex.JetSourceFilterScope;
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetTopLevelFunctionFqnNameIndex;
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetTopLevelPropertyFqnNameIndex;
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -89,10 +89,10 @@ public class JetSourceNavigationHelper {
|
||||
|
||||
@NotNull
|
||||
private static GlobalSearchScope createLibraryOrSourcesScope(
|
||||
@NotNull JetNamedDeclaration declaration,
|
||||
@NotNull KtNamedDeclaration declaration,
|
||||
@NotNull NavigationKind navigationKind
|
||||
) {
|
||||
JetFile containingFile = declaration.getContainingJetFile();
|
||||
KtFile containingFile = declaration.getContainingJetFile();
|
||||
VirtualFile libraryFile = containingFile.getVirtualFile();
|
||||
if (libraryFile == null) return GlobalSearchScope.EMPTY_SCOPE;
|
||||
|
||||
@@ -107,20 +107,20 @@ public class JetSourceNavigationHelper {
|
||||
: JetSourceFilterScope.kotlinLibraryClassFiles(GlobalSearchScope.allScope(project), project);
|
||||
}
|
||||
|
||||
private static List<JetFile> getContainingFiles(@NotNull Iterable<JetNamedDeclaration> declarations) {
|
||||
Set<JetFile> result = Sets.newHashSet();
|
||||
for (JetNamedDeclaration declaration : declarations) {
|
||||
private static List<KtFile> getContainingFiles(@NotNull Iterable<KtNamedDeclaration> declarations) {
|
||||
Set<KtFile> result = Sets.newHashSet();
|
||||
for (KtNamedDeclaration declaration : declarations) {
|
||||
PsiFile containingFile = declaration.getContainingFile();
|
||||
if (containingFile instanceof JetFile) {
|
||||
result.add((JetFile) containingFile);
|
||||
if (containingFile instanceof KtFile) {
|
||||
result.add((KtFile) containingFile);
|
||||
}
|
||||
}
|
||||
return Lists.newArrayList(result);
|
||||
}
|
||||
|
||||
private static boolean haveRenamesInImports(@NotNull List<JetFile> files) {
|
||||
for (JetFile file : files) {
|
||||
for (JetImportDirective importDirective : file.getImportDirectives()) {
|
||||
private static boolean haveRenamesInImports(@NotNull List<KtFile> files) {
|
||||
for (KtFile file : files) {
|
||||
for (KtImportDirective importDirective : file.getImportDirectives()) {
|
||||
if (importDirective.getAliasName() != null) {
|
||||
return true;
|
||||
}
|
||||
@@ -130,18 +130,18 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JetNamedDeclaration findSpecialProperty(@NotNull Name memberName, @NotNull JetClass containingClass) {
|
||||
private static KtNamedDeclaration findSpecialProperty(@NotNull Name memberName, @NotNull KtClass containingClass) {
|
||||
// property constructor parameters
|
||||
List<JetParameter> constructorParameters = containingClass.getPrimaryConstructorParameters();
|
||||
for (JetParameter constructorParameter : constructorParameters) {
|
||||
List<KtParameter> constructorParameters = containingClass.getPrimaryConstructorParameters();
|
||||
for (KtParameter constructorParameter : constructorParameters) {
|
||||
if (memberName.equals(constructorParameter.getNameAsName()) && constructorParameter.hasValOrVar()) {
|
||||
return constructorParameter;
|
||||
}
|
||||
}
|
||||
|
||||
// enum entries
|
||||
if (containingClass.hasModifier(JetTokens.ENUM_KEYWORD)) {
|
||||
for (JetEnumEntry enumEntry : ContainerUtil.findAll(containingClass.getDeclarations(), JetEnumEntry.class)) {
|
||||
if (containingClass.hasModifier(KtTokens.ENUM_KEYWORD)) {
|
||||
for (KtEnumEntry enumEntry : ContainerUtil.findAll(containingClass.getDeclarations(), KtEnumEntry.class)) {
|
||||
if (memberName.equals(enumEntry.getNameAsName())) {
|
||||
return enumEntry;
|
||||
}
|
||||
@@ -151,14 +151,14 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JetNamedDeclaration convertPropertyOrFunction(
|
||||
@NotNull JetNamedDeclaration declaration,
|
||||
private static KtNamedDeclaration convertPropertyOrFunction(
|
||||
@NotNull KtNamedDeclaration declaration,
|
||||
@NotNull NavigationKind navigationKind
|
||||
) {
|
||||
if (declaration instanceof JetPrimaryConstructor) {
|
||||
JetClassOrObject sourceClassOrObject =
|
||||
convertNamedClassOrObject(((JetPrimaryConstructor) declaration).getContainingClassOrObject(), navigationKind);
|
||||
JetPrimaryConstructor primaryConstructor = sourceClassOrObject != null ? sourceClassOrObject.getPrimaryConstructor() : null;
|
||||
if (declaration instanceof KtPrimaryConstructor) {
|
||||
KtClassOrObject sourceClassOrObject =
|
||||
convertNamedClassOrObject(((KtPrimaryConstructor) declaration).getContainingClassOrObject(), navigationKind);
|
||||
KtPrimaryConstructor primaryConstructor = sourceClassOrObject != null ? sourceClassOrObject.getPrimaryConstructor() : null;
|
||||
return primaryConstructor != null ? primaryConstructor : sourceClassOrObject;
|
||||
}
|
||||
|
||||
@@ -171,23 +171,23 @@ public class JetSourceNavigationHelper {
|
||||
|
||||
PsiElement decompiledContainer = declaration.getParent();
|
||||
|
||||
Collection<JetNamedDeclaration> candidates;
|
||||
if (decompiledContainer instanceof JetFile) {
|
||||
Collection<KtNamedDeclaration> candidates;
|
||||
if (decompiledContainer instanceof KtFile) {
|
||||
candidates = getInitialTopLevelCandidates(declaration, navigationKind);
|
||||
}
|
||||
else if (decompiledContainer instanceof JetClassBody) {
|
||||
JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent();
|
||||
JetClassOrObject sourceClassOrObject = convertNamedClassOrObject(decompiledClassOrObject, navigationKind);
|
||||
else if (decompiledContainer instanceof KtClassBody) {
|
||||
KtClassOrObject decompiledClassOrObject = (KtClassOrObject) decompiledContainer.getParent();
|
||||
KtClassOrObject sourceClassOrObject = convertNamedClassOrObject(decompiledClassOrObject, navigationKind);
|
||||
|
||||
//noinspection unchecked
|
||||
candidates = sourceClassOrObject == null
|
||||
? Collections.<JetNamedDeclaration>emptyList()
|
||||
? Collections.<KtNamedDeclaration>emptyList()
|
||||
: getInitialMemberCandidates(sourceClassOrObject, memberName,
|
||||
(Class<JetNamedDeclaration>) declaration.getClass());
|
||||
(Class<KtNamedDeclaration>) declaration.getClass());
|
||||
|
||||
if (candidates.isEmpty()) {
|
||||
if (declaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) {
|
||||
return findSpecialProperty(memberName, (JetClass) sourceClassOrObject);
|
||||
if (declaration instanceof KtProperty && sourceClassOrObject instanceof KtClass) {
|
||||
return findSpecialProperty(memberName, (KtClass) sourceClassOrObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,12 +220,12 @@ public class JetSourceNavigationHelper {
|
||||
|
||||
KotlinCodeAnalyzer analyzer = createAnalyzer(candidates, declaration.getProject());
|
||||
|
||||
for (JetNamedDeclaration candidate : candidates) {
|
||||
for (KtNamedDeclaration candidate : candidates) {
|
||||
//noinspection unchecked
|
||||
CallableDescriptor candidateDescriptor = (CallableDescriptor) analyzer.resolveToDescriptor(candidate);
|
||||
if (receiversMatch(declaration, candidateDescriptor)
|
||||
&& valueParametersTypesMatch(declaration, candidateDescriptor)
|
||||
&& typeParametersMatch((JetTypeParameterListOwner) declaration, candidateDescriptor.getTypeParameters())) {
|
||||
&& typeParametersMatch((KtTypeParameterListOwner) declaration, candidateDescriptor.getTypeParameters())) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ public class JetSourceNavigationHelper {
|
||||
|
||||
@NotNull
|
||||
private static KotlinCodeAnalyzer createAnalyzer(
|
||||
@NotNull Collection<JetNamedDeclaration> candidates,
|
||||
@NotNull Collection<KtNamedDeclaration> candidates,
|
||||
@NotNull Project project
|
||||
) {
|
||||
|
||||
@@ -268,8 +268,8 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JetClassOrObject convertNamedClassOrObject(
|
||||
@NotNull JetClassOrObject classOrObject,
|
||||
private static KtClassOrObject convertNamedClassOrObject(
|
||||
@NotNull KtClassOrObject classOrObject,
|
||||
@NotNull NavigationKind navigationKind
|
||||
) {
|
||||
FqName classFqName = classOrObject.getFqName();
|
||||
@@ -279,7 +279,7 @@ public class JetSourceNavigationHelper {
|
||||
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
|
||||
return null;
|
||||
}
|
||||
Collection<JetClassOrObject> classes = JetFullClassNameIndex.getInstance()
|
||||
Collection<KtClassOrObject> classes = JetFullClassNameIndex.getInstance()
|
||||
.get(classFqName.asString(), classOrObject.getProject(), librarySourcesScope);
|
||||
if (classes.isEmpty()) {
|
||||
return null;
|
||||
@@ -288,8 +288,8 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<JetNamedDeclaration> getInitialTopLevelCandidates(
|
||||
@NotNull JetNamedDeclaration declaration,
|
||||
private static Collection<KtNamedDeclaration> getInitialTopLevelCandidates(
|
||||
@NotNull KtNamedDeclaration declaration,
|
||||
@NotNull NavigationKind navigationKind
|
||||
) {
|
||||
FqName memberFqName = declaration.getFqName();
|
||||
@@ -300,59 +300,59 @@ public class JetSourceNavigationHelper {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
//noinspection unchecked
|
||||
StringStubIndexExtension<JetNamedDeclaration> index =
|
||||
(StringStubIndexExtension<JetNamedDeclaration>) getIndexForTopLevelPropertyOrFunction(declaration);
|
||||
StringStubIndexExtension<KtNamedDeclaration> index =
|
||||
(StringStubIndexExtension<KtNamedDeclaration>) getIndexForTopLevelPropertyOrFunction(declaration);
|
||||
return index.get(memberFqName.asString(), declaration.getProject(), librarySourcesScope);
|
||||
}
|
||||
|
||||
private static StringStubIndexExtension<? extends JetNamedDeclaration> getIndexForTopLevelPropertyOrFunction(
|
||||
@NotNull JetNamedDeclaration decompiledDeclaration
|
||||
private static StringStubIndexExtension<? extends KtNamedDeclaration> getIndexForTopLevelPropertyOrFunction(
|
||||
@NotNull KtNamedDeclaration decompiledDeclaration
|
||||
) {
|
||||
if (decompiledDeclaration instanceof JetNamedFunction) {
|
||||
if (decompiledDeclaration instanceof KtNamedFunction) {
|
||||
return JetTopLevelFunctionFqnNameIndex.getInstance();
|
||||
}
|
||||
if (decompiledDeclaration instanceof JetProperty) {
|
||||
if (decompiledDeclaration instanceof KtProperty) {
|
||||
return JetTopLevelPropertyFqnNameIndex.getInstance();
|
||||
}
|
||||
throw new IllegalArgumentException("Neither function nor declaration: " + decompiledDeclaration.getClass().getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<JetNamedDeclaration> getInitialMemberCandidates(
|
||||
@NotNull JetClassOrObject sourceClassOrObject,
|
||||
private static List<KtNamedDeclaration> getInitialMemberCandidates(
|
||||
@NotNull KtClassOrObject sourceClassOrObject,
|
||||
@NotNull final Name name,
|
||||
@NotNull Class<JetNamedDeclaration> declarationClass
|
||||
@NotNull Class<KtNamedDeclaration> declarationClass
|
||||
) {
|
||||
List<JetNamedDeclaration> allByClass = ContainerUtil.findAll(sourceClassOrObject.getDeclarations(), declarationClass);
|
||||
return ContainerUtil.filter(allByClass, new Condition<JetNamedDeclaration>() {
|
||||
List<KtNamedDeclaration> allByClass = ContainerUtil.findAll(sourceClassOrObject.getDeclarations(), declarationClass);
|
||||
return ContainerUtil.filter(allByClass, new Condition<KtNamedDeclaration>() {
|
||||
@Override
|
||||
public boolean value(JetNamedDeclaration declaration) {
|
||||
public boolean value(KtNamedDeclaration declaration) {
|
||||
return name.equals(declaration.getNameAsSafeName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<JetNamedDeclaration> filterByReceiverPresenceAndParametersCount(
|
||||
final @NotNull JetNamedDeclaration decompiledDeclaration,
|
||||
@NotNull Collection<JetNamedDeclaration> candidates
|
||||
private static List<KtNamedDeclaration> filterByReceiverPresenceAndParametersCount(
|
||||
final @NotNull KtNamedDeclaration decompiledDeclaration,
|
||||
@NotNull Collection<KtNamedDeclaration> candidates
|
||||
) {
|
||||
return ContainerUtil.filter(candidates, new Condition<JetNamedDeclaration>() {
|
||||
return ContainerUtil.filter(candidates, new Condition<KtNamedDeclaration>() {
|
||||
@Override
|
||||
public boolean value(JetNamedDeclaration candidate) {
|
||||
public boolean value(KtNamedDeclaration candidate) {
|
||||
return sameReceiverPresenceAndParametersCount(candidate, decompiledDeclaration);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<JetNamedDeclaration> filterByReceiverAndParameterTypes(
|
||||
final @NotNull JetNamedDeclaration decompiledDeclaration,
|
||||
@NotNull Collection<JetNamedDeclaration> candidates
|
||||
private static List<KtNamedDeclaration> filterByReceiverAndParameterTypes(
|
||||
final @NotNull KtNamedDeclaration decompiledDeclaration,
|
||||
@NotNull Collection<KtNamedDeclaration> candidates
|
||||
) {
|
||||
return ContainerUtil.filter(candidates, new Condition<JetNamedDeclaration>() {
|
||||
return ContainerUtil.filter(candidates, new Condition<KtNamedDeclaration>() {
|
||||
@Override
|
||||
public boolean value(JetNamedDeclaration candidate) {
|
||||
public boolean value(KtNamedDeclaration candidate) {
|
||||
return receiverAndParametersShortTypesMatch(candidate, decompiledDeclaration);
|
||||
}
|
||||
});
|
||||
@@ -364,7 +364,7 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiClass getOriginalPsiClassOrCreateLightClass(@NotNull JetClassOrObject classOrObject) {
|
||||
public static PsiClass getOriginalPsiClassOrCreateLightClass(@NotNull KtClassOrObject classOrObject) {
|
||||
if (LightClassUtil.INSTANCE$.belongsToKotlinBuiltIns(classOrObject.getContainingJetFile())) {
|
||||
FqName fqName = classOrObject.getFqName();
|
||||
if (fqName != null) {
|
||||
@@ -381,7 +381,7 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiClass getOriginalClass(@NotNull JetClassOrObject classOrObject) {
|
||||
public static PsiClass getOriginalClass(@NotNull KtClassOrObject classOrObject) {
|
||||
// Copied from JavaPsiImplementationHelperImpl:getOriginalClass()
|
||||
String internalName = PsiCodegenPredictor.getPredefinedJvmInternalName(classOrObject, NoResolveFileClassesProvider.INSTANCE$);
|
||||
if (internalName == null) {
|
||||
@@ -389,7 +389,7 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
String fqName = JvmClassName.byInternalName(internalName).getFqNameForClassNameWithoutDollars().asString();
|
||||
|
||||
JetFile file = classOrObject.getContainingJetFile();
|
||||
KtFile file = classOrObject.getContainingJetFile();
|
||||
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
Project project = file.getProject();
|
||||
@@ -427,18 +427,18 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetDeclaration getNavigationElement(@NotNull JetDeclaration declaration) {
|
||||
public static KtDeclaration getNavigationElement(@NotNull KtDeclaration declaration) {
|
||||
return navigateToDeclaration(declaration, NavigationKind.CLASS_FILES_TO_SOURCES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetDeclaration getOriginalElement(@NotNull JetDeclaration declaration) {
|
||||
public static KtDeclaration getOriginalElement(@NotNull KtDeclaration declaration) {
|
||||
return navigateToDeclaration(declaration, NavigationKind.SOURCES_TO_CLASS_FILES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetDeclaration navigateToDeclaration(
|
||||
@NotNull JetDeclaration from,
|
||||
public static KtDeclaration navigateToDeclaration(
|
||||
@NotNull KtDeclaration from,
|
||||
@NotNull NavigationKind navigationKind) {
|
||||
if (DumbService.isDumb(from.getProject())) return from;
|
||||
|
||||
@@ -449,15 +449,15 @@ public class JetSourceNavigationHelper {
|
||||
case SOURCES_TO_CLASS_FILES:
|
||||
if (from.getContainingJetFile().isCompiled()) return from;
|
||||
if (!ProjectRootsUtil.isInContent(from, false, true, false)) return from;
|
||||
if (JetPsiUtil.isLocal(from)) return from;
|
||||
if (KtPsiUtil.isLocal(from)) return from;
|
||||
break;
|
||||
}
|
||||
|
||||
JetDeclaration result = from.accept(new SourceAndDecompiledConversionVisitor(navigationKind), null);
|
||||
KtDeclaration result = from.accept(new SourceAndDecompiledConversionVisitor(navigationKind), null);
|
||||
return result != null ? result : from;
|
||||
}
|
||||
|
||||
private static class SourceAndDecompiledConversionVisitor extends JetVisitor<JetDeclaration, Void> {
|
||||
private static class SourceAndDecompiledConversionVisitor extends KtVisitor<KtDeclaration, Void> {
|
||||
private final NavigationKind navigationKind;
|
||||
|
||||
public SourceAndDecompiledConversionVisitor(@NotNull NavigationKind navigationKind) {
|
||||
@@ -465,45 +465,45 @@ public class JetSourceNavigationHelper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetDeclaration visitNamedFunction(@NotNull JetNamedFunction function, Void data) {
|
||||
public KtDeclaration visitNamedFunction(@NotNull KtNamedFunction function, Void data) {
|
||||
return convertPropertyOrFunction(function, navigationKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetDeclaration visitProperty(@NotNull JetProperty property, Void data) {
|
||||
public KtDeclaration visitProperty(@NotNull KtProperty property, Void data) {
|
||||
return convertPropertyOrFunction(property, navigationKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetDeclaration visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, Void data) {
|
||||
public KtDeclaration visitObjectDeclaration(@NotNull KtObjectDeclaration declaration, Void data) {
|
||||
return convertNamedClassOrObject(declaration, navigationKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetDeclaration visitClass(@NotNull JetClass klass, Void data) {
|
||||
public KtDeclaration visitClass(@NotNull KtClass klass, Void data) {
|
||||
return convertNamedClassOrObject(klass, navigationKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetDeclaration visitParameter(@NotNull JetParameter parameter, Void data) {
|
||||
JetCallableDeclaration callableDeclaration = (JetCallableDeclaration) parameter.getParent().getParent();
|
||||
List<JetParameter> parameters = callableDeclaration.getValueParameters();
|
||||
public KtDeclaration visitParameter(@NotNull KtParameter parameter, Void data) {
|
||||
KtCallableDeclaration callableDeclaration = (KtCallableDeclaration) parameter.getParent().getParent();
|
||||
List<KtParameter> parameters = callableDeclaration.getValueParameters();
|
||||
int index = parameters.indexOf(parameter);
|
||||
|
||||
JetCallableDeclaration sourceCallable = (JetCallableDeclaration) callableDeclaration.accept(this, null);
|
||||
KtCallableDeclaration sourceCallable = (KtCallableDeclaration) callableDeclaration.accept(this, null);
|
||||
if (sourceCallable == null) return null;
|
||||
List<JetParameter> sourceParameters = sourceCallable.getValueParameters();
|
||||
List<KtParameter> sourceParameters = sourceCallable.getValueParameters();
|
||||
if (sourceParameters.size() != parameters.size()) return null;
|
||||
return sourceParameters.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetDeclaration visitPrimaryConstructor(@NotNull JetPrimaryConstructor constructor, Void data) {
|
||||
public KtDeclaration visitPrimaryConstructor(@NotNull KtPrimaryConstructor constructor, Void data) {
|
||||
return convertPropertyOrFunction(constructor, navigationKind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetDeclaration visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor, Void data) {
|
||||
public KtDeclaration visitSecondaryConstructor(@NotNull KtSecondaryConstructor constructor, Void data) {
|
||||
return convertPropertyOrFunction(constructor, navigationKind);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,13 +17,13 @@
|
||||
package org.jetbrains.kotlin.idea.decompiler.navigation
|
||||
|
||||
import org.jetbrains.kotlin.psi.KotlinDeclarationNavigationPolicy
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import com.intellij.openapi.project.DumbService
|
||||
|
||||
public class KotlinDeclarationNavigationPolicyImpl : KotlinDeclarationNavigationPolicy {
|
||||
override fun getOriginalElement(declaration: JetDeclaration) =
|
||||
override fun getOriginalElement(declaration: KtDeclaration) =
|
||||
JetSourceNavigationHelper.getOriginalElement(declaration)
|
||||
override fun getNavigationElement(declaration: JetDeclaration) =
|
||||
override fun getNavigationElement(declaration: KtDeclaration) =
|
||||
JetSourceNavigationHelper.getNavigationElement(declaration)
|
||||
}
|
||||
|
||||
+46
-46
@@ -28,12 +28,12 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -41,39 +41,39 @@ import java.util.Set;
|
||||
public class MemberMatching {
|
||||
/* DECLARATIONS ROUGH MATCHING */
|
||||
@Nullable
|
||||
private static JetTypeReference getReceiverType(@NotNull JetNamedDeclaration propertyOrFunction) {
|
||||
if (propertyOrFunction instanceof JetCallableDeclaration) {
|
||||
return ((JetCallableDeclaration) propertyOrFunction).getReceiverTypeReference();
|
||||
private static KtTypeReference getReceiverType(@NotNull KtNamedDeclaration propertyOrFunction) {
|
||||
if (propertyOrFunction instanceof KtCallableDeclaration) {
|
||||
return ((KtCallableDeclaration) propertyOrFunction).getReceiverTypeReference();
|
||||
}
|
||||
throw new IllegalArgumentException("Not a callable declaration: " + propertyOrFunction.getClass().getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<JetParameter> getValueParameters(@NotNull JetNamedDeclaration propertyOrFunction) {
|
||||
if (propertyOrFunction instanceof JetCallableDeclaration) {
|
||||
return ((JetCallableDeclaration) propertyOrFunction).getValueParameters();
|
||||
private static List<KtParameter> getValueParameters(@NotNull KtNamedDeclaration propertyOrFunction) {
|
||||
if (propertyOrFunction instanceof KtCallableDeclaration) {
|
||||
return ((KtCallableDeclaration) propertyOrFunction).getValueParameters();
|
||||
}
|
||||
throw new IllegalArgumentException("Not a callable declaration: " + propertyOrFunction.getClass().getName());
|
||||
}
|
||||
|
||||
private static String getTypeShortName(@NotNull JetTypeReference typeReference) {
|
||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
private static String getTypeShortName(@NotNull KtTypeReference typeReference) {
|
||||
KtTypeElement typeElement = typeReference.getTypeElement();
|
||||
assert typeElement != null;
|
||||
return typeElement.accept(new JetVisitor<String, Void>() {
|
||||
return typeElement.accept(new KtVisitor<String, Void>() {
|
||||
@Override
|
||||
public String visitDeclaration(@NotNull JetDeclaration declaration, Void data) {
|
||||
public String visitDeclaration(@NotNull KtDeclaration declaration, Void data) {
|
||||
throw new IllegalStateException("This visitor shouldn't be invoked for " + declaration.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitUserType(@NotNull JetUserType type, Void data) {
|
||||
JetSimpleNameExpression referenceExpression = type.getReferenceExpression();
|
||||
public String visitUserType(@NotNull KtUserType type, Void data) {
|
||||
KtSimpleNameExpression referenceExpression = type.getReferenceExpression();
|
||||
assert referenceExpression != null;
|
||||
return referenceExpression.getReferencedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitFunctionType(@NotNull JetFunctionType type, Void data) {
|
||||
public String visitFunctionType(@NotNull KtFunctionType type, Void data) {
|
||||
int parameterCount = type.getParameters().size();
|
||||
if (type.getReceiverTypeReference() != null) {
|
||||
return KotlinBuiltIns.getExtensionFunctionName(parameterCount);
|
||||
@@ -84,32 +84,32 @@ public class MemberMatching {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitNullableType(@NotNull JetNullableType nullableType, Void data) {
|
||||
JetTypeElement innerType = nullableType.getInnerType();
|
||||
public String visitNullableType(@NotNull KtNullableType nullableType, Void data) {
|
||||
KtTypeElement innerType = nullableType.getInnerType();
|
||||
assert innerType != null : "No inner type: " + nullableType;
|
||||
return innerType.accept(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitDynamicType(@NotNull JetDynamicType type, Void data) {
|
||||
public String visitDynamicType(@NotNull KtDynamicType type, Void data) {
|
||||
return "dynamic";
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
private static boolean typesHaveSameShortName(@NotNull JetTypeReference a, @NotNull JetTypeReference b) {
|
||||
private static boolean typesHaveSameShortName(@NotNull KtTypeReference a, @NotNull KtTypeReference b) {
|
||||
return getTypeShortName(a).equals(getTypeShortName(b));
|
||||
}
|
||||
|
||||
static boolean sameReceiverPresenceAndParametersCount(@NotNull JetNamedDeclaration a, @NotNull JetNamedDeclaration b) {
|
||||
static boolean sameReceiverPresenceAndParametersCount(@NotNull KtNamedDeclaration a, @NotNull KtNamedDeclaration b) {
|
||||
boolean sameReceiverPresence = (getReceiverType(a) == null) == (getReceiverType(b) == null);
|
||||
boolean sameParametersCount = getValueParameters(a).size() == getValueParameters(b).size();
|
||||
return sameReceiverPresence && sameParametersCount;
|
||||
}
|
||||
|
||||
static boolean receiverAndParametersShortTypesMatch(@NotNull JetNamedDeclaration a, @NotNull JetNamedDeclaration b) {
|
||||
JetTypeReference aReceiver = getReceiverType(a);
|
||||
JetTypeReference bReceiver = getReceiverType(b);
|
||||
static boolean receiverAndParametersShortTypesMatch(@NotNull KtNamedDeclaration a, @NotNull KtNamedDeclaration b) {
|
||||
KtTypeReference aReceiver = getReceiverType(a);
|
||||
KtTypeReference bReceiver = getReceiverType(b);
|
||||
if ((aReceiver == null) != (bReceiver == null)) {
|
||||
return false;
|
||||
}
|
||||
@@ -118,14 +118,14 @@ public class MemberMatching {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<JetParameter> aParameters = getValueParameters(a);
|
||||
List<JetParameter> bParameters = getValueParameters(b);
|
||||
List<KtParameter> aParameters = getValueParameters(a);
|
||||
List<KtParameter> bParameters = getValueParameters(b);
|
||||
if (aParameters.size() != bParameters.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < aParameters.size(); i++) {
|
||||
JetTypeReference aType = aParameters.get(i).getTypeReference();
|
||||
JetTypeReference bType = bParameters.get(i).getTypeReference();
|
||||
KtTypeReference aType = aParameters.get(i).getTypeReference();
|
||||
KtTypeReference bType = bParameters.get(i).getTypeReference();
|
||||
|
||||
assert aType != null;
|
||||
assert bType != null;
|
||||
@@ -139,8 +139,8 @@ public class MemberMatching {
|
||||
|
||||
|
||||
/* DECLARATION AND DESCRIPTOR STRICT MATCHING */
|
||||
static boolean receiversMatch(@NotNull JetNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) {
|
||||
JetTypeReference declarationReceiver = getReceiverType(declaration);
|
||||
static boolean receiversMatch(@NotNull KtNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) {
|
||||
KtTypeReference declarationReceiver = getReceiverType(declaration);
|
||||
ReceiverParameterDescriptor descriptorReceiver = descriptor.getExtensionReceiverParameter();
|
||||
if (declarationReceiver == null && descriptorReceiver == null) {
|
||||
return true;
|
||||
@@ -151,8 +151,8 @@ public class MemberMatching {
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean valueParametersTypesMatch(@NotNull JetNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) {
|
||||
List<JetParameter> declarationParameters = getValueParameters(declaration);
|
||||
static boolean valueParametersTypesMatch(@NotNull KtNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) {
|
||||
List<KtParameter> declarationParameters = getValueParameters(declaration);
|
||||
List<ValueParameterDescriptor> descriptorParameters = descriptor.getValueParameters();
|
||||
if (descriptorParameters.size() != declarationParameters.size()) {
|
||||
return false;
|
||||
@@ -160,20 +160,20 @@ public class MemberMatching {
|
||||
|
||||
for (int i = 0; i < descriptorParameters.size(); i++) {
|
||||
ValueParameterDescriptor descriptorParameter = descriptorParameters.get(i);
|
||||
JetParameter declarationParameter = declarationParameters.get(i);
|
||||
JetTypeReference typeReference = declarationParameter.getTypeReference();
|
||||
KtParameter declarationParameter = declarationParameters.get(i);
|
||||
KtTypeReference typeReference = declarationParameter.getTypeReference();
|
||||
if (typeReference == null) {
|
||||
return false;
|
||||
}
|
||||
JetModifierList modifierList = declarationParameter.getModifierList();
|
||||
boolean varargInDeclaration = modifierList != null && modifierList.hasModifier(JetTokens.VARARG_KEYWORD);
|
||||
KtModifierList modifierList = declarationParameter.getModifierList();
|
||||
boolean varargInDeclaration = modifierList != null && modifierList.hasModifier(KtTokens.VARARG_KEYWORD);
|
||||
boolean varargInDescriptor = descriptorParameter.getVarargElementType() != null;
|
||||
if (varargInDeclaration != varargInDescriptor) {
|
||||
return false;
|
||||
}
|
||||
String declarationTypeText = typeReference.getText();
|
||||
|
||||
JetType typeToRender = varargInDeclaration ? descriptorParameter.getVarargElementType() : descriptorParameter.getType();
|
||||
KtType typeToRender = varargInDeclaration ? descriptorParameter.getVarargElementType() : descriptorParameter.getType();
|
||||
assert typeToRender != null;
|
||||
String descriptorParameterText = DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(typeToRender);
|
||||
if (!declarationTypeText.equals(descriptorParameterText)) {
|
||||
@@ -184,34 +184,34 @@ public class MemberMatching {
|
||||
}
|
||||
|
||||
static boolean typeParametersMatch(
|
||||
@NotNull JetTypeParameterListOwner typeParameterListOwner,
|
||||
@NotNull KtTypeParameterListOwner typeParameterListOwner,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameterDescriptors
|
||||
) {
|
||||
List<JetTypeParameter> decompiledParameters = typeParameterListOwner.getTypeParameters();
|
||||
List<KtTypeParameter> decompiledParameters = typeParameterListOwner.getTypeParameters();
|
||||
if (decompiledParameters.size() != typeParameterDescriptors.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Multimap<Name, String> decompiledParameterToBounds = HashMultimap.create();
|
||||
for (JetTypeParameter parameter : decompiledParameters) {
|
||||
JetTypeReference extendsBound = parameter.getExtendsBound();
|
||||
for (KtTypeParameter parameter : decompiledParameters) {
|
||||
KtTypeReference extendsBound = parameter.getExtendsBound();
|
||||
if (extendsBound != null) {
|
||||
decompiledParameterToBounds.put(parameter.getNameAsName(), extendsBound.getText());
|
||||
}
|
||||
}
|
||||
|
||||
for (JetTypeConstraint typeConstraint : typeParameterListOwner.getTypeConstraints()) {
|
||||
JetSimpleNameExpression typeParameterName = typeConstraint.getSubjectTypeParameterName();
|
||||
for (KtTypeConstraint typeConstraint : typeParameterListOwner.getTypeConstraints()) {
|
||||
KtSimpleNameExpression typeParameterName = typeConstraint.getSubjectTypeParameterName();
|
||||
assert typeParameterName != null;
|
||||
|
||||
JetTypeReference bound = typeConstraint.getBoundTypeReference();
|
||||
KtTypeReference bound = typeConstraint.getBoundTypeReference();
|
||||
assert bound != null;
|
||||
|
||||
decompiledParameterToBounds.put(typeParameterName.getReferencedNameAsName(), bound.getText());
|
||||
}
|
||||
|
||||
for (int i = 0; i < decompiledParameters.size(); i++) {
|
||||
JetTypeParameter decompiledParameter = decompiledParameters.get(i);
|
||||
KtTypeParameter decompiledParameter = decompiledParameters.get(i);
|
||||
TypeParameterDescriptor descriptor = typeParameterDescriptors.get(i);
|
||||
|
||||
Name name = decompiledParameter.getNameAsName();
|
||||
@@ -221,9 +221,9 @@ public class MemberMatching {
|
||||
}
|
||||
|
||||
Set<String> descriptorUpperBounds = Sets.newHashSet(ContainerUtil.map(
|
||||
descriptor.getUpperBounds(), new Function<JetType, String>() {
|
||||
descriptor.getUpperBounds(), new Function<KtType, String>() {
|
||||
@Override
|
||||
public String fun(JetType type) {
|
||||
public String fun(KtType type) {
|
||||
return DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(type);
|
||||
}
|
||||
}));
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinFunctionStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPropertyStubImpl
|
||||
@@ -235,8 +235,8 @@ private class ConstructorClsStubBuilder(
|
||||
|
||||
override fun doCreateCallableStub(parent: StubElement<out PsiElement>): StubElement<out PsiElement> {
|
||||
return if (Flags.IS_SECONDARY.get(constructorProto.flags))
|
||||
KotlinPlaceHolderStubImpl(parent, JetStubElementTypes.SECONDARY_CONSTRUCTOR)
|
||||
KotlinPlaceHolderStubImpl(parent, KtStubElementTypes.SECONDARY_CONSTRUCTOR)
|
||||
else
|
||||
KotlinPlaceHolderStubImpl(parent, JetStubElementTypes.PRIMARY_CONSTRUCTOR)
|
||||
KotlinPlaceHolderStubImpl(parent, KtStubElementTypes.PRIMARY_CONSTRUCTOR)
|
||||
}
|
||||
}
|
||||
|
||||
+22
-25
@@ -19,18 +19,15 @@ package org.jetbrains.kotlin.idea.decompiler.stubBuilder
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.DATA
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.INNER
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.MODALITY
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.VISIBILITY
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.idea.decompiler.stubBuilder.FlagsToModifiers.*
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.JetClassBody
|
||||
import org.jetbrains.kotlin.psi.JetDelegationSpecifierList
|
||||
import org.jetbrains.kotlin.psi.JetDelegatorToSuperClass
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetClassElementType
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.KtClassBody
|
||||
import org.jetbrains.kotlin.psi.KtDelegationSpecifierList
|
||||
import org.jetbrains.kotlin.psi.KtDelegatorToSuperClass
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtClassElementType
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinClassStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinModifierListStubImpl
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinObjectStubImpl
|
||||
@@ -92,10 +89,10 @@ private class ClassClsStubBuilder(
|
||||
relevantFlags.add(MODALITY)
|
||||
}
|
||||
val additionalModifiers = when (classKind) {
|
||||
ProtoBuf.Class.Kind.ENUM_CLASS -> listOf(JetTokens.ENUM_KEYWORD)
|
||||
ProtoBuf.Class.Kind.COMPANION_OBJECT -> listOf(JetTokens.COMPANION_KEYWORD)
|
||||
ProtoBuf.Class.Kind.ANNOTATION_CLASS -> listOf(JetTokens.ANNOTATION_KEYWORD)
|
||||
else -> listOf<JetModifierKeywordToken>()
|
||||
ProtoBuf.Class.Kind.ENUM_CLASS -> listOf(KtTokens.ENUM_KEYWORD)
|
||||
ProtoBuf.Class.Kind.COMPANION_OBJECT -> listOf(KtTokens.COMPANION_KEYWORD)
|
||||
ProtoBuf.Class.Kind.ANNOTATION_CLASS -> listOf(KtTokens.ANNOTATION_KEYWORD)
|
||||
else -> listOf<KtModifierKeywordToken>()
|
||||
}
|
||||
return createModifierListStubForDeclaration(parent, classProto.getFlags(), relevantFlags, additionalModifiers)
|
||||
}
|
||||
@@ -120,7 +117,7 @@ private class ClassClsStubBuilder(
|
||||
}
|
||||
else -> {
|
||||
KotlinClassStubImpl(
|
||||
JetClassElementType.getStubType(classKind == ProtoBuf.Class.Kind.ENUM_ENTRY),
|
||||
KtClassElementType.getStubType(classKind == ProtoBuf.Class.Kind.ENUM_ENTRY),
|
||||
parentStub,
|
||||
fqName.ref(),
|
||||
shortName,
|
||||
@@ -147,25 +144,25 @@ private class ClassClsStubBuilder(
|
||||
if (supertypeIds.isEmpty()) return
|
||||
|
||||
val delegationSpecifierListStub =
|
||||
KotlinPlaceHolderStubImpl<JetDelegationSpecifierList>(classOrObjectStub, JetStubElementTypes.DELEGATION_SPECIFIER_LIST)
|
||||
KotlinPlaceHolderStubImpl<KtDelegationSpecifierList>(classOrObjectStub, KtStubElementTypes.DELEGATION_SPECIFIER_LIST)
|
||||
|
||||
classProto.supertypes(c.typeTable).forEach { type ->
|
||||
val superClassStub = KotlinPlaceHolderStubImpl<JetDelegatorToSuperClass>(
|
||||
delegationSpecifierListStub, JetStubElementTypes.DELEGATOR_SUPER_CLASS
|
||||
val superClassStub = KotlinPlaceHolderStubImpl<KtDelegatorToSuperClass>(
|
||||
delegationSpecifierListStub, KtStubElementTypes.DELEGATOR_SUPER_CLASS
|
||||
)
|
||||
typeStubBuilder.createTypeReferenceStub(superClassStub, type)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createClassBodyAndMemberStubs() {
|
||||
val classBody = KotlinPlaceHolderStubImpl<JetClassBody>(classOrObjectStub, JetStubElementTypes.CLASS_BODY)
|
||||
val classBody = KotlinPlaceHolderStubImpl<KtClassBody>(classOrObjectStub, KtStubElementTypes.CLASS_BODY)
|
||||
createEnumEntryStubs(classBody)
|
||||
createCompanionObjectStub(classBody)
|
||||
createCallableMemberStubs(classBody)
|
||||
createInnerAndNestedClasses(classBody)
|
||||
}
|
||||
|
||||
private fun createCompanionObjectStub(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
private fun createCompanionObjectStub(classBody: KotlinPlaceHolderStubImpl<KtClassBody>) {
|
||||
if (companionObjectName == null) {
|
||||
return
|
||||
}
|
||||
@@ -174,11 +171,11 @@ private class ClassClsStubBuilder(
|
||||
createNestedClassStub(classBody, companionObjectId)
|
||||
}
|
||||
|
||||
private fun createEnumEntryStubs(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
private fun createEnumEntryStubs(classBody: KotlinPlaceHolderStubImpl<KtClassBody>) {
|
||||
classProto.getEnumEntryList().forEach { id ->
|
||||
val name = c.nameResolver.getName(id)
|
||||
KotlinClassStubImpl(
|
||||
JetStubElementTypes.ENUM_ENTRY,
|
||||
KtStubElementTypes.ENUM_ENTRY,
|
||||
classBody,
|
||||
qualifiedName = c.containerFqName.child(name).ref(),
|
||||
name = name.ref(),
|
||||
@@ -191,7 +188,7 @@ private class ClassClsStubBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
private fun createCallableMemberStubs(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
private fun createCallableMemberStubs(classBody: KotlinPlaceHolderStubImpl<KtClassBody>) {
|
||||
val container = ProtoContainer(classProto, null, c.nameResolver, c.typeTable)
|
||||
|
||||
for (secondaryConstructorProto in classProto.constructorList) {
|
||||
@@ -209,7 +206,7 @@ private class ClassClsStubBuilder(
|
||||
classKind == ProtoBuf.Class.Kind.ANNOTATION_CLASS
|
||||
}
|
||||
|
||||
private fun createInnerAndNestedClasses(classBody: KotlinPlaceHolderStubImpl<JetClassBody>) {
|
||||
private fun createInnerAndNestedClasses(classBody: KotlinPlaceHolderStubImpl<KtClassBody>) {
|
||||
classProto.getNestedClassNameList().forEach { id ->
|
||||
val nestedClassName = c.nameResolver.getName(id)
|
||||
if (nestedClassName != companionObjectName) {
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.load.kotlin.header.isCompatibleFileFacadeKind
|
||||
import org.jetbrains.kotlin.load.kotlin.header.isCompatibleMultifileClassKind
|
||||
import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil
|
||||
|
||||
@@ -50,7 +50,7 @@ public open class KotlinClsStubBuilder : ClsStubBuilder() {
|
||||
return doBuildFileStub(file)
|
||||
}
|
||||
|
||||
fun doBuildFileStub(file: VirtualFile): PsiFileStub<JetFile>? {
|
||||
fun doBuildFileStub(file: VirtualFile): PsiFileStub<KtFile>? {
|
||||
val kotlinBinaryClass = KotlinBinaryClassCache.getKotlinBinaryClass(file)!!
|
||||
val header = kotlinBinaryClass.getClassHeader()
|
||||
val classId = kotlinBinaryClass.getClassId()
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.idea.decompiler.navigation.JsMetaFileUtils
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DirectoryBasedKotlinJavaScriptDataFinder
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DirectoryBasedKotlinJavaScriptMetaFileFinder
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.serialization.deserialization.TypeTable
|
||||
@@ -48,7 +48,7 @@ public open class KotlinJavaScriptStubBuilder : ClsStubBuilder() {
|
||||
return doBuildFileStub(file)
|
||||
}
|
||||
|
||||
fun doBuildFileStub(file: VirtualFile): PsiFileStub<JetFile>? {
|
||||
fun doBuildFileStub(file: VirtualFile): PsiFileStub<KtFile>? {
|
||||
val packageFqName = JsMetaFileUtils.getPackageFqName(file)
|
||||
|
||||
val content = file.contentsToByteArray(false)
|
||||
|
||||
+29
-29
@@ -20,15 +20,15 @@ import com.google.protobuf.MessageLite
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.stubs.StubElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinUserTypeStub
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.*
|
||||
import org.jetbrains.kotlin.serialization.Flags
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
@@ -46,7 +46,7 @@ import java.util.*
|
||||
class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
|
||||
fun createTypeReferenceStub(parent: StubElement<out PsiElement>, type: Type) {
|
||||
val typeReference = KotlinPlaceHolderStubImpl<JetTypeReference>(parent, JetStubElementTypes.TYPE_REFERENCE)
|
||||
val typeReference = KotlinPlaceHolderStubImpl<KtTypeReference>(parent, KtStubElementTypes.TYPE_REFERENCE)
|
||||
|
||||
val annotations = c.components.annotationLoader.loadTypeAnnotations(type, c.nameResolver).filterNot {
|
||||
val isTopLevelClass = !it.isNestedClass()
|
||||
@@ -54,7 +54,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
}
|
||||
|
||||
val effectiveParent =
|
||||
if (type.getNullable()) KotlinPlaceHolderStubImpl<JetNullableType>(typeReference, JetStubElementTypes.NULLABLE_TYPE)
|
||||
if (type.getNullable()) KotlinPlaceHolderStubImpl<KtNullableType>(typeReference, KtStubElementTypes.NULLABLE_TYPE)
|
||||
else typeReference
|
||||
|
||||
fun createTypeParameterStub(name: Name) {
|
||||
@@ -74,7 +74,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
val id = c.nameResolver.getString(type.getFlexibleTypeCapabilitiesId())
|
||||
|
||||
if (id == DynamicTypeCapabilities.id) {
|
||||
KotlinPlaceHolderStubImpl<JetDynamicType>(parent, JetStubElementTypes.DYNAMIC_TYPE)
|
||||
KotlinPlaceHolderStubImpl<KtDynamicType>(parent, KtStubElementTypes.DYNAMIC_TYPE)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -101,12 +101,12 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
if (typeArgumentProtoList.isEmpty()) {
|
||||
return
|
||||
}
|
||||
val typeArgumentsListStub = KotlinPlaceHolderStubImpl<JetTypeArgumentList>(typeStub, JetStubElementTypes.TYPE_ARGUMENT_LIST)
|
||||
val typeArgumentsListStub = KotlinPlaceHolderStubImpl<KtTypeArgumentList>(typeStub, KtStubElementTypes.TYPE_ARGUMENT_LIST)
|
||||
typeArgumentProtoList.forEach { typeArgumentProto ->
|
||||
val projectionKind = typeArgumentProto.projection.toProjectionKind()
|
||||
val typeProjection = KotlinTypeProjectionStubImpl(typeArgumentsListStub, projectionKind.ordinal())
|
||||
if (projectionKind != JetProjectionKind.STAR) {
|
||||
val modifierKeywordToken = projectionKind.token as? JetModifierKeywordToken
|
||||
if (projectionKind != KtProjectionKind.STAR) {
|
||||
val modifierKeywordToken = projectionKind.token as? KtModifierKeywordToken
|
||||
createModifierListStub(typeProjection, modifierKeywordToken.singletonOrEmptyList())
|
||||
createTypeReferenceStub(typeProjection, typeArgumentProto.type(c.typeTable)!!)
|
||||
}
|
||||
@@ -114,23 +114,23 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
}
|
||||
|
||||
private fun Projection.toProjectionKind() = when (this) {
|
||||
Projection.IN -> JetProjectionKind.IN
|
||||
Projection.OUT -> JetProjectionKind.OUT
|
||||
Projection.INV -> JetProjectionKind.NONE
|
||||
Projection.STAR -> JetProjectionKind.STAR
|
||||
Projection.IN -> KtProjectionKind.IN
|
||||
Projection.OUT -> KtProjectionKind.OUT
|
||||
Projection.INV -> KtProjectionKind.NONE
|
||||
Projection.STAR -> KtProjectionKind.STAR
|
||||
}
|
||||
|
||||
private fun createFunctionTypeStub(parent: StubElement<out PsiElement>, type: Type, isExtensionFunctionType: Boolean) {
|
||||
val typeArgumentList = type.argumentList
|
||||
val functionType = KotlinPlaceHolderStubImpl<JetFunctionType>(parent, JetStubElementTypes.FUNCTION_TYPE)
|
||||
val functionType = KotlinPlaceHolderStubImpl<KtFunctionType>(parent, KtStubElementTypes.FUNCTION_TYPE)
|
||||
if (isExtensionFunctionType) {
|
||||
val functionTypeReceiverStub
|
||||
= KotlinPlaceHolderStubImpl<JetFunctionTypeReceiver>(functionType, JetStubElementTypes.FUNCTION_TYPE_RECEIVER)
|
||||
= KotlinPlaceHolderStubImpl<KtFunctionTypeReceiver>(functionType, KtStubElementTypes.FUNCTION_TYPE_RECEIVER)
|
||||
val receiverTypeProto = typeArgumentList.first().type(c.typeTable)!!
|
||||
createTypeReferenceStub(functionTypeReceiverStub, receiverTypeProto)
|
||||
}
|
||||
|
||||
val parameterList = KotlinPlaceHolderStubImpl<JetParameterList>(functionType, JetStubElementTypes.VALUE_PARAMETER_LIST)
|
||||
val parameterList = KotlinPlaceHolderStubImpl<KtParameterList>(functionType, KtStubElementTypes.VALUE_PARAMETER_LIST)
|
||||
val typeArgumentsWithoutReceiverAndReturnType
|
||||
= typeArgumentList.subList(if (isExtensionFunctionType) 1 else 0, typeArgumentList.size() - 1)
|
||||
typeArgumentsWithoutReceiverAndReturnType.forEach { argument ->
|
||||
@@ -150,7 +150,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
parameters: List<ProtoBuf.ValueParameter>,
|
||||
container: ProtoContainer
|
||||
) {
|
||||
val parameterListStub = KotlinPlaceHolderStubImpl<JetParameterList>(parent, JetStubElementTypes.VALUE_PARAMETER_LIST)
|
||||
val parameterListStub = KotlinPlaceHolderStubImpl<KtParameterList>(parent, KtStubElementTypes.VALUE_PARAMETER_LIST)
|
||||
for ((index, valueParameterProto) in parameters.withIndex()) {
|
||||
val name = c.nameResolver.getName(valueParameterProto.name)
|
||||
val parameterStub = KotlinParameterStubImpl(
|
||||
@@ -163,11 +163,11 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
)
|
||||
val varargElementType = valueParameterProto.varargElementType(c.typeTable)
|
||||
val typeProto = varargElementType ?: valueParameterProto.type(c.typeTable)
|
||||
val modifiers = arrayListOf<JetModifierKeywordToken>()
|
||||
val modifiers = arrayListOf<KtModifierKeywordToken>()
|
||||
|
||||
if (varargElementType != null) { modifiers.add(JetTokens.VARARG_KEYWORD) }
|
||||
if (Flags.IS_CROSSINLINE.get(valueParameterProto.flags)) { modifiers.add(JetTokens.CROSSINLINE_KEYWORD) }
|
||||
if (Flags.IS_NOINLINE.get(valueParameterProto.flags)) { modifiers.add(JetTokens.NOINLINE_KEYWORD) }
|
||||
if (varargElementType != null) { modifiers.add(KtTokens.VARARG_KEYWORD) }
|
||||
if (Flags.IS_CROSSINLINE.get(valueParameterProto.flags)) { modifiers.add(KtTokens.CROSSINLINE_KEYWORD) }
|
||||
if (Flags.IS_NOINLINE.get(valueParameterProto.flags)) { modifiers.add(KtTokens.NOINLINE_KEYWORD) }
|
||||
|
||||
val modifierList = createModifierListStub(parameterStub, modifiers)
|
||||
val parameterAnnotations = c.components.annotationLoader.loadValueParameterAnnotations(
|
||||
@@ -185,7 +185,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
return KotlinModifierListStubImpl(
|
||||
parameterStub,
|
||||
ModifierMaskUtils.computeMask { false },
|
||||
JetStubElementTypes.MODIFIER_LIST
|
||||
KtStubElementTypes.MODIFIER_LIST
|
||||
)
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
): List<Pair<Name, Type>> {
|
||||
if (typeParameterProtoList.isEmpty()) return listOf()
|
||||
|
||||
val typeParameterListStub = KotlinPlaceHolderStubImpl<JetTypeParameterList>(parent, JetStubElementTypes.TYPE_PARAMETER_LIST)
|
||||
val typeParameterListStub = KotlinPlaceHolderStubImpl<KtTypeParameterList>(parent, KtStubElementTypes.TYPE_PARAMETER_LIST)
|
||||
val protosForTypeConstraintList = arrayListOf<Pair<Name, Type>>()
|
||||
for (proto in typeParameterProtoList) {
|
||||
val name = c.nameResolver.getName(proto.name)
|
||||
@@ -225,9 +225,9 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
if (protosForTypeConstraintList.isEmpty()) {
|
||||
return
|
||||
}
|
||||
val typeConstraintListStub = KotlinPlaceHolderStubImpl<JetTypeConstraintList>(parent, JetStubElementTypes.TYPE_CONSTRAINT_LIST)
|
||||
val typeConstraintListStub = KotlinPlaceHolderStubImpl<KtTypeConstraintList>(parent, KtStubElementTypes.TYPE_CONSTRAINT_LIST)
|
||||
for ((name, type) in protosForTypeConstraintList) {
|
||||
val typeConstraintStub = KotlinPlaceHolderStubImpl<JetTypeConstraint>(typeConstraintListStub, JetStubElementTypes.TYPE_CONSTRAINT)
|
||||
val typeConstraintStub = KotlinPlaceHolderStubImpl<KtTypeConstraint>(typeConstraintListStub, KtStubElementTypes.TYPE_CONSTRAINT)
|
||||
KotlinNameReferenceExpressionStubImpl(typeConstraintStub, name.ref())
|
||||
createTypeReferenceStub(typeConstraintStub, type)
|
||||
}
|
||||
@@ -237,13 +237,13 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||
typeParameterStub: KotlinTypeParameterStubImpl,
|
||||
typeParameterProto: ProtoBuf.TypeParameter
|
||||
) {
|
||||
val modifiers = ArrayList<JetModifierKeywordToken>()
|
||||
val modifiers = ArrayList<KtModifierKeywordToken>()
|
||||
when (typeParameterProto.getVariance()) {
|
||||
Variance.IN -> modifiers.add(JetTokens.IN_KEYWORD)
|
||||
Variance.OUT -> modifiers.add(JetTokens.OUT_KEYWORD)
|
||||
Variance.IN -> modifiers.add(KtTokens.IN_KEYWORD)
|
||||
Variance.OUT -> modifiers.add(KtTokens.OUT_KEYWORD)
|
||||
}
|
||||
if (typeParameterProto.getReified()) {
|
||||
modifiers.add(JetTokens.REIFIED_KEYWORD)
|
||||
modifiers.add(KtTokens.REIFIED_KEYWORD)
|
||||
}
|
||||
createModifierListStub(typeParameterStub, modifiers)
|
||||
}
|
||||
|
||||
+41
-41
@@ -22,15 +22,15 @@ import com.intellij.psi.stubs.StubElement
|
||||
import com.intellij.util.io.StringRef
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFileStubForIde
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinUserTypeStub
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.*
|
||||
import org.jetbrains.kotlin.serialization.Flags
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
@@ -99,12 +99,12 @@ fun createFileStub(packageFqName: FqName): KotlinFileStubImpl {
|
||||
}
|
||||
|
||||
private fun setupFileStub(fileStub: KotlinFileStubImpl, packageFqName: FqName) {
|
||||
val packageDirectiveStub = KotlinPlaceHolderStubImpl<JetPackageDirective>(fileStub, JetStubElementTypes.PACKAGE_DIRECTIVE)
|
||||
val packageDirectiveStub = KotlinPlaceHolderStubImpl<KtPackageDirective>(fileStub, KtStubElementTypes.PACKAGE_DIRECTIVE)
|
||||
createStubForPackageName(packageDirectiveStub, packageFqName)
|
||||
KotlinPlaceHolderStubImpl<JetImportList>(fileStub, JetStubElementTypes.IMPORT_LIST)
|
||||
KotlinPlaceHolderStubImpl<KtImportList>(fileStub, KtStubElementTypes.IMPORT_LIST)
|
||||
}
|
||||
|
||||
fun createStubForPackageName(packageDirectiveStub: KotlinPlaceHolderStubImpl<JetPackageDirective>, packageFqName: FqName) {
|
||||
fun createStubForPackageName(packageDirectiveStub: KotlinPlaceHolderStubImpl<KtPackageDirective>, packageFqName: FqName) {
|
||||
val segments = packageFqName.pathSegments().toArrayList()
|
||||
val iterator = segments.listIterator(segments.size())
|
||||
|
||||
@@ -117,7 +117,7 @@ fun createStubForPackageName(packageDirectiveStub: KotlinPlaceHolderStubImpl<Jet
|
||||
}
|
||||
else -> {
|
||||
val lastSegment = iterator.previous()
|
||||
val receiver = KotlinPlaceHolderStubImpl<JetDotQualifiedExpression>(current, JetStubElementTypes.DOT_QUALIFIED_EXPRESSION)
|
||||
val receiver = KotlinPlaceHolderStubImpl<KtDotQualifiedExpression>(current, KtStubElementTypes.DOT_QUALIFIED_EXPRESSION)
|
||||
recCreateStubForPackageName(receiver)
|
||||
KotlinNameReferenceExpressionStubImpl(receiver, lastSegment.ref())
|
||||
}
|
||||
@@ -150,93 +150,93 @@ fun createStubForTypeName(typeClassId: ClassId, parent: StubElement<out PsiEleme
|
||||
|
||||
enum class FlagsToModifiers {
|
||||
MODALITY {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken {
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken {
|
||||
val modality = Flags.MODALITY.get(flags)
|
||||
return when (modality) {
|
||||
ProtoBuf.Modality.ABSTRACT -> JetTokens.ABSTRACT_KEYWORD
|
||||
ProtoBuf.Modality.FINAL -> JetTokens.FINAL_KEYWORD
|
||||
ProtoBuf.Modality.OPEN -> JetTokens.OPEN_KEYWORD
|
||||
ProtoBuf.Modality.SEALED -> JetTokens.SEALED_KEYWORD
|
||||
ProtoBuf.Modality.ABSTRACT -> KtTokens.ABSTRACT_KEYWORD
|
||||
ProtoBuf.Modality.FINAL -> KtTokens.FINAL_KEYWORD
|
||||
ProtoBuf.Modality.OPEN -> KtTokens.OPEN_KEYWORD
|
||||
ProtoBuf.Modality.SEALED -> KtTokens.SEALED_KEYWORD
|
||||
null -> throw IllegalStateException("Unexpected modality: null")
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
VISIBILITY {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
val visibility = Flags.VISIBILITY.get(flags)
|
||||
return when (visibility) {
|
||||
ProtoBuf.Visibility.PRIVATE, ProtoBuf.Visibility.PRIVATE_TO_THIS -> JetTokens.PRIVATE_KEYWORD
|
||||
ProtoBuf.Visibility.INTERNAL -> JetTokens.INTERNAL_KEYWORD
|
||||
ProtoBuf.Visibility.PROTECTED -> JetTokens.PROTECTED_KEYWORD
|
||||
ProtoBuf.Visibility.PUBLIC -> JetTokens.PUBLIC_KEYWORD
|
||||
ProtoBuf.Visibility.PRIVATE, ProtoBuf.Visibility.PRIVATE_TO_THIS -> KtTokens.PRIVATE_KEYWORD
|
||||
ProtoBuf.Visibility.INTERNAL -> KtTokens.INTERNAL_KEYWORD
|
||||
ProtoBuf.Visibility.PROTECTED -> KtTokens.PROTECTED_KEYWORD
|
||||
ProtoBuf.Visibility.PUBLIC -> KtTokens.PUBLIC_KEYWORD
|
||||
else -> throw IllegalStateException("Unexpected visibility: $visibility")
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
INNER {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_INNER.get(flags)) JetTokens.INNER_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_INNER.get(flags)) KtTokens.INNER_KEYWORD else null
|
||||
}
|
||||
},
|
||||
|
||||
CONST {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_CONST.get(flags)) JetTokens.CONST_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_CONST.get(flags)) KtTokens.CONST_KEYWORD else null
|
||||
}
|
||||
},
|
||||
|
||||
LATEINIT {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_LATEINIT.get(flags)) JetTokens.LATEINIT_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_LATEINIT.get(flags)) KtTokens.LATEINIT_KEYWORD else null
|
||||
}
|
||||
},
|
||||
|
||||
OPERATOR {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_OPERATOR.get(flags)) JetTokens.OPERATOR_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_OPERATOR.get(flags)) KtTokens.OPERATOR_KEYWORD else null
|
||||
}
|
||||
},
|
||||
|
||||
INFIX {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_INFIX.get(flags)) JetTokens.INFIX_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_INFIX.get(flags)) KtTokens.INFIX_KEYWORD else null
|
||||
}
|
||||
},
|
||||
|
||||
DATA {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_DATA.get(flags)) JetTokens.DATA_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_DATA.get(flags)) KtTokens.DATA_KEYWORD else null
|
||||
}
|
||||
},
|
||||
|
||||
EXTERNAL_FUN {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_EXTERNAL_FUNCTION.get(flags)) JetTokens.EXTERNAL_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_EXTERNAL_FUNCTION.get(flags)) KtTokens.EXTERNAL_KEYWORD else null
|
||||
}
|
||||
},
|
||||
|
||||
INLINE {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_INLINE.get(flags)) JetTokens.INLINE_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_INLINE.get(flags)) KtTokens.INLINE_KEYWORD else null
|
||||
}
|
||||
},
|
||||
|
||||
TAILREC {
|
||||
override fun getModifiers(flags: Int): JetModifierKeywordToken? {
|
||||
return if (Flags.IS_TAILREC.get(flags)) JetTokens.TAILREC_KEYWORD else null
|
||||
override fun getModifiers(flags: Int): KtModifierKeywordToken? {
|
||||
return if (Flags.IS_TAILREC.get(flags)) KtTokens.TAILREC_KEYWORD else null
|
||||
}
|
||||
};
|
||||
|
||||
abstract fun getModifiers(flags: Int): JetModifierKeywordToken?
|
||||
abstract fun getModifiers(flags: Int): KtModifierKeywordToken?
|
||||
}
|
||||
|
||||
fun createModifierListStubForDeclaration(
|
||||
parent: StubElement<out PsiElement>,
|
||||
flags: Int,
|
||||
flagsToTranslate: List<FlagsToModifiers> = listOf(),
|
||||
additionalModifiers: List<JetModifierKeywordToken> = listOf()
|
||||
additionalModifiers: List<KtModifierKeywordToken> = listOf()
|
||||
): KotlinModifierListStubImpl {
|
||||
assert(flagsToTranslate.isNotEmpty())
|
||||
|
||||
@@ -246,7 +246,7 @@ fun createModifierListStubForDeclaration(
|
||||
|
||||
fun createModifierListStub(
|
||||
parent: StubElement<out PsiElement>,
|
||||
modifiers: Collection<JetModifierKeywordToken>
|
||||
modifiers: Collection<KtModifierKeywordToken>
|
||||
): KotlinModifierListStubImpl? {
|
||||
if (modifiers.isEmpty()) {
|
||||
return null
|
||||
@@ -254,7 +254,7 @@ fun createModifierListStub(
|
||||
return KotlinModifierListStubImpl(
|
||||
parent,
|
||||
ModifierMaskUtils.computeMask { it in modifiers },
|
||||
JetStubElementTypes.MODIFIER_LIST
|
||||
KtStubElementTypes.MODIFIER_LIST
|
||||
)
|
||||
}
|
||||
|
||||
@@ -278,8 +278,8 @@ fun createTargetedAnnotationStubs(
|
||||
if (target != null) {
|
||||
KotlinAnnotationUseSiteTargetStubImpl(annotationEntryStubImpl, StringRef.fromString(target.name())!!)
|
||||
}
|
||||
val constructorCallee = KotlinPlaceHolderStubImpl<JetConstructorCalleeExpression>(annotationEntryStubImpl, JetStubElementTypes.CONSTRUCTOR_CALLEE)
|
||||
val typeReference = KotlinPlaceHolderStubImpl<JetTypeReference>(constructorCallee, JetStubElementTypes.TYPE_REFERENCE)
|
||||
val constructorCallee = KotlinPlaceHolderStubImpl<KtConstructorCalleeExpression>(annotationEntryStubImpl, KtStubElementTypes.CONSTRUCTOR_CALLEE)
|
||||
val typeReference = KotlinPlaceHolderStubImpl<KtTypeReference>(constructorCallee, KtStubElementTypes.TYPE_REFERENCE)
|
||||
createStubForTypeName(annotationClassId, typeReference)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -24,8 +24,8 @@ import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScopeImpl
|
||||
import org.jetbrains.kotlin.types.ErrorUtils.createErrorType
|
||||
import org.jetbrains.kotlin.types.TypeProjection
|
||||
import org.jetbrains.kotlin.types.TypeSubstitution
|
||||
@@ -35,12 +35,12 @@ import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
private class PackageFragmentWithMissingDependencies(override val fqName: FqName, moduleDescriptor: ModuleDescriptor) :
|
||||
PackageFragmentDescriptorImpl(moduleDescriptor, fqName) {
|
||||
override fun getMemberScope(): JetScope {
|
||||
override fun getMemberScope(): KtScope {
|
||||
return ScopeWithMissingDependencies(fqName, this)
|
||||
}
|
||||
}
|
||||
|
||||
private class ScopeWithMissingDependencies(val fqName: FqName, val containing: DeclarationDescriptor) : JetScopeImpl() {
|
||||
private class ScopeWithMissingDependencies(val fqName: FqName, val containing: DeclarationDescriptor) : KtScopeImpl() {
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
||||
return containing
|
||||
}
|
||||
@@ -74,7 +74,7 @@ private class MissingDependencyErrorClassDescriptor(
|
||||
val emptyConstructor = ConstructorDescriptorImpl.create(this, Annotations.EMPTY, true, SourceElement.NO_SOURCE)
|
||||
emptyConstructor.initialize(listOf(), listOf(), Visibilities.DEFAULT_VISIBILITY)
|
||||
emptyConstructor.setReturnType(createErrorType("<ERROR RETURN TYPE>"))
|
||||
initialize(JetScope.Empty, setOf(emptyConstructor), emptyConstructor)
|
||||
initialize(KtScope.Empty, setOf(emptyConstructor), emptyConstructor)
|
||||
}
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor) = this
|
||||
|
||||
+9
-9
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
|
||||
public class JetFindUsagesProvider : FindUsagesProvider {
|
||||
public override fun canFindUsagesFor(psiElement: PsiElement): Boolean =
|
||||
psiElement is JetNamedDeclaration
|
||||
psiElement is KtNamedDeclaration
|
||||
|
||||
public override fun getWordsScanner() = null
|
||||
|
||||
@@ -32,14 +32,14 @@ public class JetFindUsagesProvider : FindUsagesProvider {
|
||||
|
||||
public override fun getType(element: PsiElement): String {
|
||||
return when(element) {
|
||||
is JetNamedFunction -> "function"
|
||||
is JetClass -> "class"
|
||||
is JetParameter -> "parameter"
|
||||
is JetProperty -> if (element.isLocal()) "variable" else "property"
|
||||
is JetMultiDeclarationEntry -> "variable"
|
||||
is JetTypeParameter -> "type parameter"
|
||||
is JetSecondaryConstructor -> "constructor"
|
||||
is JetObjectDeclaration -> "object"
|
||||
is KtNamedFunction -> "function"
|
||||
is KtClass -> "class"
|
||||
is KtParameter -> "parameter"
|
||||
is KtProperty -> if (element.isLocal()) "variable" else "property"
|
||||
is KtMultiDeclarationEntry -> "variable"
|
||||
is KtTypeParameter -> "type parameter"
|
||||
is KtSecondaryConstructor -> "constructor"
|
||||
is KtObjectDeclaration -> "object"
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.findUsages.UsageTypeEnum.*
|
||||
import org.jetbrains.kotlin.idea.references.*
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
@@ -33,31 +33,31 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
public object UsageTypeUtils {
|
||||
public fun getUsageType(element: PsiElement?): UsageTypeEnum? {
|
||||
when (element) {
|
||||
is JetForExpression -> return IMPLICIT_ITERATION
|
||||
is JetMultiDeclaration -> return READ
|
||||
is JetPropertyDelegate -> return PROPERTY_DELEGATION
|
||||
is JetStringTemplateExpression -> return USAGE_IN_STRING_LITERAL
|
||||
is KtForExpression -> return IMPLICIT_ITERATION
|
||||
is KtMultiDeclaration -> return READ
|
||||
is KtPropertyDelegate -> return PROPERTY_DELEGATION
|
||||
is KtStringTemplateExpression -> return USAGE_IN_STRING_LITERAL
|
||||
}
|
||||
|
||||
val refExpr = element?.getNonStrictParentOfType<JetReferenceExpression>()
|
||||
val refExpr = element?.getNonStrictParentOfType<KtReferenceExpression>()
|
||||
if (refExpr == null) return null
|
||||
|
||||
val context = refExpr.analyze()
|
||||
|
||||
fun getCommonUsageType(): UsageTypeEnum? {
|
||||
return when {
|
||||
refExpr.getNonStrictParentOfType<JetImportDirective>() != null ->
|
||||
refExpr.getNonStrictParentOfType<KtImportDirective>() != null ->
|
||||
CLASS_IMPORT
|
||||
refExpr.getParentOfTypeAndBranch<JetCallableReferenceExpression>(){ getCallableReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<KtCallableReferenceExpression>(){ getCallableReference() } != null ->
|
||||
CALLABLE_REFERENCE
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun getClassUsageType(): UsageTypeEnum? {
|
||||
if (refExpr.getNonStrictParentOfType<JetTypeProjection>() != null) return TYPE_PARAMETER
|
||||
if (refExpr.getNonStrictParentOfType<KtTypeProjection>() != null) return TYPE_PARAMETER
|
||||
|
||||
val property = refExpr.getNonStrictParentOfType<JetProperty>()
|
||||
val property = refExpr.getNonStrictParentOfType<KtProperty>()
|
||||
if (property != null) {
|
||||
when {
|
||||
property.getTypeReference().isAncestor(refExpr) ->
|
||||
@@ -68,7 +68,7 @@ public object UsageTypeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
val function = refExpr.getNonStrictParentOfType<JetFunction>()
|
||||
val function = refExpr.getNonStrictParentOfType<KtFunction>()
|
||||
if (function != null) {
|
||||
when {
|
||||
function.getTypeReference().isAncestor(refExpr) ->
|
||||
@@ -79,40 +79,40 @@ public object UsageTypeUtils {
|
||||
}
|
||||
|
||||
return when {
|
||||
refExpr.getParentOfTypeAndBranch<JetTypeParameter>(){ getExtendsBound() } != null
|
||||
|| refExpr.getParentOfTypeAndBranch<JetTypeConstraint>(){ getBoundTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<KtTypeParameter>(){ getExtendsBound() } != null
|
||||
|| refExpr.getParentOfTypeAndBranch<KtTypeConstraint>(){ getBoundTypeReference() } != null ->
|
||||
TYPE_CONSTRAINT
|
||||
|
||||
refExpr is JetDelegationSpecifier
|
||||
|| refExpr.getParentOfTypeAndBranch<JetDelegationSpecifier>(){ getTypeReference() } != null ->
|
||||
refExpr is KtDelegationSpecifier
|
||||
|| refExpr.getParentOfTypeAndBranch<KtDelegationSpecifier>(){ getTypeReference() } != null ->
|
||||
SUPER_TYPE
|
||||
|
||||
refExpr.getParentOfTypeAndBranch<JetTypedef>(){ getTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<KtTypedef>(){ getTypeReference() } != null ->
|
||||
TYPE_DEFINITION
|
||||
|
||||
refExpr.getParentOfTypeAndBranch<JetParameter>(){ getTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<KtParameter>(){ getTypeReference() } != null ->
|
||||
VALUE_PARAMETER_TYPE
|
||||
|
||||
refExpr.getParentOfTypeAndBranch<JetIsExpression>(){ getTypeReference() } != null
|
||||
|| refExpr.getParentOfTypeAndBranch<JetWhenConditionIsPattern>(){ getTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<KtIsExpression>(){ getTypeReference() } != null
|
||||
|| refExpr.getParentOfTypeAndBranch<KtWhenConditionIsPattern>(){ getTypeReference() } != null ->
|
||||
IS
|
||||
|
||||
with(refExpr.getParentOfTypeAndBranch<JetBinaryExpressionWithTypeRHS>(){ getRight() }) {
|
||||
with(refExpr.getParentOfTypeAndBranch<KtBinaryExpressionWithTypeRHS>(){ getRight() }) {
|
||||
val opType = this?.getOperationReference()?.getReferencedNameElementType()
|
||||
opType == JetTokens.AS_KEYWORD || opType == JetTokens.AS_SAFE
|
||||
opType == KtTokens.AS_KEYWORD || opType == KtTokens.AS_SAFE
|
||||
} ->
|
||||
CLASS_CAST_TO
|
||||
|
||||
with(refExpr.getNonStrictParentOfType<JetDotQualifiedExpression>()) {
|
||||
with(refExpr.getNonStrictParentOfType<KtDotQualifiedExpression>()) {
|
||||
if (this == null) false
|
||||
else if (getReceiverExpression() == refExpr) true
|
||||
else
|
||||
getSelectorExpression() == refExpr
|
||||
&& getParentOfTypeAndBranch<JetDotQualifiedExpression>(strict = true) { getReceiverExpression() } != null
|
||||
&& getParentOfTypeAndBranch<KtDotQualifiedExpression>(strict = true) { getReceiverExpression() } != null
|
||||
} ->
|
||||
CLASS_OBJECT_ACCESS
|
||||
|
||||
refExpr.getParentOfTypeAndBranch<JetSuperExpression>(){ getSuperTypeQualifier() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<KtSuperExpression>(){ getSuperTypeQualifier() } != null ->
|
||||
SUPER_TYPE_QUALIFIER
|
||||
|
||||
else -> null
|
||||
@@ -120,13 +120,13 @@ public object UsageTypeUtils {
|
||||
}
|
||||
|
||||
fun getVariableUsageType(): UsageTypeEnum? {
|
||||
if (refExpr.getParentOfTypeAndBranch<JetDelegatorByExpressionSpecifier>(){ getDelegateExpression() } != null) {
|
||||
if (refExpr.getParentOfTypeAndBranch<KtDelegatorByExpressionSpecifier>(){ getDelegateExpression() } != null) {
|
||||
return DELEGATE
|
||||
}
|
||||
|
||||
if (refExpr.getParent() is JetValueArgumentName) return NAMED_ARGUMENT
|
||||
if (refExpr.getParent() is KtValueArgumentName) return NAMED_ARGUMENT
|
||||
|
||||
val dotQualifiedExpression = refExpr.getNonStrictParentOfType<JetDotQualifiedExpression>()
|
||||
val dotQualifiedExpression = refExpr.getNonStrictParentOfType<KtDotQualifiedExpression>()
|
||||
|
||||
if (dotQualifiedExpression != null) {
|
||||
val parent = dotQualifiedExpression.getParent()
|
||||
@@ -134,7 +134,7 @@ public object UsageTypeUtils {
|
||||
dotQualifiedExpression.getReceiverExpression().isAncestor(refExpr) ->
|
||||
return RECEIVER
|
||||
|
||||
parent is JetDotQualifiedExpression && parent.getReceiverExpression().isAncestor(refExpr) ->
|
||||
parent is KtDotQualifiedExpression && parent.getReceiverExpression().isAncestor(refExpr) ->
|
||||
return RECEIVER
|
||||
}
|
||||
}
|
||||
@@ -147,32 +147,32 @@ public object UsageTypeUtils {
|
||||
|
||||
fun getFunctionUsageType(descriptor: FunctionDescriptor): UsageTypeEnum? {
|
||||
when (refExpr.mainReference) {
|
||||
is JetArrayAccessReference -> {
|
||||
is KtArrayAccessReference -> {
|
||||
return when {
|
||||
context[BindingContext.INDEXED_LVALUE_GET, refExpr] != null -> IMPLICIT_GET
|
||||
context[BindingContext.INDEXED_LVALUE_SET, refExpr] != null -> IMPLICIT_SET
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
is JetInvokeFunctionReference -> return IMPLICIT_INVOKE
|
||||
is KtInvokeFunctionReference -> return IMPLICIT_INVOKE
|
||||
}
|
||||
|
||||
return when {
|
||||
refExpr.getParentOfTypeAndBranch<JetDelegationSpecifier>(){ getTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<KtDelegationSpecifier>(){ getTypeReference() } != null ->
|
||||
SUPER_TYPE
|
||||
|
||||
descriptor is ConstructorDescriptor
|
||||
&& refExpr.getParentOfTypeAndBranch<JetAnnotationEntry>(){ getTypeReference() } != null ->
|
||||
&& refExpr.getParentOfTypeAndBranch<KtAnnotationEntry>(){ getTypeReference() } != null ->
|
||||
ANNOTATION
|
||||
|
||||
with(refExpr.getParentOfTypeAndBranch<JetCallExpression>(){ getCalleeExpression() }) {
|
||||
this?.getCalleeExpression() is JetSimpleNameExpression
|
||||
with(refExpr.getParentOfTypeAndBranch<KtCallExpression>(){ getCalleeExpression() }) {
|
||||
this?.getCalleeExpression() is KtSimpleNameExpression
|
||||
} ->
|
||||
if (descriptor is ConstructorDescriptor) CLASS_NEW_OPERATOR else FUNCTION_CALL
|
||||
|
||||
refExpr.getParentOfTypeAndBranch<JetBinaryExpression>(){ getOperationReference() } != null,
|
||||
refExpr.getParentOfTypeAndBranch<JetUnaryExpression>(){ getOperationReference() } != null,
|
||||
refExpr.getParentOfTypeAndBranch<JetWhenConditionInRange>(){ getOperationReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<KtBinaryExpression>(){ getOperationReference() } != null,
|
||||
refExpr.getParentOfTypeAndBranch<KtUnaryExpression>(){ getOperationReference() } != null,
|
||||
refExpr.getParentOfTypeAndBranch<KtWhenConditionInRange>(){ getOperationReference() } != null ->
|
||||
FUNCTION_CALL
|
||||
|
||||
else -> null
|
||||
@@ -181,8 +181,8 @@ public object UsageTypeUtils {
|
||||
|
||||
fun getPackageUsageType(): UsageTypeEnum? {
|
||||
return when {
|
||||
refExpr.getNonStrictParentOfType<JetPackageDirective>() != null -> PACKAGE_DIRECTIVE
|
||||
refExpr.getNonStrictParentOfType<JetQualifiedExpression>() != null -> PACKAGE_MEMBER_ACCESS
|
||||
refExpr.getNonStrictParentOfType<KtPackageDirective>() != null -> PACKAGE_DIRECTIVE
|
||||
refExpr.getNonStrictParentOfType<KtQualifiedExpression>() != null -> PACKAGE_MEMBER_ACCESS
|
||||
else -> getClassUsageType()
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -25,9 +25,9 @@ import org.jetbrains.kotlin.checkers.DebugInfoUtil;
|
||||
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils;
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||
import org.jetbrains.kotlin.psi.JetCodeFragment;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression;
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
|
||||
/**
|
||||
@@ -45,26 +45,26 @@ public class DebugInfoAnnotator implements Annotator {
|
||||
return;
|
||||
}
|
||||
|
||||
if (element instanceof JetFile && !(element instanceof JetCodeFragment)) {
|
||||
JetFile file = (JetFile) element;
|
||||
if (element instanceof KtFile && !(element instanceof KtCodeFragment)) {
|
||||
KtFile file = (KtFile) element;
|
||||
try {
|
||||
BindingContext bindingContext = ResolutionUtils.analyzeFully(file);
|
||||
DebugInfoUtil.markDebugAnnotations(file, bindingContext, new DebugInfoUtil.DebugInfoReporter() {
|
||||
@Override
|
||||
public void reportElementWithErrorType(@NotNull JetReferenceExpression expression) {
|
||||
public void reportElementWithErrorType(@NotNull KtReferenceExpression expression) {
|
||||
holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element")
|
||||
.setTextAttributes(JetHighlightingColors.RESOLVED_TO_ERROR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportMissingUnresolved(@NotNull JetReferenceExpression expression) {
|
||||
public void reportMissingUnresolved(@NotNull KtReferenceExpression expression) {
|
||||
holder.createErrorAnnotation(expression,
|
||||
"[DEBUG] Reference is not resolved to anything, but is not marked unresolved")
|
||||
.setTextAttributes(JetHighlightingColors.DEBUG_INFO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportUnresolvedWithTarget(@NotNull JetReferenceExpression expression, @NotNull String target) {
|
||||
public void reportUnresolvedWithTarget(@NotNull KtReferenceExpression expression, @NotNull String target) {
|
||||
holder.createErrorAnnotation(expression, "[DEBUG] Reference marked as unresolved is actually resolved to " + target)
|
||||
.setTextAttributes(JetHighlightingColors.DEBUG_INFO);
|
||||
}
|
||||
|
||||
+6
-6
@@ -27,22 +27,22 @@ import org.jetbrains.kotlin.idea.caches.resolve.GetModuleInfoKt;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils;
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector;
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||
import org.jetbrains.kotlin.psi.JetElement;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration;
|
||||
import org.jetbrains.kotlin.psi.KtElement;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||
|
||||
public class DuplicateJvmSignatureAnnotator implements Annotator {
|
||||
@Override
|
||||
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
|
||||
if (!(element instanceof JetFile) && !(element instanceof JetDeclaration)) return;
|
||||
if (!(element instanceof KtFile) && !(element instanceof KtDeclaration)) return;
|
||||
if (!ProjectRootsUtil.isInProjectSource(element)) return;
|
||||
|
||||
PsiFile file = element.getContainingFile();
|
||||
if (!(file instanceof JetFile) || TargetPlatformDetector.getPlatform((JetFile) file) != JvmPlatform.INSTANCE$) return;
|
||||
if (!(file instanceof KtFile) || TargetPlatformDetector.getPlatform((KtFile) file) != JvmPlatform.INSTANCE$) return;
|
||||
|
||||
Diagnostics otherDiagnostics = ResolutionUtils.analyzeFully((JetElement) element).getDiagnostics();
|
||||
Diagnostics otherDiagnostics = ResolutionUtils.analyzeFully((KtElement) element).getDiagnostics();
|
||||
GlobalSearchScope moduleScope = GetModuleInfoKt.getModuleInfo(element).contentScope();
|
||||
Diagnostics diagnostics = DuplicateJvmSignatureUtilKt.getJvmSignatureDiagnostics(element, otherDiagnostics, moduleScope);
|
||||
|
||||
|
||||
+13
-13
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
|
||||
public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
@@ -37,7 +37,7 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitNamedFunction(@NotNull JetNamedFunction function) {
|
||||
public void visitNamedFunction(@NotNull KtNamedFunction function) {
|
||||
PsiElement nameIdentifier = function.getNameIdentifier();
|
||||
if (nameIdentifier != null) {
|
||||
NameHighlighter.highlightName(holder, nameIdentifier, JetHighlightingColors.FUNCTION_DECLARATION);
|
||||
@@ -47,13 +47,13 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDelegationToSuperCallSpecifier(@NotNull JetDelegatorToSuperCall call) {
|
||||
JetConstructorCalleeExpression calleeExpression = call.getCalleeExpression();
|
||||
JetTypeReference typeRef = calleeExpression.getTypeReference();
|
||||
public void visitDelegationToSuperCallSpecifier(@NotNull KtDelegatorToSuperCall call) {
|
||||
KtConstructorCalleeExpression calleeExpression = call.getCalleeExpression();
|
||||
KtTypeReference typeRef = calleeExpression.getTypeReference();
|
||||
if (typeRef != null) {
|
||||
JetTypeElement typeElement = typeRef.getTypeElement();
|
||||
if (typeElement instanceof JetUserType) {
|
||||
JetSimpleNameExpression nameExpression = ((JetUserType)typeElement).getReferenceExpression();
|
||||
KtTypeElement typeElement = typeRef.getTypeElement();
|
||||
if (typeElement instanceof KtUserType) {
|
||||
KtSimpleNameExpression nameExpression = ((KtUserType)typeElement).getReferenceExpression();
|
||||
if (nameExpression != null) {
|
||||
NameHighlighter.highlightName(holder, nameExpression, JetHighlightingColors.CONSTRUCTOR_CALL);
|
||||
}
|
||||
@@ -63,10 +63,10 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCallExpression(@NotNull JetCallExpression expression) {
|
||||
JetExpression callee = expression.getCalleeExpression();
|
||||
public void visitCallExpression(@NotNull KtCallExpression expression) {
|
||||
KtExpression callee = expression.getCalleeExpression();
|
||||
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expression, bindingContext);
|
||||
if (callee instanceof JetReferenceExpression && resolvedCall != null) {
|
||||
if (callee instanceof KtReferenceExpression && resolvedCall != null) {
|
||||
CallableDescriptor calleeDescriptor = resolvedCall.getResultingDescriptor();
|
||||
|
||||
if (DynamicCallsKt.isDynamic(calleeDescriptor)) {
|
||||
@@ -103,13 +103,13 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
|
||||
return false;
|
||||
}
|
||||
|
||||
JetType defaultType = ((ClassDescriptor) parent).getDefaultType();
|
||||
KtType defaultType = ((ClassDescriptor) parent).getDefaultType();
|
||||
|
||||
if (KotlinBuiltIns.isFunctionOrExtensionFunctionType(defaultType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (JetType supertype : TypeUtils.getAllSupertypes(defaultType)) {
|
||||
for (KtType supertype : TypeUtils.getAllSupertypes(defaultType)) {
|
||||
if (KotlinBuiltIns.isFunctionOrExtensionFunctionType(supertype)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@
|
||||
package org.jetbrains.kotlin.idea.highlighter;
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import org.jetbrains.kotlin.psi.JetVisitorVoid;
|
||||
import org.jetbrains.kotlin.psi.KtVisitorVoid;
|
||||
|
||||
public abstract class HighlightingVisitor extends JetVisitorVoid {
|
||||
public abstract class HighlightingVisitor extends KtVisitorVoid {
|
||||
protected AnnotationHolder holder;
|
||||
|
||||
protected HighlightingVisitor(AnnotationHolder holder) {
|
||||
|
||||
+6
-6
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.Table
|
||||
import org.jetbrains.kotlin.idea.highlighter.renderersUtil.RenderersUtilKt;
|
||||
import org.jetbrains.kotlin.renderer.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPosition;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -43,7 +43,7 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Renderer<JetType> getTypeRenderer() {
|
||||
public Renderer<KtType> getTypeRenderer() {
|
||||
return IdeRenderers.HTML_RENDER_TYPE;
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
|
||||
}
|
||||
|
||||
private void renderFunctionArguments(
|
||||
@Nullable JetType receiverType,
|
||||
@NotNull List<JetType> argumentTypes,
|
||||
@Nullable KtType receiverType,
|
||||
@NotNull List<KtType> argumentTypes,
|
||||
Predicate<ConstraintPosition> isErrorPosition,
|
||||
StringBuilder result
|
||||
) {
|
||||
@@ -141,8 +141,8 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
|
||||
|
||||
td(result, RenderersUtilKt.renderStrong("("));
|
||||
int i = 0;
|
||||
for (Iterator<JetType> iterator = argumentTypes.iterator(); iterator.hasNext(); ) {
|
||||
JetType argumentType = iterator.next();
|
||||
for (Iterator<KtType> iterator = argumentTypes.iterator(); iterator.hasNext(); ) {
|
||||
KtType argumentType = iterator.next();
|
||||
boolean error = false;
|
||||
if (isErrorPosition.apply(VALUE_PARAMETER_POSITION.position(i))) {
|
||||
error = true;
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.InferenceErrorData
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ConflictingJvmDeclarationsData
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
|
||||
public object IdeRenderers {
|
||||
public val HTML_AMBIGUOUS_CALLS: Renderer<Collection<ResolvedCall<*>>> = Renderer {
|
||||
@@ -36,7 +36,7 @@ public object IdeRenderers {
|
||||
.joinToString("") { "<li>" + DescriptorRenderer.HTML.render(it) + "</li>" }
|
||||
}
|
||||
|
||||
public val HTML_RENDER_TYPE: Renderer<JetType> = Renderer {
|
||||
public val HTML_RENDER_TYPE: Renderer<KtType> = Renderer {
|
||||
DescriptorRenderer.HTML.renderType(it)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -49,45 +49,45 @@ public class JetHighlighter extends SyntaxHighlighterBase {
|
||||
keys1 = new HashMap<IElementType, TextAttributesKey>();
|
||||
keys2 = new HashMap<IElementType, TextAttributesKey>();
|
||||
|
||||
fillMap(keys1, JetTokens.KEYWORDS, JetHighlightingColors.KEYWORD);
|
||||
fillMap(keys1, KtTokens.KEYWORDS, JetHighlightingColors.KEYWORD);
|
||||
|
||||
keys1.put(JetTokens.AS_SAFE, JetHighlightingColors.KEYWORD);
|
||||
keys1.put(JetTokens.INTEGER_LITERAL, JetHighlightingColors.NUMBER);
|
||||
keys1.put(JetTokens.FLOAT_LITERAL, JetHighlightingColors.NUMBER);
|
||||
keys1.put(KtTokens.AS_SAFE, JetHighlightingColors.KEYWORD);
|
||||
keys1.put(KtTokens.INTEGER_LITERAL, JetHighlightingColors.NUMBER);
|
||||
keys1.put(KtTokens.FLOAT_LITERAL, JetHighlightingColors.NUMBER);
|
||||
|
||||
fillMap(keys1,
|
||||
TokenSet.andNot(JetTokens.OPERATIONS,
|
||||
TokenSet.andNot(KtTokens.OPERATIONS,
|
||||
TokenSet.orSet(
|
||||
TokenSet.create(JetTokens.IDENTIFIER, JetTokens.AT),
|
||||
JetTokens.KEYWORDS)),
|
||||
TokenSet.create(KtTokens.IDENTIFIER, KtTokens.AT),
|
||||
KtTokens.KEYWORDS)),
|
||||
JetHighlightingColors.OPERATOR_SIGN);
|
||||
|
||||
keys1.put(JetTokens.LPAR, JetHighlightingColors.PARENTHESIS);
|
||||
keys1.put(JetTokens.RPAR, JetHighlightingColors.PARENTHESIS);
|
||||
keys1.put(JetTokens.LBRACE, JetHighlightingColors.BRACES);
|
||||
keys1.put(JetTokens.RBRACE, JetHighlightingColors.BRACES);
|
||||
keys1.put(JetTokens.LBRACKET, JetHighlightingColors.BRACKETS);
|
||||
keys1.put(JetTokens.RBRACKET, JetHighlightingColors.BRACKETS);
|
||||
keys1.put(JetTokens.COMMA, JetHighlightingColors.COMMA);
|
||||
keys1.put(JetTokens.SEMICOLON, JetHighlightingColors.SEMICOLON);
|
||||
keys1.put(JetTokens.DOT, JetHighlightingColors.DOT);
|
||||
keys1.put(JetTokens.ARROW, JetHighlightingColors.ARROW);
|
||||
keys1.put(KtTokens.LPAR, JetHighlightingColors.PARENTHESIS);
|
||||
keys1.put(KtTokens.RPAR, JetHighlightingColors.PARENTHESIS);
|
||||
keys1.put(KtTokens.LBRACE, JetHighlightingColors.BRACES);
|
||||
keys1.put(KtTokens.RBRACE, JetHighlightingColors.BRACES);
|
||||
keys1.put(KtTokens.LBRACKET, JetHighlightingColors.BRACKETS);
|
||||
keys1.put(KtTokens.RBRACKET, JetHighlightingColors.BRACKETS);
|
||||
keys1.put(KtTokens.COMMA, JetHighlightingColors.COMMA);
|
||||
keys1.put(KtTokens.SEMICOLON, JetHighlightingColors.SEMICOLON);
|
||||
keys1.put(KtTokens.DOT, JetHighlightingColors.DOT);
|
||||
keys1.put(KtTokens.ARROW, JetHighlightingColors.ARROW);
|
||||
|
||||
keys1.put(JetTokens.OPEN_QUOTE, JetHighlightingColors.STRING);
|
||||
keys1.put(JetTokens.CLOSING_QUOTE, JetHighlightingColors.STRING);
|
||||
keys1.put(JetTokens.REGULAR_STRING_PART, JetHighlightingColors.STRING);
|
||||
keys1.put(JetTokens.LONG_TEMPLATE_ENTRY_END, JetHighlightingColors.STRING_ESCAPE);
|
||||
keys1.put(JetTokens.LONG_TEMPLATE_ENTRY_START, JetHighlightingColors.STRING_ESCAPE);
|
||||
keys1.put(JetTokens.SHORT_TEMPLATE_ENTRY_START, JetHighlightingColors.STRING_ESCAPE);
|
||||
keys1.put(KtTokens.OPEN_QUOTE, JetHighlightingColors.STRING);
|
||||
keys1.put(KtTokens.CLOSING_QUOTE, JetHighlightingColors.STRING);
|
||||
keys1.put(KtTokens.REGULAR_STRING_PART, JetHighlightingColors.STRING);
|
||||
keys1.put(KtTokens.LONG_TEMPLATE_ENTRY_END, JetHighlightingColors.STRING_ESCAPE);
|
||||
keys1.put(KtTokens.LONG_TEMPLATE_ENTRY_START, JetHighlightingColors.STRING_ESCAPE);
|
||||
keys1.put(KtTokens.SHORT_TEMPLATE_ENTRY_START, JetHighlightingColors.STRING_ESCAPE);
|
||||
|
||||
keys1.put(JetTokens.ESCAPE_SEQUENCE, JetHighlightingColors.STRING_ESCAPE);
|
||||
keys1.put(KtTokens.ESCAPE_SEQUENCE, JetHighlightingColors.STRING_ESCAPE);
|
||||
|
||||
keys1.put(JetTokens.CHARACTER_LITERAL, JetHighlightingColors.STRING);
|
||||
keys1.put(KtTokens.CHARACTER_LITERAL, JetHighlightingColors.STRING);
|
||||
|
||||
keys1.put(JetTokens.EOL_COMMENT, JetHighlightingColors.LINE_COMMENT);
|
||||
keys1.put(JetTokens.SHEBANG_COMMENT, JetHighlightingColors.LINE_COMMENT);
|
||||
keys1.put(JetTokens.BLOCK_COMMENT, JetHighlightingColors.BLOCK_COMMENT);
|
||||
keys1.put(JetTokens.DOC_COMMENT, JetHighlightingColors.DOC_COMMENT);
|
||||
keys1.put(KtTokens.EOL_COMMENT, JetHighlightingColors.LINE_COMMENT);
|
||||
keys1.put(KtTokens.SHEBANG_COMMENT, JetHighlightingColors.LINE_COMMENT);
|
||||
keys1.put(KtTokens.BLOCK_COMMENT, JetHighlightingColors.BLOCK_COMMENT);
|
||||
keys1.put(KtTokens.DOC_COMMENT, JetHighlightingColors.DOC_COMMENT);
|
||||
|
||||
fillMap(keys1, KDocTokens.KDOC_HIGHLIGHT_TOKENS, JetHighlightingColors.DOC_COMMENT);
|
||||
keys1.put(KDocTokens.TAG_NAME, JetHighlightingColors.KDOC_TAG);
|
||||
|
||||
+4
-4
@@ -19,13 +19,13 @@ package org.jetbrains.kotlin.idea.highlighter;
|
||||
import com.intellij.lexer.LayeredLexer;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocLexer;
|
||||
import org.jetbrains.kotlin.lexer.JetLexer;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KotlinLexer;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
|
||||
public class JetHighlightingLexer extends LayeredLexer {
|
||||
public JetHighlightingLexer() {
|
||||
super(new JetLexer());
|
||||
super(new KotlinLexer());
|
||||
|
||||
registerSelfStoppingLayer(new KDocLexer(), new IElementType[]{JetTokens.DOC_COMMENT}, IElementType.EMPTY_ARRAY);
|
||||
registerSelfStoppingLayer(new KDocLexer(), new IElementType[]{KtTokens.DOC_COMMENT}, IElementType.EMPTY_ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,10 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
|
||||
import org.jetbrains.kotlin.idea.quickfix.QuickFixes
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.psi.JetCodeFragment
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||
import java.lang.reflect.*
|
||||
@@ -55,9 +55,9 @@ import java.util.*
|
||||
public open class JetPsiChecker : Annotator, HighlightRangeExtension {
|
||||
|
||||
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
|
||||
if (!(ProjectRootsUtil.isInProjectOrLibraryContent(element) || element.getContainingFile() is JetCodeFragment)) return
|
||||
if (!(ProjectRootsUtil.isInProjectOrLibraryContent(element) || element.getContainingFile() is KtCodeFragment)) return
|
||||
|
||||
val file = element.getContainingFile() as JetFile
|
||||
val file = element.getContainingFile() as KtFile
|
||||
|
||||
val analysisResult = file.analyzeFullyAndGetResult()
|
||||
if (analysisResult.isError()) {
|
||||
@@ -72,13 +72,13 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
|
||||
}
|
||||
|
||||
override fun isForceHighlightParents(file: PsiFile): Boolean {
|
||||
return file is JetFile
|
||||
return file is KtFile
|
||||
}
|
||||
|
||||
open protected fun shouldSuppressUnusedParameter(parameter: JetParameter): Boolean = false
|
||||
open protected fun shouldSuppressUnusedParameter(parameter: KtParameter): Boolean = false
|
||||
|
||||
fun annotateElement(element: PsiElement, holder: AnnotationHolder, diagnostics: Diagnostics) {
|
||||
if (ProjectRootsUtil.isInProjectSource(element) || element.getContainingFile() is JetCodeFragment) {
|
||||
if (ProjectRootsUtil.isInProjectSource(element) || element.getContainingFile() is KtCodeFragment) {
|
||||
val elementAnnotator = ElementAnnotator(element, holder)
|
||||
for (diagnostic in diagnostics.forElement(element)) {
|
||||
elementAnnotator.registerDiagnosticAnnotations(diagnostic)
|
||||
@@ -100,7 +100,7 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
|
||||
Severity.ERROR -> {
|
||||
when (factory) {
|
||||
in Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS -> {
|
||||
val referenceExpression = element as JetReferenceExpression
|
||||
val referenceExpression = element as KtReferenceExpression
|
||||
val reference = referenceExpression.mainReference
|
||||
if (reference is MultiRangeReference) {
|
||||
AnnotationPresentationInfo(diagnostic,
|
||||
@@ -127,7 +127,7 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
|
||||
}
|
||||
}
|
||||
Severity.WARNING -> {
|
||||
if (factory == Errors.UNUSED_PARAMETER && shouldSuppressUnusedParameter(element as JetParameter)) {
|
||||
if (factory == Errors.UNUSED_PARAMETER && shouldSuppressUnusedParameter(element as KtParameter)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -34,10 +34,10 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiRecursiveElementVisitor
|
||||
import org.jetbrains.kotlin.idea.kdoc.KDocHighlightingVisitor
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
public class KotlinBeforeResolveHighlightingPass(
|
||||
private val file: JetFile,
|
||||
private val file: KtFile,
|
||||
document: Document
|
||||
) : TextEditorHighlightingPass(file.project, document), DumbAware {
|
||||
|
||||
@@ -74,7 +74,7 @@ public class KotlinBeforeResolveHighlightingPass(
|
||||
}
|
||||
|
||||
override fun createHighlightingPass(file: PsiFile, editor: Editor): TextEditorHighlightingPass? {
|
||||
if (file !is JetFile) return null
|
||||
if (file !is KtFile) return null
|
||||
return KotlinBeforeResolveHighlightingPass(file, editor.document)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,13 +18,13 @@ package org.jetbrains.kotlin.idea.highlighter
|
||||
|
||||
import com.intellij.codeInsight.daemon.ProblemHighlightFilter
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.idea.JetFileType
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import com.intellij.ide.projectView.impl.ProjectRootsUtil
|
||||
|
||||
class KotlinProblemHighlightFilter : ProblemHighlightFilter() {
|
||||
|
||||
override fun shouldHighlight(psiFile: PsiFile): Boolean {
|
||||
return psiFile.getFileType() != JetFileType.INSTANCE || !ProjectRootsUtil.isOutsideSourceRoot(psiFile)
|
||||
return psiFile.getFileType() != KotlinFileType.INSTANCE || !ProjectRootsUtil.isOutsideSourceRoot(psiFile)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+18
-18
@@ -54,7 +54,7 @@ fun createSuppressWarningActions(element: PsiElement, diagnosticFactory: Diagnos
|
||||
var current: PsiElement? = element
|
||||
var suppressAtStatementAllowed = true
|
||||
while (current != null) {
|
||||
if (current is JetDeclaration && current !is JetMultiDeclaration) {
|
||||
if (current is KtDeclaration && current !is KtMultiDeclaration) {
|
||||
val declaration = current
|
||||
val kind = DeclarationKindDetector.detect(declaration)
|
||||
if (kind != null) {
|
||||
@@ -62,10 +62,10 @@ fun createSuppressWarningActions(element: PsiElement, diagnosticFactory: Diagnos
|
||||
}
|
||||
suppressAtStatementAllowed = false
|
||||
}
|
||||
else if (current is JetExpression && suppressAtStatementAllowed) {
|
||||
else if (current is KtExpression && suppressAtStatementAllowed) {
|
||||
// Add suppress action at first statement
|
||||
if (current.parent is JetBlockExpression || current.parent is JetMultiDeclaration) {
|
||||
val kind = if (current.parent is JetBlockExpression) "statement" else "initializer"
|
||||
if (current.parent is KtBlockExpression || current.parent is KtMultiDeclaration) {
|
||||
val kind = if (current.parent is KtBlockExpression) "statement" else "initializer"
|
||||
actions.add(KotlinSuppressIntentionAction(current, diagnosticFactory,
|
||||
AnnotationHostKind(kind, "", true)))
|
||||
suppressAtStatementAllowed = false
|
||||
@@ -77,33 +77,33 @@ fun createSuppressWarningActions(element: PsiElement, diagnosticFactory: Diagnos
|
||||
return actions
|
||||
}
|
||||
|
||||
private object DeclarationKindDetector : JetVisitor<AnnotationHostKind?, Unit?>() {
|
||||
private object DeclarationKindDetector : KtVisitor<AnnotationHostKind?, Unit?>() {
|
||||
|
||||
fun detect(declaration: JetDeclaration) = declaration.accept(this, null)
|
||||
fun detect(declaration: KtDeclaration) = declaration.accept(this, null)
|
||||
|
||||
override fun visitDeclaration(d: JetDeclaration, data: Unit?) = null
|
||||
override fun visitDeclaration(d: KtDeclaration, data: Unit?) = null
|
||||
|
||||
override fun visitClass(d: JetClass, data: Unit?) = detect(d, if (d.isInterface()) "interface" else "class")
|
||||
override fun visitClass(d: KtClass, data: Unit?) = detect(d, if (d.isInterface()) "interface" else "class")
|
||||
|
||||
override fun visitNamedFunction(d: JetNamedFunction, data: Unit?) = detect(d, "fun")
|
||||
override fun visitNamedFunction(d: KtNamedFunction, data: Unit?) = detect(d, "fun")
|
||||
|
||||
override fun visitProperty(d: JetProperty, data: Unit?) = detect(d, d.getValOrVarKeyword().getText()!!)
|
||||
override fun visitProperty(d: KtProperty, data: Unit?) = detect(d, d.getValOrVarKeyword().getText()!!)
|
||||
|
||||
override fun visitMultiDeclaration(d: JetMultiDeclaration, data: Unit?) = detect(d, d.getValOrVarKeyword()?.getText() ?: "val",
|
||||
override fun visitMultiDeclaration(d: KtMultiDeclaration, data: Unit?) = detect(d, d.getValOrVarKeyword()?.getText() ?: "val",
|
||||
name = d.getEntries().map { it.getName()!! }.join(", ", "(", ")"))
|
||||
|
||||
override fun visitTypeParameter(d: JetTypeParameter, data: Unit?) = detect(d, "type parameter", newLineNeeded = false)
|
||||
override fun visitTypeParameter(d: KtTypeParameter, data: Unit?) = detect(d, "type parameter", newLineNeeded = false)
|
||||
|
||||
override fun visitEnumEntry(d: JetEnumEntry, data: Unit?) = detect(d, "enum entry")
|
||||
override fun visitEnumEntry(d: KtEnumEntry, data: Unit?) = detect(d, "enum entry")
|
||||
|
||||
override fun visitParameter(d: JetParameter, data: Unit?) = detect(d, "parameter", newLineNeeded = false)
|
||||
override fun visitParameter(d: KtParameter, data: Unit?) = detect(d, "parameter", newLineNeeded = false)
|
||||
|
||||
override fun visitObjectDeclaration(d: JetObjectDeclaration, data: Unit?): AnnotationHostKind? {
|
||||
if (d.isCompanion()) return detect(d, "companion object", name = "${d.getName()} of ${d.getStrictParentOfType<JetClass>()?.getName()}")
|
||||
if (d.getParent() is JetObjectLiteralExpression) return null
|
||||
override fun visitObjectDeclaration(d: KtObjectDeclaration, data: Unit?): AnnotationHostKind? {
|
||||
if (d.isCompanion()) return detect(d, "companion object", name = "${d.getName()} of ${d.getStrictParentOfType<KtClass>()?.getName()}")
|
||||
if (d.getParent() is KtObjectLiteralExpression) return null
|
||||
return detect(d, "object")
|
||||
}
|
||||
|
||||
private fun detect(declaration: JetDeclaration, kind: String, name: String = declaration.getName() ?: "<anonymous>", newLineNeeded: Boolean = true)
|
||||
private fun detect(declaration: KtDeclaration, kind: String, name: String = declaration.getName() ?: "<anonymous>", newLineNeeded: Boolean = true)
|
||||
= AnnotationHostKind(kind, name, newLineNeeded)
|
||||
}
|
||||
|
||||
+6
-6
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.idea.highlighter;
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.psi.JetExpressionWithLabel;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.JetVisitorVoid;
|
||||
import org.jetbrains.kotlin.psi.KtExpressionWithLabel;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtVisitorVoid;
|
||||
|
||||
class LabelsHighlightingVisitor extends JetVisitorVoid {
|
||||
class LabelsHighlightingVisitor extends KtVisitorVoid {
|
||||
private final AnnotationHolder holder;
|
||||
|
||||
LabelsHighlightingVisitor(AnnotationHolder holder) {
|
||||
@@ -30,8 +30,8 @@ class LabelsHighlightingVisitor extends JetVisitorVoid {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpressionWithLabel(@NotNull JetExpressionWithLabel expression) {
|
||||
JetSimpleNameExpression targetLabel = expression.getTargetLabel();
|
||||
public void visitExpressionWithLabel(@NotNull KtExpressionWithLabel expression) {
|
||||
KtSimpleNameExpression targetLabel = expression.getTargetLabel();
|
||||
if (targetLabel != null) {
|
||||
NameHighlighter.highlightName(holder, targetLabel, JetHighlightingColors.LABEL);
|
||||
}
|
||||
|
||||
+10
-10
@@ -23,11 +23,11 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.JetParameter;
|
||||
import org.jetbrains.kotlin.psi.JetProperty;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.JetThisExpression;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.KtParameter;
|
||||
import org.jetbrains.kotlin.psi.KtProperty;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtThisExpression;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
@@ -38,8 +38,8 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) {
|
||||
if (expression.getParent() instanceof JetThisExpression) {
|
||||
public void visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression) {
|
||||
if (expression.getParent() instanceof KtThisExpression) {
|
||||
return;
|
||||
}
|
||||
DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||
@@ -52,13 +52,13 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
highlightProperty(expression, (PropertyDescriptor) target, false);
|
||||
if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
||||
if (expression.getReferencedNameElementType() == KtTokens.FIELD_IDENTIFIER) {
|
||||
NameHighlighter.highlightName(holder, expression, JetHighlightingColors.BACKING_FIELD_ACCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitProperty(@NotNull JetProperty property) {
|
||||
public void visitProperty(@NotNull KtProperty property) {
|
||||
PsiElement nameIdentifier = property.getNameIdentifier();
|
||||
if (nameIdentifier == null) return;
|
||||
VariableDescriptor propertyDescriptor = bindingContext.get(BindingContext.VARIABLE, property);
|
||||
@@ -71,7 +71,7 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitParameter(@NotNull JetParameter parameter) {
|
||||
public void visitParameter(@NotNull KtParameter parameter) {
|
||||
PsiElement nameIdentifier = parameter.getNameIdentifier();
|
||||
if (nameIdentifier == null) return;
|
||||
PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
|
||||
|
||||
+10
-10
@@ -23,12 +23,12 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteral;
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression;
|
||||
import org.jetbrains.kotlin.psi.JetVisitorVoid;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.KtFunctionLiteral;
|
||||
import org.jetbrains.kotlin.psi.KtFunctionLiteralExpression;
|
||||
import org.jetbrains.kotlin.psi.KtVisitorVoid;
|
||||
|
||||
class SoftKeywordsHighlightingVisitor extends JetVisitorVoid {
|
||||
class SoftKeywordsHighlightingVisitor extends KtVisitorVoid {
|
||||
private final AnnotationHolder holder;
|
||||
|
||||
SoftKeywordsHighlightingVisitor(AnnotationHolder holder) {
|
||||
@@ -39,23 +39,23 @@ class SoftKeywordsHighlightingVisitor extends JetVisitorVoid {
|
||||
public void visitElement(PsiElement element) {
|
||||
if (element instanceof LeafPsiElement) {
|
||||
IElementType elementType = ((LeafPsiElement)element).getElementType();
|
||||
if (JetTokens.SOFT_KEYWORDS.contains(elementType)) {
|
||||
if (KtTokens.SOFT_KEYWORDS.contains(elementType)) {
|
||||
TextAttributesKey attributes = JetHighlightingColors.KEYWORD;
|
||||
if (JetTokens.MODIFIER_KEYWORDS.contains(elementType)) {
|
||||
if (KtTokens.MODIFIER_KEYWORDS.contains(elementType)) {
|
||||
attributes = JetHighlightingColors.BUILTIN_ANNOTATION;
|
||||
}
|
||||
holder.createInfoAnnotation(element, null).setTextAttributes(attributes);
|
||||
}
|
||||
if (JetTokens.SAFE_ACCESS.equals(elementType)) {
|
||||
if (KtTokens.SAFE_ACCESS.equals(elementType)) {
|
||||
holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.SAFE_ACCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFunctionLiteralExpression(@NotNull JetFunctionLiteralExpression expression) {
|
||||
public void visitFunctionLiteralExpression(@NotNull KtFunctionLiteralExpression expression) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||
KtFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||
holder.createInfoAnnotation(functionLiteral.getLBrace(), null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW);
|
||||
PsiElement closingBrace = functionLiteral.getRBrace();
|
||||
if (closingBrace != null) {
|
||||
|
||||
+9
-9
@@ -22,10 +22,10 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.JetDynamicType;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.JetTypeParameter;
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
||||
import org.jetbrains.kotlin.psi.KtDynamicType;
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.KtTypeParameter;
|
||||
import org.jetbrains.kotlin.psi.psiUtil.JetPsiUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
|
||||
@@ -35,7 +35,7 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) {
|
||||
public void visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression) {
|
||||
if (NameHighlighter.namesHighlightingEnabled) {
|
||||
DeclarationDescriptor referenceTarget = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||
if (referenceTarget instanceof ConstructorDescriptor) {
|
||||
@@ -57,13 +57,13 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void highlightAnnotation(@NotNull JetSimpleNameExpression expression) {
|
||||
private void highlightAnnotation(@NotNull KtSimpleNameExpression expression) {
|
||||
TextRange toHighlight = JetPsiUtilKt.getCalleeHighlightingRange(expression);
|
||||
NameHighlighter.highlightName(holder, toHighlight, JetHighlightingColors.ANNOTATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeParameter(@NotNull JetTypeParameter parameter) {
|
||||
public void visitTypeParameter(@NotNull KtTypeParameter parameter) {
|
||||
PsiElement identifier = parameter.getNameIdentifier();
|
||||
if (identifier != null) {
|
||||
highlightName(identifier, JetHighlightingColors.TYPE_PARAMETER);
|
||||
@@ -72,7 +72,7 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClassOrObject(@NotNull JetClassOrObject classOrObject) {
|
||||
public void visitClassOrObject(@NotNull KtClassOrObject classOrObject) {
|
||||
PsiElement identifier = classOrObject.getNameIdentifier();
|
||||
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, classOrObject);
|
||||
if (identifier != null && classDescriptor != null) {
|
||||
@@ -82,7 +82,7 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDynamicType(@NotNull JetDynamicType type) {
|
||||
public void visitDynamicType(@NotNull KtDynamicType type) {
|
||||
// Do nothing: 'dynamic' is highlighted as a keyword
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.expressions.CaptureKind;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
||||
@@ -38,7 +38,7 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) {
|
||||
public void visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression) {
|
||||
DeclarationDescriptor target = bindingContext.get(REFERENCE_TARGET, expression);
|
||||
if (target == null) {
|
||||
return;
|
||||
@@ -56,20 +56,20 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitProperty(@NotNull JetProperty property) {
|
||||
public void visitProperty(@NotNull KtProperty property) {
|
||||
visitVariableDeclaration(property);
|
||||
super.visitProperty(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitParameter(@NotNull JetParameter parameter) {
|
||||
public void visitParameter(@NotNull KtParameter parameter) {
|
||||
visitVariableDeclaration(parameter);
|
||||
super.visitParameter(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpression(@NotNull JetExpression expression) {
|
||||
JetType smartCast = bindingContext.get(SMARTCAST, expression);
|
||||
public void visitExpression(@NotNull KtExpression expression) {
|
||||
KtType smartCast = bindingContext.get(SMARTCAST, expression);
|
||||
if (smartCast != null) {
|
||||
holder.createInfoAnnotation(expression, "Smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast)).setTextAttributes(
|
||||
JetHighlightingColors.SMART_CAST_VALUE);
|
||||
@@ -77,7 +77,7 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
super.visitExpression(expression);
|
||||
}
|
||||
|
||||
private void visitVariableDeclaration(JetNamedDeclaration declaration) {
|
||||
private void visitVariableDeclaration(KtNamedDeclaration declaration) {
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
PsiElement nameIdentifier = declaration.getNameIdentifier();
|
||||
if (nameIdentifier != null && declarationDescriptor != null) {
|
||||
|
||||
+4
-4
@@ -32,9 +32,9 @@ import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingRangeIntention
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
|
||||
public abstract class IntentionBasedInspection<TElement : JetElement>(
|
||||
public abstract class IntentionBasedInspection<TElement : KtElement>(
|
||||
public val intentions: List<IntentionBasedInspection.IntentionData<TElement>>,
|
||||
protected val problemText: String?,
|
||||
protected val elementType: Class<TElement>
|
||||
@@ -43,7 +43,7 @@ public abstract class IntentionBasedInspection<TElement : JetElement>(
|
||||
constructor(intention: JetSelfTargetingRangeIntention<TElement>, additionalChecker: (TElement) -> Boolean = { true })
|
||||
: this(listOf(IntentionData(intention, additionalChecker)), null, intention.elementType)
|
||||
|
||||
public data class IntentionData<TElement : JetElement>(
|
||||
public data class IntentionData<TElement : KtElement>(
|
||||
val intention: JetSelfTargetingRangeIntention<TElement>,
|
||||
val additionalChecker: (TElement) -> Boolean = { true }
|
||||
)
|
||||
@@ -88,7 +88,7 @@ public abstract class IntentionBasedInspection<TElement : JetElement>(
|
||||
get() = ProblemHighlightType.GENERIC_ERROR_OR_WARNING
|
||||
|
||||
/* we implement IntentionAction to provide isAvailable which will be used to hide outdated items and make sure we never call 'invoke' for such item */
|
||||
private class IntentionBasedQuickFix<TElement : JetElement>(
|
||||
private class IntentionBasedQuickFix<TElement : KtElement>(
|
||||
private val intention: JetSelfTargetingRangeIntention<TElement>,
|
||||
private val text: String,
|
||||
private val additionalChecker: (TElement) -> Boolean,
|
||||
|
||||
+5
-5
@@ -29,12 +29,12 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containsInside
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import java.util.HashMap
|
||||
|
||||
public abstract class JetSelfTargetingIntention<TElement : JetElement>(
|
||||
public abstract class JetSelfTargetingIntention<TElement : KtElement>(
|
||||
public val elementType: Class<TElement>,
|
||||
private var text: String,
|
||||
private val familyName: String = text
|
||||
@@ -109,7 +109,7 @@ public abstract class JetSelfTargetingIntention<TElement : JetElement>(
|
||||
companion object {
|
||||
private val intentionBasedInspections = HashMap<Class<out JetSelfTargetingIntention<*>>, IntentionBasedInspection<*>?>()
|
||||
|
||||
fun <TElement : JetElement> findInspection(intentionClass: Class<out JetSelfTargetingIntention<TElement>>): IntentionBasedInspection<TElement>? {
|
||||
fun <TElement : KtElement> findInspection(intentionClass: Class<out JetSelfTargetingIntention<TElement>>): IntentionBasedInspection<TElement>? {
|
||||
if (intentionBasedInspections.containsKey(intentionClass)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return intentionBasedInspections[intentionClass] as IntentionBasedInspection<TElement>?
|
||||
@@ -129,7 +129,7 @@ public abstract class JetSelfTargetingIntention<TElement : JetElement>(
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class JetSelfTargetingRangeIntention<TElement : JetElement>(
|
||||
public abstract class JetSelfTargetingRangeIntention<TElement : KtElement>(
|
||||
elementType: Class<TElement>,
|
||||
text: String,
|
||||
familyName: String = text
|
||||
@@ -143,7 +143,7 @@ public abstract class JetSelfTargetingRangeIntention<TElement : JetElement>(
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class JetSelfTargetingOffsetIndependentIntention<TElement : JetElement>(
|
||||
public abstract class JetSelfTargetingOffsetIndependentIntention<TElement : KtElement>(
|
||||
elementType: Class<TElement>,
|
||||
text: String,
|
||||
familyName: String = text
|
||||
|
||||
+75
-75
@@ -20,51 +20,51 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpression>(javaClass(), "Replace overloaded operator with function call") {
|
||||
public class OperatorToFunctionIntention : JetSelfTargetingIntention<KtExpression>(javaClass(), "Replace overloaded operator with function call") {
|
||||
companion object {
|
||||
private fun isApplicablePrefix(element: JetPrefixExpression, caretOffset: Int): Boolean {
|
||||
private fun isApplicablePrefix(element: KtPrefixExpression, caretOffset: Int): Boolean {
|
||||
val opRef = element.getOperationReference()
|
||||
if (!opRef.getTextRange().containsOffset(caretOffset)) return false
|
||||
return when (opRef.getReferencedNameElementType()) {
|
||||
JetTokens.PLUS, JetTokens.MINUS, JetTokens.PLUSPLUS, JetTokens.MINUSMINUS, JetTokens.EXCL -> true
|
||||
KtTokens.PLUS, KtTokens.MINUS, KtTokens.PLUSPLUS, KtTokens.MINUSMINUS, KtTokens.EXCL -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun isApplicablePostfix(element: JetPostfixExpression, caretOffset: Int): Boolean {
|
||||
private fun isApplicablePostfix(element: KtPostfixExpression, caretOffset: Int): Boolean {
|
||||
val opRef = element.getOperationReference()
|
||||
if (!opRef.getTextRange().containsOffset(caretOffset)) return false
|
||||
if (element.getBaseExpression() == null) return false
|
||||
return when (opRef.getReferencedNameElementType()) {
|
||||
JetTokens.PLUSPLUS, JetTokens.MINUSMINUS -> true
|
||||
KtTokens.PLUSPLUS, KtTokens.MINUSMINUS -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun isApplicableBinary(element: JetBinaryExpression, caretOffset: Int): Boolean {
|
||||
private fun isApplicableBinary(element: KtBinaryExpression, caretOffset: Int): Boolean {
|
||||
val opRef = element.getOperationReference()
|
||||
if (!opRef.getTextRange().containsOffset(caretOffset)) return false
|
||||
return when (opRef.getReferencedNameElementType()) {
|
||||
JetTokens.PLUS, JetTokens.MINUS, JetTokens.MUL, JetTokens.DIV, JetTokens.PERC, JetTokens.RANGE, JetTokens.IN_KEYWORD, JetTokens.NOT_IN, JetTokens.PLUSEQ, JetTokens.MINUSEQ, JetTokens.MULTEQ, JetTokens.DIVEQ, JetTokens.PERCEQ, JetTokens.EQEQ, JetTokens.EXCLEQ, JetTokens.GT, JetTokens.LT, JetTokens.GTEQ, JetTokens.LTEQ -> true
|
||||
JetTokens.EQ -> element.getLeft() is JetArrayAccessExpression
|
||||
KtTokens.PLUS, KtTokens.MINUS, KtTokens.MUL, KtTokens.DIV, KtTokens.PERC, KtTokens.RANGE, KtTokens.IN_KEYWORD, KtTokens.NOT_IN, KtTokens.PLUSEQ, KtTokens.MINUSEQ, KtTokens.MULTEQ, KtTokens.DIVEQ, KtTokens.PERCEQ, KtTokens.EQEQ, KtTokens.EXCLEQ, KtTokens.GT, KtTokens.LT, KtTokens.GTEQ, KtTokens.LTEQ -> true
|
||||
KtTokens.EQ -> element.getLeft() is KtArrayAccessExpression
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun isApplicableArrayAccess(element: JetArrayAccessExpression, caretOffset: Int): Boolean {
|
||||
private fun isApplicableArrayAccess(element: KtArrayAccessExpression, caretOffset: Int): Boolean {
|
||||
val lbracket = element.getLeftBracket() ?: return false
|
||||
val rbracket = element.getRightBracket() ?: return false
|
||||
return lbracket.getTextRange().containsOffset(caretOffset) || rbracket.getTextRange().containsOffset(caretOffset)
|
||||
}
|
||||
|
||||
private fun isApplicableCall(element: JetCallExpression, caretOffset: Int): Boolean {
|
||||
private fun isApplicableCall(element: KtCallExpression, caretOffset: Int): Boolean {
|
||||
val lbrace = (element.getValueArgumentList()?.getLeftParenthesis()
|
||||
?: element.getFunctionLiteralArguments().firstOrNull()?.getFunctionLiteral()?.getLeftCurlyBrace()
|
||||
?: return false) as PsiElement
|
||||
@@ -73,55 +73,55 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
val resolvedCall = element.getResolvedCall(element.analyze())
|
||||
val descriptor = resolvedCall?.getResultingDescriptor()
|
||||
if (descriptor is FunctionDescriptor && descriptor.getName() == OperatorNameConventions.INVOKE) {
|
||||
if (element.getParent() is JetDotQualifiedExpression &&
|
||||
if (element.getParent() is KtDotQualifiedExpression &&
|
||||
element.getCalleeExpression()?.getText() == OperatorNameConventions.INVOKE.asString()) return false
|
||||
return element.getValueArgumentList() != null || element.getFunctionLiteralArguments().isNotEmpty()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun convertPrefix(element: JetPrefixExpression): JetExpression {
|
||||
private fun convertPrefix(element: KtPrefixExpression): KtExpression {
|
||||
val op = element.getOperationReference().getReferencedNameElementType()
|
||||
val base = element.getBaseExpression()!!.getText()
|
||||
|
||||
val call = when (op) {
|
||||
JetTokens.PLUS -> "plus()"
|
||||
JetTokens.MINUS -> "minus()"
|
||||
JetTokens.PLUSPLUS -> "inc()"
|
||||
JetTokens.MINUSMINUS -> "dec()"
|
||||
JetTokens.EXCL -> "not()"
|
||||
KtTokens.PLUS -> "plus()"
|
||||
KtTokens.MINUS -> "minus()"
|
||||
KtTokens.PLUSPLUS -> "inc()"
|
||||
KtTokens.MINUSMINUS -> "dec()"
|
||||
KtTokens.EXCL -> "not()"
|
||||
else -> return element
|
||||
}
|
||||
|
||||
val transformation = "$base.$call"
|
||||
val transformed = JetPsiFactory(element).createExpression(transformation)
|
||||
return element.replace(transformed) as JetExpression
|
||||
val transformed = KtPsiFactory(element).createExpression(transformation)
|
||||
return element.replace(transformed) as KtExpression
|
||||
}
|
||||
|
||||
private fun convertPostFix(element: JetPostfixExpression): JetExpression {
|
||||
private fun convertPostFix(element: KtPostfixExpression): KtExpression {
|
||||
val op = element.getOperationReference().getReferencedNameElementType()
|
||||
val base = element.getBaseExpression()!!.getText()
|
||||
|
||||
val call = when (op) {
|
||||
JetTokens.PLUSPLUS -> "inc()"
|
||||
JetTokens.MINUSMINUS -> "dec()"
|
||||
KtTokens.PLUSPLUS -> "inc()"
|
||||
KtTokens.MINUSMINUS -> "dec()"
|
||||
else -> return element
|
||||
}
|
||||
|
||||
val transformation = "$base.$call"
|
||||
val transformed = JetPsiFactory(element).createExpression(transformation)
|
||||
return element.replace(transformed) as JetExpression
|
||||
val transformed = KtPsiFactory(element).createExpression(transformation)
|
||||
return element.replace(transformed) as KtExpression
|
||||
}
|
||||
|
||||
private fun convertBinary(element: JetBinaryExpression): JetExpression {
|
||||
private fun convertBinary(element: KtBinaryExpression): KtExpression {
|
||||
val op = element.getOperationReference().getReferencedNameElementType()
|
||||
val left = element.getLeft()!!
|
||||
val right = element.getRight()!!
|
||||
val leftText = left.getText()
|
||||
val rightText = right.getText()
|
||||
|
||||
if (op == JetTokens.EQ) {
|
||||
if (left is JetArrayAccessExpression) {
|
||||
if (op == KtTokens.EQ) {
|
||||
if (left is KtArrayAccessExpression) {
|
||||
convertArrayAccess(left)
|
||||
}
|
||||
return element
|
||||
@@ -133,42 +133,42 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
val elemType = context.getType(left)
|
||||
|
||||
val transformation = when (op) {
|
||||
JetTokens.PLUS -> "$leftText.plus($rightText)"
|
||||
JetTokens.MINUS -> "$leftText.minus($rightText)"
|
||||
JetTokens.MUL -> "$leftText.times($rightText)"
|
||||
JetTokens.DIV -> "$leftText.div($rightText)"
|
||||
JetTokens.PERC -> "$leftText.mod($rightText)"
|
||||
JetTokens.RANGE -> "$leftText.rangeTo($rightText)"
|
||||
JetTokens.IN_KEYWORD -> "$rightText.contains($leftText)"
|
||||
JetTokens.NOT_IN -> "!$rightText.contains($leftText)"
|
||||
JetTokens.PLUSEQ -> if (functionName == "plusAssign") "$leftText.plusAssign($rightText)" else "$leftText = $leftText.plus($rightText)"
|
||||
JetTokens.MINUSEQ -> if (functionName == "minusAssign") "$leftText.minusAssign($rightText)" else "$leftText = $leftText.minus($rightText)"
|
||||
JetTokens.MULTEQ -> if (functionName == "multAssign") "$leftText.multAssign($rightText)" else "$leftText = $leftText.mult($rightText)"
|
||||
JetTokens.DIVEQ -> if (functionName == "divAssign") "$leftText.divAssign($rightText)" else "$leftText = $leftText.div($rightText)"
|
||||
JetTokens.PERCEQ -> if (functionName == "modAssign") "$leftText.modAssign($rightText)" else "$leftText = $leftText.mod($rightText)"
|
||||
JetTokens.EQEQ -> if (elemType?.isMarkedNullable() ?: true) "$leftText?.equals($rightText) ?: $rightText.identityEquals(null)" else "$leftText.equals($rightText)"
|
||||
JetTokens.EXCLEQ -> if (elemType?.isMarkedNullable() ?: true) "!($leftText?.equals($rightText) ?: $rightText.identityEquals(null))" else "!$leftText.equals($rightText)"
|
||||
JetTokens.GT -> "$leftText.compareTo($rightText) > 0"
|
||||
JetTokens.LT -> "$leftText.compareTo($rightText) < 0"
|
||||
JetTokens.GTEQ -> "$leftText.compareTo($rightText) >= 0"
|
||||
JetTokens.LTEQ -> "$leftText.compareTo($rightText) <= 0"
|
||||
KtTokens.PLUS -> "$leftText.plus($rightText)"
|
||||
KtTokens.MINUS -> "$leftText.minus($rightText)"
|
||||
KtTokens.MUL -> "$leftText.times($rightText)"
|
||||
KtTokens.DIV -> "$leftText.div($rightText)"
|
||||
KtTokens.PERC -> "$leftText.mod($rightText)"
|
||||
KtTokens.RANGE -> "$leftText.rangeTo($rightText)"
|
||||
KtTokens.IN_KEYWORD -> "$rightText.contains($leftText)"
|
||||
KtTokens.NOT_IN -> "!$rightText.contains($leftText)"
|
||||
KtTokens.PLUSEQ -> if (functionName == "plusAssign") "$leftText.plusAssign($rightText)" else "$leftText = $leftText.plus($rightText)"
|
||||
KtTokens.MINUSEQ -> if (functionName == "minusAssign") "$leftText.minusAssign($rightText)" else "$leftText = $leftText.minus($rightText)"
|
||||
KtTokens.MULTEQ -> if (functionName == "multAssign") "$leftText.multAssign($rightText)" else "$leftText = $leftText.mult($rightText)"
|
||||
KtTokens.DIVEQ -> if (functionName == "divAssign") "$leftText.divAssign($rightText)" else "$leftText = $leftText.div($rightText)"
|
||||
KtTokens.PERCEQ -> if (functionName == "modAssign") "$leftText.modAssign($rightText)" else "$leftText = $leftText.mod($rightText)"
|
||||
KtTokens.EQEQ -> if (elemType?.isMarkedNullable() ?: true) "$leftText?.equals($rightText) ?: $rightText.identityEquals(null)" else "$leftText.equals($rightText)"
|
||||
KtTokens.EXCLEQ -> if (elemType?.isMarkedNullable() ?: true) "!($leftText?.equals($rightText) ?: $rightText.identityEquals(null))" else "!$leftText.equals($rightText)"
|
||||
KtTokens.GT -> "$leftText.compareTo($rightText) > 0"
|
||||
KtTokens.LT -> "$leftText.compareTo($rightText) < 0"
|
||||
KtTokens.GTEQ -> "$leftText.compareTo($rightText) >= 0"
|
||||
KtTokens.LTEQ -> "$leftText.compareTo($rightText) <= 0"
|
||||
else -> return element
|
||||
}
|
||||
|
||||
val transformed = JetPsiFactory(element).createExpression(transformation)
|
||||
val transformed = KtPsiFactory(element).createExpression(transformation)
|
||||
|
||||
return element.replace(transformed) as JetExpression
|
||||
return element.replace(transformed) as KtExpression
|
||||
}
|
||||
|
||||
private fun convertArrayAccess(element: JetArrayAccessExpression): JetExpression {
|
||||
private fun convertArrayAccess(element: KtArrayAccessExpression): KtExpression {
|
||||
val parent = element.getParent()
|
||||
val array = element.getArrayExpression()!!.getText()
|
||||
val indices = element.getIndicesNode()
|
||||
val indicesText = indices.getText()?.removeSurrounding("[","]") ?: throw AssertionError("Indices node of ArrayExpression shouldn't be null: JetArrayAccessExpression = ${element.getText()}")
|
||||
|
||||
val transformation : String
|
||||
val replaced : JetElement
|
||||
if (parent is JetBinaryExpression && parent.getOperationReference().getReferencedNameElementType() == JetTokens.EQ) {
|
||||
val replaced : KtElement
|
||||
if (parent is KtBinaryExpression && parent.getOperationReference().getReferencedNameElementType() == KtTokens.EQ) {
|
||||
// part of an assignment
|
||||
val right = parent.getRight()!!.getText()
|
||||
transformation = "$array.set($indicesText, $right)"
|
||||
@@ -179,11 +179,11 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
replaced = element
|
||||
}
|
||||
|
||||
val transformed = JetPsiFactory(element).createExpression(transformation)
|
||||
return replaced.replace(transformed) as JetExpression
|
||||
val transformed = KtPsiFactory(element).createExpression(transformation)
|
||||
return replaced.replace(transformed) as KtExpression
|
||||
}
|
||||
|
||||
private fun convertCall(element: JetCallExpression): JetExpression {
|
||||
private fun convertCall(element: KtCallExpression): KtExpression {
|
||||
val callee = element.getCalleeExpression()!!
|
||||
val arguments = element.getValueArgumentList()
|
||||
val argumentString = arguments?.getText()?.removeSurrounding("(", ")")
|
||||
@@ -191,18 +191,18 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
val calleeText = callee.getText()
|
||||
val transformation = "$calleeText.${OperatorNameConventions.INVOKE.asString()}" +
|
||||
(if (argumentString == null) "" else "($argumentString)")
|
||||
val transformed = JetPsiFactory(element).createExpression(transformation)
|
||||
val transformed = KtPsiFactory(element).createExpression(transformation)
|
||||
funcLitArgs.forEach { transformed.add(it) }
|
||||
return callee.getParent()!!.replace(transformed) as JetExpression
|
||||
return callee.getParent()!!.replace(transformed) as KtExpression
|
||||
}
|
||||
|
||||
public fun convert(element: JetExpression): Pair<JetExpression, JetSimpleNameExpression> {
|
||||
public fun convert(element: KtExpression): Pair<KtExpression, KtSimpleNameExpression> {
|
||||
val result = when (element) {
|
||||
is JetPrefixExpression -> convertPrefix(element)
|
||||
is JetPostfixExpression -> convertPostFix(element)
|
||||
is JetBinaryExpression -> convertBinary(element)
|
||||
is JetArrayAccessExpression -> convertArrayAccess(element)
|
||||
is JetCallExpression -> convertCall(element)
|
||||
is KtPrefixExpression -> convertPrefix(element)
|
||||
is KtPostfixExpression -> convertPostFix(element)
|
||||
is KtBinaryExpression -> convertBinary(element)
|
||||
is KtArrayAccessExpression -> convertArrayAccess(element)
|
||||
is KtCallExpression -> convertCall(element)
|
||||
else -> throw IllegalArgumentException(element.toString())
|
||||
}
|
||||
|
||||
@@ -211,34 +211,34 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
|
||||
return result to callName
|
||||
}
|
||||
|
||||
private fun findCallName(result: JetExpression): JetSimpleNameExpression? {
|
||||
private fun findCallName(result: KtExpression): KtSimpleNameExpression? {
|
||||
return when (result) {
|
||||
is JetBinaryExpression -> {
|
||||
if (JetPsiUtil.isAssignment(result))
|
||||
is KtBinaryExpression -> {
|
||||
if (KtPsiUtil.isAssignment(result))
|
||||
findCallName(result.getRight()!!)
|
||||
else
|
||||
findCallName(result.getLeft()!!)
|
||||
}
|
||||
|
||||
is JetUnaryExpression -> findCallName(result.getBaseExpression()!!)
|
||||
is KtUnaryExpression -> findCallName(result.getBaseExpression()!!)
|
||||
|
||||
else -> result.getQualifiedElementSelector() as JetSimpleNameExpression?
|
||||
else -> result.getQualifiedElementSelector() as KtSimpleNameExpression?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun isApplicableTo(element: JetExpression, caretOffset: Int): Boolean {
|
||||
override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean {
|
||||
return when (element) {
|
||||
is JetPrefixExpression -> isApplicablePrefix(element, caretOffset)
|
||||
is JetPostfixExpression -> isApplicablePostfix(element, caretOffset)
|
||||
is JetBinaryExpression -> isApplicableBinary(element, caretOffset)
|
||||
is JetArrayAccessExpression -> isApplicableArrayAccess(element, caretOffset)
|
||||
is JetCallExpression -> isApplicableCall(element, caretOffset)
|
||||
is KtPrefixExpression -> isApplicablePrefix(element, caretOffset)
|
||||
is KtPostfixExpression -> isApplicablePostfix(element, caretOffset)
|
||||
is KtBinaryExpression -> isApplicableBinary(element, caretOffset)
|
||||
is KtArrayAccessExpression -> isApplicableArrayAccess(element, caretOffset)
|
||||
is KtCallExpression -> isApplicableCall(element, caretOffset)
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun applyTo(element: JetExpression, editor: Editor) {
|
||||
override fun applyTo(element: KtExpression, editor: Editor) {
|
||||
convert(element)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.jetbrains.kotlin.idea.kdoc
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.JetFunction
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtFunction
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
||||
class KDocElementFactory(val project: Project) {
|
||||
public fun createKDocFromText(text: String): KDoc {
|
||||
val fileText = text + " fun foo { }"
|
||||
val function = JetPsiFactory(project).createDeclaration<JetFunction>(fileText)
|
||||
val function = KtPsiFactory(project).createDeclaration<KtFunction>(fileText)
|
||||
return PsiTreeUtil.findChildOfType(function, javaClass<KDoc>())!!
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
|
||||
@@ -30,11 +30,11 @@ object KDocFinder {
|
||||
if (declaration is DeclarationDescriptorWithSource) {
|
||||
var psiDeclaration = (declaration.getSource() as? PsiSourceElement)?.psi?.getNavigationElement()
|
||||
// KDoc for primary constructor is located inside of its class KDoc
|
||||
if (psiDeclaration is JetPrimaryConstructor) {
|
||||
if (psiDeclaration is KtPrimaryConstructor) {
|
||||
psiDeclaration = psiDeclaration.getContainingClassOrObject()
|
||||
}
|
||||
|
||||
if (psiDeclaration is JetDeclaration) {
|
||||
if (psiDeclaration is KtDeclaration) {
|
||||
val kdoc = psiDeclaration.getDocComment()
|
||||
if (kdoc != null) {
|
||||
if (declaration is ConstructorDescriptor) {
|
||||
|
||||
@@ -22,12 +22,12 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileTopLevelScope
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.references.JetMultiReference
|
||||
import org.jetbrains.kotlin.idea.references.KtMultiReference
|
||||
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
|
||||
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
|
||||
public class KDocReference(element: KDocName): JetMultiReference<KDocName>(element) {
|
||||
public class KDocReference(element: KDocName): KtMultiReference<KDocName>(element) {
|
||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
val declaration = getElement().getContainingDoc().getOwner()
|
||||
if (declaration == null) {
|
||||
@@ -127,7 +127,7 @@ private fun resolveParamLink(fromDescriptor: DeclarationDescriptor, qualifiedNam
|
||||
return getParamDescriptors(fromDescriptor).filter { it.getName().asString() == name }
|
||||
}
|
||||
|
||||
private fun getPackageInnerScope(descriptor: PackageFragmentDescriptor): JetScope {
|
||||
private fun getPackageInnerScope(descriptor: PackageFragmentDescriptor): KtScope {
|
||||
return descriptor.getContainingDeclaration().getPackage(descriptor.fqName).memberScope
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ public fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: De
|
||||
private fun getOuterScope(descriptor: DeclarationDescriptorWithSource, resolutionFacade: ResolutionFacade): LexicalScope {
|
||||
val parent = descriptor.getContainingDeclaration()
|
||||
if (parent is PackageFragmentDescriptor) {
|
||||
val containingFile = (descriptor.getSource() as? PsiSourceElement)?.psi?.getContainingFile() as? JetFile
|
||||
val containingFile = (descriptor.getSource() as? PsiSourceElement)?.psi?.getContainingFile() as? KtFile
|
||||
if (containingFile != null) {
|
||||
return resolutionFacade.getFileTopLevelScope(containingFile)
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.idea.project
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.LocalDescriptorResolver
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException
|
||||
public class IdeaLocalDescriptorResolver(
|
||||
private val resolveElementCache: ResolveElementCache
|
||||
): LocalDescriptorResolver {
|
||||
override fun resolveLocalDeclaration(declaration: JetDeclaration): DeclarationDescriptor {
|
||||
override fun resolveLocalDeclaration(declaration: KtDeclaration): DeclarationDescriptor {
|
||||
val context = resolveElementCache.resolveToElement(declaration, BodyResolveMode.FULL)
|
||||
return context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
||||
?: throw NoDescriptorForDeclarationException(declaration)
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.project
|
||||
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
|
||||
val JetElement.platform: TargetPlatform
|
||||
val KtElement.platform: TargetPlatform
|
||||
get() = TargetPlatformDetector.getPlatform(getContainingJetFile())
|
||||
@@ -35,10 +35,10 @@ import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.JetFileType;
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType;
|
||||
import org.jetbrains.kotlin.idea.framework.JsLibraryStdDetectionUtil;
|
||||
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryCoreUtil;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -51,7 +51,7 @@ public class ProjectStructureUtil {
|
||||
private ProjectStructureUtil() {
|
||||
}
|
||||
|
||||
public static boolean isJsKotlinModule(@NotNull JetFile file) {
|
||||
public static boolean isJsKotlinModule(@NotNull KtFile file) {
|
||||
Module module = ModuleUtilCore.findModuleForPsiElement(file);
|
||||
return module != null && isJsKotlinModule(module);
|
||||
}
|
||||
@@ -158,10 +158,10 @@ public class ProjectStructureUtil {
|
||||
}
|
||||
|
||||
public static boolean hasKotlinFilesInSources(@NotNull Module module) {
|
||||
return FileTypeIndex.containsFileOfType(JetFileType.INSTANCE, module.getModuleScope(false));
|
||||
return FileTypeIndex.containsFileOfType(KotlinFileType.INSTANCE, module.getModuleScope(false));
|
||||
}
|
||||
|
||||
public static boolean hasKotlinFilesOnlyInTests(@NotNull Module module) {
|
||||
return !hasKotlinFilesInSources(module) && FileTypeIndex.containsFileOfType(JetFileType.INSTANCE, module.getModuleScope(true));
|
||||
return !hasKotlinFilesInSources(module) && FileTypeIndex.containsFileOfType(KotlinFileType.INSTANCE, module.getModuleScope(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,16 +51,16 @@ public class ResolveElementCache(
|
||||
private val targetPlatform: TargetPlatform,
|
||||
private val codeFragmentAnalyzer: CodeFragmentAnalyzer
|
||||
) : BodyResolveCache {
|
||||
private class CachedFullResolve(val bindingContext: BindingContext, resolveElement: JetElement) {
|
||||
private class CachedFullResolve(val bindingContext: BindingContext, resolveElement: KtElement) {
|
||||
private val modificationStamp: Long? = modificationStamp(resolveElement)
|
||||
|
||||
fun isUpToDate(resolveElement: JetElement) = modificationStamp == modificationStamp(resolveElement)
|
||||
fun isUpToDate(resolveElement: KtElement) = modificationStamp == modificationStamp(resolveElement)
|
||||
|
||||
private fun modificationStamp(resolveElement: JetElement): Long? {
|
||||
private fun modificationStamp(resolveElement: KtElement): Long? {
|
||||
val file = resolveElement.containingFile
|
||||
return if (!file.isPhysical) // for non-physical file we don't get OUT_OF_CODE_BLOCK_MODIFICATION_COUNT increased and must reset data on any modification of the file
|
||||
file.modificationStamp
|
||||
else if (resolveElement is JetDeclaration && KotlinCodeBlockModificationListener.isBlockDeclaration(resolveElement))
|
||||
else if (resolveElement is KtDeclaration && KotlinCodeBlockModificationListener.isBlockDeclaration(resolveElement))
|
||||
resolveElement.getModificationStamp()
|
||||
else
|
||||
null
|
||||
@@ -68,22 +68,22 @@ public class ResolveElementCache(
|
||||
}
|
||||
|
||||
// drop whole cache after change "out of code block"
|
||||
private val fullResolveCache: CachedValue<MutableMap<JetElement, CachedFullResolve>> = CachedValuesManager.getManager(project).createCachedValue(
|
||||
object : CachedValueProvider<MutableMap<JetElement, CachedFullResolve>> {
|
||||
override fun compute(): CachedValueProvider.Result<MutableMap<JetElement, CachedFullResolve>> {
|
||||
return CachedValueProvider.Result.create(ContainerUtil.createConcurrentSoftValueMap<JetElement, CachedFullResolve>(),
|
||||
private val fullResolveCache: CachedValue<MutableMap<KtElement, CachedFullResolve>> = CachedValuesManager.getManager(project).createCachedValue(
|
||||
object : CachedValueProvider<MutableMap<KtElement, CachedFullResolve>> {
|
||||
override fun compute(): CachedValueProvider.Result<MutableMap<KtElement, CachedFullResolve>> {
|
||||
return CachedValueProvider.Result.create(ContainerUtil.createConcurrentSoftValueMap<KtElement, CachedFullResolve>(),
|
||||
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT,
|
||||
resolveSession.exceptionTracker)
|
||||
}
|
||||
},
|
||||
false)
|
||||
|
||||
private class CachedPartialResolve(val bindingContext: BindingContext, file: JetFile) {
|
||||
private class CachedPartialResolve(val bindingContext: BindingContext, file: KtFile) {
|
||||
private val modificationStamp: Long? = modificationStamp(file)
|
||||
|
||||
fun isUpToDate(file: JetFile) = modificationStamp == modificationStamp(file)
|
||||
fun isUpToDate(file: KtFile) = modificationStamp == modificationStamp(file)
|
||||
|
||||
private fun modificationStamp(file: JetFile): Long? {
|
||||
private fun modificationStamp(file: KtFile): Long? {
|
||||
return if (!file.isPhysical) // for non-physical file we don't get MODIFICATION_COUNT increased and must reset data on any modification of the file
|
||||
file.modificationStamp
|
||||
else
|
||||
@@ -91,10 +91,10 @@ public class ResolveElementCache(
|
||||
}
|
||||
}
|
||||
|
||||
private val partialBodyResolveCache: CachedValue<MutableMap<JetExpression, CachedPartialResolve>> = CachedValuesManager.getManager(project).createCachedValue(
|
||||
object : CachedValueProvider<MutableMap<JetExpression, CachedPartialResolve>> {
|
||||
override fun compute(): CachedValueProvider.Result<MutableMap<JetExpression, CachedPartialResolve>> {
|
||||
return CachedValueProvider.Result.create(ContainerUtil.createConcurrentSoftValueMap<JetExpression, CachedPartialResolve>(),
|
||||
private val partialBodyResolveCache: CachedValue<MutableMap<KtExpression, CachedPartialResolve>> = CachedValuesManager.getManager(project).createCachedValue(
|
||||
object : CachedValueProvider<MutableMap<KtExpression, CachedPartialResolve>> {
|
||||
override fun compute(): CachedValueProvider.Result<MutableMap<KtExpression, CachedPartialResolve>> {
|
||||
return CachedValueProvider.Result.create(ContainerUtil.createConcurrentSoftValueMap<KtExpression, CachedPartialResolve>(),
|
||||
PsiModificationTracker.MODIFICATION_COUNT,
|
||||
resolveSession.exceptionTracker)
|
||||
}
|
||||
@@ -109,11 +109,11 @@ public class ResolveElementCache(
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolveFunctionBody(function: JetNamedFunction)
|
||||
override fun resolveFunctionBody(function: KtNamedFunction)
|
||||
= getElementAdditionalResolve(function, function, BodyResolveMode.FULL)
|
||||
|
||||
|
||||
fun getElementAdditionalResolve(resolveElement: JetElement, contextElement: JetElement, bodyResolveMode: BodyResolveMode): BindingContext {
|
||||
fun getElementAdditionalResolve(resolveElement: KtElement, contextElement: KtElement, bodyResolveMode: BodyResolveMode): BindingContext {
|
||||
// check if full additional resolve already performed and is up-to-date
|
||||
val fullResolveMap = fullResolveCache.value
|
||||
val cachedFullResolve = fullResolveMap[resolveElement]
|
||||
@@ -134,7 +134,7 @@ public class ResolveElementCache(
|
||||
}
|
||||
|
||||
BodyResolveMode.PARTIAL -> {
|
||||
if (resolveElement !is JetDeclaration) {
|
||||
if (resolveElement !is KtDeclaration) {
|
||||
return getElementAdditionalResolve(resolveElement, contextElement, BodyResolveMode.FULL)
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class ResolveElementCache(
|
||||
}
|
||||
|
||||
BodyResolveMode.PARTIAL_FOR_COMPLETION -> {
|
||||
if (resolveElement !is JetDeclaration) {
|
||||
if (resolveElement !is KtDeclaration) {
|
||||
return getElementAdditionalResolve(resolveElement, contextElement, BodyResolveMode.FULL)
|
||||
}
|
||||
|
||||
@@ -175,12 +175,12 @@ public class ResolveElementCache(
|
||||
}
|
||||
}
|
||||
|
||||
public fun resolveToElement(element: JetElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext {
|
||||
public fun resolveToElement(element: KtElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext {
|
||||
var contextElement = element
|
||||
|
||||
val elementOfAdditionalResolve = findElementOfAdditionalResolve(contextElement)
|
||||
|
||||
if (elementOfAdditionalResolve is JetParameter) {
|
||||
if (elementOfAdditionalResolve is KtParameter) {
|
||||
// Parameters for function literal could be met inside other parameters. We can't make resolveToDescriptors for internal elements.
|
||||
contextElement = elementOfAdditionalResolve
|
||||
}
|
||||
@@ -188,8 +188,8 @@ public class ResolveElementCache(
|
||||
return getElementAdditionalResolve(elementOfAdditionalResolve, contextElement, bodyResolveMode)
|
||||
}
|
||||
|
||||
val declaration = contextElement.getParentOfType<JetDeclaration>(false)
|
||||
if (declaration != null && declaration !is JetClassInitializer) {
|
||||
val declaration = contextElement.getParentOfType<KtDeclaration>(false)
|
||||
if (declaration != null && declaration !is KtClassInitializer) {
|
||||
// Activate descriptor resolution
|
||||
resolveSession.resolveToDescriptor(declaration)
|
||||
}
|
||||
@@ -197,37 +197,37 @@ public class ResolveElementCache(
|
||||
return resolveSession.getBindingContext()
|
||||
}
|
||||
|
||||
private fun findElementOfAdditionalResolve(element: JetElement): JetElement? {
|
||||
val elementOfAdditionalResolve = JetPsiUtil.getTopmostParentOfTypes(
|
||||
private fun findElementOfAdditionalResolve(element: KtElement): KtElement? {
|
||||
val elementOfAdditionalResolve = KtPsiUtil.getTopmostParentOfTypes(
|
||||
element,
|
||||
javaClass<JetNamedFunction>(),
|
||||
javaClass<JetClassInitializer>(),
|
||||
javaClass<JetSecondaryConstructor>(),
|
||||
javaClass<JetProperty>(),
|
||||
javaClass<JetParameter>(),
|
||||
javaClass<JetDelegationSpecifierList>(),
|
||||
javaClass<JetInitializerList>(),
|
||||
javaClass<JetImportList>(),
|
||||
javaClass<JetAnnotationEntry>(),
|
||||
javaClass<JetTypeParameter>(),
|
||||
javaClass<JetTypeConstraint>(),
|
||||
javaClass<JetPackageDirective>(),
|
||||
javaClass<JetCodeFragment>()) as JetElement?
|
||||
javaClass<KtNamedFunction>(),
|
||||
javaClass<KtClassInitializer>(),
|
||||
javaClass<KtSecondaryConstructor>(),
|
||||
javaClass<KtProperty>(),
|
||||
javaClass<KtParameter>(),
|
||||
javaClass<KtDelegationSpecifierList>(),
|
||||
javaClass<KtInitializerList>(),
|
||||
javaClass<KtImportList>(),
|
||||
javaClass<KtAnnotationEntry>(),
|
||||
javaClass<KtTypeParameter>(),
|
||||
javaClass<KtTypeConstraint>(),
|
||||
javaClass<KtPackageDirective>(),
|
||||
javaClass<KtCodeFragment>()) as KtElement?
|
||||
|
||||
when (elementOfAdditionalResolve) {
|
||||
null -> {
|
||||
// Case of JetAnnotationEntry on top level class
|
||||
if (element is JetAnnotationEntry) {
|
||||
if (element is KtAnnotationEntry) {
|
||||
return element
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
is JetPackageDirective -> return element
|
||||
is KtPackageDirective -> return element
|
||||
|
||||
is JetParameter -> {
|
||||
val klass = elementOfAdditionalResolve.getParentOfType<JetClass>(strict = true)
|
||||
is KtParameter -> {
|
||||
val klass = elementOfAdditionalResolve.getParentOfType<KtClass>(strict = true)
|
||||
if (klass != null && elementOfAdditionalResolve.getParent() == klass.getPrimaryConstructorParameterList()) {
|
||||
return klass
|
||||
}
|
||||
@@ -239,17 +239,17 @@ public class ResolveElementCache(
|
||||
}
|
||||
}
|
||||
|
||||
private fun performElementAdditionalResolve(resolveElement: JetElement, contextElement: JetElement, bodyResolveMode: BodyResolveMode): Pair<BindingContext, StatementFilter> {
|
||||
private fun performElementAdditionalResolve(resolveElement: KtElement, contextElement: KtElement, bodyResolveMode: BodyResolveMode): Pair<BindingContext, StatementFilter> {
|
||||
val file = resolveElement.getContainingJetFile()
|
||||
|
||||
var statementFilterUsed = StatementFilter.NONE
|
||||
|
||||
fun createStatementFilter(): StatementFilter {
|
||||
assert(resolveElement is JetDeclaration)
|
||||
assert(resolveElement is KtDeclaration)
|
||||
if (bodyResolveMode != BodyResolveMode.FULL) {
|
||||
statementFilterUsed = PartialBodyResolveFilter(
|
||||
contextElement,
|
||||
resolveElement as JetDeclaration,
|
||||
resolveElement as KtDeclaration,
|
||||
probablyNothingCallableNames(),
|
||||
bodyResolveMode == BodyResolveMode.PARTIAL_FOR_COMPLETION)
|
||||
}
|
||||
@@ -257,36 +257,36 @@ public class ResolveElementCache(
|
||||
}
|
||||
|
||||
val trace: BindingTrace = when (resolveElement) {
|
||||
is JetNamedFunction -> functionAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
|
||||
is KtNamedFunction -> functionAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
|
||||
|
||||
is JetClassInitializer -> initializerAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
|
||||
is KtClassInitializer -> initializerAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
|
||||
|
||||
is JetSecondaryConstructor -> secondaryConstructorAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
|
||||
is KtSecondaryConstructor -> secondaryConstructorAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
|
||||
|
||||
is JetProperty -> propertyAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
|
||||
is KtProperty -> propertyAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
|
||||
|
||||
is JetDelegationSpecifierList -> delegationSpecifierAdditionalResolve(resolveSession, resolveElement, resolveElement.getParent() as JetClassOrObject, file)
|
||||
is KtDelegationSpecifierList -> delegationSpecifierAdditionalResolve(resolveSession, resolveElement, resolveElement.getParent() as KtClassOrObject, file)
|
||||
|
||||
is JetInitializerList -> delegationSpecifierAdditionalResolve(resolveSession, resolveElement, resolveElement.getParent() as JetEnumEntry, file)
|
||||
is KtInitializerList -> delegationSpecifierAdditionalResolve(resolveSession, resolveElement, resolveElement.getParent() as KtEnumEntry, file)
|
||||
|
||||
is JetImportList -> {
|
||||
is KtImportList -> {
|
||||
val scope = resolveSession.getFileScopeProvider().getFileScope(resolveElement.getContainingJetFile())
|
||||
scope.forceResolveAllImports()
|
||||
resolveSession.trace
|
||||
}
|
||||
|
||||
is JetAnnotationEntry -> annotationAdditionalResolve(resolveSession, resolveElement)
|
||||
is KtAnnotationEntry -> annotationAdditionalResolve(resolveSession, resolveElement)
|
||||
|
||||
is JetClass -> constructorAdditionalResolve(resolveSession, resolveElement, file)
|
||||
is KtClass -> constructorAdditionalResolve(resolveSession, resolveElement, file)
|
||||
|
||||
is JetTypeParameter -> typeParameterAdditionalResolve(resolveSession, resolveElement)
|
||||
is KtTypeParameter -> typeParameterAdditionalResolve(resolveSession, resolveElement)
|
||||
|
||||
is JetTypeConstraint -> typeConstraintAdditionalResolve(resolveSession, resolveElement)
|
||||
is KtTypeConstraint -> typeConstraintAdditionalResolve(resolveSession, resolveElement)
|
||||
|
||||
is JetCodeFragment -> codeFragmentAdditionalResolve(resolveSession, resolveElement, bodyResolveMode)
|
||||
is KtCodeFragment -> codeFragmentAdditionalResolve(resolveSession, resolveElement, bodyResolveMode)
|
||||
|
||||
else -> {
|
||||
if (resolveElement.getParentOfType<JetPackageDirective>(true) != null) {
|
||||
if (resolveElement.getParentOfType<KtPackageDirective>(true) != null) {
|
||||
packageRefAdditionalResolve(resolveSession, resolveElement)
|
||||
}
|
||||
else {
|
||||
@@ -302,22 +302,22 @@ public class ResolveElementCache(
|
||||
return Pair(trace.getBindingContext(), statementFilterUsed)
|
||||
}
|
||||
|
||||
private fun packageRefAdditionalResolve(resolveSession: ResolveSession, jetElement: JetElement): BindingTrace {
|
||||
val trace = createDelegatingTrace(jetElement)
|
||||
private fun packageRefAdditionalResolve(resolveSession: ResolveSession, ktElement: KtElement): BindingTrace {
|
||||
val trace = createDelegatingTrace(ktElement)
|
||||
|
||||
if (jetElement is JetSimpleNameExpression) {
|
||||
val header = jetElement.getParentOfType<JetPackageDirective>(true)!!
|
||||
if (ktElement is KtSimpleNameExpression) {
|
||||
val header = ktElement.getParentOfType<KtPackageDirective>(true)!!
|
||||
|
||||
if (trace.getBindingContext()[BindingContext.RESOLUTION_SCOPE, jetElement] == null) {
|
||||
val scope = resolveSession.getModuleDescriptor().getPackage(header.getFqName(jetElement).parent()).memberScope
|
||||
trace.record(BindingContext.RESOLUTION_SCOPE, jetElement, scope)
|
||||
if (trace.getBindingContext()[BindingContext.RESOLUTION_SCOPE, ktElement] == null) {
|
||||
val scope = resolveSession.getModuleDescriptor().getPackage(header.getFqName(ktElement).parent()).memberScope
|
||||
trace.record(BindingContext.RESOLUTION_SCOPE, ktElement, scope)
|
||||
}
|
||||
|
||||
if (Name.isValidIdentifier(jetElement.getReferencedName())) {
|
||||
if (trace.getBindingContext()[BindingContext.REFERENCE_TARGET, jetElement] == null) {
|
||||
val fqName = header.getFqName(jetElement)
|
||||
if (Name.isValidIdentifier(ktElement.getReferencedName())) {
|
||||
if (trace.getBindingContext()[BindingContext.REFERENCE_TARGET, ktElement] == null) {
|
||||
val fqName = header.getFqName(ktElement)
|
||||
val packageDescriptor = resolveSession.getModuleDescriptor().getPackage(fqName)
|
||||
trace.record(BindingContext.REFERENCE_TARGET, jetElement, packageDescriptor)
|
||||
trace.record(BindingContext.REFERENCE_TARGET, ktElement, packageDescriptor)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,8 +325,8 @@ public class ResolveElementCache(
|
||||
return trace
|
||||
}
|
||||
|
||||
private fun typeConstraintAdditionalResolve(analyzer: KotlinCodeAnalyzer, jetTypeConstraint: JetTypeConstraint): BindingTrace {
|
||||
val declaration = jetTypeConstraint.getParentOfType<JetDeclaration>(true)!!
|
||||
private fun typeConstraintAdditionalResolve(analyzer: KotlinCodeAnalyzer, jetTypeConstraint: KtTypeConstraint): BindingTrace {
|
||||
val declaration = jetTypeConstraint.getParentOfType<KtDeclaration>(true)!!
|
||||
val descriptor = analyzer.resolveToDescriptor(declaration) as ClassDescriptor
|
||||
|
||||
for (parameterDescriptor in descriptor.getTypeConstructor().getParameters()) {
|
||||
@@ -336,7 +336,7 @@ public class ResolveElementCache(
|
||||
return resolveSession.trace
|
||||
}
|
||||
|
||||
private fun codeFragmentAdditionalResolve(resolveSession: ResolveSession, codeFragment: JetCodeFragment, bodyResolveMode: BodyResolveMode): BindingTrace {
|
||||
private fun codeFragmentAdditionalResolve(resolveSession: ResolveSession, codeFragment: KtCodeFragment, bodyResolveMode: BodyResolveMode): BindingTrace {
|
||||
val trace = createDelegatingTrace(codeFragment)
|
||||
|
||||
val contextResolveMode = if (bodyResolveMode == BodyResolveMode.PARTIAL)
|
||||
@@ -348,18 +348,18 @@ public class ResolveElementCache(
|
||||
return trace
|
||||
}
|
||||
|
||||
private fun annotationAdditionalResolve(resolveSession: ResolveSession, jetAnnotationEntry: JetAnnotationEntry): BindingTrace {
|
||||
val modifierList = jetAnnotationEntry.getParentOfType<JetModifierList>(true)
|
||||
val declaration = modifierList?.getParentOfType<JetDeclaration>(true)
|
||||
private fun annotationAdditionalResolve(resolveSession: ResolveSession, ktAnnotationEntry: KtAnnotationEntry): BindingTrace {
|
||||
val modifierList = ktAnnotationEntry.getParentOfType<KtModifierList>(true)
|
||||
val declaration = modifierList?.getParentOfType<KtDeclaration>(true)
|
||||
if (declaration != null) {
|
||||
doResolveAnnotations(getAnnotationsByDeclaration(resolveSession, modifierList!!, declaration))
|
||||
}
|
||||
else {
|
||||
val fileAnnotationList = jetAnnotationEntry.getParentOfType<JetFileAnnotationList>(true)
|
||||
val fileAnnotationList = ktAnnotationEntry.getParentOfType<KtFileAnnotationList>(true)
|
||||
if (fileAnnotationList != null) {
|
||||
doResolveAnnotations(resolveSession.getFileAnnotations(fileAnnotationList.getContainingJetFile()))
|
||||
}
|
||||
if (modifierList != null && modifierList.getParent() is JetFile) {
|
||||
if (modifierList != null && modifierList.getParent() is KtFile) {
|
||||
doResolveAnnotations(resolveSession.getDanglingAnnotations(modifierList.getContainingJetFile()))
|
||||
}
|
||||
}
|
||||
@@ -371,31 +371,31 @@ public class ResolveElementCache(
|
||||
ForceResolveUtil.forceResolveAllContents(annotations)
|
||||
}
|
||||
|
||||
private fun getAnnotationsByDeclaration(resolveSession: ResolveSession, modifierList: JetModifierList, declaration: JetDeclaration): Annotations {
|
||||
private fun getAnnotationsByDeclaration(resolveSession: ResolveSession, modifierList: KtModifierList, declaration: KtDeclaration): Annotations {
|
||||
var descriptor = resolveSession.resolveToDescriptor(declaration)
|
||||
if (declaration is JetClass) {
|
||||
if (declaration is KtClass) {
|
||||
if (modifierList == declaration.getPrimaryConstructorModifierList()) {
|
||||
descriptor = (descriptor as ClassDescriptor).getUnsubstitutedPrimaryConstructor()
|
||||
?: error("No constructor found: ${declaration.getText()}")
|
||||
}
|
||||
}
|
||||
|
||||
if (declaration is JetClassOrObject && modifierList.getParent() == declaration.getBody() && descriptor is LazyClassDescriptor) {
|
||||
if (declaration is KtClassOrObject && modifierList.getParent() == declaration.getBody() && descriptor is LazyClassDescriptor) {
|
||||
return descriptor.getDanglingAnnotations()
|
||||
}
|
||||
|
||||
return descriptor.getAnnotations()
|
||||
}
|
||||
|
||||
private fun typeParameterAdditionalResolve(analyzer: KotlinCodeAnalyzer, typeParameter: JetTypeParameter): BindingTrace {
|
||||
private fun typeParameterAdditionalResolve(analyzer: KotlinCodeAnalyzer, typeParameter: KtTypeParameter): BindingTrace {
|
||||
val descriptor = analyzer.resolveToDescriptor(typeParameter)
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor)
|
||||
|
||||
return resolveSession.trace
|
||||
}
|
||||
|
||||
private fun delegationSpecifierAdditionalResolve(resolveSession: ResolveSession, jetElement: JetElement, classOrObject: JetClassOrObject, file: JetFile): BindingTrace {
|
||||
val trace = createDelegatingTrace(jetElement)
|
||||
private fun delegationSpecifierAdditionalResolve(resolveSession: ResolveSession, ktElement: KtElement, classOrObject: KtClassOrObject, file: KtFile): BindingTrace {
|
||||
val trace = createDelegatingTrace(ktElement)
|
||||
val descriptor = resolveSession.resolveToDescriptor(classOrObject) as LazyClassDescriptor
|
||||
|
||||
// Activate resolving of supertypes
|
||||
@@ -412,7 +412,7 @@ public class ResolveElementCache(
|
||||
return trace
|
||||
}
|
||||
|
||||
private fun propertyAdditionalResolve(resolveSession: ResolveSession, jetProperty: JetProperty, file: JetFile, statementFilter: StatementFilter): BindingTrace {
|
||||
private fun propertyAdditionalResolve(resolveSession: ResolveSession, jetProperty: KtProperty, file: KtFile, statementFilter: StatementFilter): BindingTrace {
|
||||
val trace = createDelegatingTrace(jetProperty)
|
||||
val propertyResolutionScope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(jetProperty)
|
||||
|
||||
@@ -444,7 +444,7 @@ public class ResolveElementCache(
|
||||
return trace
|
||||
}
|
||||
|
||||
private fun functionAdditionalResolve(resolveSession: ResolveSession, namedFunction: JetNamedFunction, file: JetFile, statementFilter: StatementFilter): BindingTrace {
|
||||
private fun functionAdditionalResolve(resolveSession: ResolveSession, namedFunction: KtNamedFunction, file: KtFile, statementFilter: StatementFilter): BindingTrace {
|
||||
val trace = createDelegatingTrace(namedFunction)
|
||||
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(namedFunction)
|
||||
@@ -457,7 +457,7 @@ public class ResolveElementCache(
|
||||
return trace
|
||||
}
|
||||
|
||||
private fun secondaryConstructorAdditionalResolve(resolveSession: ResolveSession, constructor: JetSecondaryConstructor, file: JetFile, statementFilter: StatementFilter): BindingTrace {
|
||||
private fun secondaryConstructorAdditionalResolve(resolveSession: ResolveSession, constructor: KtSecondaryConstructor, file: KtFile, statementFilter: StatementFilter): BindingTrace {
|
||||
val trace = createDelegatingTrace(constructor)
|
||||
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(constructor)
|
||||
@@ -470,7 +470,7 @@ public class ResolveElementCache(
|
||||
return trace
|
||||
}
|
||||
|
||||
private fun constructorAdditionalResolve(resolveSession: ResolveSession, klass: JetClass, file: JetFile): BindingTrace {
|
||||
private fun constructorAdditionalResolve(resolveSession: ResolveSession, klass: KtClass, file: KtFile): BindingTrace {
|
||||
val trace = createDelegatingTrace(klass)
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(klass)
|
||||
|
||||
@@ -484,10 +484,10 @@ public class ResolveElementCache(
|
||||
return trace
|
||||
}
|
||||
|
||||
private fun initializerAdditionalResolve(resolveSession: ResolveSession, classInitializer: JetClassInitializer, file: JetFile, statementFilter: StatementFilter): BindingTrace {
|
||||
private fun initializerAdditionalResolve(resolveSession: ResolveSession, classInitializer: KtClassInitializer, file: KtFile, statementFilter: StatementFilter): BindingTrace {
|
||||
val trace = createDelegatingTrace(classInitializer)
|
||||
|
||||
val classOrObject = classInitializer.getParentOfType<JetClassOrObject>(true)!!
|
||||
val classOrObject = classInitializer.getParentOfType<KtClassOrObject>(true)!!
|
||||
val classOrObjectDescriptor = resolveSession.resolveToDescriptor(classOrObject) as LazyClassDescriptor
|
||||
|
||||
val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter)
|
||||
@@ -499,7 +499,7 @@ public class ResolveElementCache(
|
||||
private fun createBodyResolver(
|
||||
resolveSession: ResolveSession,
|
||||
trace: BindingTrace,
|
||||
file: JetFile,
|
||||
file: KtFile,
|
||||
statementFilter: StatementFilter
|
||||
): BodyResolver {
|
||||
val globalContext = SimpleGlobalContext(resolveSession.storageManager, resolveSession.getExceptionTracker())
|
||||
@@ -513,30 +513,30 @@ public class ResolveElementCache(
|
||||
}
|
||||
|
||||
// All additional resolve should be done to separate trace
|
||||
private fun createDelegatingTrace(resolveElement: JetElement): BindingTrace {
|
||||
private fun createDelegatingTrace(resolveElement: KtElement): BindingTrace {
|
||||
return resolveSession.storageManager.createSafeTrace(
|
||||
DelegatingBindingTrace(resolveSession.getBindingContext(), "trace to resolve element", resolveElement))
|
||||
}
|
||||
|
||||
private class BodyResolveContextForLazy(
|
||||
private val topDownAnalysisMode: TopDownAnalysisMode,
|
||||
private val declaringScopes: Function1<JetDeclaration, LexicalScope?>
|
||||
private val declaringScopes: Function1<KtDeclaration, LexicalScope?>
|
||||
) : BodiesResolveContext {
|
||||
override fun getFiles(): Collection<JetFile> = setOf()
|
||||
override fun getFiles(): Collection<KtFile> = setOf()
|
||||
|
||||
override fun getDeclaredClasses(): MutableMap<JetClassOrObject, ClassDescriptorWithResolutionScopes> = hashMapOf()
|
||||
override fun getDeclaredClasses(): MutableMap<KtClassOrObject, ClassDescriptorWithResolutionScopes> = hashMapOf()
|
||||
|
||||
override fun getAnonymousInitializers(): MutableMap<JetClassInitializer, ClassDescriptorWithResolutionScopes> = hashMapOf()
|
||||
override fun getAnonymousInitializers(): MutableMap<KtClassInitializer, ClassDescriptorWithResolutionScopes> = hashMapOf()
|
||||
|
||||
override fun getSecondaryConstructors(): MutableMap<JetSecondaryConstructor, ConstructorDescriptor> = hashMapOf()
|
||||
override fun getSecondaryConstructors(): MutableMap<KtSecondaryConstructor, ConstructorDescriptor> = hashMapOf()
|
||||
|
||||
override fun getProperties(): MutableMap<JetProperty, PropertyDescriptor> = hashMapOf()
|
||||
override fun getProperties(): MutableMap<KtProperty, PropertyDescriptor> = hashMapOf()
|
||||
|
||||
override fun getFunctions(): MutableMap<JetNamedFunction, SimpleFunctionDescriptor> = hashMapOf()
|
||||
override fun getFunctions(): MutableMap<KtNamedFunction, SimpleFunctionDescriptor> = hashMapOf()
|
||||
|
||||
override fun getDeclaringScope(declaration: JetDeclaration): LexicalScope? = declaringScopes(declaration)
|
||||
override fun getDeclaringScope(declaration: KtDeclaration): LexicalScope? = declaringScopes(declaration)
|
||||
|
||||
override fun getScripts(): MutableMap<JetScript, ScriptDescriptor> = hashMapOf()
|
||||
override fun getScripts(): MutableMap<KtScript, ScriptDescriptor> = hashMapOf()
|
||||
|
||||
override fun getOuterDataFlowInfo(): DataFlowInfo = DataFlowInfo.EMPTY
|
||||
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform;
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class TargetPlatformDetector {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TargetPlatform getPlatform(@NotNull JetFile file) {
|
||||
public static TargetPlatform getPlatform(@NotNull KtFile file) {
|
||||
VirtualFile virtualFile = file.getOriginalFile().getVirtualFile();
|
||||
if (virtualFile == null) {
|
||||
return getDefaultPlatform();
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.psi.JetCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import java.util.Collections
|
||||
|
||||
// TODO: Replace with trait when all subclasses are translated to Kotlin
|
||||
@@ -27,7 +27,7 @@ public abstract class JetIntentionActionsFactory {
|
||||
protected abstract fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction>
|
||||
|
||||
public fun createActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||
if (diagnostic.getPsiElement().getContainingFile() is JetCodeFragment && !isApplicableForCodeFragment()) {
|
||||
if (diagnostic.getPsiElement().getContainingFile() is KtCodeFragment && !isApplicableForCodeFragment()) {
|
||||
return emptyList()
|
||||
}
|
||||
return doCreateActions(diagnostic)
|
||||
|
||||
+17
-17
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.idea.util.JetPsiPrecedences
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
|
||||
public class KotlinSuppressIntentionAction(
|
||||
private val suppressAt: JetExpression,
|
||||
private val suppressAt: KtExpression,
|
||||
private val diagnosticFactory: DiagnosticFactory<*>,
|
||||
private val kind: AnnotationHostKind
|
||||
) : SuppressIntentionAction() {
|
||||
@@ -41,24 +41,24 @@ public class KotlinSuppressIntentionAction(
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, element: PsiElement) {
|
||||
val id = "\"${diagnosticFactory.getName()}\""
|
||||
if (suppressAt is JetModifierListOwner) {
|
||||
if (suppressAt is KtModifierListOwner) {
|
||||
suppressAtModifierListOwner(suppressAt, id)
|
||||
}
|
||||
else if (suppressAt is JetAnnotatedExpression) {
|
||||
else if (suppressAt is KtAnnotatedExpression) {
|
||||
suppressAtAnnotatedExpression(CaretBox(suppressAt, editor), id)
|
||||
}
|
||||
else if (suppressAt is JetExpression) {
|
||||
else if (suppressAt is KtExpression) {
|
||||
suppressAtExpression(CaretBox(suppressAt, editor), id)
|
||||
}
|
||||
}
|
||||
|
||||
private fun suppressAtModifierListOwner(suppressAt: JetModifierListOwner, id: String) {
|
||||
private fun suppressAtModifierListOwner(suppressAt: KtModifierListOwner, id: String) {
|
||||
val modifierList = suppressAt.getModifierList()
|
||||
val psiFactory = JetPsiFactory(suppressAt)
|
||||
val psiFactory = KtPsiFactory(suppressAt)
|
||||
if (modifierList == null) {
|
||||
// create a modifier list from scratch
|
||||
val newModifierList = psiFactory.createModifierList(suppressAnnotationText(id))
|
||||
val replaced = JetPsiUtil.replaceModifierList(suppressAt, newModifierList)
|
||||
val replaced = KtPsiUtil.replaceModifierList(suppressAt, newModifierList)
|
||||
val whiteSpace = psiFactory.createWhiteSpace(kind)
|
||||
suppressAt.addAfter(whiteSpace, replaced)
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class KotlinSuppressIntentionAction(
|
||||
}
|
||||
}
|
||||
|
||||
private fun suppressAtAnnotatedExpression(suppressAt: CaretBox<JetAnnotatedExpression>, id: String) {
|
||||
private fun suppressAtAnnotatedExpression(suppressAt: CaretBox<KtAnnotatedExpression>, id: String) {
|
||||
val entry = findSuppressAnnotation(suppressAt.expression)
|
||||
if (entry != null) {
|
||||
// already annotated with @suppress
|
||||
@@ -89,18 +89,18 @@ public class KotlinSuppressIntentionAction(
|
||||
}
|
||||
}
|
||||
|
||||
private fun suppressAtExpression(caretBox: CaretBox<JetExpression>, id: String) {
|
||||
private fun suppressAtExpression(caretBox: CaretBox<KtExpression>, id: String) {
|
||||
val suppressAt = caretBox.expression
|
||||
assert(suppressAt !is JetDeclaration) { "Declarations should have been checked for above" }
|
||||
assert(suppressAt !is KtDeclaration) { "Declarations should have been checked for above" }
|
||||
|
||||
val parentheses = JetPsiPrecedences.getPrecedence(suppressAt) > JetPsiPrecedences.PRECEDENCE_OF_PREFIX_EXPRESSION
|
||||
val placeholderText = "PLACEHOLDER_ID"
|
||||
val inner = if (parentheses) "($placeholderText)" else placeholderText
|
||||
val annotatedExpression = JetPsiFactory(suppressAt).createExpression(suppressAnnotationText(id) + "\n" + inner)
|
||||
val annotatedExpression = KtPsiFactory(suppressAt).createExpression(suppressAnnotationText(id) + "\n" + inner)
|
||||
|
||||
val copy = suppressAt.copy()!!
|
||||
|
||||
val afterReplace = suppressAt.replace(annotatedExpression) as JetAnnotatedExpression
|
||||
val afterReplace = suppressAt.replace(annotatedExpression) as KtAnnotatedExpression
|
||||
val toReplace = afterReplace.findElementAt(afterReplace.getTextLength() - 2)!!
|
||||
assert (toReplace.getText() == placeholderText)
|
||||
val result = toReplace.replace(copy)!!
|
||||
@@ -108,10 +108,10 @@ public class KotlinSuppressIntentionAction(
|
||||
caretBox.positionCaretInCopy(result)
|
||||
}
|
||||
|
||||
private fun addArgumentToSuppressAnnotation(entry: JetAnnotationEntry, id: String) {
|
||||
private fun addArgumentToSuppressAnnotation(entry: KtAnnotationEntry, id: String) {
|
||||
// add new arguments to an existing entry
|
||||
val args = entry.getValueArgumentList()
|
||||
val psiFactory = JetPsiFactory(entry)
|
||||
val psiFactory = KtPsiFactory(entry)
|
||||
val newArgList = psiFactory.createCallArguments("($id)")
|
||||
if (args == null) {
|
||||
// new argument list
|
||||
@@ -128,7 +128,7 @@ public class KotlinSuppressIntentionAction(
|
||||
|
||||
private fun suppressAnnotationText(id: String) = "@Suppress($id)"
|
||||
|
||||
private fun findSuppressAnnotation(annotated: JetAnnotated): JetAnnotationEntry? {
|
||||
private fun findSuppressAnnotation(annotated: KtAnnotated): KtAnnotationEntry? {
|
||||
val context = annotated.analyze()
|
||||
for (entry in annotated.getAnnotationEntries()) {
|
||||
val annotationDescriptor = context.get(BindingContext.ANNOTATION, entry)
|
||||
@@ -142,11 +142,11 @@ public class KotlinSuppressIntentionAction(
|
||||
|
||||
public class AnnotationHostKind(val kind: String, val name: String, val newLineNeeded: Boolean)
|
||||
|
||||
private fun JetPsiFactory.createWhiteSpace(kind: AnnotationHostKind): PsiElement {
|
||||
private fun KtPsiFactory.createWhiteSpace(kind: AnnotationHostKind): PsiElement {
|
||||
return if (kind.newLineNeeded) createNewLine() else createWhiteSpace()
|
||||
}
|
||||
|
||||
private class CaretBox<out E: JetExpression>(
|
||||
private class CaretBox<out E: KtExpression>(
|
||||
val expression: E,
|
||||
private val editor: Editor?
|
||||
) {
|
||||
|
||||
@@ -44,9 +44,9 @@ public fun moveCaretIntoGeneratedElement(editor: Editor, element: PsiElement) {
|
||||
private fun moveCaretIntoGeneratedElementDocumentUnblocked(editor: Editor, element: PsiElement): Boolean {
|
||||
// Inspired by GenerateMembersUtils.positionCaret()
|
||||
|
||||
if (element is JetDeclarationWithBody && element.hasBody()) {
|
||||
if (element is KtDeclarationWithBody && element.hasBody()) {
|
||||
val expression = element.getBodyExpression()
|
||||
if (expression is JetBlockExpression) {
|
||||
if (expression is KtBlockExpression) {
|
||||
val lBrace = expression.getLBrace()
|
||||
val rBrace = expression.getRBrace()
|
||||
|
||||
@@ -68,7 +68,7 @@ private fun moveCaretIntoGeneratedElementDocumentUnblocked(editor: Editor, eleme
|
||||
}
|
||||
}
|
||||
|
||||
if (element is JetWithExpressionInitializer && element.hasInitializer()) {
|
||||
if (element is KtWithExpressionInitializer && element.hasInitializer()) {
|
||||
val expression = element.getInitializer()
|
||||
if (expression == null) throw AssertionError()
|
||||
|
||||
@@ -85,7 +85,7 @@ private fun moveCaretIntoGeneratedElementDocumentUnblocked(editor: Editor, eleme
|
||||
return true
|
||||
}
|
||||
|
||||
if (element is JetProperty) {
|
||||
if (element is KtProperty) {
|
||||
for (accessor in element.getAccessors()) {
|
||||
if (moveCaretIntoGeneratedElementDocumentUnblocked(editor, accessor)) {
|
||||
return true
|
||||
@@ -101,7 +101,7 @@ public fun Editor.moveCaret(offset: Int, scrollType: ScrollType = ScrollType.REL
|
||||
getScrollingModel().scrollToCaret(scrollType)
|
||||
}
|
||||
|
||||
private fun findInsertAfterAnchor(editor: Editor?, body: JetClassBody): PsiElement? {
|
||||
private fun findInsertAfterAnchor(editor: Editor?, body: KtClassBody): PsiElement? {
|
||||
val afterAnchor = body.lBrace ?: return null
|
||||
|
||||
val offset = editor?.caretModel?.offset ?: body.startOffset
|
||||
@@ -129,7 +129,7 @@ private fun removeAfterOffset(offset: Int, whiteSpace: PsiWhiteSpace): PsiElemen
|
||||
beforeWhiteSpaceText += "\n"
|
||||
}
|
||||
|
||||
val factory = JetPsiFactory(whiteSpace.project)
|
||||
val factory = KtPsiFactory(whiteSpace.project)
|
||||
|
||||
val insertAfter = whiteSpace.prevSibling
|
||||
whiteSpace.delete()
|
||||
@@ -143,9 +143,9 @@ private fun removeAfterOffset(offset: Int, whiteSpace: PsiWhiteSpace): PsiElemen
|
||||
return whiteSpace
|
||||
}
|
||||
|
||||
public fun <T : JetDeclaration> insertMembersAfter(
|
||||
public fun <T : KtDeclaration> insertMembersAfter(
|
||||
editor: Editor?,
|
||||
classOrObject: JetClassOrObject,
|
||||
classOrObject: KtClassOrObject,
|
||||
members: Collection<T>,
|
||||
anchor: PsiElement? = null
|
||||
): List<T> {
|
||||
@@ -170,6 +170,6 @@ public fun <T : JetDeclaration> insertMembersAfter(
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T : JetDeclaration> insertMember(editor: Editor, classOrObject: JetClassOrObject, declaration: T): T {
|
||||
public fun <T : KtDeclaration> insertMember(editor: Editor, classOrObject: KtClassOrObject, declaration: T): T {
|
||||
return insertMembersAfter(editor, classOrObject, listOf(declaration)).single()
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import com.intellij.psi.PsiMember
|
||||
import com.intellij.psi.PsiPackage
|
||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ public fun PsiElement.getKotlinFqName(): FqName? {
|
||||
val prefix = element.getContainingClass()?.getQualifiedName()
|
||||
FqName(if (prefix != null) "$prefix.$name" else name)
|
||||
}
|
||||
is JetNamedDeclaration -> element.getFqName()
|
||||
is KtNamedDeclaration -> element.getFqName()
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.frontend.di.createLazyResolveSession
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
@@ -49,7 +49,7 @@ public class BuiltInsReferenceResolver(val project: Project, val startupManager:
|
||||
|
||||
@Volatile private var moduleDescriptor: ModuleDescriptor? = null
|
||||
|
||||
@Volatile public var builtInsSources: Set<JetFile>? = null
|
||||
@Volatile public var builtInsSources: Set<KtFile>? = null
|
||||
private set
|
||||
|
||||
@Volatile private var builtinsPackageFragment: PackageFragmentDescriptor? = null
|
||||
@@ -85,18 +85,18 @@ public class BuiltInsReferenceResolver(val project: Project, val startupManager:
|
||||
}
|
||||
}
|
||||
|
||||
private fun getJetBuiltInsFiles(): Set<JetFile> {
|
||||
return getBuiltInsDirUrls().flatMapTo(hashSetOf<JetFile>()) { getBuiltInSourceFiles(it) }
|
||||
private fun getJetBuiltInsFiles(): Set<KtFile> {
|
||||
return getBuiltInsDirUrls().flatMapTo(hashSetOf<KtFile>()) { getBuiltInSourceFiles(it) }
|
||||
}
|
||||
|
||||
private fun getBuiltInSourceFiles(url: URL): Set<JetFile> {
|
||||
private fun getBuiltInSourceFiles(url: URL): Set<KtFile> {
|
||||
val fromUrl = VfsUtilCore.convertFromUrl(url)
|
||||
val vf = VirtualFileManager.getInstance().findFileByUrl(fromUrl)
|
||||
assert(vf != null) { "Virtual file not found by URL: $url" }
|
||||
|
||||
val psiDirectory = PsiManager.getInstance(project).findDirectory(vf!!)
|
||||
assert(psiDirectory != null) { "No PsiDirectory for $vf" }
|
||||
return psiDirectory!!.getFiles().filterIsInstance<JetFile>().toHashSet()
|
||||
return psiDirectory!!.getFiles().filterIsInstance<KtFile>().toHashSet()
|
||||
}
|
||||
|
||||
private fun findCurrentDescriptorForMember(originalDescriptor: MemberDescriptor): DeclarationDescriptor? {
|
||||
@@ -166,7 +166,7 @@ public class BuiltInsReferenceResolver(val project: Project, val startupManager:
|
||||
return url != null && VfsUtilCore.isUnder(url, builtInDirUrls)
|
||||
}
|
||||
|
||||
private fun getMemberScope(parent: DeclarationDescriptor?): JetScope? = when(parent) {
|
||||
private fun getMemberScope(parent: DeclarationDescriptor?): KtScope? = when(parent) {
|
||||
is ClassDescriptor -> parent.getDefaultType().getMemberScope()
|
||||
is PackageFragmentDescriptor -> parent.getMemberScope()
|
||||
else -> null
|
||||
|
||||
+20
-20
@@ -21,18 +21,18 @@ import com.intellij.psi.*
|
||||
import com.intellij.util.ProcessingContext
|
||||
import org.jetbrains.kotlin.idea.kdoc.KDocReference
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
public class JetReferenceContributor() : PsiReferenceContributor() {
|
||||
public class KotlinReferenceContributor() : PsiReferenceContributor() {
|
||||
public override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) {
|
||||
with(registrar) {
|
||||
registerProvider(javaClass<JetSimpleNameExpression>()) {
|
||||
JetSimpleNameReference(it)
|
||||
registerProvider(javaClass<KtSimpleNameExpression>()) {
|
||||
KtSimpleNameReference(it)
|
||||
}
|
||||
|
||||
registerMultiProvider(javaClass<JetNameReferenceExpression>()) {
|
||||
if (it.getReferencedNameElementType() != JetTokens.IDENTIFIER) return@registerMultiProvider emptyArray()
|
||||
registerMultiProvider(javaClass<KtNameReferenceExpression>()) {
|
||||
if (it.getReferencedNameElementType() != KtTokens.IDENTIFIER) return@registerMultiProvider emptyArray()
|
||||
|
||||
when (it.readWriteAccess(useResolveForReadWrite = false)) {
|
||||
ReferenceAccess.READ -> arrayOf(SyntheticPropertyAccessorReference.Getter(it))
|
||||
@@ -41,28 +41,28 @@ public class JetReferenceContributor() : PsiReferenceContributor() {
|
||||
}
|
||||
}
|
||||
|
||||
registerProvider(javaClass<JetConstructorDelegationReferenceExpression>()) {
|
||||
JetConstructorDelegationReference(it)
|
||||
registerProvider(javaClass<KtConstructorDelegationReferenceExpression>()) {
|
||||
KtConstructorDelegationReference(it)
|
||||
}
|
||||
|
||||
registerProvider(javaClass<JetCallExpression>()) {
|
||||
JetInvokeFunctionReference(it)
|
||||
registerProvider(javaClass<KtCallExpression>()) {
|
||||
KtInvokeFunctionReference(it)
|
||||
}
|
||||
|
||||
registerProvider(javaClass<JetArrayAccessExpression>()) {
|
||||
JetArrayAccessReference(it)
|
||||
registerProvider(javaClass<KtArrayAccessExpression>()) {
|
||||
KtArrayAccessReference(it)
|
||||
}
|
||||
|
||||
registerProvider(javaClass<JetForExpression>()) {
|
||||
JetForLoopInReference(it)
|
||||
registerProvider(javaClass<KtForExpression>()) {
|
||||
KtForLoopInReference(it)
|
||||
}
|
||||
|
||||
registerProvider(javaClass<JetPropertyDelegate>()) {
|
||||
JetPropertyDelegationMethodsReference(it)
|
||||
registerProvider(javaClass<KtPropertyDelegate>()) {
|
||||
KtPropertyDelegationMethodsReference(it)
|
||||
}
|
||||
|
||||
registerProvider(javaClass<JetMultiDeclaration>()) {
|
||||
JetMultiDeclarationReference(it)
|
||||
registerProvider(javaClass<KtMultiDeclaration>()) {
|
||||
KtMultiDeclarationReference(it)
|
||||
}
|
||||
|
||||
registerProvider(javaClass<KDocName>()) {
|
||||
@@ -71,11 +71,11 @@ public class JetReferenceContributor() : PsiReferenceContributor() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <E : JetElement> PsiReferenceRegistrar.registerProvider(elementClass: Class<E>, factory: (E) -> JetReference) {
|
||||
private fun <E : KtElement> PsiReferenceRegistrar.registerProvider(elementClass: Class<E>, factory: (E) -> KtReference) {
|
||||
registerMultiProvider(elementClass, { arrayOf(factory(it)) })
|
||||
}
|
||||
|
||||
private fun <E : JetElement> PsiReferenceRegistrar.registerMultiProvider(elementClass: Class<E>, factory: (E) -> Array<PsiReference>) {
|
||||
private fun <E : KtElement> PsiReferenceRegistrar.registerMultiProvider(elementClass: Class<E>, factory: (E) -> Array<PsiReference>) {
|
||||
registerReferenceProvider(PlatformPatterns.psiElement(elementClass), object: PsiReferenceProvider() {
|
||||
override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array<PsiReference> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
+8
-8
@@ -25,9 +25,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.JetArrayAccessExpression;
|
||||
import org.jetbrains.kotlin.psi.JetContainerNode;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.KtArrayAccessExpression;
|
||||
import org.jetbrains.kotlin.psi.KtContainerNode;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
|
||||
@@ -38,9 +38,9 @@ import java.util.List;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.INDEXED_LVALUE_GET;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.INDEXED_LVALUE_SET;
|
||||
|
||||
public class JetArrayAccessReference extends JetSimpleReference<JetArrayAccessExpression> implements MultiRangeReference {
|
||||
public class KtArrayAccessReference extends KtSimpleReference<KtArrayAccessExpression> implements MultiRangeReference {
|
||||
|
||||
public JetArrayAccessReference(@NotNull JetArrayAccessExpression expression) {
|
||||
public KtArrayAccessReference(@NotNull KtArrayAccessExpression expression) {
|
||||
super(expression);
|
||||
}
|
||||
|
||||
@@ -71,13 +71,13 @@ public class JetArrayAccessReference extends JetSimpleReference<JetArrayAccessEx
|
||||
public List<TextRange> getRanges() {
|
||||
List<TextRange> list = new ArrayList<TextRange>();
|
||||
|
||||
JetContainerNode indices = getExpression().getIndicesNode();
|
||||
TextRange textRange = indices.getNode().findChildByType(JetTokens.LBRACKET).getTextRange();
|
||||
KtContainerNode indices = getExpression().getIndicesNode();
|
||||
TextRange textRange = indices.getNode().findChildByType(KtTokens.LBRACKET).getTextRange();
|
||||
TextRange lBracketRange = textRange.shiftRight(-getExpression().getTextOffset());
|
||||
|
||||
list.add(lBracketRange);
|
||||
|
||||
ASTNode rBracket = indices.getNode().findChildByType(JetTokens.RBRACKET);
|
||||
ASTNode rBracket = indices.getNode().findChildByType(KtTokens.RBRACKET);
|
||||
if (rBracket != null) {
|
||||
textRange = rBracket.getTextRange();
|
||||
TextRange rBracketRange = textRange.shiftRight(-getExpression().getTextOffset());
|
||||
+3
-3
@@ -17,10 +17,10 @@
|
||||
package org.jetbrains.kotlin.idea.references;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.kotlin.psi.JetConstructorDelegationReferenceExpression;
|
||||
import org.jetbrains.kotlin.psi.KtConstructorDelegationReferenceExpression;
|
||||
|
||||
public class JetConstructorDelegationReference extends JetSimpleReference<JetConstructorDelegationReferenceExpression> {
|
||||
public JetConstructorDelegationReference(JetConstructorDelegationReferenceExpression expression) {
|
||||
public class KtConstructorDelegationReference extends KtSimpleReference<KtConstructorDelegationReferenceExpression> {
|
||||
public KtConstructorDelegationReference(KtConstructorDelegationReferenceExpression expression) {
|
||||
super(expression);
|
||||
}
|
||||
|
||||
+3
-3
@@ -18,11 +18,11 @@ package org.jetbrains.kotlin.idea.references
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetForExpression
|
||||
import org.jetbrains.kotlin.psi.KtForExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import java.util.Collections
|
||||
import java.util.*
|
||||
|
||||
public class JetForLoopInReference(element: JetForExpression) : JetMultiReference<JetForExpression>(element) {
|
||||
public class KtForLoopInReference(element: KtForExpression) : KtMultiReference<KtForExpression>(element) {
|
||||
|
||||
override fun getRangeInElement(): TextRange {
|
||||
val inKeywordNode = expression.getInKeywordNode()
|
||||
+9
-9
@@ -23,7 +23,7 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
@@ -35,9 +35,9 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JetInvokeFunctionReference extends JetSimpleReference<JetCallExpression> implements MultiRangeReference {
|
||||
public class KtInvokeFunctionReference extends KtSimpleReference<KtCallExpression> implements MultiRangeReference {
|
||||
|
||||
public JetInvokeFunctionReference(@NotNull JetCallExpression expression) {
|
||||
public KtInvokeFunctionReference(@NotNull KtCallExpression expression) {
|
||||
super(expression);
|
||||
}
|
||||
|
||||
@@ -64,16 +64,16 @@ public class JetInvokeFunctionReference extends JetSimpleReference<JetCallExpres
|
||||
@Override
|
||||
public List<TextRange> getRanges() {
|
||||
List<TextRange> list = new ArrayList<TextRange>();
|
||||
JetValueArgumentList valueArgumentList = getExpression().getValueArgumentList();
|
||||
KtValueArgumentList valueArgumentList = getExpression().getValueArgumentList();
|
||||
if (valueArgumentList != null) {
|
||||
if (valueArgumentList.getArguments().size() > 0) {
|
||||
ASTNode valueArgumentListNode = valueArgumentList.getNode();
|
||||
ASTNode lPar = valueArgumentListNode.findChildByType(JetTokens.LPAR);
|
||||
ASTNode lPar = valueArgumentListNode.findChildByType(KtTokens.LPAR);
|
||||
if (lPar != null) {
|
||||
list.add(getRange(lPar));
|
||||
}
|
||||
|
||||
ASTNode rPar = valueArgumentListNode.findChildByType(JetTokens.RPAR);
|
||||
ASTNode rPar = valueArgumentListNode.findChildByType(KtTokens.RPAR);
|
||||
if (rPar != null) {
|
||||
list.add(getRange(rPar));
|
||||
}
|
||||
@@ -83,9 +83,9 @@ public class JetInvokeFunctionReference extends JetSimpleReference<JetCallExpres
|
||||
}
|
||||
}
|
||||
|
||||
List<JetFunctionLiteralArgument> functionLiteralArguments = getExpression().getFunctionLiteralArguments();
|
||||
for (JetFunctionLiteralArgument functionLiteralArgument : functionLiteralArguments) {
|
||||
JetFunctionLiteralExpression functionLiteralExpression = functionLiteralArgument.getFunctionLiteral();
|
||||
List<KtFunctionLiteralArgument> functionLiteralArguments = getExpression().getFunctionLiteralArguments();
|
||||
for (KtFunctionLiteralArgument functionLiteralArgument : functionLiteralArguments) {
|
||||
KtFunctionLiteralExpression functionLiteralExpression = functionLiteralArgument.getFunctionLiteral();
|
||||
list.add(getRange(functionLiteralExpression.getLeftCurlyBrace()));
|
||||
ASTNode rightCurlyBrace = functionLiteralExpression.getRightCurlyBrace();
|
||||
if (rightCurlyBrace != null) {
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.references
|
||||
|
||||
import org.jetbrains.kotlin.psi.JetMultiDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtMultiDeclaration
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import com.intellij.openapi.util.TextRange
|
||||
@@ -25,7 +25,7 @@ import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
|
||||
class JetMultiDeclarationReference(element: JetMultiDeclaration) : JetMultiReference<JetMultiDeclaration>(element) {
|
||||
class KtMultiDeclarationReference(element: KtMultiDeclaration) : KtMultiReference<KtMultiDeclaration>(element) {
|
||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
return expression.getEntries().map { entry ->
|
||||
context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry)?.getCandidateDescriptor()
|
||||
+4
-4
@@ -19,13 +19,13 @@ package org.jetbrains.kotlin.idea.references
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetProperty
|
||||
import org.jetbrains.kotlin.psi.JetPropertyDelegate
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtPropertyDelegate
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class JetPropertyDelegationMethodsReference(element: JetPropertyDelegate) : JetMultiReference<JetPropertyDelegate>(element) {
|
||||
public class KtPropertyDelegationMethodsReference(element: KtPropertyDelegate) : KtMultiReference<KtPropertyDelegate>(element) {
|
||||
|
||||
override fun getRangeInElement(): TextRange {
|
||||
val byKeywordNode = expression.getByKeywordNode()
|
||||
@@ -34,7 +34,7 @@ public class JetPropertyDelegationMethodsReference(element: JetPropertyDelegate)
|
||||
}
|
||||
|
||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
val property = expression.getStrictParentOfType<JetProperty>()
|
||||
val property = expression.getStrictParentOfType<KtProperty>()
|
||||
if (property == null) {
|
||||
return Collections.emptyList()
|
||||
}
|
||||
+10
-10
@@ -22,22 +22,22 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.Collections
|
||||
import java.util.*
|
||||
|
||||
public interface JetReference : PsiPolyVariantReference {
|
||||
public interface KtReference : PsiPolyVariantReference {
|
||||
fun resolveToDescriptors(bindingContext: BindingContext): Collection<DeclarationDescriptor>
|
||||
|
||||
override fun getElement(): JetElement
|
||||
override fun getElement(): KtElement
|
||||
}
|
||||
|
||||
public abstract class AbstractJetReference<T : JetElement>(element: T)
|
||||
: PsiPolyVariantReferenceBase<T>(element), JetReference {
|
||||
public abstract class AbstractJetReference<T : KtElement>(element: T)
|
||||
: PsiPolyVariantReferenceBase<T>(element), KtReference {
|
||||
|
||||
public val expression: T
|
||||
get() = getElement()
|
||||
@@ -107,7 +107,7 @@ public abstract class AbstractJetReference<T : JetElement>(element: T)
|
||||
|
||||
private fun getLabelTargets(context: BindingContext): Collection<PsiElement>? {
|
||||
val reference = expression
|
||||
if (reference !is JetReferenceExpression) {
|
||||
if (reference !is KtReferenceExpression) {
|
||||
return null
|
||||
}
|
||||
val labelTarget = context[BindingContext.LABEL_TARGET, reference]
|
||||
@@ -120,8 +120,8 @@ public abstract class AbstractJetReference<T : JetElement>(element: T)
|
||||
override fun toString() = javaClass.getSimpleName() + ": " + expression.getText()
|
||||
}
|
||||
|
||||
public abstract class JetSimpleReference<T : JetReferenceExpression>(expression: T) : AbstractJetReference<T>(expression) {
|
||||
public abstract class KtSimpleReference<T : KtReferenceExpression>(expression: T) : AbstractJetReference<T>(expression) {
|
||||
override fun getTargetDescriptors(context: BindingContext) = expression.getReferenceTargets(context)
|
||||
}
|
||||
|
||||
public abstract class JetMultiReference<T : JetElement>(expression: T) : AbstractJetReference<T>(expression)
|
||||
public abstract class KtMultiReference<T : KtElement>(expression: T) : AbstractJetReference<T>(expression)
|
||||
+22
-22
@@ -25,8 +25,8 @@ import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
|
||||
import org.jetbrains.kotlin.idea.intentions.OperatorToFunctionIntention
|
||||
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences
|
||||
import org.jetbrains.kotlin.lexer.JetToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.isOneSegmentFQN
|
||||
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
|
||||
class JetSimpleNameReference(expression: JetSimpleNameExpression) : JetSimpleReference<JetSimpleNameExpression>(expression) {
|
||||
class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleReference<KtSimpleNameExpression>(expression) {
|
||||
override fun isReferenceTo(element: PsiElement?): Boolean {
|
||||
if (element != null) {
|
||||
if (!canBeReferenceTo(element)) return false
|
||||
@@ -63,10 +63,10 @@ class JetSimpleNameReference(expression: JetSimpleNameExpression) : JetSimpleRef
|
||||
}
|
||||
|
||||
override fun canRename(): Boolean {
|
||||
if (expression.getParentOfTypeAndBranch<JetWhenConditionInRange>(strict = true){ getOperationReference() } != null) return false
|
||||
if (expression.getParentOfTypeAndBranch<KtWhenConditionInRange>(strict = true){ getOperationReference() } != null) return false
|
||||
|
||||
val elementType = expression.getReferencedNameElementType()
|
||||
if (elementType == JetTokens.PLUSPLUS || elementType == JetTokens.MINUSMINUS) return false
|
||||
if (elementType == KtTokens.PLUSPLUS || elementType == KtTokens.MINUSMINUS) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -78,14 +78,14 @@ class JetSimpleNameReference(expression: JetSimpleNameExpression) : JetSimpleRef
|
||||
// Do not rename if the reference corresponds to synthesized component function
|
||||
val expressionText = expression.getText()
|
||||
if (expressionText != null && Name.isValidIdentifier(expressionText)) {
|
||||
if (isComponentLike(Name.identifier(expressionText)) && resolve() is JetParameter) {
|
||||
if (isComponentLike(Name.identifier(expressionText)) && resolve() is KtParameter) {
|
||||
return expression
|
||||
}
|
||||
}
|
||||
|
||||
val psiFactory = JetPsiFactory(expression)
|
||||
val psiFactory = KtPsiFactory(expression)
|
||||
val element = when (expression.getReferencedNameElementType()) {
|
||||
JetTokens.FIELD_IDENTIFIER -> psiFactory.createFieldIdentifier(newElementName)
|
||||
KtTokens.FIELD_IDENTIFIER -> psiFactory.createFieldIdentifier(newElementName)
|
||||
|
||||
else -> {
|
||||
Extensions.getArea(expression.getProject()).getExtensionPoint(SimpleNameReferenceExtension.EP_NAME).getExtensions()
|
||||
@@ -98,8 +98,8 @@ class JetSimpleNameReference(expression: JetSimpleNameExpression) : JetSimpleRef
|
||||
val nameElement = expression.getReferencedNameElement()
|
||||
|
||||
val elementType = nameElement.getNode().getElementType()
|
||||
if (elementType is JetToken && OperatorConventions.getNameForOperationSymbol(elementType) != null) {
|
||||
val opExpression = expression.getParent() as? JetOperationExpression
|
||||
if (elementType is KtToken && OperatorConventions.getNameForOperationSymbol(elementType) != null) {
|
||||
val opExpression = expression.getParent() as? KtOperationExpression
|
||||
if (opExpression != null) {
|
||||
val (newExpression, newNameElement) = OperatorToFunctionIntention.convert(opExpression)
|
||||
newNameElement.replace(element)
|
||||
@@ -129,16 +129,16 @@ class JetSimpleNameReference(expression: JetSimpleNameExpression) : JetSimpleRef
|
||||
if (fqName.isRoot) return expression
|
||||
|
||||
// not supported for infix calls and operators
|
||||
if (expression !is JetNameReferenceExpression) return expression
|
||||
if (expression.parent is JetThisExpression || expression.parent is JetSuperExpression) return expression // TODO: it's a bad design of PSI tree, we should change it
|
||||
if (expression !is KtNameReferenceExpression) return expression
|
||||
if (expression.parent is KtThisExpression || expression.parent is KtSuperExpression) return expression // TODO: it's a bad design of PSI tree, we should change it
|
||||
|
||||
val newExpression = expression.changeQualifiedName(fqName).getQualifiedElementSelector() as JetNameReferenceExpression
|
||||
val newExpression = expression.changeQualifiedName(fqName).getQualifiedElementSelector() as KtNameReferenceExpression
|
||||
val newQualifiedElement = newExpression.getQualifiedElement()
|
||||
|
||||
if (shorteningMode == ShorteningMode.NO_SHORTENING) return newExpression
|
||||
|
||||
val needToShorten =
|
||||
PsiTreeUtil.getParentOfType(expression, javaClass<JetImportDirective>(), javaClass<JetPackageDirective>()) == null
|
||||
PsiTreeUtil.getParentOfType(expression, javaClass<KtImportDirective>(), javaClass<KtPackageDirective>()) == null
|
||||
if (needToShorten) {
|
||||
if (shorteningMode == ShorteningMode.FORCED_SHORTENING) {
|
||||
ShortenReferences.DEFAULT.process(newQualifiedElement)
|
||||
@@ -152,17 +152,17 @@ class JetSimpleNameReference(expression: JetSimpleNameExpression) : JetSimpleRef
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace [[JetNameReferenceExpression]] (and its enclosing qualifier) with qualified element given by FqName
|
||||
* Result is either the same as original element, or [[JetQualifiedExpression]], or [[JetUserType]]
|
||||
* Replace [[KtNameReferenceExpression]] (and its enclosing qualifier) with qualified element given by FqName
|
||||
* Result is either the same as original element, or [[KtQualifiedExpression]], or [[KtUserType]]
|
||||
* Note that FqName may not be empty
|
||||
*/
|
||||
private fun JetNameReferenceExpression.changeQualifiedName(fqName: FqName): JetElement {
|
||||
private fun KtNameReferenceExpression.changeQualifiedName(fqName: FqName): KtElement {
|
||||
assert(!fqName.isRoot()) { "Can't set empty FqName for element $this" }
|
||||
|
||||
val shortName = fqName.shortName().asString()
|
||||
val psiFactory = JetPsiFactory(this)
|
||||
val fqNameBase = (getParent() as? JetCallExpression)?.let { parent ->
|
||||
val callCopy = parent.copy() as JetCallExpression
|
||||
val psiFactory = KtPsiFactory(this)
|
||||
val fqNameBase = (getParent() as? KtCallExpression)?.let { parent ->
|
||||
val callCopy = parent.copy() as KtCallExpression
|
||||
callCopy.getCalleeExpression()!!.replace(psiFactory.createSimpleName(shortName)).getParent()!!.getText()
|
||||
} ?: shortName
|
||||
|
||||
@@ -170,12 +170,12 @@ class JetSimpleNameReference(expression: JetSimpleNameExpression) : JetSimpleRef
|
||||
|
||||
val elementToReplace = getQualifiedElement()
|
||||
return when (elementToReplace) {
|
||||
is JetUserType -> {
|
||||
is KtUserType -> {
|
||||
val typeText = "$text${elementToReplace.getTypeArgumentList()?.getText() ?: ""}"
|
||||
elementToReplace.replace(psiFactory.createType(typeText).typeElement!!)
|
||||
}
|
||||
else -> elementToReplace.replace(psiFactory.createExpression(text))
|
||||
} as JetElement
|
||||
} as KtElement
|
||||
}
|
||||
|
||||
override fun getCanonicalText(): String = expression.getText()
|
||||
+6
-6
@@ -22,13 +22,13 @@ import com.intellij.util.SmartList
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpression, private val getter: Boolean) : JetSimpleReference<JetNameReferenceExpression>(expression) {
|
||||
sealed class SyntheticPropertyAccessorReference(expression: KtNameReferenceExpression, private val getter: Boolean) : KtSimpleReference<KtNameReferenceExpression>(expression) {
|
||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
val descriptors = super.getTargetDescriptors(context)
|
||||
if (descriptors.none { it is SyntheticJavaPropertyDescriptor }) return emptyList()
|
||||
@@ -65,11 +65,11 @@ sealed class SyntheticPropertyAccessorReference(expression: JetNameReferenceExpr
|
||||
}
|
||||
if (newName == null) return expression //TODO: handle the case when get/set becomes ordinary method
|
||||
|
||||
val nameIdentifier = JetPsiFactory(expression).createNameIdentifier(newName.getIdentifier())
|
||||
val nameIdentifier = KtPsiFactory(expression).createNameIdentifier(newName.getIdentifier())
|
||||
expression.getReferencedNameElement().replace(nameIdentifier)
|
||||
return expression
|
||||
}
|
||||
|
||||
public class Getter(expression: JetNameReferenceExpression) : SyntheticPropertyAccessorReference(expression, true)
|
||||
public class Setter(expression: JetNameReferenceExpression) : SyntheticPropertyAccessorReference(expression, false)
|
||||
public class Getter(expression: KtNameReferenceExpression) : SyntheticPropertyAccessorReference(expression, true)
|
||||
public class Setter(expression: KtNameReferenceExpression) : SyntheticPropertyAccessorReference(expression, false)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.idea.kdoc.KDocReference
|
||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
@@ -49,7 +49,7 @@ public val PsiReference.unwrappedTargets: Set<PsiElement>
|
||||
fun PsiElement.adjust(): PsiElement? {
|
||||
val target = unwrapped?.getOriginalElement()
|
||||
return when {
|
||||
target is JetPropertyAccessor -> target.getNonStrictParentOfType<JetProperty>()
|
||||
target is KtPropertyAccessor -> target.getNonStrictParentOfType<KtProperty>()
|
||||
else -> target
|
||||
}
|
||||
}
|
||||
@@ -74,11 +74,11 @@ public fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean {
|
||||
|
||||
// Optimizations
|
||||
when (this) {
|
||||
is JetInvokeFunctionReference -> {
|
||||
if (candidateTarget !is JetNamedFunction) return false
|
||||
is KtInvokeFunctionReference -> {
|
||||
if (candidateTarget !is KtNamedFunction) return false
|
||||
}
|
||||
is JetMultiDeclarationReference -> {
|
||||
if (candidateTarget !is JetNamedFunction && candidateTarget !is JetParameter) return false
|
||||
is KtMultiDeclarationReference -> {
|
||||
if (candidateTarget !is KtNamedFunction && candidateTarget !is KtParameter) return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,27 +87,27 @@ public fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean {
|
||||
// TODO: Investigate why PsiCompiledElement identity changes
|
||||
if (unwrappedCandidate is PsiCompiledElement && targets.any { it.isEquivalentTo(unwrappedCandidate) }) return true
|
||||
|
||||
if (this is JetReference) {
|
||||
if (this is KtReference) {
|
||||
return targets.any {
|
||||
it.isConstructorOf(unwrappedCandidate)
|
||||
|| it is JetObjectDeclaration && it.isCompanion() && it.getNonStrictParentOfType<JetClass>() == unwrappedCandidate
|
||||
|| it is KtObjectDeclaration && it.isCompanion() && it.getNonStrictParentOfType<KtClass>() == unwrappedCandidate
|
||||
}
|
||||
}
|
||||
// TODO: Workaround for Kotlin constructor search in Java code. To be removed after refactoring of the search API
|
||||
else if (this is PsiJavaCodeReferenceElement && unwrappedCandidate is JetConstructor<*>) {
|
||||
else if (this is PsiJavaCodeReferenceElement && unwrappedCandidate is KtConstructor<*>) {
|
||||
var parent = getElement().getParent()
|
||||
if (parent is PsiAnonymousClass) {
|
||||
parent = parent.getParent()
|
||||
}
|
||||
if ((parent as? PsiNewExpression)?.resolveConstructor()?.unwrapped == unwrappedCandidate) return true
|
||||
}
|
||||
if (this is PsiJavaCodeReferenceElement && candidateTarget is JetObjectDeclaration && unwrappedTargets.size() == 1) {
|
||||
if (this is PsiJavaCodeReferenceElement && candidateTarget is KtObjectDeclaration && unwrappedTargets.size() == 1) {
|
||||
val referredClass = unwrappedTargets.first()
|
||||
if (referredClass is JetClass && candidateTarget in referredClass.getCompanionObjects()) {
|
||||
if (referredClass is KtClass && candidateTarget in referredClass.getCompanionObjects()) {
|
||||
if (getParent() is PsiImportStaticStatement) return true
|
||||
|
||||
return getParent().getReference()?.unwrappedTargets?.any {
|
||||
(it is JetProperty || it is JetNamedFunction) && it.getParent()?.getParent() == candidateTarget
|
||||
(it is KtProperty || it is KtNamedFunction) && it.getParent()?.getParent() == candidateTarget
|
||||
} ?: false
|
||||
}
|
||||
}
|
||||
@@ -118,9 +118,9 @@ private fun PsiElement.isConstructorOf(unwrappedCandidate: PsiElement) =
|
||||
// call to Java constructor
|
||||
(this is PsiMethod && isConstructor() && getContainingClass() == unwrappedCandidate) ||
|
||||
// call to Kotlin constructor
|
||||
(this is JetConstructor<*> && getContainingClassOrObject() == unwrappedCandidate)
|
||||
(this is KtConstructor<*> && getContainingClassOrObject() == unwrappedCandidate)
|
||||
|
||||
fun AbstractJetReference<out JetExpression>.renameImplicitConventionalCall(newName: String?): JetExpression {
|
||||
fun AbstractJetReference<out KtExpression>.renameImplicitConventionalCall(newName: String?): KtExpression {
|
||||
if (newName == null) return expression
|
||||
|
||||
val (newExpression, newNameElement) = OperatorToFunctionIntention.convert(expression)
|
||||
@@ -128,21 +128,21 @@ fun AbstractJetReference<out JetExpression>.renameImplicitConventionalCall(newNa
|
||||
return newExpression
|
||||
}
|
||||
|
||||
val JetSimpleNameExpression.mainReference: JetSimpleNameReference
|
||||
val KtSimpleNameExpression.mainReference: KtSimpleNameReference
|
||||
get() = getReferences().firstIsInstance()
|
||||
|
||||
val JetReferenceExpression.mainReference: JetReference
|
||||
get() = if (this is JetSimpleNameExpression) mainReference else getReferences().firstIsInstance<JetReference>()
|
||||
val KtReferenceExpression.mainReference: KtReference
|
||||
get() = if (this is KtSimpleNameExpression) mainReference else getReferences().firstIsInstance<KtReference>()
|
||||
|
||||
val KDocName.mainReference: KDocReference
|
||||
get() = getReferences().firstIsInstance()
|
||||
|
||||
val JetElement.mainReference: JetReference?
|
||||
val KtElement.mainReference: KtReference?
|
||||
get() {
|
||||
return when {
|
||||
this is JetReferenceExpression -> mainReference
|
||||
this is KtReferenceExpression -> mainReference
|
||||
this is KDocName -> mainReference
|
||||
else -> getReferences().firstIsInstanceOrNull<JetReference>()
|
||||
else -> getReferences().firstIsInstanceOrNull<KtReference>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,12 +152,12 @@ public enum class ReferenceAccess {
|
||||
READ, WRITE, READ_WRITE
|
||||
}
|
||||
|
||||
public fun JetExpression.readWriteAccess(useResolveForReadWrite: Boolean): ReferenceAccess {
|
||||
public fun KtExpression.readWriteAccess(useResolveForReadWrite: Boolean): ReferenceAccess {
|
||||
var expression = getQualifiedExpressionForSelectorOrThis()
|
||||
loop@ while (true) {
|
||||
val parent = expression.parent
|
||||
when (parent) {
|
||||
is JetParenthesizedExpression, is JetAnnotatedExpression, is JetLabeledExpression -> expression = parent as JetExpression
|
||||
is KtParenthesizedExpression, is KtAnnotatedExpression, is KtLabeledExpression -> expression = parent as KtExpression
|
||||
else -> break@loop
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public fun JetExpression.readWriteAccess(useResolveForReadWrite: Boolean): Refer
|
||||
val assignment = expression.getAssignmentByLHS()
|
||||
if (assignment != null) {
|
||||
when (assignment.operationToken) {
|
||||
JetTokens.EQ -> return ReferenceAccess.WRITE
|
||||
KtTokens.EQ -> return ReferenceAccess.WRITE
|
||||
|
||||
else -> {
|
||||
if (!useResolveForReadWrite) return ReferenceAccess.READ_WRITE
|
||||
@@ -181,17 +181,17 @@ public fun JetExpression.readWriteAccess(useResolveForReadWrite: Boolean): Refer
|
||||
}
|
||||
}
|
||||
|
||||
return if ((expression.parent as? JetUnaryExpression)?.operationToken in constant { setOf(JetTokens.PLUSPLUS, JetTokens.MINUSMINUS) })
|
||||
return if ((expression.parent as? KtUnaryExpression)?.operationToken in constant { setOf(KtTokens.PLUSPLUS, KtTokens.MINUSMINUS) })
|
||||
ReferenceAccess.READ_WRITE
|
||||
else
|
||||
ReferenceAccess.READ
|
||||
}
|
||||
|
||||
public fun JetReference.canBeResolvedViaImport(target: DeclarationDescriptor): Boolean {
|
||||
public fun KtReference.canBeResolvedViaImport(target: DeclarationDescriptor): Boolean {
|
||||
if (!target.canBeReferencedViaImport()) return false
|
||||
if (target.isExtension) return true // assume that any type of reference can use imports when resolved to extension
|
||||
val referenceExpression = this.element as? JetNameReferenceExpression ?: return false
|
||||
val referenceExpression = this.element as? KtNameReferenceExpression ?: return false
|
||||
if (CallTypeAndReceiver.detect(referenceExpression).receiver != null) return false
|
||||
if (element.parent is JetThisExpression || element.parent is JetSuperExpression) return false // TODO: it's a bad design of PSI tree, we should change it
|
||||
if (element.parent is KtThisExpression || element.parent is KtSuperExpression) return false // TODO: it's a bad design of PSI tree, we should change it
|
||||
return true
|
||||
}
|
||||
+7
-7
@@ -22,25 +22,25 @@ import com.intellij.psi.impl.search.IndexPatternBuilder
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
|
||||
import org.jetbrains.kotlin.lexer.JetLexer
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.lexer.KotlinLexer
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
public class KotlinIndexPatternBuilder: IndexPatternBuilder {
|
||||
private val TODO_COMMENT_TOKENS = TokenSet.orSet(JetTokens.COMMENTS, TokenSet.create(KDocTokens.KDOC))
|
||||
private val TODO_COMMENT_TOKENS = TokenSet.orSet(KtTokens.COMMENTS, TokenSet.create(KDocTokens.KDOC))
|
||||
|
||||
override fun getCommentTokenSet(file: PsiFile): TokenSet? {
|
||||
return if (file is JetFile) TODO_COMMENT_TOKENS else null
|
||||
return if (file is KtFile) TODO_COMMENT_TOKENS else null
|
||||
}
|
||||
|
||||
override fun getIndexingLexer(file: PsiFile): Lexer? {
|
||||
return if (file is JetFile) JetLexer() else null
|
||||
return if (file is KtFile) KotlinLexer() else null
|
||||
}
|
||||
|
||||
override fun getCommentStartDelta(tokenType: IElementType?): Int = 0
|
||||
|
||||
override fun getCommentEndDelta(tokenType: IElementType?): Int = when(tokenType) {
|
||||
JetTokens.BLOCK_COMMENT -> "*/".length()
|
||||
KtTokens.BLOCK_COMMENT -> "*/".length()
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,19 +28,19 @@ import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.ALL_SEARCHABLE_OPERATIONS
|
||||
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
|
||||
import org.jetbrains.kotlin.lexer.JetLexer
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KotlinLexer
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import java.util.*
|
||||
|
||||
val KOTLIN_NAMED_ARGUMENT_SEARCH_CONTEXT: Short = 0x20
|
||||
|
||||
class KotlinFilterLexer(private val occurrenceConsumer: OccurrenceConsumer): BaseFilterLexer(JetLexer(), occurrenceConsumer) {
|
||||
class KotlinFilterLexer(private val occurrenceConsumer: OccurrenceConsumer): BaseFilterLexer(KotlinLexer(), occurrenceConsumer) {
|
||||
private val codeTokens = TokenSet.orSet(
|
||||
TokenSet.create(*ALL_SEARCHABLE_OPERATIONS.toTypedArray()),
|
||||
TokenSet.create(JetTokens.IDENTIFIER, JetTokens.FIELD_IDENTIFIER)
|
||||
TokenSet.create(KtTokens.IDENTIFIER, KtTokens.FIELD_IDENTIFIER)
|
||||
)
|
||||
|
||||
private val commentTokens = TokenSet.orSet(JetTokens.COMMENTS, TokenSet.create(KDocTokens.KDOC))
|
||||
private val commentTokens = TokenSet.orSet(KtTokens.COMMENTS, TokenSet.create(KDocTokens.KDOC))
|
||||
|
||||
private val MAX_PREV_TOKENS = 2
|
||||
private val prevTokens = ArrayDeque<IElementType>(MAX_PREV_TOKENS)
|
||||
@@ -51,22 +51,22 @@ class KotlinFilterLexer(private val occurrenceConsumer: OccurrenceConsumer): Bas
|
||||
val tokenType = myDelegate.tokenType
|
||||
|
||||
when (tokenType) {
|
||||
JetTokens.EQ -> {
|
||||
if (prevTokens.peekFirst() == JetTokens.IDENTIFIER) {
|
||||
KtTokens.EQ -> {
|
||||
if (prevTokens.peekFirst() == KtTokens.IDENTIFIER) {
|
||||
val prevPrev = prevTokens.elementAtOrNull(1)
|
||||
if (prevPrev == JetTokens.COMMA || prevPrev == JetTokens.LPAR) {
|
||||
if (prevPrev == KtTokens.COMMA || prevPrev == KtTokens.LPAR) {
|
||||
occurrenceConsumer.addOccurrence(bufferSequence, null, prevTokenStart, prevTokenEnd, KOTLIN_NAMED_ARGUMENT_SEARCH_CONTEXT.toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JetTokens.LPAR -> {
|
||||
KtTokens.LPAR -> {
|
||||
if (isMultiDeclarationPosition()) {
|
||||
addOccurrenceInToken(UsageSearchContext.IN_CODE.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
JetTokens.IDENTIFIER -> {
|
||||
KtTokens.IDENTIFIER -> {
|
||||
if (myDelegate.tokenText.startsWith("`")) {
|
||||
scanWordsInToken(UsageSearchContext.IN_CODE.toInt(), false, false)
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class KotlinFilterLexer(private val occurrenceConsumer: OccurrenceConsumer): Bas
|
||||
|
||||
in codeTokens -> addOccurrenceInToken(UsageSearchContext.IN_CODE.toInt())
|
||||
|
||||
in JetTokens.STRINGS -> scanWordsInToken(UsageSearchContext.IN_STRINGS + UsageSearchContext.IN_FOREIGN_LANGUAGES, false, true)
|
||||
in KtTokens.STRINGS -> scanWordsInToken(UsageSearchContext.IN_STRINGS + UsageSearchContext.IN_FOREIGN_LANGUAGES, false, true)
|
||||
|
||||
in commentTokens -> {
|
||||
scanWordsInToken(UsageSearchContext.IN_COMMENTS.toInt(), false, false)
|
||||
@@ -99,8 +99,8 @@ class KotlinFilterLexer(private val occurrenceConsumer: OccurrenceConsumer): Bas
|
||||
|
||||
private fun isMultiDeclarationPosition(): Boolean {
|
||||
val first = prevTokens.peekFirst()
|
||||
if (first == JetTokens.VAL_KEYWORD || first == JetTokens.VAR_KEYWORD) return true
|
||||
return first == JetTokens.LPAR && prevTokens.elementAtOrNull(1) == JetTokens.FOR_KEYWORD
|
||||
if (first == KtTokens.VAL_KEYWORD || first == KtTokens.VAR_KEYWORD) return true
|
||||
return first == KtTokens.LPAR && prevTokens.elementAtOrNull(1) == KtTokens.FOR_KEYWORD
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import com.intellij.psi.PsiClass
|
||||
import com.intellij.util.Query
|
||||
import com.intellij.psi.PsiModifier
|
||||
import com.intellij.psi.PsiAnonymousClass
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch
|
||||
@@ -28,7 +28,7 @@ import com.intellij.util.EmptyQuery
|
||||
|
||||
public fun HierarchySearchRequest<*>.searchInheritors(): Query<PsiClass> {
|
||||
val psiClass: PsiClass? = when (originalElement) {
|
||||
is JetClassOrObject -> LightClassUtil.getPsiClass(originalElement)
|
||||
is KtClassOrObject -> LightClassUtil.getPsiClass(originalElement)
|
||||
is PsiClass -> originalElement
|
||||
else -> null
|
||||
}
|
||||
|
||||
+2
-2
@@ -28,13 +28,13 @@ import com.intellij.util.Query
|
||||
import org.jetbrains.kotlin.asJava.toLightMethods
|
||||
import org.jetbrains.kotlin.idea.search.allScope
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isOverridable
|
||||
import java.util.*
|
||||
|
||||
fun PsiElement.isOverridableElement(): Boolean = when (this) {
|
||||
is PsiMethod -> PsiUtil.canBeOverriden(this)
|
||||
is JetDeclaration -> isOverridable()
|
||||
is KtDeclaration -> isOverridable()
|
||||
else -> false
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
public class KotlinReadWriteAccessDetector : ReadWriteAccessDetector() {
|
||||
override fun isReadWriteAccessible(element: PsiElement) = element is JetVariableDeclaration || element is JetParameter
|
||||
override fun isReadWriteAccessible(element: PsiElement) = element is KtVariableDeclaration || element is KtParameter
|
||||
|
||||
override fun isDeclarationWriteAccess(element: PsiElement) = isReadWriteAccessible(element)
|
||||
|
||||
@@ -40,9 +40,9 @@ public class KotlinReadWriteAccessDetector : ReadWriteAccessDetector() {
|
||||
val refTarget = reference.resolve()
|
||||
if (refTarget is KotlinLightMethod) {
|
||||
val origin = refTarget.getOrigin()
|
||||
val declaration: JetNamedDeclaration = when (origin) {
|
||||
is JetPropertyAccessor -> origin.getNonStrictParentOfType<JetProperty>()
|
||||
is JetProperty, is JetParameter -> origin as JetNamedDeclaration
|
||||
val declaration: KtNamedDeclaration = when (origin) {
|
||||
is KtPropertyAccessor -> origin.getNonStrictParentOfType<KtProperty>()
|
||||
is KtProperty, is KtParameter -> origin as KtNamedDeclaration
|
||||
else -> null
|
||||
} ?: return ReadWriteAccessDetector.Access.ReadWrite
|
||||
|
||||
@@ -57,7 +57,7 @@ public class KotlinReadWriteAccessDetector : ReadWriteAccessDetector() {
|
||||
}
|
||||
|
||||
override fun getExpressionAccess(expression: PsiElement): ReadWriteAccessDetector.Access {
|
||||
if (expression !is JetExpression) { //TODO: there should be a more correct scheme of access type detection for cross-language references
|
||||
if (expression !is KtExpression) { //TODO: there should be a more correct scheme of access type detection for cross-language references
|
||||
return JavaReadWriteAccessDetector().getExpressionAccess(expression)
|
||||
}
|
||||
|
||||
|
||||
+27
-27
@@ -25,8 +25,8 @@ import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import com.intellij.util.Processor
|
||||
import org.jetbrains.kotlin.asJava.*
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.idea.JetFileType
|
||||
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.search.KOTLIN_NAMED_ARGUMENT_SEARCH_CONTEXT
|
||||
import org.jetbrains.kotlin.idea.search.allScope
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.*
|
||||
@@ -70,7 +70,7 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
|
||||
val effectiveSearchScope = runReadAction { queryParameters.effectiveSearchScope }
|
||||
|
||||
val refFilter: (PsiReference) -> Boolean = if (unwrappedElement is JetParameter)
|
||||
val refFilter: (PsiReference) -> Boolean = if (unwrappedElement is KtParameter)
|
||||
({ ref: PsiReference -> !ref.isNamedArgumentReference()/* they are processed later*/ })
|
||||
else
|
||||
({true})
|
||||
@@ -93,16 +93,16 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
resultProcessor)
|
||||
}
|
||||
|
||||
if (unwrappedElement is JetParameter) {
|
||||
if (unwrappedElement is KtParameter) {
|
||||
runReadAction { searchNamedArguments(unwrappedElement, queryParameters) }
|
||||
}
|
||||
|
||||
if (!(unwrappedElement is JetElement && isOnlyKotlinSearch(effectiveSearchScope))) {
|
||||
if (!(unwrappedElement is KtElement && isOnlyKotlinSearch(effectiveSearchScope))) {
|
||||
searchLightElements(queryParameters, element)
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchNamedArguments(parameter: JetParameter, queryParameters: ReferencesSearch.SearchParameters) {
|
||||
private fun searchNamedArguments(parameter: KtParameter, queryParameters: ReferencesSearch.SearchParameters) {
|
||||
val parameterName = parameter.name ?: return
|
||||
val function = parameter.ownerFunction ?: return
|
||||
if (function.nameAsName?.isSpecial ?: true) return
|
||||
@@ -127,7 +127,7 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
}
|
||||
|
||||
private fun PsiReference.isNamedArgumentReference(): Boolean {
|
||||
return this is JetSimpleNameReference && expression.parent is JetValueArgumentName
|
||||
return this is KtSimpleNameReference && expression.parent is KtValueArgumentName
|
||||
}
|
||||
|
||||
private class MyRequestResultProcessor(
|
||||
@@ -155,7 +155,7 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
if (isReferenceTo(element)) {
|
||||
return true
|
||||
}
|
||||
if (originalElement is JetNamedDeclaration) {
|
||||
if (originalElement is KtNamedDeclaration) {
|
||||
if (options.acceptCallableOverrides && isCallableOverrideUsage(originalElement)) {
|
||||
return true
|
||||
}
|
||||
@@ -171,14 +171,14 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
}
|
||||
|
||||
companion object {
|
||||
public fun processJetClassOrObject(element: JetClassOrObject, queryParameters: ReferencesSearch.SearchParameters) {
|
||||
public fun processJetClassOrObject(element: KtClassOrObject, queryParameters: ReferencesSearch.SearchParameters) {
|
||||
val className = element.getName()
|
||||
if (className != null) {
|
||||
val lightClass = runReadAction { LightClassUtil.getPsiClass(element) }
|
||||
if (lightClass != null) {
|
||||
searchNamedElement(queryParameters, lightClass, className)
|
||||
|
||||
if (element is JetObjectDeclaration && element.isCompanion()) {
|
||||
if (element is KtObjectDeclaration && element.isCompanion()) {
|
||||
val fieldForCompanionObject = runReadAction { LightClassUtil.getLightFieldForCompanionObject(element) }
|
||||
if (fieldForCompanionObject != null) {
|
||||
searchNamedElement(queryParameters, fieldForCompanionObject)
|
||||
@@ -187,7 +187,7 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
val kotlinReferencesSearchOptions = (queryParameters as? KotlinReferencesSearchParameters)?.kotlinOptions
|
||||
if (kotlinReferencesSearchOptions?.acceptCompanionObjectMembers == true) {
|
||||
runReadAction {
|
||||
val originClass = element.getStrictParentOfType<JetClass>()
|
||||
val originClass = element.getStrictParentOfType<KtClass>()
|
||||
val originLightClass = LightClassUtil.getPsiClass(originClass)
|
||||
if (originLightClass != null) {
|
||||
val lightDeclarations: List<KotlinLightElement<*, *>?> =
|
||||
@@ -208,12 +208,12 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
}
|
||||
}
|
||||
|
||||
private fun findStaticMethodFromCompanionObject(function: JetFunction): PsiMethod? {
|
||||
private fun findStaticMethodFromCompanionObject(function: KtFunction): PsiMethod? {
|
||||
val originObject = function.parents
|
||||
.dropWhile { it is JetClassBody }
|
||||
.firstOrNull() as? JetObjectDeclaration ?: return null
|
||||
.dropWhile { it is KtClassBody }
|
||||
.firstOrNull() as? KtObjectDeclaration ?: return null
|
||||
if (originObject.isCompanion()) {
|
||||
val originClass = originObject.getStrictParentOfType<JetClass>()
|
||||
val originClass = originObject.getStrictParentOfType<KtClass>()
|
||||
val originLightClass = LightClassUtil.getPsiClass(originClass)
|
||||
val allMethods = originLightClass?.allMethods
|
||||
return allMethods?.find { it is KotlinLightMethod && it.getOrigin() == function }
|
||||
@@ -221,7 +221,7 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
return null
|
||||
}
|
||||
|
||||
private fun searchPropertyMethods(queryParameters: ReferencesSearch.SearchParameters, parameter: JetParameter) {
|
||||
private fun searchPropertyMethods(queryParameters: ReferencesSearch.SearchParameters, parameter: KtParameter) {
|
||||
val propertyMethods = runReadAction { LightClassUtil.getLightClassPropertyMethods(parameter) }
|
||||
propertyMethods.allDeclarations.forEach { searchNamedElement(queryParameters, it) }
|
||||
}
|
||||
@@ -239,9 +239,9 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
|
||||
private fun searchLightElements(queryParameters: ReferencesSearch.SearchParameters, element: PsiElement) {
|
||||
when (element) {
|
||||
is JetClassOrObject -> processJetClassOrObject(element, queryParameters)
|
||||
is JetNamedFunction, is JetSecondaryConstructor -> {
|
||||
val function = element as JetFunction
|
||||
is KtClassOrObject -> processJetClassOrObject(element, queryParameters)
|
||||
is KtNamedFunction, is KtSecondaryConstructor -> {
|
||||
val function = element as KtFunction
|
||||
val name = runReadAction { function.getName() }
|
||||
if (name != null) {
|
||||
val methods = runReadAction { LightClassUtil.getLightClassMethods(function) }
|
||||
@@ -256,17 +256,17 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
}
|
||||
}
|
||||
|
||||
is JetProperty -> {
|
||||
is KtProperty -> {
|
||||
val propertyMethods = runReadAction { LightClassUtil.getLightClassPropertyMethods(element) }
|
||||
propertyMethods.allDeclarations.forEach { searchNamedElement(queryParameters, it) }
|
||||
}
|
||||
|
||||
is JetParameter -> {
|
||||
is KtParameter -> {
|
||||
searchPropertyMethods(queryParameters, element)
|
||||
runReadAction {
|
||||
val componentFunctionDescriptor = element.dataClassComponentFunction()
|
||||
if (componentFunctionDescriptor != null) {
|
||||
val containingClass = LightClassUtil.getPsiClass(element.getStrictParentOfType<JetClassOrObject>())
|
||||
val containingClass = LightClassUtil.getPsiClass(element.getStrictParentOfType<KtClassOrObject>())
|
||||
searchDataClassComponentUsages(queryParameters, containingClass, componentFunctionDescriptor)
|
||||
}
|
||||
}
|
||||
@@ -274,14 +274,14 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
|
||||
is KotlinLightMethod -> {
|
||||
val declaration = element.getOrigin()
|
||||
if (declaration is JetProperty || (declaration is JetParameter && declaration.hasValOrVar())) {
|
||||
if (declaration is KtProperty || (declaration is KtParameter && declaration.hasValOrVar())) {
|
||||
searchNamedElement(queryParameters, declaration as PsiNamedElement)
|
||||
}
|
||||
else if (declaration is JetPropertyAccessor) {
|
||||
val property = declaration.getStrictParentOfType<JetProperty>()
|
||||
else if (declaration is KtPropertyAccessor) {
|
||||
val property = declaration.getStrictParentOfType<KtProperty>()
|
||||
searchNamedElement(queryParameters, property)
|
||||
}
|
||||
else if (declaration is JetFunction) {
|
||||
else if (declaration is KtFunction) {
|
||||
val staticFromCompanionObject = runReadAction { findStaticMethodFromCompanionObject(declaration) }
|
||||
if (staticFromCompanionObject != null) {
|
||||
searchNamedElement(queryParameters, staticFromCompanionObject)
|
||||
@@ -304,7 +304,7 @@ public class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, Referenc
|
||||
|
||||
private fun isOnlyKotlinSearch(searchScope: SearchScope) =
|
||||
searchScope is LocalSearchScope && runReadAction {
|
||||
searchScope.getScope().all { it.getContainingFile().getFileType() == JetFileType.INSTANCE }
|
||||
searchScope.getScope().all { it.getContainingFile().getFileType() == KotlinFileType.INSTANCE }
|
||||
}
|
||||
|
||||
private fun searchNamedElement(queryParameters: ReferencesSearch.SearchParameters,
|
||||
|
||||
+13
-13
@@ -17,16 +17,16 @@
|
||||
package org.jetbrains.kotlin.idea.search.usagesSearch
|
||||
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import org.jetbrains.kotlin.lexer.JetToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DelegatedPropertyResolver
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
public val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<JetToken> = ImmutableSet
|
||||
.builder<JetToken>()
|
||||
public val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<KtToken> = ImmutableSet
|
||||
.builder<KtToken>()
|
||||
.addAll(UNARY_OPERATION_NAMES.keySet())
|
||||
.addAll(BINARY_OPERATION_NAMES.keySet())
|
||||
.addAll(ASSIGNMENT_OPERATIONS.keySet())
|
||||
@@ -34,31 +34,31 @@ public val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<JetToken> = ImmutableSet
|
||||
.addAll(EQUALS_OPERATIONS)
|
||||
.addAll(IDENTITY_EQUALS_OPERATIONS)
|
||||
.addAll(IN_OPERATIONS)
|
||||
.add(JetTokens.LBRACKET)
|
||||
.add(JetTokens.BY_KEYWORD)
|
||||
.add(KtTokens.LBRACKET)
|
||||
.add(KtTokens.BY_KEYWORD)
|
||||
.build()
|
||||
|
||||
public val INDEXING_OPERATION_NAMES = setOf(OperatorNameConventions.GET, OperatorNameConventions.SET)
|
||||
|
||||
public val DELEGATE_ACCESSOR_NAMES = setOf(Name.identifier("getValue"), Name.identifier("setValue"))
|
||||
|
||||
public val IN_OPERATIONS_TO_SEARCH = setOf(JetTokens.IN_KEYWORD)
|
||||
public val IN_OPERATIONS_TO_SEARCH = setOf(KtTokens.IN_KEYWORD)
|
||||
|
||||
public val COMPARISON_OPERATIONS_TO_SEARCH = setOf(JetTokens.LT, JetTokens.GT)
|
||||
public val COMPARISON_OPERATIONS_TO_SEARCH = setOf(KtTokens.LT, KtTokens.GT)
|
||||
|
||||
public fun Name.getOperationSymbolsToSearch(): Set<JetToken> {
|
||||
public fun Name.getOperationSymbolsToSearch(): Set<KtToken> {
|
||||
when (this) {
|
||||
OperatorNameConventions.COMPARE_TO -> return COMPARISON_OPERATIONS_TO_SEARCH
|
||||
OperatorNameConventions.EQUALS -> return EQUALS_OPERATIONS
|
||||
OperatorNameConventions.IDENTITY_EQUALS -> return IDENTITY_EQUALS_OPERATIONS
|
||||
OperatorNameConventions.CONTAINS -> return IN_OPERATIONS_TO_SEARCH
|
||||
OperatorNameConventions.ITERATOR -> return IN_OPERATIONS_TO_SEARCH
|
||||
in INDEXING_OPERATION_NAMES -> return setOf(JetTokens.LBRACKET)
|
||||
in DELEGATE_ACCESSOR_NAMES -> return setOf(JetTokens.BY_KEYWORD)
|
||||
DelegatedPropertyResolver.PROPERTY_DELEGATED_FUNCTION_NAME -> return setOf(JetTokens.BY_KEYWORD)
|
||||
in INDEXING_OPERATION_NAMES -> return setOf(KtTokens.LBRACKET)
|
||||
in DELEGATE_ACCESSOR_NAMES -> return setOf(KtTokens.BY_KEYWORD)
|
||||
DelegatedPropertyResolver.PROPERTY_DELEGATED_FUNCTION_NAME -> return setOf(KtTokens.BY_KEYWORD)
|
||||
}
|
||||
|
||||
if (isComponentLike(this)) return setOf(JetTokens.LPAR)
|
||||
if (isComponentLike(this)) return setOf(KtTokens.LPAR)
|
||||
|
||||
val unaryOp = UNARY_OPERATION_NAMES_WITH_DEPRECATED_INVERTED[this]
|
||||
if (unaryOp != null) return setOf(unaryOp)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user