rename Jet* classes to Kt*
This commit is contained in:
@@ -20,9 +20,9 @@ import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import org.jetbrains.kotlin.lexer.JetToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
@@ -32,7 +32,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB
|
||||
public constructor(originalElement: PsiElement, saveLineBreaks: Boolean = false/*TODO?*/) : this(PsiChildRange.singleElement(originalElement), saveLineBreaks)
|
||||
|
||||
private val SAVED_TREE_KEY = Key<TreeElement>("SAVED_TREE")
|
||||
private val psiFactory = JetPsiFactory(originalElements.first!!)
|
||||
private val psiFactory = KtPsiFactory(originalElements.first!!)
|
||||
|
||||
private abstract class TreeElement {
|
||||
public companion object {
|
||||
@@ -122,7 +122,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB
|
||||
}
|
||||
|
||||
private class StandardTreeElement() : TreeElement()
|
||||
private class TokenTreeElement(val tokenType: JetToken) : TreeElement()
|
||||
private class TokenTreeElement(val tokenType: KtToken) : TreeElement()
|
||||
private class LineBreakTreeElement() : TreeElement()
|
||||
|
||||
private class CommentTreeElement(
|
||||
@@ -314,7 +314,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB
|
||||
|
||||
bindNewElement(restored, commentTreeElement) // will be used when restoring line breaks
|
||||
|
||||
if (restored.tokenType == JetTokens.EOL_COMMENT) {
|
||||
if (restored.tokenType == KtTokens.EOL_COMMENT) {
|
||||
needAdjustIndentAfterRestore = true // TODO: do we really need it?
|
||||
}
|
||||
}
|
||||
@@ -336,7 +336,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB
|
||||
}
|
||||
|
||||
|
||||
val tokensToMatch = arrayListOf<JetToken>()
|
||||
val tokensToMatch = arrayListOf<KtToken>()
|
||||
for (leaf in lineBreakElement.prevLeafs) {
|
||||
var psiElement = findRestored(leaf)
|
||||
if (psiElement != null) {
|
||||
@@ -352,7 +352,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB
|
||||
}
|
||||
}
|
||||
|
||||
private fun skipTokensForward(psiElement: PsiElement, tokensToMatch: List<JetToken>): PsiElement? {
|
||||
private fun skipTokensForward(psiElement: PsiElement, tokensToMatch: List<KtToken>): PsiElement? {
|
||||
var currentPsiElement = psiElement
|
||||
for (token in tokensToMatch) {
|
||||
currentPsiElement = currentPsiElement.nextLeaf(nonSpaceAndNonEmptyFilter) ?: return null
|
||||
@@ -432,7 +432,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB
|
||||
}
|
||||
|
||||
// don't put end of line comment right before comma
|
||||
if (anchor.before && comment.tokenType == JetTokens.EOL_COMMENT) {
|
||||
if (anchor.before && comment.tokenType == KtTokens.EOL_COMMENT) {
|
||||
psiElement = shiftNewLineAnchor(psiElement)
|
||||
}
|
||||
|
||||
@@ -442,14 +442,14 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB
|
||||
// don't put line break right before comma
|
||||
private fun shiftNewLineAnchor(putAfter: PsiElement): PsiElement {
|
||||
val next = putAfter.nextLeaf(nonSpaceAndNonEmptyFilter)
|
||||
return if (next?.tokenType == JetTokens.COMMA) next!! else putAfter
|
||||
return if (next?.tokenType == KtTokens.COMMA) next!! else putAfter
|
||||
}
|
||||
|
||||
private val nonSpaceAndNonEmptyFilter = { element: PsiElement -> element !is PsiWhiteSpace && element.getTextLength() > 0 }
|
||||
|
||||
companion object {
|
||||
//TODO: making it private causes error on runtime (KT-7874?)
|
||||
val PsiElement.tokenType: JetToken?
|
||||
get() = getNode().getElementType() as? JetToken
|
||||
val PsiElement.tokenType: KtToken?
|
||||
get() = getNode().getElementType() as? KtToken
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,11 @@ import org.jetbrains.kotlin.idea.util.ImportInsertHelper
|
||||
import org.jetbrains.kotlin.load.java.components.JavaAnnotationMapper
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
import java.util.*
|
||||
|
||||
class ImportableFqNameClassifier(private val file: JetFile) {
|
||||
class ImportableFqNameClassifier(private val file: KtFile) {
|
||||
private val preciseImports = HashSet<FqName>()
|
||||
private val preciseImportPackages = HashSet<FqName>()
|
||||
private val allUnderImports = HashSet<FqName>()
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.FuzzyType
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
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.receivers.ExpressionReceiver
|
||||
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.ExpressionTypingContext
|
||||
import org.jetbrains.kotlin.types.expressions.ForLoopConventionsChecker
|
||||
@@ -42,37 +42,37 @@ public class IterableTypesDetection(
|
||||
private val iteratorName = Name.identifier("iterator")
|
||||
}
|
||||
|
||||
public fun createDetector(scope: JetScope): IterableTypesDetector {
|
||||
public fun createDetector(scope: KtScope): IterableTypesDetector {
|
||||
return Detector(scope)
|
||||
}
|
||||
private inner class Detector(private val scope: JetScope): IterableTypesDetector {
|
||||
private inner class Detector(private val scope: KtScope): IterableTypesDetector {
|
||||
private val cache = HashMap<FuzzyType, FuzzyType?>()
|
||||
|
||||
private val typesWithExtensionIterator: Collection<JetType> = scope.getFunctions(iteratorName, NoLookupLocation.FROM_IDE)
|
||||
private val typesWithExtensionIterator: Collection<KtType> = scope.getFunctions(iteratorName, NoLookupLocation.FROM_IDE)
|
||||
.map { it.getExtensionReceiverParameter() }
|
||||
.filterNotNull()
|
||||
.map { it.getType() }
|
||||
|
||||
override fun isIterable(type: FuzzyType, loopVarType: JetType?): Boolean {
|
||||
override fun isIterable(type: FuzzyType, loopVarType: KtType?): Boolean {
|
||||
val elementType = elementType(type) ?: return false
|
||||
return loopVarType == null || elementType.checkIsSubtypeOf(loopVarType) != null
|
||||
}
|
||||
|
||||
override fun isIterable(type: JetType, loopVarType: JetType?): Boolean
|
||||
override fun isIterable(type: KtType, loopVarType: KtType?): Boolean
|
||||
= isIterable(FuzzyType(type, emptyList()), loopVarType)
|
||||
|
||||
private fun elementType(type: FuzzyType): FuzzyType? {
|
||||
return cache.getOrPut(type, { elementTypeNoCache(type) })
|
||||
}
|
||||
|
||||
override fun elementType(type: JetType): FuzzyType?
|
||||
override fun elementType(type: KtType): FuzzyType?
|
||||
= elementType(FuzzyType(type, emptyList()))
|
||||
|
||||
private fun elementTypeNoCache(type: FuzzyType): FuzzyType? {
|
||||
// optimization
|
||||
if (!canBeIterable(type)) return null
|
||||
|
||||
val expression = JetPsiFactory(project).createExpression("fake")
|
||||
val expression = KtPsiFactory(project).createExpression("fake")
|
||||
val expressionReceiver = ExpressionReceiver(expression, type.type)
|
||||
val context = ExpressionTypingContext.newContext(BindingTraceContext(), scope.asLexicalScope(), DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE)
|
||||
val elementType = forLoopConventionsChecker.checkIterableConvention(expressionReceiver, context)
|
||||
@@ -87,9 +87,9 @@ public class IterableTypesDetection(
|
||||
}
|
||||
|
||||
public interface IterableTypesDetector {
|
||||
public fun isIterable(type: JetType, loopVarType: JetType? = null): Boolean
|
||||
public fun isIterable(type: KtType, loopVarType: KtType? = null): Boolean
|
||||
|
||||
public fun isIterable(type: FuzzyType, loopVarType: JetType? = null): Boolean
|
||||
public fun isIterable(type: FuzzyType, loopVarType: KtType? = null): Boolean
|
||||
|
||||
public fun elementType(type: JetType): FuzzyType?
|
||||
public fun elementType(type: KtType): FuzzyType?
|
||||
}
|
||||
@@ -30,14 +30,14 @@ import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||
import org.jetbrains.kotlin.idea.util.receiverTypes
|
||||
import org.jetbrains.kotlin.idea.util.substituteExtensionIfCallable
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSessionUtils
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.KtType
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.*
|
||||
@@ -60,7 +60,7 @@ public class KotlinIndicesHelper(
|
||||
}
|
||||
|
||||
public fun getTopLevelCallablesByName(name: String): Collection<CallableDescriptor> {
|
||||
val declarations = HashSet<JetNamedDeclaration>()
|
||||
val declarations = HashSet<KtNamedDeclaration>()
|
||||
declarations.addTopLevelNonExtensionCallablesByName(JetFunctionShortNameIndex.getInstance(), name)
|
||||
declarations.addTopLevelNonExtensionCallablesByName(JetPropertyShortNameIndex.getInstance(), name)
|
||||
return declarations.flatMap {
|
||||
@@ -73,11 +73,11 @@ public class KotlinIndicesHelper(
|
||||
}.filter { it.getExtensionReceiverParameter() == null && descriptorFilter(it) }
|
||||
}
|
||||
|
||||
private fun MutableSet<JetNamedDeclaration>.addTopLevelNonExtensionCallablesByName(
|
||||
index: StringStubIndexExtension<out JetCallableDeclaration>,
|
||||
private fun MutableSet<KtNamedDeclaration>.addTopLevelNonExtensionCallablesByName(
|
||||
index: StringStubIndexExtension<out KtCallableDeclaration>,
|
||||
name: String
|
||||
) {
|
||||
index.get(name, project, scope).filterTo(this) { it.getParent() is JetFile && it.getReceiverTypeReference() == null }
|
||||
index.get(name, project, scope).filterTo(this) { it.getParent() is KtFile && it.getReceiverTypeReference() == null }
|
||||
}
|
||||
|
||||
public fun getTopLevelCallables(nameFilter: (String) -> Boolean): Collection<CallableDescriptor> {
|
||||
@@ -92,7 +92,7 @@ public class KotlinIndicesHelper(
|
||||
public fun getCallableTopLevelExtensions(
|
||||
nameFilter: (String) -> Boolean,
|
||||
callTypeAndReceiver: CallTypeAndReceiver<*, *>,
|
||||
position: JetExpression,
|
||||
position: KtExpression,
|
||||
bindingContext: BindingContext
|
||||
): Collection<CallableDescriptor> {
|
||||
val receiverTypes = callTypeAndReceiver.receiverTypes(bindingContext, position, moduleDescriptor, predictableSmartCastsOnly = false)
|
||||
@@ -114,7 +114,7 @@ public class KotlinIndicesHelper(
|
||||
return findSuitableExtensions(declarations, receiverTypes, callTypeAndReceiver.callType)
|
||||
}
|
||||
|
||||
private fun MutableCollection<String>.addTypeNames(type: JetType) {
|
||||
private fun MutableCollection<String>.addTypeNames(type: KtType) {
|
||||
val constructor = type.getConstructor()
|
||||
addIfNotNull(constructor.getDeclarationDescriptor()?.getName()?.asString())
|
||||
constructor.getSupertypes().forEach { addTypeNames(it) }
|
||||
@@ -124,8 +124,8 @@ public class KotlinIndicesHelper(
|
||||
* Check that function or property with the given qualified name can be resolved in given scope and called on given receiver
|
||||
*/
|
||||
private fun findSuitableExtensions(
|
||||
declarations: Sequence<JetCallableDeclaration>,
|
||||
receiverTypes: Collection<JetType>,
|
||||
declarations: Sequence<KtCallableDeclaration>,
|
||||
receiverTypes: Collection<KtType>,
|
||||
callType: CallType<*>
|
||||
): Collection<CallableDescriptor> {
|
||||
val result = LinkedHashSet<CallableDescriptor>()
|
||||
|
||||
@@ -18,14 +18,14 @@ package org.jetbrains.kotlin.idea.core
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
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 org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.ErrorUtils
|
||||
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.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeSmart
|
||||
import java.util.*
|
||||
@@ -33,7 +33,7 @@ import java.util.regex.Pattern
|
||||
|
||||
public object KotlinNameSuggester {
|
||||
|
||||
public fun suggestNamesByExpressionAndType(expression: JetExpression, bindingContext: BindingContext, validator: (String) -> Boolean, defaultName: String?): Collection<String> {
|
||||
public fun suggestNamesByExpressionAndType(expression: KtExpression, bindingContext: BindingContext, validator: (String) -> Boolean, defaultName: String?): Collection<String> {
|
||||
val result = LinkedHashSet<String>()
|
||||
|
||||
result.addNamesByExpression(expression, validator)
|
||||
@@ -50,7 +50,7 @@ public object KotlinNameSuggester {
|
||||
return result
|
||||
}
|
||||
|
||||
public fun suggestNamesByType(type: JetType, validator: (String) -> Boolean, defaultName: String? = null): List<String> {
|
||||
public fun suggestNamesByType(type: KtType, validator: (String) -> Boolean, defaultName: String? = null): List<String> {
|
||||
val result = ArrayList<String>()
|
||||
|
||||
result.addNamesByType(type, validator)
|
||||
@@ -62,7 +62,7 @@ public object KotlinNameSuggester {
|
||||
return result
|
||||
}
|
||||
|
||||
public fun suggestNamesByExpressionOnly(expression: JetExpression, validator: (String) -> Boolean, defaultName: String? = null): List<String> {
|
||||
public fun suggestNamesByExpressionOnly(expression: KtExpression, validator: (String) -> Boolean, defaultName: String? = null): List<String> {
|
||||
val result = ArrayList<String>()
|
||||
|
||||
result.addNamesByExpression(expression, validator)
|
||||
@@ -74,7 +74,7 @@ public object KotlinNameSuggester {
|
||||
return result
|
||||
}
|
||||
|
||||
public fun suggestIterationVariableNames(collection: JetExpression, elementType: JetType, validator: (String) -> Boolean, defaultName: String?): Collection<String> {
|
||||
public fun suggestIterationVariableNames(collection: KtExpression, elementType: KtType, validator: (String) -> Boolean, defaultName: String?): Collection<String> {
|
||||
val result = LinkedHashSet<String>()
|
||||
|
||||
suggestNamesByExpressionOnly(collection, { true })
|
||||
@@ -133,10 +133,10 @@ public object KotlinNameSuggester {
|
||||
}
|
||||
}
|
||||
|
||||
private fun MutableCollection<String>.addNamesByType(type: JetType, validator: (String) -> Boolean) {
|
||||
private fun MutableCollection<String>.addNamesByType(type: KtType, validator: (String) -> Boolean) {
|
||||
var type = TypeUtils.makeNotNullable(type) // wipe out '?'
|
||||
val builtIns = type.builtIns
|
||||
val typeChecker = JetTypeChecker.DEFAULT
|
||||
val typeChecker = KotlinTypeChecker.DEFAULT
|
||||
if (ErrorUtils.containsErrorType(type)) return
|
||||
|
||||
if (typeChecker.equalTypes(builtIns.getBooleanType(), type)) {
|
||||
@@ -261,18 +261,18 @@ public object KotlinNameSuggester {
|
||||
return matcher.replaceAll("")
|
||||
}
|
||||
|
||||
private fun MutableCollection<String>.addNamesByExpression(expression: JetExpression?, validator: (String) -> Boolean) {
|
||||
private fun MutableCollection<String>.addNamesByExpression(expression: KtExpression?, validator: (String) -> Boolean) {
|
||||
if (expression == null) return
|
||||
|
||||
val expression = JetPsiUtil.safeDeparenthesize(expression)
|
||||
val expression = KtPsiUtil.safeDeparenthesize(expression)
|
||||
when (expression) {
|
||||
is JetSimpleNameExpression -> addCamelNames(expression.getReferencedName(), validator)
|
||||
is KtSimpleNameExpression -> addCamelNames(expression.getReferencedName(), validator)
|
||||
|
||||
is JetQualifiedExpression -> addNamesByExpression(expression.getSelectorExpression(), validator)
|
||||
is KtQualifiedExpression -> addNamesByExpression(expression.getSelectorExpression(), validator)
|
||||
|
||||
is JetCallExpression -> addNamesByExpression(expression.getCalleeExpression(), validator)
|
||||
is KtCallExpression -> addNamesByExpression(expression.getCalleeExpression(), validator)
|
||||
|
||||
is JetPostfixExpression -> addNamesByExpression(expression.getBaseExpression(), validator)
|
||||
is KtPostfixExpression -> addNamesByExpression(expression.getBaseExpression(), validator)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,9 +289,9 @@ public object KotlinNameSuggester {
|
||||
public fun isIdentifier(name: String?): Boolean {
|
||||
if (name == null || name.isEmpty()) return false
|
||||
|
||||
val lexer = JetLexer()
|
||||
val lexer = KotlinLexer()
|
||||
lexer.start(name, 0, name.length())
|
||||
if (lexer.getTokenType() !== JetTokens.IDENTIFIER) return false
|
||||
if (lexer.getTokenType() !== KtTokens.IDENTIFIER) return false
|
||||
lexer.advance()
|
||||
return lexer.getTokenType() == null
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.util.Collections
|
||||
@@ -58,14 +58,14 @@ public class CollectingNameValidator @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
public class NewDeclarationNameValidator(
|
||||
private val visibleDeclarationsContext: JetElement?,
|
||||
private val visibleDeclarationsContext: KtElement?,
|
||||
private val checkDeclarationsIn: Sequence<PsiElement>,
|
||||
private val target: NewDeclarationNameValidator.Target
|
||||
) : (String) -> Boolean {
|
||||
|
||||
public constructor(container: PsiElement, anchor: PsiElement?, target: NewDeclarationNameValidator.Target)
|
||||
: this(
|
||||
(anchor ?: container).parentsWithSelf.firstIsInstanceOrNull<JetElement>(),
|
||||
(anchor ?: container).parentsWithSelf.firstIsInstanceOrNull<KtElement>(),
|
||||
anchor?.siblings() ?: container.allChildren,
|
||||
target)
|
||||
|
||||
@@ -84,11 +84,11 @@ public class NewDeclarationNameValidator(
|
||||
}
|
||||
|
||||
return checkDeclarationsIn.none {
|
||||
it.findDescendantOfType<JetNamedDeclaration> { it.isConflicting(identifier) } != null
|
||||
it.findDescendantOfType<KtNamedDeclaration> { it.isConflicting(identifier) } != null
|
||||
}
|
||||
}
|
||||
|
||||
private fun JetScope.hasConflict(name: Name): Boolean {
|
||||
private fun KtScope.hasConflict(name: Name): Boolean {
|
||||
val inDeclaration = getContainingDeclaration()
|
||||
|
||||
fun DeclarationDescriptor.isVisible(): Boolean {
|
||||
@@ -107,12 +107,12 @@ public class NewDeclarationNameValidator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun JetNamedDeclaration.isConflicting(name: Name): Boolean {
|
||||
private fun KtNamedDeclaration.isConflicting(name: Name): Boolean {
|
||||
if (getNameAsName() != name) return false
|
||||
if (this is JetCallableDeclaration && getReceiverTypeReference() != null) return false
|
||||
if (this is KtCallableDeclaration && getReceiverTypeReference() != null) return false
|
||||
return when(target) {
|
||||
Target.VARIABLES -> this is JetVariableDeclaration
|
||||
Target.FUNCTIONS_AND_CLASSES -> this is JetNamedFunction || this is JetClassOrObject
|
||||
Target.VARIABLES -> this is KtVariableDeclaration
|
||||
Target.FUNCTIONS_AND_CLASSES -> this is KtNamedFunction || this is KtClassOrObject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.ValueArgument
|
||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -74,10 +74,10 @@ public object OptionalParametersHelper {
|
||||
return argumentExpression.getText() == expression.getText() //TODO
|
||||
}
|
||||
|
||||
private fun DefaultValue.substituteArguments(resolvedCall: ResolvedCall<out CallableDescriptor>): JetExpression {
|
||||
private fun DefaultValue.substituteArguments(resolvedCall: ResolvedCall<out CallableDescriptor>): KtExpression {
|
||||
if (parameterUsages.isEmpty()) return expression
|
||||
|
||||
val key = Key<JetExpression>("SUBSTITUTION")
|
||||
val key = Key<KtExpression>("SUBSTITUTION")
|
||||
|
||||
for ((parameter, usages) in parameterUsages) {
|
||||
val resolvedArgument = resolvedCall.getValueArguments()[parameter]!!
|
||||
@@ -90,10 +90,10 @@ public object OptionalParametersHelper {
|
||||
|
||||
var expressionCopy = expression.copied()
|
||||
|
||||
expression.forEachDescendantOfType<JetExpression> { it.putCopyableUserData(key, null) }
|
||||
expression.forEachDescendantOfType<KtExpression> { it.putCopyableUserData(key, null) }
|
||||
|
||||
val replacements = ArrayList<Pair<JetExpression, JetExpression>>()
|
||||
expressionCopy.forEachDescendantOfType<JetExpression> {
|
||||
val replacements = ArrayList<Pair<KtExpression, KtExpression>>()
|
||||
expressionCopy.forEachDescendantOfType<KtExpression> {
|
||||
val replacement = it.getCopyableUserData(key)
|
||||
if (replacement != null) {
|
||||
replacements.add(it to replacement)
|
||||
@@ -101,7 +101,7 @@ public object OptionalParametersHelper {
|
||||
}
|
||||
|
||||
for ((expression, replacement) in replacements) {
|
||||
val replaced = expression.replace(replacement) as JetExpression
|
||||
val replaced = expression.replace(replacement) as KtExpression
|
||||
if (expression == expressionCopy) {
|
||||
expressionCopy = replaced
|
||||
}
|
||||
@@ -111,11 +111,11 @@ public object OptionalParametersHelper {
|
||||
}
|
||||
|
||||
public data class DefaultValue(
|
||||
public val expression: JetExpression,
|
||||
public val parameterUsages: Map<ValueParameterDescriptor, Collection<JetExpression>>
|
||||
public val expression: KtExpression,
|
||||
public val parameterUsages: Map<ValueParameterDescriptor, Collection<KtExpression>>
|
||||
)
|
||||
|
||||
public fun defaultParameterValueExpression(parameter: ValueParameterDescriptor, project: Project): JetExpression? {
|
||||
public fun defaultParameterValueExpression(parameter: ValueParameterDescriptor, project: Project): KtExpression? {
|
||||
if (!parameter.hasDefaultValue()) return null
|
||||
|
||||
if (!parameter.declaresDefaultValue()) {
|
||||
@@ -125,7 +125,7 @@ public object OptionalParametersHelper {
|
||||
|
||||
//TODO: parameter in overriding method!
|
||||
//TODO: it's a temporary code while we don't have default values accessible from descriptors
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, parameter)?.getNavigationElement() as? JetParameter
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, parameter)?.getNavigationElement() as? KtParameter
|
||||
return declaration?.defaultValue
|
||||
}
|
||||
|
||||
@@ -136,10 +136,10 @@ public object OptionalParametersHelper {
|
||||
|
||||
val allParameters = parameter.getContainingDeclaration().getValueParameters().toSet()
|
||||
|
||||
val parameterUsages = HashMap<ValueParameterDescriptor, MutableCollection<JetExpression>>()
|
||||
val parameterUsages = HashMap<ValueParameterDescriptor, MutableCollection<KtExpression>>()
|
||||
|
||||
val bindingContext = expression.analyze(BodyResolveMode.PARTIAL)
|
||||
expression.forEachDescendantOfType<JetSimpleNameExpression> {
|
||||
expression.forEachDescendantOfType<KtSimpleNameExpression> {
|
||||
val target = bindingContext[BindingContext.REFERENCE_TARGET, it]
|
||||
if (target is ValueParameterDescriptor && target in allParameters) {
|
||||
parameterUsages.getOrPut(target) { ArrayList() }.add(it)
|
||||
|
||||
@@ -41,13 +41,13 @@ import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.KtScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
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.types.expressions.ExpressionTypingUtils
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
import java.util.*
|
||||
@@ -93,7 +93,7 @@ public fun Call.mapArgumentsToParameters(targetDescriptor: CallableDescriptor):
|
||||
return map
|
||||
}
|
||||
|
||||
public fun ThisReceiver.asExpression(resolutionScope: JetScope, psiFactory: JetPsiFactory): JetExpression? {
|
||||
public fun ThisReceiver.asExpression(resolutionScope: KtScope, psiFactory: KtPsiFactory): KtExpression? {
|
||||
val expressionFactory = resolutionScope.getImplicitReceiversWithInstanceToExpression()
|
||||
.entrySet()
|
||||
.firstOrNull { it.key.getContainingDeclaration() == this.getDeclarationDescriptor() }
|
||||
@@ -103,34 +103,34 @@ public fun ThisReceiver.asExpression(resolutionScope: JetScope, psiFactory: JetP
|
||||
|
||||
public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolutionFacade: ResolutionFacade): LexicalScope {
|
||||
for (parent in parentsWithSelf) {
|
||||
if (parent is JetElement) {
|
||||
if (parent is KtElement) {
|
||||
val scope = bindingContext[BindingContext.LEXICAL_SCOPE, parent]
|
||||
if (scope != null) return scope
|
||||
}
|
||||
|
||||
if (parent is JetClassBody) {
|
||||
if (parent is KtClassBody) {
|
||||
val classDescriptor = bindingContext[BindingContext.CLASS, parent.getParent()] as? ClassDescriptorWithResolutionScopes
|
||||
if (classDescriptor != null) {
|
||||
return classDescriptor.getScopeForMemberDeclarationResolution()
|
||||
}
|
||||
}
|
||||
|
||||
if (parent is JetFile) {
|
||||
if (parent is KtFile) {
|
||||
return resolutionFacade.getFileTopLevelScope(parent)
|
||||
}
|
||||
}
|
||||
error("Not in JetFile")
|
||||
}
|
||||
|
||||
public fun JetImportDirective.targetDescriptors(): Collection<DeclarationDescriptor> {
|
||||
val nameExpression = importedReference?.getQualifiedElementSelector() as? JetSimpleNameExpression ?: return emptyList()
|
||||
public fun KtImportDirective.targetDescriptors(): Collection<DeclarationDescriptor> {
|
||||
val nameExpression = importedReference?.getQualifiedElementSelector() as? KtSimpleNameExpression ?: return emptyList()
|
||||
return nameExpression.mainReference.resolveToDescriptors(nameExpression.analyze())
|
||||
}
|
||||
|
||||
public fun Call.resolveCandidates(
|
||||
bindingContext: BindingContext,
|
||||
resolutionFacade: ResolutionFacade,
|
||||
expectedType: JetType = expectedType(this, bindingContext),
|
||||
expectedType: KtType = expectedType(this, bindingContext),
|
||||
filterOutWrongReceiver: Boolean = true,
|
||||
filterOutByVisibility: Boolean = true
|
||||
): Collection<ResolvedCall<FunctionDescriptor>> {
|
||||
@@ -150,7 +150,7 @@ public fun Call.resolveCandidates(
|
||||
|
||||
var candidates = results.allCandidates!!
|
||||
|
||||
if (callElement is JetConstructorDelegationCall) { // for "this(...)" delegation call exclude caller from candidates
|
||||
if (callElement is KtConstructorDelegationCall) { // for "this(...)" delegation call exclude caller from candidates
|
||||
inDescriptor as ConstructorDescriptor
|
||||
candidates = candidates.filter { it.resultingDescriptor.original != inDescriptor.original }
|
||||
}
|
||||
@@ -169,17 +169,17 @@ public fun Call.resolveCandidates(
|
||||
return candidates
|
||||
}
|
||||
|
||||
private fun expectedType(call: Call, bindingContext: BindingContext): JetType {
|
||||
return (call.callElement as? JetExpression)?.let {
|
||||
private fun expectedType(call: Call, bindingContext: BindingContext): KtType {
|
||||
return (call.callElement as? KtExpression)?.let {
|
||||
bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, it.getQualifiedExpressionForSelectorOrThis()]
|
||||
} ?: TypeUtils.NO_EXPECTED_TYPE
|
||||
}
|
||||
|
||||
fun JetCallableDeclaration.canOmitDeclaredType(initializerOrBodyExpression: JetExpression, canChangeTypeToSubtype: Boolean): Boolean {
|
||||
fun KtCallableDeclaration.canOmitDeclaredType(initializerOrBodyExpression: KtExpression, canChangeTypeToSubtype: Boolean): Boolean {
|
||||
val declaredType = (resolveToDescriptor() as? CallableDescriptor)?.returnType ?: return false
|
||||
val bindingContext = initializerOrBodyExpression.analyze()
|
||||
val scope = initializerOrBodyExpression.getResolutionScope(bindingContext, initializerOrBodyExpression.getResolutionFacade()).asJetScope()
|
||||
val expressionType = initializerOrBodyExpression.computeTypeInContext(scope) ?: return false
|
||||
if (JetTypeChecker.DEFAULT.equalTypes(expressionType, declaredType)) return true
|
||||
if (KotlinTypeChecker.DEFAULT.equalTypes(expressionType, declaredType)) return true
|
||||
return canChangeTypeToSubtype && expressionType.isSubtypeOf(declaredType)
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||
fun DeclarationDescriptorWithVisibility.isVisible(
|
||||
from: DeclarationDescriptor,
|
||||
bindingContext: BindingContext? = null,
|
||||
element: JetSimpleNameExpression? = null
|
||||
element: KtSimpleNameExpression? = null
|
||||
): Boolean {
|
||||
if (Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, this, from)) return true
|
||||
if (bindingContext == null || element == null) return false
|
||||
@@ -97,15 +97,15 @@ public fun compareDescriptors(project: Project, currentDescriptor: DeclarationDe
|
||||
return false
|
||||
}
|
||||
|
||||
public fun Visibility.toKeywordToken(): JetModifierKeywordToken {
|
||||
public fun Visibility.toKeywordToken(): KtModifierKeywordToken {
|
||||
val normalized = normalize()
|
||||
when (normalized) {
|
||||
Visibilities.PUBLIC -> return JetTokens.PUBLIC_KEYWORD
|
||||
Visibilities.PROTECTED -> return JetTokens.PROTECTED_KEYWORD
|
||||
Visibilities.INTERNAL -> return JetTokens.INTERNAL_KEYWORD
|
||||
Visibilities.PUBLIC -> return KtTokens.PUBLIC_KEYWORD
|
||||
Visibilities.PROTECTED -> return KtTokens.PROTECTED_KEYWORD
|
||||
Visibilities.INTERNAL -> return KtTokens.INTERNAL_KEYWORD
|
||||
else -> {
|
||||
if (Visibilities.isPrivate(normalized)) {
|
||||
return JetTokens.PRIVATE_KEYWORD
|
||||
return KtTokens.PRIVATE_KEYWORD
|
||||
}
|
||||
error("Unexpected visibility '$normalized'")
|
||||
}
|
||||
|
||||
+7
-7
@@ -28,13 +28,13 @@ import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.quickfix.insertMembersAfter
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
public abstract class OverrideImplementMembersHandler : LanguageCodeInsightActionHandler {
|
||||
|
||||
public fun collectMembersToGenerate(classOrObject: JetClassOrObject): Collection<OverrideMemberChooserObject> {
|
||||
public fun collectMembersToGenerate(classOrObject: KtClassOrObject): Collection<OverrideMemberChooserObject> {
|
||||
val descriptor = classOrObject.resolveToDescriptor() as? ClassDescriptor ?: return emptySet()
|
||||
return collectMembersToGenerate(descriptor, classOrObject.project)
|
||||
}
|
||||
@@ -52,9 +52,9 @@ public abstract class OverrideImplementMembersHandler : LanguageCodeInsightActio
|
||||
protected abstract fun getChooserTitle(): String
|
||||
|
||||
override fun isValidFor(editor: Editor, file: PsiFile): Boolean {
|
||||
if (file !is JetFile) return false
|
||||
if (file !is KtFile) return false
|
||||
val elementAtCaret = file.findElementAt(editor.caretModel.offset)
|
||||
val classOrObject = elementAtCaret?.getNonStrictParentOfType<JetClassOrObject>()
|
||||
val classOrObject = elementAtCaret?.getNonStrictParentOfType<KtClassOrObject>()
|
||||
return classOrObject != null
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public abstract class OverrideImplementMembersHandler : LanguageCodeInsightActio
|
||||
|
||||
public fun invoke(project: Project, editor: Editor, file: PsiFile, implementAll: Boolean) {
|
||||
val elementAtCaret = file.findElementAt(editor.caretModel.offset)
|
||||
val classOrObject = elementAtCaret?.getNonStrictParentOfType<JetClassOrObject>()!!
|
||||
val classOrObject = elementAtCaret?.getNonStrictParentOfType<KtClassOrObject>()!!
|
||||
|
||||
val members = collectMembersToGenerate(classOrObject)
|
||||
if (members.isEmpty() && !implementAll) {
|
||||
@@ -91,7 +91,7 @@ public abstract class OverrideImplementMembersHandler : LanguageCodeInsightActio
|
||||
override fun startInWriteAction(): Boolean = false
|
||||
|
||||
companion object {
|
||||
public fun generateMembers(editor: Editor, classOrObject: JetClassOrObject, selectedElements: Collection<OverrideMemberChooserObject>) {
|
||||
public fun generateMembers(editor: Editor, classOrObject: KtClassOrObject, selectedElements: Collection<OverrideMemberChooserObject>) {
|
||||
val project = classOrObject.project
|
||||
insertMembersAfter(editor, classOrObject, selectedElements.map { it.generateMember(project) })
|
||||
}
|
||||
|
||||
+7
-7
@@ -76,7 +76,7 @@ interface OverrideMemberChooserObject : ClassMember {
|
||||
}
|
||||
}
|
||||
|
||||
fun OverrideMemberChooserObject.generateMember(project: Project, asConstructorParameter: Boolean = false): JetCallableDeclaration {
|
||||
fun OverrideMemberChooserObject.generateMember(project: Project, asConstructorParameter: Boolean = false): KtCallableDeclaration {
|
||||
val descriptor = immediateSuper
|
||||
if (asConstructorParameter) {
|
||||
assert(descriptor is PropertyDescriptor) { "asConstructorParameter is valid only for PropertyDescriptor" }
|
||||
@@ -100,7 +100,7 @@ private val OVERRIDE_RENDERER = DescriptorRenderer.withOptions {
|
||||
typeNormalizer = IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES
|
||||
}
|
||||
|
||||
private fun generateProperty(project: Project, descriptor: PropertyDescriptor, bodyType: OverrideMemberChooserObject.BodyType): JetProperty {
|
||||
private fun generateProperty(project: Project, descriptor: PropertyDescriptor, bodyType: OverrideMemberChooserObject.BodyType): KtProperty {
|
||||
val newDescriptor = descriptor.copy(descriptor.containingDeclaration, Modality.OPEN, descriptor.visibility,
|
||||
descriptor.kind, /* copyOverrides = */ true) as PropertyDescriptor
|
||||
newDescriptor.addOverriddenDescriptor(descriptor)
|
||||
@@ -113,17 +113,17 @@ private fun generateProperty(project: Project, descriptor: PropertyDescriptor, b
|
||||
append("\nset(value) {}")
|
||||
}
|
||||
}
|
||||
return JetPsiFactory(project).createProperty(OVERRIDE_RENDERER.render(newDescriptor) + body)
|
||||
return KtPsiFactory(project).createProperty(OVERRIDE_RENDERER.render(newDescriptor) + body)
|
||||
}
|
||||
|
||||
private fun generateConstructorParameter(project: Project, descriptor: PropertyDescriptor): JetParameter {
|
||||
private fun generateConstructorParameter(project: Project, descriptor: PropertyDescriptor): KtParameter {
|
||||
val newDescriptor = descriptor.copy(descriptor.containingDeclaration, Modality.OPEN, descriptor.visibility,
|
||||
descriptor.kind, /* copyOverrides = */ true) as PropertyDescriptor
|
||||
newDescriptor.addOverriddenDescriptor(descriptor)
|
||||
return JetPsiFactory(project).createParameter(OVERRIDE_RENDERER.render(newDescriptor))
|
||||
return KtPsiFactory(project).createParameter(OVERRIDE_RENDERER.render(newDescriptor))
|
||||
}
|
||||
|
||||
private fun generateFunction(project: Project, descriptor: FunctionDescriptor, bodyType: OverrideMemberChooserObject.BodyType): JetNamedFunction {
|
||||
private fun generateFunction(project: Project, descriptor: FunctionDescriptor, bodyType: OverrideMemberChooserObject.BodyType): KtNamedFunction {
|
||||
val newDescriptor = descriptor.copy(descriptor.containingDeclaration, Modality.OPEN, descriptor.visibility,
|
||||
descriptor.kind, /* copyOverrides = */ true)
|
||||
newDescriptor.addOverriddenDescriptor(descriptor)
|
||||
@@ -135,7 +135,7 @@ private fun generateFunction(project: Project, descriptor: FunctionDescriptor, b
|
||||
|
||||
val body = "{" + (if (returnsNotUnit && bodyType != OverrideMemberChooserObject.BodyType.EMPTY) "return " else "") + delegation + "}"
|
||||
|
||||
return JetPsiFactory(project).createFunction(OVERRIDE_RENDERER.render(newDescriptor) + body)
|
||||
return KtPsiFactory(project).createFunction(OVERRIDE_RENDERER.render(newDescriptor) + body)
|
||||
}
|
||||
|
||||
public fun generateUnsupportedOrSuperCall(descriptor: CallableMemberDescriptor, bodyType: OverrideMemberChooserObject.BodyType): String {
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiDirectory
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiPackage
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
public fun PsiDirectory.getPackage(): PsiPackage? = JavaDirectoryService.getInstance()!!.getPackage(this)
|
||||
|
||||
@@ -30,4 +30,4 @@ public fun PsiFile.getFqNameByDirectory(): FqName {
|
||||
return qualifiedNameByDirectory?.let { FqName(it) } ?: FqName.ROOT
|
||||
}
|
||||
|
||||
public fun JetFile.packageMatchesDirectory(): Boolean = getPackageFqName() == getFqNameByDirectory()
|
||||
public fun KtFile.packageMatchesDirectory(): Boolean = getPackageFqName() == getFqNameByDirectory()
|
||||
@@ -23,12 +23,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.KotlinLightClassForDecompiledDec
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
|
||||
|
||||
public fun ResolutionFacade.psiClassToDescriptor(
|
||||
psiClass: PsiClass,
|
||||
declarationTranslator: (JetClassOrObject) -> JetClassOrObject? = { it }
|
||||
declarationTranslator: (KtClassOrObject) -> KtClassOrObject? = { it }
|
||||
): ClassifierDescriptor? {
|
||||
return if (psiClass is KotlinLightClass && psiClass !is KotlinLightClassForDecompiledDeclaration) {
|
||||
val origin = psiClass.getOrigin () ?: return null
|
||||
|
||||
@@ -22,8 +22,8 @@ import com.intellij.psi.impl.source.codeStyle.CodeEditUtil
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
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.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getFunctionLiteralArgumentName
|
||||
@@ -38,29 +38,29 @@ public inline fun <reified T: PsiElement> PsiElement.replaced(newElement: T): T
|
||||
return if (result is T)
|
||||
result
|
||||
else
|
||||
(result as JetParenthesizedExpression).getExpression() as T
|
||||
(result as KtParenthesizedExpression).getExpression() as T
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public fun <T: PsiElement> T.copied(): T = copy() as T
|
||||
|
||||
public fun JetFunctionLiteralArgument.moveInsideParentheses(bindingContext: BindingContext): JetCallExpression {
|
||||
public fun KtFunctionLiteralArgument.moveInsideParentheses(bindingContext: BindingContext): KtCallExpression {
|
||||
return moveInsideParenthesesAndReplaceWith(this.getArgumentExpression(), bindingContext)
|
||||
}
|
||||
|
||||
public fun JetFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
|
||||
replacement: JetExpression,
|
||||
public fun KtFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
|
||||
replacement: KtExpression,
|
||||
bindingContext: BindingContext
|
||||
): JetCallExpression = moveInsideParenthesesAndReplaceWith(replacement, getFunctionLiteralArgumentName(bindingContext))
|
||||
): KtCallExpression = moveInsideParenthesesAndReplaceWith(replacement, getFunctionLiteralArgumentName(bindingContext))
|
||||
|
||||
public fun JetFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
|
||||
replacement: JetExpression,
|
||||
public fun KtFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
|
||||
replacement: KtExpression,
|
||||
functionLiteralArgumentName: Name?
|
||||
): JetCallExpression {
|
||||
val oldCallExpression = getParent() as JetCallExpression
|
||||
val newCallExpression = oldCallExpression.copy() as JetCallExpression
|
||||
): KtCallExpression {
|
||||
val oldCallExpression = getParent() as KtCallExpression
|
||||
val newCallExpression = oldCallExpression.copy() as KtCallExpression
|
||||
|
||||
val psiFactory = JetPsiFactory(getProject())
|
||||
val psiFactory = KtPsiFactory(getProject())
|
||||
val argument = if (newCallExpression.getValueArgumentsInParentheses().any { it.isNamed() }) {
|
||||
psiFactory.createArgument(replacement, functionLiteralArgumentName)
|
||||
}
|
||||
@@ -80,17 +80,17 @@ public fun JetFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
|
||||
else {
|
||||
functionLiteralArgument.replace(valueArgumentList)
|
||||
}
|
||||
return oldCallExpression.replace(newCallExpression) as JetCallExpression
|
||||
return oldCallExpression.replace(newCallExpression) as KtCallExpression
|
||||
}
|
||||
|
||||
public fun JetCallExpression.moveFunctionLiteralOutsideParentheses() {
|
||||
public fun KtCallExpression.moveFunctionLiteralOutsideParentheses() {
|
||||
assert(getFunctionLiteralArguments().isEmpty())
|
||||
val argumentList = getValueArgumentList()!!
|
||||
val argument = argumentList.getArguments().last()
|
||||
val expression = argument.getArgumentExpression()!!
|
||||
assert(expression.unpackFunctionLiteral() != null)
|
||||
|
||||
val dummyCall = JetPsiFactory(this).createExpressionByPattern("foo()$0:'{}'", expression) as JetCallExpression
|
||||
val dummyCall = KtPsiFactory(this).createExpressionByPattern("foo()$0:'{}'", expression) as KtCallExpression
|
||||
val functionLiteralArgument = dummyCall.getFunctionLiteralArguments().single()
|
||||
this.add(functionLiteralArgument)
|
||||
if (argumentList.getArguments().size() > 1) {
|
||||
@@ -101,9 +101,9 @@ public fun JetCallExpression.moveFunctionLiteralOutsideParentheses() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun JetBlockExpression.appendElement(element: JetElement, addNewLine: Boolean = false): JetElement {
|
||||
public fun KtBlockExpression.appendElement(element: KtElement, addNewLine: Boolean = false): KtElement {
|
||||
val rBrace = getRBrace()
|
||||
val newLine = JetPsiFactory(this).createNewLine()
|
||||
val newLine = KtPsiFactory(this).createNewLine()
|
||||
val anchor = if (rBrace == null) {
|
||||
val lastChild = getLastChild()
|
||||
if (lastChild !is PsiWhiteSpace) addAfter(newLine, lastChild)!! else lastChild
|
||||
@@ -111,7 +111,7 @@ public fun JetBlockExpression.appendElement(element: JetElement, addNewLine: Boo
|
||||
else {
|
||||
rBrace.getPrevSibling()!!
|
||||
}
|
||||
val addedElement = addAfter(element, anchor)!! as JetElement
|
||||
val addedElement = addAfter(element, anchor)!! as KtElement
|
||||
if (addNewLine) {
|
||||
addAfter(newLine, addedElement)
|
||||
}
|
||||
@@ -159,21 +159,21 @@ public fun PsiElement.deleteSingle() {
|
||||
CodeEditUtil.removeChild(getParent()?.getNode() ?: return, getNode() ?: return)
|
||||
}
|
||||
|
||||
public fun JetClass.getOrCreateCompanionObject() : JetObjectDeclaration {
|
||||
public fun KtClass.getOrCreateCompanionObject() : KtObjectDeclaration {
|
||||
getCompanionObjects().firstOrNull()?.let { return it }
|
||||
return addDeclaration(JetPsiFactory(this).createCompanionObject()) as JetObjectDeclaration
|
||||
return addDeclaration(KtPsiFactory(this).createCompanionObject()) as KtObjectDeclaration
|
||||
}
|
||||
|
||||
//TODO: code style option whether to insert redundant 'public' keyword or not
|
||||
public fun JetDeclaration.setVisibility(visibilityModifier: JetModifierKeywordToken) {
|
||||
val defaultVisibilityKeyword = if (hasModifier(JetTokens.OVERRIDE_KEYWORD)) {
|
||||
public fun KtDeclaration.setVisibility(visibilityModifier: KtModifierKeywordToken) {
|
||||
val defaultVisibilityKeyword = if (hasModifier(KtTokens.OVERRIDE_KEYWORD)) {
|
||||
(resolveToDescriptor() as? CallableMemberDescriptor)
|
||||
?.overriddenDescriptors
|
||||
?.let { OverridingUtil.findMaxVisibility(it) }
|
||||
?.toKeywordToken()
|
||||
}
|
||||
else {
|
||||
JetTokens.DEFAULT_VISIBILITY_KEYWORD
|
||||
KtTokens.DEFAULT_VISIBILITY_KEYWORD
|
||||
}
|
||||
|
||||
if (visibilityModifier == defaultVisibilityKeyword) {
|
||||
|
||||
@@ -37,8 +37,8 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.types.DeferredType;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.kotlin.types.KtType;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
|
||||
public class QuickFixUtil {
|
||||
private QuickFixUtil() {
|
||||
@@ -58,12 +58,12 @@ public class QuickFixUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetType getDeclarationReturnType(JetNamedDeclaration declaration) {
|
||||
public static KtType getDeclarationReturnType(KtNamedDeclaration declaration) {
|
||||
PsiFile file = declaration.getContainingFile();
|
||||
if (!(file instanceof JetFile)) return null;
|
||||
if (!(file instanceof KtFile)) return null;
|
||||
DeclarationDescriptor descriptor = ResolutionUtils.resolveToDescriptor(declaration);
|
||||
if (!(descriptor instanceof CallableDescriptor)) return null;
|
||||
JetType type = ((CallableDescriptor) descriptor).getReturnType();
|
||||
KtType type = ((CallableDescriptor) descriptor).getReturnType();
|
||||
if (type instanceof DeferredType) {
|
||||
type = ((DeferredType) type).getDelegate();
|
||||
}
|
||||
@@ -71,17 +71,17 @@ public class QuickFixUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetType findLowerBoundOfOverriddenCallablesReturnTypes(@NotNull CallableDescriptor descriptor) {
|
||||
JetType matchingReturnType = null;
|
||||
public static KtType findLowerBoundOfOverriddenCallablesReturnTypes(@NotNull CallableDescriptor descriptor) {
|
||||
KtType matchingReturnType = null;
|
||||
for (CallableDescriptor overriddenDescriptor : ((CallableDescriptor) descriptor).getOverriddenDescriptors()) {
|
||||
JetType overriddenReturnType = overriddenDescriptor.getReturnType();
|
||||
KtType overriddenReturnType = overriddenDescriptor.getReturnType();
|
||||
if (overriddenReturnType == null) {
|
||||
return null;
|
||||
}
|
||||
if (matchingReturnType == null || JetTypeChecker.DEFAULT.isSubtypeOf(overriddenReturnType, matchingReturnType)) {
|
||||
if (matchingReturnType == null || KotlinTypeChecker.DEFAULT.isSubtypeOf(overriddenReturnType, matchingReturnType)) {
|
||||
matchingReturnType = overriddenReturnType;
|
||||
}
|
||||
else if (!JetTypeChecker.DEFAULT.isSubtypeOf(matchingReturnType, overriddenReturnType)) {
|
||||
else if (!KotlinTypeChecker.DEFAULT.isSubtypeOf(matchingReturnType, overriddenReturnType)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -100,23 +100,23 @@ public class QuickFixUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetParameter getParameterDeclarationForValueArgument(
|
||||
public static KtParameter getParameterDeclarationForValueArgument(
|
||||
@NotNull ResolvedCall<?> resolvedCall,
|
||||
@Nullable ValueArgument valueArgument
|
||||
) {
|
||||
PsiElement declaration = safeGetDeclaration(CallUtilKt.getParameterForArgument(resolvedCall, valueArgument));
|
||||
return declaration instanceof JetParameter ? (JetParameter) declaration : null;
|
||||
return declaration instanceof KtParameter ? (KtParameter) declaration : null;
|
||||
}
|
||||
|
||||
private static boolean equalOrLastInThenOrElse(JetExpression thenOrElse, JetExpression expression) {
|
||||
private static boolean equalOrLastInThenOrElse(KtExpression thenOrElse, KtExpression expression) {
|
||||
if (thenOrElse == expression) return true;
|
||||
return thenOrElse instanceof JetBlockExpression && expression.getParent() == thenOrElse &&
|
||||
PsiTreeUtil.getNextSiblingOfType(expression, JetExpression.class) == null;
|
||||
return thenOrElse instanceof KtBlockExpression && expression.getParent() == thenOrElse &&
|
||||
PsiTreeUtil.getNextSiblingOfType(expression, KtExpression.class) == null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetIfExpression getParentIfForBranch(@Nullable JetExpression expression) {
|
||||
JetIfExpression ifExpression = PsiTreeUtil.getParentOfType(expression, JetIfExpression.class, true);
|
||||
public static KtIfExpression getParentIfForBranch(@Nullable KtExpression expression) {
|
||||
KtIfExpression ifExpression = PsiTreeUtil.getParentOfType(expression, KtIfExpression.class, true);
|
||||
if (ifExpression == null) return null;
|
||||
if (equalOrLastInThenOrElse(ifExpression.getThen(), expression)
|
||||
|| equalOrLastInThenOrElse(ifExpression.getElse(), expression)) {
|
||||
@@ -125,13 +125,13 @@ public class QuickFixUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean canEvaluateTo(JetExpression parent, JetExpression child) {
|
||||
public static boolean canEvaluateTo(KtExpression parent, KtExpression child) {
|
||||
if (parent == null || child == null) {
|
||||
return false;
|
||||
}
|
||||
while (parent != child) {
|
||||
if (child.getParent() instanceof JetParenthesizedExpression) {
|
||||
child = (JetExpression) child.getParent();
|
||||
if (child.getParent() instanceof KtParenthesizedExpression) {
|
||||
child = (KtExpression) child.getParent();
|
||||
continue;
|
||||
}
|
||||
child = getParentIfForBranch(child);
|
||||
@@ -140,22 +140,22 @@ public class QuickFixUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canFunctionOrGetterReturnExpression(@NotNull JetDeclaration functionOrGetter, @NotNull JetExpression expression) {
|
||||
if (functionOrGetter instanceof JetFunctionLiteral) {
|
||||
JetBlockExpression functionLiteralBody = ((JetFunctionLiteral) functionOrGetter).getBodyExpression();
|
||||
public static boolean canFunctionOrGetterReturnExpression(@NotNull KtDeclaration functionOrGetter, @NotNull KtExpression expression) {
|
||||
if (functionOrGetter instanceof KtFunctionLiteral) {
|
||||
KtBlockExpression functionLiteralBody = ((KtFunctionLiteral) functionOrGetter).getBodyExpression();
|
||||
PsiElement returnedElement = functionLiteralBody == null ? null : functionLiteralBody.getLastChild();
|
||||
return returnedElement instanceof JetExpression && canEvaluateTo((JetExpression) returnedElement, expression);
|
||||
return returnedElement instanceof KtExpression && canEvaluateTo((KtExpression) returnedElement, expression);
|
||||
}
|
||||
else {
|
||||
if (functionOrGetter instanceof JetWithExpressionInitializer && canEvaluateTo(((JetWithExpressionInitializer) functionOrGetter).getInitializer(), expression)) {
|
||||
if (functionOrGetter instanceof KtWithExpressionInitializer && canEvaluateTo(((KtWithExpressionInitializer) functionOrGetter).getInitializer(), expression)) {
|
||||
return true;
|
||||
}
|
||||
JetReturnExpression returnExpression = PsiTreeUtil.getParentOfType(expression, JetReturnExpression.class);
|
||||
KtReturnExpression returnExpression = PsiTreeUtil.getParentOfType(expression, KtReturnExpression.class);
|
||||
return returnExpression != null && canEvaluateTo(returnExpression.getReturnedExpression(), expression);
|
||||
}
|
||||
}
|
||||
|
||||
public static String renderTypeWithFqNameOnClash(JetType type, String nameToCheckAgainst) {
|
||||
public static String renderTypeWithFqNameOnClash(KtType type, String nameToCheckAgainst) {
|
||||
FqName typeFqName = DescriptorUtils.getFqNameSafe(DescriptorUtils.getClassDescriptorForType(type));
|
||||
FqName fqNameToCheckAgainst = new FqName(nameToCheckAgainst);
|
||||
DescriptorRenderer renderer = typeFqName.shortName().equals(fqNameToCheckAgainst.shortName())
|
||||
|
||||
+10
-10
@@ -27,10 +27,10 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.JetDescriptorIconProvider
|
||||
import org.jetbrains.kotlin.psi.JetClass
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.NameShortness
|
||||
import org.jetbrains.kotlin.renderer.render
|
||||
@@ -45,16 +45,16 @@ public open class DescriptorMemberChooserObject(
|
||||
override fun getParentNodeDelegate(): MemberChooserObject {
|
||||
val parent = descriptor.containingDeclaration ?: error("No parent for $descriptor")
|
||||
|
||||
val declaration = if (psiElement is JetDeclaration) { // kotlin
|
||||
PsiTreeUtil.getStubOrPsiParentOfType(psiElement, javaClass<JetNamedDeclaration>())
|
||||
?: PsiTreeUtil.getStubOrPsiParentOfType(psiElement, javaClass<JetFile>())
|
||||
val declaration = if (psiElement is KtDeclaration) { // kotlin
|
||||
PsiTreeUtil.getStubOrPsiParentOfType(psiElement, javaClass<KtNamedDeclaration>())
|
||||
?: PsiTreeUtil.getStubOrPsiParentOfType(psiElement, javaClass<KtFile>())
|
||||
}
|
||||
else { // java or compiled
|
||||
(psiElement as PsiMember).containingClass
|
||||
} ?: error("No parent for $psiElement")
|
||||
|
||||
return when (declaration) {
|
||||
is JetFile -> PsiElementMemberChooserObject(declaration, declaration.name)
|
||||
is KtFile -> PsiElementMemberChooserObject(declaration, declaration.name)
|
||||
else -> DescriptorMemberChooserObject(declaration, parent)
|
||||
}
|
||||
}
|
||||
@@ -82,9 +82,9 @@ public open class DescriptorMemberChooserObject(
|
||||
|
||||
public fun getIcon(declaration: PsiElement?, descriptor: DeclarationDescriptor): Icon {
|
||||
if (declaration != null && declaration.isValid) {
|
||||
val isClass = declaration is PsiClass || declaration is JetClass
|
||||
val isClass = declaration is PsiClass || declaration is KtClass
|
||||
val flags = if (isClass) 0 else Iconable.ICON_FLAG_VISIBILITY
|
||||
if (declaration is JetDeclaration) {
|
||||
if (declaration is KtDeclaration) {
|
||||
// kotlin declaration
|
||||
// visibility and abstraction better detect by a descriptor
|
||||
return JetDescriptorIconProvider.getIcon(descriptor, declaration, flags)
|
||||
|
||||
Reference in New Issue
Block a user