Renamed classes
This commit is contained in:
+2
-2
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
|
|||||||
import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings
|
import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings
|
||||||
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
||||||
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||||
import org.jetbrains.kotlin.psi.JetExpression
|
import org.jetbrains.kotlin.psi.JetExpression
|
||||||
@@ -142,7 +142,7 @@ class ParameterNameAndTypeCompletion(
|
|||||||
ProgressManager.checkCanceled()
|
ProgressManager.checkCanceled()
|
||||||
if (suggestionsByTypesAdded.contains(type)) return // don't add suggestions for the same with longer user prefix
|
if (suggestionsByTypesAdded.contains(type)) return // don't add suggestions for the same with longer user prefix
|
||||||
|
|
||||||
val nameSuggestions = JetNameSuggester.getCamelNames(className, EmptyValidator, userPrefix.isEmpty())
|
val nameSuggestions = KotlinNameSuggester.getCamelNames(className, EmptyValidator, userPrefix.isEmpty())
|
||||||
for (name in nameSuggestions) {
|
for (name in nameSuggestions) {
|
||||||
if (prefixMatcher.prefixMatches(name)) {
|
if (prefixMatcher.prefixMatches(name)) {
|
||||||
val lookupElement = MyLookupElement.create(userPrefix, name, type, lookupElementFactory)
|
val lookupElement = MyLookupElement.create(userPrefix, name, type, lookupElementFactory)
|
||||||
|
|||||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.completion.ExpectedInfos
|
import org.jetbrains.kotlin.idea.completion.ExpectedInfos
|
||||||
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
@@ -103,7 +103,7 @@ private fun buildTemplate(lambdaType: JetType, explicitParameterTypes: Boolean,
|
|||||||
template.addTextSegment(", ")
|
template.addTextSegment(", ")
|
||||||
}
|
}
|
||||||
//TODO: check for names in scope
|
//TODO: check for names in scope
|
||||||
template.addVariable(ParameterNameExpression(JetNameSuggester.suggestNames(parameterType, EmptyValidator, "p")), true)
|
template.addVariable(ParameterNameExpression(KotlinNameSuggester.suggestNames(parameterType, EmptyValidator, "p")), true)
|
||||||
if (explicitParameterTypes) {
|
if (explicitParameterTypes) {
|
||||||
template.addTextSegment(": " + IdeDescriptorRenderers.SOURCE_CODE.renderType(parameterType))
|
template.addTextSegment(": " + IdeDescriptorRenderers.SOURCE_CODE.renderType(parameterType))
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -21,7 +21,7 @@ import com.intellij.openapi.util.text.StringUtil
|
|||||||
import com.intellij.util.ArrayUtil
|
import com.intellij.util.ArrayUtil
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameValidator
|
import org.jetbrains.kotlin.idea.core.NameValidator
|
||||||
import org.jetbrains.kotlin.lexer.JetLexer
|
import org.jetbrains.kotlin.lexer.JetLexer
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -33,9 +33,9 @@ import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
public object JetNameSuggester {
|
public object KotlinNameSuggester {
|
||||||
|
|
||||||
private fun addName(result: ArrayList<String>, name: String?, validator: JetNameValidator) {
|
private fun addName(result: ArrayList<String>, name: String?, validator: NameValidator) {
|
||||||
var name = name ?: return
|
var name = name ?: return
|
||||||
if ("class" == name) name = "clazz"
|
if ("class" == name) name = "clazz"
|
||||||
if (!isIdentifier(name)) return
|
if (!isIdentifier(name)) return
|
||||||
@@ -58,7 +58,7 @@ public object JetNameSuggester {
|
|||||||
* *
|
* *
|
||||||
* @return possible names
|
* @return possible names
|
||||||
*/
|
*/
|
||||||
public fun suggestNames(expression: JetExpression, validator: JetNameValidator, defaultName: String?): Array<String> {
|
public fun suggestNames(expression: JetExpression, validator: NameValidator, defaultName: String?): Array<String> {
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
|
|
||||||
val bindingContext = expression.analyze(BodyResolveMode.FULL)
|
val bindingContext = expression.analyze(BodyResolveMode.FULL)
|
||||||
@@ -72,20 +72,20 @@ public object JetNameSuggester {
|
|||||||
return ArrayUtil.toStringArray(result)
|
return ArrayUtil.toStringArray(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun suggestNames(type: JetType, validator: JetNameValidator, defaultName: String?): Array<String> {
|
public fun suggestNames(type: JetType, validator: NameValidator, defaultName: String?): Array<String> {
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
addNamesForType(result, type, validator)
|
addNamesForType(result, type, validator)
|
||||||
if (result.isEmpty()) addName(result, defaultName, validator)
|
if (result.isEmpty()) addName(result, defaultName, validator)
|
||||||
return ArrayUtil.toStringArray(result)
|
return ArrayUtil.toStringArray(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun suggestNamesForType(jetType: JetType, validator: JetNameValidator): Array<String> {
|
public fun suggestNamesForType(jetType: JetType, validator: NameValidator): Array<String> {
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
addNamesForType(result, jetType, validator)
|
addNamesForType(result, jetType, validator)
|
||||||
return ArrayUtil.toStringArray(result)
|
return ArrayUtil.toStringArray(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
jvmOverloads public fun suggestNamesForExpression(expression: JetExpression, validator: JetNameValidator, defaultName: String? = null): Array<String> {
|
jvmOverloads public fun suggestNamesForExpression(expression: JetExpression, validator: NameValidator, defaultName: String? = null): Array<String> {
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
addNamesForExpression(result, expression, validator)
|
addNamesForExpression(result, expression, validator)
|
||||||
if (result.isEmpty()) addName(result, defaultName, validator)
|
if (result.isEmpty()) addName(result, defaultName, validator)
|
||||||
@@ -94,7 +94,7 @@ public object JetNameSuggester {
|
|||||||
|
|
||||||
private val COMMON_TYPE_PARAMETER_NAMES = arrayOf("T", "U", "V", "W", "X", "Y", "Z")
|
private val COMMON_TYPE_PARAMETER_NAMES = arrayOf("T", "U", "V", "W", "X", "Y", "Z")
|
||||||
|
|
||||||
public fun suggestNamesForTypeParameters(count: Int, validator: JetNameValidator): Array<String> {
|
public fun suggestNamesForTypeParameters(count: Int, validator: NameValidator): Array<String> {
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
for (i in 0..count - 1) {
|
for (i in 0..count - 1) {
|
||||||
result.add(validator.validateNameWithVariants(*COMMON_TYPE_PARAMETER_NAMES))
|
result.add(validator.validateNameWithVariants(*COMMON_TYPE_PARAMETER_NAMES))
|
||||||
@@ -102,7 +102,7 @@ public object JetNameSuggester {
|
|||||||
return ArrayUtil.toStringArray(result)
|
return ArrayUtil.toStringArray(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNamesForType(result: ArrayList<String>, jetType: JetType, validator: JetNameValidator) {
|
private fun addNamesForType(result: ArrayList<String>, jetType: JetType, validator: NameValidator) {
|
||||||
var jetType = jetType
|
var jetType = jetType
|
||||||
val builtIns = KotlinBuiltIns.getInstance()
|
val builtIns = KotlinBuiltIns.getInstance()
|
||||||
val typeChecker = JetTypeChecker.DEFAULT
|
val typeChecker = JetTypeChecker.DEFAULT
|
||||||
@@ -177,7 +177,7 @@ public object JetNameSuggester {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addForClassType(result: ArrayList<String>, jetType: JetType, validator: JetNameValidator) {
|
private fun addForClassType(result: ArrayList<String>, jetType: JetType, validator: NameValidator) {
|
||||||
val descriptor = jetType.getConstructor().getDeclarationDescriptor()
|
val descriptor = jetType.getConstructor().getDeclarationDescriptor()
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
val className = descriptor.getName()
|
val className = descriptor.getName()
|
||||||
@@ -189,13 +189,13 @@ public object JetNameSuggester {
|
|||||||
|
|
||||||
private val ACCESSOR_PREFIXES = arrayOf("get", "is", "set")
|
private val ACCESSOR_PREFIXES = arrayOf("get", "is", "set")
|
||||||
|
|
||||||
public fun getCamelNames(name: String, validator: JetNameValidator, startLowerCase: Boolean): List<String> {
|
public fun getCamelNames(name: String, validator: NameValidator, startLowerCase: Boolean): List<String> {
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
addCamelNames(result, name, validator, startLowerCase)
|
addCamelNames(result, name, validator, startLowerCase)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addCamelNames(result: ArrayList<String>, name: String, validator: JetNameValidator, startLowerCase: Boolean = true) {
|
private fun addCamelNames(result: ArrayList<String>, name: String, validator: NameValidator, startLowerCase: Boolean = true) {
|
||||||
if (name === "") return
|
if (name === "") return
|
||||||
var s = deleteNonLetterFromString(name)
|
var s = deleteNonLetterFromString(name)
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ public object JetNameSuggester {
|
|||||||
return matcher.replaceAll("")
|
return matcher.replaceAll("")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNamesForExpression(result: ArrayList<String>, expression: JetExpression?, validator: JetNameValidator) {
|
private fun addNamesForExpression(result: ArrayList<String>, expression: JetExpression?, validator: NameValidator) {
|
||||||
if (expression == null) return
|
if (expression == null) return
|
||||||
|
|
||||||
expression.accept(object : JetVisitorVoid() {
|
expression.accept(object : JetVisitorVoid() {
|
||||||
+3
-3
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.core
|
|||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
|
||||||
public abstract class JetNameValidator {
|
public abstract class NameValidator {
|
||||||
/**
|
/**
|
||||||
* Validates name, and slightly improves it by adding number to name in case of conflicts
|
* Validates name, and slightly improves it by adding number to name in case of conflicts
|
||||||
* @param name to check it in scope
|
* @param name to check it in scope
|
||||||
@@ -55,14 +55,14 @@ public abstract class JetNameValidator {
|
|||||||
protected abstract fun validateInner(name: String): Boolean
|
protected abstract fun validateInner(name: String): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
public object EmptyValidator : JetNameValidator() {
|
public object EmptyValidator : NameValidator() {
|
||||||
override fun validateInner(name: String): Boolean = true
|
override fun validateInner(name: String): Boolean = true
|
||||||
}
|
}
|
||||||
|
|
||||||
public open class CollectingValidator(
|
public open class CollectingValidator(
|
||||||
existingNames: Collection<String> = Collections.emptySet(),
|
existingNames: Collection<String> = Collections.emptySet(),
|
||||||
val filter: (String) -> Boolean = { true }
|
val filter: (String) -> Boolean = { true }
|
||||||
): JetNameValidator() {
|
): NameValidator() {
|
||||||
private val suggestedSet = HashSet(existingNames)
|
private val suggestedSet = HashSet(existingNames)
|
||||||
|
|
||||||
override fun validateInner(name: String): Boolean {
|
override fun validateInner(name: String): Boolean {
|
||||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.core.IterableTypesDetector
|
import org.jetbrains.kotlin.idea.core.IterableTypesDetector
|
||||||
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.core.replaced
|
import org.jetbrains.kotlin.idea.core.replaced
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -60,7 +60,7 @@ public class IterateExpressionIntention : JetSelfTargetingIntention<JetExpressio
|
|||||||
val elementType = data(element)!!.elementType
|
val elementType = data(element)!!.elementType
|
||||||
//TODO: base on expression too
|
//TODO: base on expression too
|
||||||
//TODO: name validation
|
//TODO: name validation
|
||||||
val names = JetNameSuggester.suggestNames(elementType, EmptyValidator, "e")
|
val names = KotlinNameSuggester.suggestNames(elementType, EmptyValidator, "e")
|
||||||
|
|
||||||
var forExpression = JetPsiFactory(element).createExpressionByPattern("for($0 in $1) {\nx\n}", names[0], element) as JetForExpression
|
var forExpression = JetPsiFactory(element).createExpressionByPattern("for($0 in $1) {\nx\n}", names[0], element) as JetForExpression
|
||||||
forExpression = element.replaced(forExpression)
|
forExpression = element.replaced(forExpression)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
|||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.kotlin.idea.JetBundle;
|
import org.jetbrains.kotlin.idea.JetBundle;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameValidator;
|
import org.jetbrains.kotlin.idea.core.NameValidator;
|
||||||
import org.jetbrains.kotlin.idea.core.SimpleCollectingValidator;
|
import org.jetbrains.kotlin.idea.core.SimpleCollectingValidator;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*;
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*;
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
@@ -130,7 +130,7 @@ public class AddFunctionParametersFix extends ChangeFunctionSignatureFix {
|
|||||||
public Unit invoke(JetMutableMethodDescriptor descriptor) {
|
public Unit invoke(JetMutableMethodDescriptor descriptor) {
|
||||||
List<ValueParameterDescriptor> parameters = functionDescriptor.getValueParameters();
|
List<ValueParameterDescriptor> parameters = functionDescriptor.getValueParameters();
|
||||||
List<? extends ValueArgument> arguments = callElement.getValueArguments();
|
List<? extends ValueArgument> arguments = callElement.getValueArguments();
|
||||||
JetNameValidator validator = new SimpleCollectingValidator();
|
NameValidator validator = new SimpleCollectingValidator();
|
||||||
|
|
||||||
for (int i = 0; i < arguments.size(); i ++) {
|
for (int i = 0; i < arguments.size(); i ++) {
|
||||||
ValueArgument argument = arguments.get(i);
|
ValueArgument argument = arguments.get(i);
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.kotlin.idea.JetBundle;
|
import org.jetbrains.kotlin.idea.JetBundle;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester;
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameValidator;
|
import org.jetbrains.kotlin.idea.core.NameValidator;
|
||||||
import org.jetbrains.kotlin.idea.core.SimpleCollectingValidator;
|
import org.jetbrains.kotlin.idea.core.SimpleCollectingValidator;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*;
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
@@ -68,10 +68,10 @@ public class ChangeFunctionLiteralSignatureFix extends ChangeFunctionSignatureFi
|
|||||||
new Function1<JetMutableMethodDescriptor, Unit>() {
|
new Function1<JetMutableMethodDescriptor, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public Unit invoke(JetMutableMethodDescriptor descriptor) {
|
public Unit invoke(JetMutableMethodDescriptor descriptor) {
|
||||||
JetNameValidator validator = new SimpleCollectingValidator();
|
NameValidator validator = new SimpleCollectingValidator();
|
||||||
descriptor.clearNonReceiverParameters();
|
descriptor.clearNonReceiverParameters();
|
||||||
for (JetType type : parameterTypes) {
|
for (JetType type : parameterTypes) {
|
||||||
String name = JetNameSuggester.INSTANCE$.suggestNames(type, validator, "param")[0];
|
String name = KotlinNameSuggester.INSTANCE$.suggestNames(type, validator, "param")[0];
|
||||||
descriptor.addParameter(
|
descriptor.addParameter(
|
||||||
new JetParameterInfo(functionDescriptor, -1, name, type, null, null, JetValVar.None, null)
|
new JetParameterInfo(functionDescriptor, -1, name, type, null, null, JetValVar.None, null)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import org.jetbrains.kotlin.idea.JetBundle;
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
||||||
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil;
|
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester;
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameValidator;
|
import org.jetbrains.kotlin.idea.core.NameValidator;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo;
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar;
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar;
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
@@ -97,7 +97,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String getNewArgumentName(ValueArgument argument, JetNameValidator validator) {
|
protected static String getNewArgumentName(ValueArgument argument, NameValidator validator) {
|
||||||
ValueArgumentName argumentName = argument.getArgumentName();
|
ValueArgumentName argumentName = argument.getArgumentName();
|
||||||
JetExpression expression = argument.getArgumentExpression();
|
JetExpression expression = argument.getArgumentExpression();
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
|||||||
return validator.validateName(argumentName.getAsName().asString());
|
return validator.validateName(argumentName.getAsName().asString());
|
||||||
}
|
}
|
||||||
else if (expression != null) {
|
else if (expression != null) {
|
||||||
return JetNameSuggester.INSTANCE$.suggestNames(expression, validator, "param")[0];
|
return KotlinNameSuggester.INSTANCE$.suggestNames(expression, validator, "param")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return validator.validateName("param");
|
return validator.validateName("param");
|
||||||
@@ -115,7 +115,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
|||||||
FunctionDescriptor functionDescriptor,
|
FunctionDescriptor functionDescriptor,
|
||||||
BindingContext bindingContext,
|
BindingContext bindingContext,
|
||||||
ValueArgument argument,
|
ValueArgument argument,
|
||||||
JetNameValidator validator
|
NameValidator validator
|
||||||
) {
|
) {
|
||||||
String name = getNewArgumentName(argument, validator);
|
String name = getNewArgumentName(argument, validator);
|
||||||
JetExpression expression = argument.getArgumentExpression();
|
JetExpression expression = argument.getArgumentExpression();
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||||
import org.jetbrains.kotlin.idea.core.*
|
import org.jetbrains.kotlin.idea.core.*
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameValidator
|
import org.jetbrains.kotlin.idea.core.NameValidator
|
||||||
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeArgumentsIntention
|
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeArgumentsIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.setType
|
import org.jetbrains.kotlin.idea.intentions.setType
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
@@ -662,11 +662,11 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun suggestName(validator: JetNameValidator): Name {
|
fun suggestName(validator: NameValidator): Name {
|
||||||
val name = if (nameSuggestion != null)
|
val name = if (nameSuggestion != null)
|
||||||
validator.validateName(nameSuggestion)
|
validator.validateName(nameSuggestion)
|
||||||
else
|
else
|
||||||
JetNameSuggester.suggestNamesForExpression(value, validator, "t").first()
|
KotlinNameSuggester.suggestNamesForExpression(value, validator, "t").first()
|
||||||
return Name.identifier(name)
|
return Name.identifier(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -690,7 +690,7 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val name = suggestName(object : JetNameValidator() {
|
val name = suggestName(object : NameValidator() {
|
||||||
override fun validateInner(name: String): Boolean {
|
override fun validateInner(name: String): Boolean {
|
||||||
return resolutionScope.getLocalVariable(Name.identifier(name)) == null && !isNameUsed(name)
|
return resolutionScope.getLocalVariable(Name.identifier(name)) == null && !isNameUsed(name)
|
||||||
}
|
}
|
||||||
@@ -723,7 +723,7 @@ public abstract class DeprecatedSymbolUsageFixBase(
|
|||||||
psiFactory.createExpressionByPattern("$0${dot}let { $1 }", value, expression)
|
psiFactory.createExpressionByPattern("$0${dot}let { $1 }", value, expression)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val name = suggestName(object : JetNameValidator() {
|
val name = suggestName(object : NameValidator() {
|
||||||
override fun validateInner(name: String) = !isNameUsed(name)
|
override fun validateInner(name: String) = !isNameUsed(name)
|
||||||
})
|
})
|
||||||
replaceUsages(name)
|
replaceUsages(name)
|
||||||
|
|||||||
+3
-3
@@ -47,7 +47,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.getJavaClassDescriptor
|
|||||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
|
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
|
||||||
import org.jetbrains.kotlin.idea.core.CollectingValidator
|
import org.jetbrains.kotlin.idea.core.CollectingValidator
|
||||||
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.*
|
import org.jetbrains.kotlin.idea.core.refactoring.*
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.ClassKind
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.ClassKind
|
||||||
import org.jetbrains.kotlin.idea.util.*
|
import org.jetbrains.kotlin.idea.util.*
|
||||||
@@ -397,7 +397,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val validator = CollectingValidator { scope.getClassifier(Name.identifier(it)) == null }
|
val validator = CollectingValidator { scope.getClassifier(Name.identifier(it)) == null }
|
||||||
val parameterNames = JetNameSuggester.suggestNamesForTypeParameters(typeParameterCount, validator)
|
val parameterNames = KotlinNameSuggester.suggestNamesForTypeParameters(typeParameterCount, validator)
|
||||||
val typeParameters = (0..typeParameterCount - 1).map {
|
val typeParameters = (0..typeParameterCount - 1).map {
|
||||||
TypeParameterDescriptorImpl.createWithDefaultBound(
|
TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||||
fakeFunction,
|
fakeFunction,
|
||||||
@@ -821,7 +821,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
// figure out suggested names for each type option
|
// figure out suggested names for each type option
|
||||||
val parameterTypeToNamesMap = HashMap<String, Array<String>>()
|
val parameterTypeToNamesMap = HashMap<String, Array<String>>()
|
||||||
typeCandidates[parameter.typeInfo]!!.forEach { typeCandidate ->
|
typeCandidates[parameter.typeInfo]!!.forEach { typeCandidate ->
|
||||||
val suggestedNames = JetNameSuggester.suggestNamesForType(typeCandidate.theType, EmptyValidator)
|
val suggestedNames = KotlinNameSuggester.suggestNamesForType(typeCandidate.theType, EmptyValidator)
|
||||||
parameterTypeToNamesMap[typeCandidate.renderedType!!] = suggestedNames
|
parameterTypeToNamesMap[typeCandidate.renderedType!!] = suggestedNames
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -20,7 +20,7 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.util.ArrayUtil
|
import com.intellij.util.ArrayUtil
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
import org.jetbrains.kotlin.idea.core.EmptyValidator
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.ClassInfo
|
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.ClassInfo
|
||||||
import org.jetbrains.kotlin.idea.util.makeNotNullable
|
import org.jetbrains.kotlin.idea.util.makeNotNullable
|
||||||
import org.jetbrains.kotlin.idea.util.supertypes
|
import org.jetbrains.kotlin.idea.util.supertypes
|
||||||
@@ -44,7 +44,7 @@ abstract class TypeInfo(val variance: Variance) {
|
|||||||
|
|
||||||
class ByExpression(val expression: JetExpression, variance: Variance): TypeInfo(variance) {
|
class ByExpression(val expression: JetExpression, variance: Variance): TypeInfo(variance) {
|
||||||
override val possibleNamesFromExpression: Array<String> by Delegates.lazy {
|
override val possibleNamesFromExpression: Array<String> by Delegates.lazy {
|
||||||
JetNameSuggester.suggestNamesForExpression(expression, EmptyValidator)
|
KotlinNameSuggester.suggestNamesForExpression(expression, EmptyValidator)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPossibleTypes(builder: CallableBuilder): List<JetType> =
|
override fun getPossibleTypes(builder: CallableBuilder): List<JetType> =
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.refactoring
|
|||||||
|
|
||||||
import com.intellij.lang.refactoring.NamesValidator
|
import com.intellij.lang.refactoring.NamesValidator
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.lexer.JetKeywordToken
|
import org.jetbrains.kotlin.lexer.JetKeywordToken
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
|
|
||||||
@@ -26,5 +26,5 @@ public class KotlinNamesValidator : NamesValidator {
|
|||||||
private val KEYWORD_SET = JetTokens.KEYWORDS.getTypes().filterIsInstance<JetKeywordToken>().map { it.getValue() }.toSet()
|
private val KEYWORD_SET = JetTokens.KEYWORDS.getTypes().filterIsInstance<JetKeywordToken>().map { it.getValue() }.toSet()
|
||||||
|
|
||||||
override fun isKeyword(name: String, project: Project?): Boolean = name in KEYWORD_SET
|
override fun isKeyword(name: String, project: Project?): Boolean = name in KEYWORD_SET
|
||||||
override fun isIdentifier(name: String, project: Project?): Boolean = JetNameSuggester.isIdentifier(name)
|
override fun isIdentifier(name: String, project: Project?): Boolean = KotlinNameSuggester.isIdentifier(name)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -21,7 +21,7 @@ import com.intellij.psi.PsiElement;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.core.CorePackage;
|
import org.jetbrains.kotlin.idea.core.CorePackage;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameValidator;
|
import org.jetbrains.kotlin.idea.core.NameValidator;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.JetElement;
|
import org.jetbrains.kotlin.psi.JetElement;
|
||||||
import org.jetbrains.kotlin.psi.JetExpression;
|
import org.jetbrains.kotlin.psi.JetExpression;
|
||||||
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class JetNameValidatorImpl extends JetNameValidator {
|
public class NameValidatorImpl extends NameValidator {
|
||||||
public static enum Target {
|
public static enum Target {
|
||||||
FUNCTIONS_AND_CLASSES,
|
FUNCTIONS_AND_CLASSES,
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
@@ -43,7 +43,7 @@ public class JetNameValidatorImpl extends JetNameValidator {
|
|||||||
private final PsiElement myAnchor;
|
private final PsiElement myAnchor;
|
||||||
private final Target myTarget;
|
private final Target myTarget;
|
||||||
|
|
||||||
public JetNameValidatorImpl(PsiElement container, PsiElement anchor, Target target) {
|
public NameValidatorImpl(PsiElement container, PsiElement anchor, Target target) {
|
||||||
myContainer = container;
|
myContainer = container;
|
||||||
myAnchor = anchor;
|
myAnchor = anchor;
|
||||||
myTarget = target;
|
myTarget = target;
|
||||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||||
import org.jetbrains.kotlin.idea.core.CollectingValidator
|
import org.jetbrains.kotlin.idea.core.CollectingValidator
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.JetFunctionDefinitionUsage
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.JetFunctionDefinitionUsage
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.JetClass
|
import org.jetbrains.kotlin.psi.JetClass
|
||||||
@@ -82,7 +82,7 @@ public class JetChangeSignatureData(
|
|||||||
}
|
}
|
||||||
} ?: CollectingValidator(paramNames)
|
} ?: CollectingValidator(paramNames)
|
||||||
val receiverType = baseDescriptor.getExtensionReceiverParameter()?.getType() ?: return null
|
val receiverType = baseDescriptor.getExtensionReceiverParameter()?.getType() ?: return null
|
||||||
val receiverName = JetNameSuggester.suggestNames(receiverType, validator, "receiver").first()
|
val receiverName = KotlinNameSuggester.suggestNames(receiverType, validator, "receiver").first()
|
||||||
return JetParameterInfo(functionDescriptor = baseDescriptor, name = receiverName, type = receiverType)
|
return JetParameterInfo(functionDescriptor = baseDescriptor, name = receiverName, type = receiverType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -30,7 +30,7 @@ import kotlin.jvm.functions.Function1;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.idea.JetFileType;
|
import org.jetbrains.kotlin.idea.JetFileType;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester;
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.RefactoringPackage;
|
import org.jetbrains.kotlin.idea.core.refactoring.RefactoringPackage;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle;
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*;
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*;
|
||||||
@@ -102,9 +102,9 @@ public class KotlinExtractFunctionDialog extends DialogWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkNames() {
|
private boolean checkNames() {
|
||||||
if (!JetNameSuggester.INSTANCE$.isIdentifier(getFunctionName())) return false;
|
if (!KotlinNameSuggester.INSTANCE$.isIdentifier(getFunctionName())) return false;
|
||||||
for (KotlinParameterTablePanel.ParameterInfo parameterInfo : parameterTablePanel.getParameterInfos()) {
|
for (KotlinParameterTablePanel.ParameterInfo parameterInfo : parameterTablePanel.getParameterInfos()) {
|
||||||
if (!JetNameSuggester.INSTANCE$.isIdentifier(parameterInfo.getName())) return false;
|
if (!KotlinNameSuggester.INSTANCE$.isIdentifier(parameterInfo.getName())) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -30,7 +30,7 @@ import kotlin.jvm.functions.Function1;
|
|||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester;
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.Parameter;
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.Parameter;
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
@@ -345,7 +345,7 @@ public class KotlinParameterTablePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
case PARAMETER_NAME_COLUMN: {
|
case PARAMETER_NAME_COLUMN: {
|
||||||
String name = (String) aValue;
|
String name = (String) aValue;
|
||||||
if (JetNameSuggester.INSTANCE$.isIdentifier(name)) {
|
if (KotlinNameSuggester.INSTANCE$.isIdentifier(name)) {
|
||||||
info.setName(name);
|
info.setName(name);
|
||||||
}
|
}
|
||||||
updateSignature();
|
updateSignature();
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ import com.intellij.util.containers.MultiMap
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.core.replaced
|
import org.jetbrains.kotlin.idea.core.replaced
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.ErrorMessage
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.ErrorMessage
|
||||||
@@ -85,7 +85,7 @@ class RenameReplacement(override val parameter: Parameter): ParameterReplacement
|
|||||||
var expressionToReplace = (e.getParent() as? JetThisExpression ?: e).getQualifiedExpressionForSelectorOrThis()
|
var expressionToReplace = (e.getParent() as? JetThisExpression ?: e).getQualifiedExpressionForSelectorOrThis()
|
||||||
val parameterName = JetPsiUtil.unquoteIdentifier(parameter.nameForRef)
|
val parameterName = JetPsiUtil.unquoteIdentifier(parameter.nameForRef)
|
||||||
val replacingName =
|
val replacingName =
|
||||||
if (e.getText().startsWith('`') || !JetNameSuggester.isIdentifier(parameterName)) "`$parameterName`" else parameterName
|
if (e.getText().startsWith('`') || !KotlinNameSuggester.isIdentifier(parameterName)) "`$parameterName`" else parameterName
|
||||||
val psiFactory = JetPsiFactory(e)
|
val psiFactory = JetPsiFactory(e)
|
||||||
val replacement =
|
val replacement =
|
||||||
if (expressionToReplace is JetOperationReferenceExpression) {
|
if (expressionToReplace is JetOperationReferenceExpression) {
|
||||||
|
|||||||
+8
-8
@@ -45,12 +45,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
|||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||||
import org.jetbrains.kotlin.idea.core.comparePossiblyOverridingDescriptors
|
import org.jetbrains.kotlin.idea.core.comparePossiblyOverridingDescriptors
|
||||||
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.createTempCopy
|
import org.jetbrains.kotlin.idea.core.refactoring.createTempCopy
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.getContextForContainingDeclarationBody
|
import org.jetbrains.kotlin.idea.core.refactoring.getContextForContainingDeclarationBody
|
||||||
import org.jetbrains.kotlin.idea.imports.importableFqNameSafe
|
import org.jetbrains.kotlin.idea.imports.importableFqNameSafe
|
||||||
import org.jetbrains.kotlin.idea.kdoc.getResolutionScope
|
import org.jetbrains.kotlin.idea.kdoc.getResolutionScope
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl
|
import org.jetbrains.kotlin.idea.refactoring.NameValidatorImpl
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.ErrorMessage
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.ErrorMessage
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.Status
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.Status
|
||||||
@@ -743,10 +743,10 @@ private fun ExtractionData.inferParametersInfo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val varNameValidator = JetNameValidatorImpl(
|
val varNameValidator = NameValidatorImpl(
|
||||||
commonParent.getNonStrictParentOfType<JetExpression>(),
|
commonParent.getNonStrictParentOfType<JetExpression>(),
|
||||||
originalElements.firstOrNull(),
|
originalElements.firstOrNull(),
|
||||||
JetNameValidatorImpl.Target.PROPERTIES
|
NameValidatorImpl.Target.PROPERTIES
|
||||||
)
|
)
|
||||||
|
|
||||||
for ((descriptorToExtract, parameter) in extractedDescriptorToParameter) {
|
for ((descriptorToExtract, parameter) in extractedDescriptorToParameter) {
|
||||||
@@ -756,7 +756,7 @@ private fun ExtractionData.inferParametersInfo(
|
|||||||
|
|
||||||
with (parameter) {
|
with (parameter) {
|
||||||
if (currentName == null) {
|
if (currentName == null) {
|
||||||
currentName = JetNameSuggester.suggestNames(getParameterType(options.allowSpecialClassNames), varNameValidator, "p").first()
|
currentName = KotlinNameSuggester.suggestNames(getParameterType(options.allowSpecialClassNames), varNameValidator, "p").first()
|
||||||
}
|
}
|
||||||
mirrorVarName = if (descriptorToExtract in modifiedVarDescriptors) varNameValidator.validateName(name) else null
|
mirrorVarName = if (descriptorToExtract in modifiedVarDescriptors) varNameValidator.validateName(name) else null
|
||||||
info.parameters.add(this)
|
info.parameters.add(this)
|
||||||
@@ -909,13 +909,13 @@ private fun ExtractionData.suggestFunctionNames(returnType: JetType): List<Strin
|
|||||||
val functionNames = LinkedHashSet<String>()
|
val functionNames = LinkedHashSet<String>()
|
||||||
|
|
||||||
val validator =
|
val validator =
|
||||||
JetNameValidatorImpl(
|
NameValidatorImpl(
|
||||||
targetSibling.getParent(),
|
targetSibling.getParent(),
|
||||||
if (targetSibling is JetClassInitializer) targetSibling.getParent() else targetSibling,
|
if (targetSibling is JetClassInitializer) targetSibling.getParent() else targetSibling,
|
||||||
if (options.extractAsProperty) JetNameValidatorImpl.Target.PROPERTIES else JetNameValidatorImpl.Target.FUNCTIONS_AND_CLASSES
|
if (options.extractAsProperty) NameValidatorImpl.Target.PROPERTIES else NameValidatorImpl.Target.FUNCTIONS_AND_CLASSES
|
||||||
)
|
)
|
||||||
if (!returnType.isDefault()) {
|
if (!returnType.isDefault()) {
|
||||||
functionNames.addAll(JetNameSuggester.suggestNamesForType(returnType, validator))
|
functionNames.addAll(KotlinNameSuggester.suggestNamesForType(returnType, validator))
|
||||||
}
|
}
|
||||||
|
|
||||||
getExpressions().singleOrNull()?.let { expr ->
|
getExpressions().singleOrNull()?.let { expr ->
|
||||||
|
|||||||
+6
-6
@@ -20,11 +20,11 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.idea.core.appendElement
|
import org.jetbrains.kotlin.idea.core.appendElement
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.isMultiLine
|
import org.jetbrains.kotlin.idea.core.refactoring.isMultiLine
|
||||||
import org.jetbrains.kotlin.idea.core.replaced
|
import org.jetbrains.kotlin.idea.core.replaced
|
||||||
import org.jetbrains.kotlin.idea.intentions.ConvertToExpressionBodyIntention
|
import org.jetbrains.kotlin.idea.intentions.ConvertToExpressionBodyIntention
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl
|
import org.jetbrains.kotlin.idea.refactoring.NameValidatorImpl
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.ExpressionValue
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.ExpressionValue
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.Initializer
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.Initializer
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.Jump
|
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.Jump
|
||||||
@@ -278,8 +278,8 @@ private fun makeCall(
|
|||||||
controlFlow.outputValueBoxer.getUnboxingExpressions(callText)
|
controlFlow.outputValueBoxer.getUnboxingExpressions(callText)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val varNameValidator = JetNameValidatorImpl(block, anchorInBlock, JetNameValidatorImpl.Target.PROPERTIES)
|
val varNameValidator = NameValidatorImpl(block, anchorInBlock, NameValidatorImpl.Target.PROPERTIES)
|
||||||
val resultVal = JetNameSuggester.suggestNames(extractableDescriptor.returnType, varNameValidator, null).first()
|
val resultVal = KotlinNameSuggester.suggestNames(extractableDescriptor.returnType, varNameValidator, null).first()
|
||||||
block.addBefore(psiFactory.createDeclaration("val $resultVal = $callText"), anchorInBlock)
|
block.addBefore(psiFactory.createDeclaration("val $resultVal = $callText"), anchorInBlock)
|
||||||
block.addBefore(newLine, anchorInBlock)
|
block.addBefore(newLine, anchorInBlock)
|
||||||
controlFlow.outputValueBoxer.getUnboxingExpressions(resultVal)
|
controlFlow.outputValueBoxer.getUnboxingExpressions(resultVal)
|
||||||
@@ -512,8 +512,8 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
|
|||||||
|
|
||||||
val (defaultExpression, expressionToUnifyWith) =
|
val (defaultExpression, expressionToUnifyWith) =
|
||||||
if (!generatorOptions.inTempFile && defaultValue != null && descriptor.controlFlow.outputValueBoxer.boxingRequired && lastExpression!!.isMultiLine()) {
|
if (!generatorOptions.inTempFile && defaultValue != null && descriptor.controlFlow.outputValueBoxer.boxingRequired && lastExpression!!.isMultiLine()) {
|
||||||
val varNameValidator = JetNameValidatorImpl(body, lastExpression, JetNameValidatorImpl.Target.PROPERTIES)
|
val varNameValidator = NameValidatorImpl(body, lastExpression, NameValidatorImpl.Target.PROPERTIES)
|
||||||
val resultVal = JetNameSuggester.suggestNames(defaultValue.valueType, varNameValidator, null).first()
|
val resultVal = KotlinNameSuggester.suggestNames(defaultValue.valueType, varNameValidator, null).first()
|
||||||
val newDecl = body.addBefore(psiFactory.createDeclaration("val $resultVal = ${lastExpression!!.getText()}"), lastExpression) as JetProperty
|
val newDecl = body.addBefore(psiFactory.createDeclaration("val $resultVal = ${lastExpression!!.getText()}"), lastExpression) as JetProperty
|
||||||
body.addBefore(psiFactory.createNewLine(), lastExpression)
|
body.addBefore(psiFactory.createNewLine(), lastExpression)
|
||||||
psiFactory.createExpression(resultVal) to newDecl.getInitializer()!!
|
psiFactory.createExpression(resultVal) to newDecl.getInitializer()!!
|
||||||
|
|||||||
+4
-4
@@ -39,9 +39,9 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||||
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
import org.jetbrains.kotlin.idea.core.getResolutionScope
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||||
import org.jetbrains.kotlin.idea.core.refactoring.runRefactoringWithPostprocessing
|
import org.jetbrains.kotlin.idea.core.refactoring.runRefactoringWithPostprocessing
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl
|
import org.jetbrains.kotlin.idea.refactoring.NameValidatorImpl
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
|
||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.KotlinIntroduceHandlerBase
|
import org.jetbrains.kotlin.idea.refactoring.introduce.KotlinIntroduceHandlerBase
|
||||||
@@ -234,8 +234,8 @@ public open class KotlinIntroduceParameterHandler(
|
|||||||
is JetClass -> targetParent.getBody()
|
is JetClass -> targetParent.getBody()
|
||||||
else -> null
|
else -> null
|
||||||
} ?: throw AssertionError("Body element is not found: ${targetParent.getElementTextWithContext()}")
|
} ?: throw AssertionError("Body element is not found: ${targetParent.getElementTextWithContext()}")
|
||||||
val nameValidator = JetNameValidatorImpl(body, null, JetNameValidatorImpl.Target.PROPERTIES)
|
val nameValidator = NameValidatorImpl(body, null, NameValidatorImpl.Target.PROPERTIES)
|
||||||
val suggestedNames = linkedSetOf(*JetNameSuggester.suggestNames(replacementType, nameValidator, "p"))
|
val suggestedNames = linkedSetOf(*KotlinNameSuggester.suggestNames(replacementType, nameValidator, "p"))
|
||||||
|
|
||||||
val parametersUsages = findInternalUsagesOfParametersAndReceiver(targetParent, functionDescriptor)
|
val parametersUsages = findInternalUsagesOfParametersAndReceiver(targetParent, functionDescriptor)
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -41,10 +41,10 @@ import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils;
|
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils;
|
||||||
import org.jetbrains.kotlin.idea.core.CorePackage;
|
import org.jetbrains.kotlin.idea.core.CorePackage;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester;
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||||
import org.jetbrains.kotlin.idea.intentions.ConvertToBlockBodyIntention;
|
import org.jetbrains.kotlin.idea.intentions.ConvertToBlockBodyIntention;
|
||||||
import org.jetbrains.kotlin.idea.intentions.RemoveCurlyBracesFromTemplateIntention;
|
import org.jetbrains.kotlin.idea.intentions.RemoveCurlyBracesFromTemplateIntention;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl;
|
import org.jetbrains.kotlin.idea.refactoring.NameValidatorImpl;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle;
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil;
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.introduce.IntroducePackage;
|
import org.jetbrains.kotlin.idea.refactoring.introduce.IntroducePackage;
|
||||||
@@ -192,12 +192,12 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
|||||||
|
|
||||||
PsiElement commonParent = PsiTreeUtil.findCommonParent(allReplaces);
|
PsiElement commonParent = PsiTreeUtil.findCommonParent(allReplaces);
|
||||||
PsiElement commonContainer = getContainer(commonParent);
|
PsiElement commonContainer = getContainer(commonParent);
|
||||||
JetNameValidatorImpl validator = new JetNameValidatorImpl(
|
NameValidatorImpl validator = new NameValidatorImpl(
|
||||||
commonContainer,
|
commonContainer,
|
||||||
calculateAnchor(commonParent, commonContainer, allReplaces),
|
calculateAnchor(commonParent, commonContainer, allReplaces),
|
||||||
JetNameValidatorImpl.Target.PROPERTIES
|
NameValidatorImpl.Target.PROPERTIES
|
||||||
);
|
);
|
||||||
final String[] suggestedNames = JetNameSuggester.INSTANCE$.suggestNames(expression, validator, "value");
|
final String[] suggestedNames = KotlinNameSuggester.INSTANCE$.suggestNames(expression, validator, "value");
|
||||||
final Ref<JetProperty> propertyRef = new Ref<JetProperty>();
|
final Ref<JetProperty> propertyRef = new Ref<JetProperty>();
|
||||||
final ArrayList<JetExpression> references = new ArrayList<JetExpression>();
|
final ArrayList<JetExpression> references = new ArrayList<JetExpression>();
|
||||||
final Ref<JetExpression> reference = new Ref<JetExpression>();
|
final Ref<JetExpression> reference = new Ref<JetExpression>();
|
||||||
|
|||||||
+2
-2
@@ -21,7 +21,7 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
|
||||||
import org.jetbrains.kotlin.idea.core.EmptyValidator;
|
import org.jetbrains.kotlin.idea.core.EmptyValidator;
|
||||||
import org.jetbrains.kotlin.idea.core.JetNameSuggester;
|
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil;
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil;
|
||||||
import org.jetbrains.kotlin.psi.JetExpression;
|
import org.jetbrains.kotlin.psi.JetExpression;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
@@ -100,7 +100,7 @@ public class JetNameSuggesterTest extends LightCodeInsightFixtureTestCase {
|
|||||||
JetRefactoringUtil.selectExpression(myFixture.getEditor(), file, new JetRefactoringUtil.SelectExpressionCallback() {
|
JetRefactoringUtil.selectExpression(myFixture.getEditor(), file, new JetRefactoringUtil.SelectExpressionCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void run(@Nullable JetExpression expression) {
|
public void run(@Nullable JetExpression expression) {
|
||||||
String[] names = JetNameSuggester.INSTANCE$.suggestNames(expression, EmptyValidator.INSTANCE$, "value");
|
String[] names = KotlinNameSuggester.INSTANCE$.suggestNames(expression, EmptyValidator.INSTANCE$, "value");
|
||||||
Arrays.sort(names);
|
Arrays.sort(names);
|
||||||
String result = StringUtil.join(names, "\n").trim();
|
String result = StringUtil.join(names, "\n").trim();
|
||||||
assertEquals(expectedResultText, result);
|
assertEquals(expectedResultText, result);
|
||||||
|
|||||||
Reference in New Issue
Block a user