Shorten References: Introduce shortening options
This commit is contained in:
+11
-7
@@ -26,8 +26,11 @@ import java.util.HashSet
|
|||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.psi.SmartPointerManager
|
import com.intellij.psi.SmartPointerManager
|
||||||
import com.intellij.openapi.diagnostic.Logger
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences.Options
|
||||||
|
|
||||||
private var Project.elementsToShorten: MutableSet<SmartPsiElementPointer<JetElement>>?
|
class ShorteningRequest(val pointer: SmartPsiElementPointer<JetElement>, val options: Options)
|
||||||
|
|
||||||
|
private var Project.elementsToShorten: MutableSet<ShorteningRequest>?
|
||||||
by UserDataProperty(Key.create("ELEMENTS_TO_SHORTEN_KEY"))
|
by UserDataProperty(Key.create("ELEMENTS_TO_SHORTEN_KEY"))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -37,7 +40,7 @@ private var Project.elementsToShorten: MutableSet<SmartPsiElementPointer<JetElem
|
|||||||
public var Project.ensureElementsToShortenIsEmptyBeforeRefactoring: Boolean
|
public var Project.ensureElementsToShortenIsEmptyBeforeRefactoring: Boolean
|
||||||
by NotNullableUserDataProperty(Key.create("ENSURE_ELEMENTS_TO_SHORTEN_IS_EMPTY"), true)
|
by NotNullableUserDataProperty(Key.create("ENSURE_ELEMENTS_TO_SHORTEN_IS_EMPTY"), true)
|
||||||
|
|
||||||
private fun Project.getOrCreateElementsToShorten(): MutableSet<SmartPsiElementPointer<JetElement>> {
|
private fun Project.getOrCreateElementsToShorten(): MutableSet<ShorteningRequest> {
|
||||||
var elements = elementsToShorten
|
var elements = elementsToShorten
|
||||||
if (elements == null) {
|
if (elements == null) {
|
||||||
elements = HashSet()
|
elements = HashSet()
|
||||||
@@ -47,16 +50,17 @@ private fun Project.getOrCreateElementsToShorten(): MutableSet<SmartPsiElementPo
|
|||||||
return elements!!
|
return elements!!
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun JetElement.addToShorteningWaitSet() {
|
public fun JetElement.addToShorteningWaitSet(options: Options = Options.DEFAULT) {
|
||||||
assert (ApplicationManager.getApplication()!!.isWriteAccessAllowed(), "Write access needed")
|
assert (ApplicationManager.getApplication()!!.isWriteAccessAllowed(), "Write access needed")
|
||||||
val project = getProject()
|
val project = getProject()
|
||||||
project.getOrCreateElementsToShorten().add(SmartPointerManager.getInstance(project).createSmartPsiElementPointer(this))
|
val elementPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(this)
|
||||||
|
project.getOrCreateElementsToShorten().add(ShorteningRequest(elementPointer, options))
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun withElementsToShorten(project: Project, f: (Set<SmartPsiElementPointer<JetElement>>) -> Unit) {
|
public fun withElementsToShorten(project: Project, f: (Set<ShorteningRequest>) -> Unit) {
|
||||||
project.elementsToShorten?.let { bindRequests ->
|
project.elementsToShorten?.let { requests ->
|
||||||
project.elementsToShorten = null
|
project.elementsToShorten = null
|
||||||
f(bindRequests)
|
f(requests)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -123,7 +123,7 @@ public class JetSimpleNameReference(
|
|||||||
PsiTreeUtil.getParentOfType(expression, javaClass<JetImportDirective>(), javaClass<JetPackageDirective>()) == null
|
PsiTreeUtil.getParentOfType(expression, javaClass<JetImportDirective>(), javaClass<JetPackageDirective>()) == null
|
||||||
if (needToShorten) {
|
if (needToShorten) {
|
||||||
if (shorteningMode == ShorteningMode.FORCED_SHORTENING) {
|
if (shorteningMode == ShorteningMode.FORCED_SHORTENING) {
|
||||||
ShortenReferences.process(newQualifiedElement)
|
ShortenReferences.DEFAULT.process(newQualifiedElement)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newQualifiedElement.addToShorteningWaitSet()
|
newQualifiedElement.addToShorteningWaitSet()
|
||||||
|
|||||||
@@ -39,8 +39,36 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
|||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences.Options
|
||||||
|
|
||||||
|
public class ShortenReferences(val options: (JetElement) -> Options = { Options.DEFAULT }) {
|
||||||
|
public data class Options(
|
||||||
|
val removeThisLabels: Boolean = false,
|
||||||
|
val removeThis: Boolean = false
|
||||||
|
) {
|
||||||
|
class object {
|
||||||
|
val DEFAULT = Options()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class object {
|
||||||
|
val DEFAULT = ShortenReferences()
|
||||||
|
|
||||||
|
private fun DeclarationDescriptor.asString()
|
||||||
|
= DescriptorRenderer.FQ_NAMES_IN_TYPES.render(this)
|
||||||
|
|
||||||
|
private fun JetReferenceExpression.targets(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||||
|
return context[BindingContext.REFERENCE_TARGET, this]?.let { listOf(it.getImportableDescriptor()) }
|
||||||
|
?: context[BindingContext.AMBIGUOUS_REFERENCE_TARGET, this]?.map { it.getImportableDescriptor() }?.toSet()
|
||||||
|
?: listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun mayImport(descriptor: DeclarationDescriptor, file: JetFile): Boolean {
|
||||||
|
if (descriptor !is ClassDescriptor && descriptor !is PackageViewDescriptor) return false
|
||||||
|
return ImportInsertHelper.getInstance(file.getProject()).mayImportByCodeStyle(descriptor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public object ShortenReferences {
|
|
||||||
public fun process(element: JetElement) {
|
public fun process(element: JetElement) {
|
||||||
process(listOf(element))
|
process(listOf(element))
|
||||||
}
|
}
|
||||||
@@ -158,6 +186,7 @@ public object ShortenReferences {
|
|||||||
|
|
||||||
private fun analyzeReferences(elements: Iterable<JetElement>, visitor: ShorteningVisitor<*>): Set<DeclarationDescriptor> {
|
private fun analyzeReferences(elements: Iterable<JetElement>, visitor: ShorteningVisitor<*>): Set<DeclarationDescriptor> {
|
||||||
for (element in elements) {
|
for (element in elements) {
|
||||||
|
visitor.options = options(element)
|
||||||
element.accept(visitor)
|
element.accept(visitor)
|
||||||
}
|
}
|
||||||
return visitor.getDescriptorsToImport()
|
return visitor.getDescriptorsToImport()
|
||||||
@@ -168,6 +197,8 @@ public object ShortenReferences {
|
|||||||
protected val elementFilter: (PsiElement) -> FilterResult,
|
protected val elementFilter: (PsiElement) -> FilterResult,
|
||||||
protected val failedToImportDescriptors: Set<DeclarationDescriptor>
|
protected val failedToImportDescriptors: Set<DeclarationDescriptor>
|
||||||
) : JetVisitorVoid() {
|
) : JetVisitorVoid() {
|
||||||
|
var options: Options = Options.DEFAULT
|
||||||
|
|
||||||
private val elementsToShorten = ArrayList<T>()
|
private val elementsToShorten = ArrayList<T>()
|
||||||
private val descriptorsToImport = LinkedHashSet<DeclarationDescriptor>()
|
private val descriptorsToImport = LinkedHashSet<DeclarationDescriptor>()
|
||||||
|
|
||||||
@@ -211,7 +242,6 @@ public object ShortenReferences {
|
|||||||
elementFilter: (PsiElement) -> FilterResult,
|
elementFilter: (PsiElement) -> FilterResult,
|
||||||
failedToImportDescriptors: Set<DeclarationDescriptor>
|
failedToImportDescriptors: Set<DeclarationDescriptor>
|
||||||
) : ShorteningVisitor<JetUserType>(file, elementFilter, failedToImportDescriptors) {
|
) : ShorteningVisitor<JetUserType>(file, elementFilter, failedToImportDescriptors) {
|
||||||
|
|
||||||
override fun visitUserType(userType: JetUserType) {
|
override fun visitUserType(userType: JetUserType) {
|
||||||
val filterResult = elementFilter(userType)
|
val filterResult = elementFilter(userType)
|
||||||
if (filterResult == FilterResult.SKIP) return
|
if (filterResult == FilterResult.SKIP) return
|
||||||
@@ -272,7 +302,14 @@ public object ShortenReferences {
|
|||||||
val bindingContext = resolutionFacade.analyze(qualifiedExpression)
|
val bindingContext = resolutionFacade.analyze(qualifiedExpression)
|
||||||
|
|
||||||
val receiver = qualifiedExpression.getReceiverExpression()
|
val receiver = qualifiedExpression.getReceiverExpression()
|
||||||
if (receiver !is JetThisExpression && bindingContext[BindingContext.QUALIFIER, receiver] == null) return false
|
when {
|
||||||
|
receiver is JetThisExpression -> {
|
||||||
|
if (!options.removeThis) return false
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
if (bindingContext[BindingContext.QUALIFIER, receiver] == null) return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (PsiTreeUtil.getParentOfType(
|
if (PsiTreeUtil.getParentOfType(
|
||||||
qualifiedExpression,
|
qualifiedExpression,
|
||||||
@@ -327,7 +364,7 @@ public object ShortenReferences {
|
|||||||
private val simpleThis = JetPsiFactory(file).createExpression("this") as JetThisExpression
|
private val simpleThis = JetPsiFactory(file).createExpression("this") as JetThisExpression
|
||||||
|
|
||||||
private fun process(thisExpression: JetThisExpression) {
|
private fun process(thisExpression: JetThisExpression) {
|
||||||
if (thisExpression.getTargetLabel() == null) return
|
if (!options.removeThisLabels || thisExpression.getTargetLabel() == null) return
|
||||||
|
|
||||||
val bindingContext = resolutionFacade.analyze(thisExpression)
|
val bindingContext = resolutionFacade.analyze(thisExpression)
|
||||||
|
|
||||||
@@ -354,20 +391,6 @@ public object ShortenReferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun DeclarationDescriptor.asString()
|
|
||||||
= DescriptorRenderer.FQ_NAMES_IN_TYPES.render(this)
|
|
||||||
|
|
||||||
private fun JetReferenceExpression.targets(context: BindingContext): Collection<DeclarationDescriptor> {
|
|
||||||
return context[BindingContext.REFERENCE_TARGET, this]?.let { listOf(it.getImportableDescriptor()) }
|
|
||||||
?: context[BindingContext.AMBIGUOUS_REFERENCE_TARGET, this]?.map { it.getImportableDescriptor() }?.toSet()
|
|
||||||
?: listOf()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun mayImport(descriptor: DeclarationDescriptor, file: JetFile): Boolean {
|
|
||||||
if (descriptor !is ClassDescriptor && descriptor !is PackageViewDescriptor) return false
|
|
||||||
return ImportInsertHelper.getInstance(file.getProject()).mayImportByCodeStyle(descriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
// this class is needed to optimize imports only when we actually insert any import (optimization)
|
// this class is needed to optimize imports only when we actually insert any import (optimization)
|
||||||
private class ImportInserter(val file: JetFile) {
|
private class ImportInserter(val file: JetFile) {
|
||||||
private var optimizeImports = true
|
private var optimizeImports = true
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
|||||||
import org.jetbrains.kotlin.descriptors.Modality;
|
import org.jetbrains.kotlin.descriptors.Modality;
|
||||||
import org.jetbrains.kotlin.idea.JetBundle;
|
import org.jetbrains.kotlin.idea.JetBundle;
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil;
|
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil;
|
||||||
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
||||||
import org.jetbrains.kotlin.psi.JetClass;
|
import org.jetbrains.kotlin.psi.JetClass;
|
||||||
import org.jetbrains.kotlin.psi.JetClassBody;
|
import org.jetbrains.kotlin.psi.JetClassBody;
|
||||||
import org.jetbrains.kotlin.psi.JetNamedFunction;
|
import org.jetbrains.kotlin.psi.JetNamedFunction;
|
||||||
@@ -105,7 +105,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
|
|||||||
PsiElement anchor = body.getRBrace();
|
PsiElement anchor = body.getRBrace();
|
||||||
JetNamedFunction insertedFunctionElement = (JetNamedFunction) body.addBefore(functionElement, anchor);
|
JetNamedFunction insertedFunctionElement = (JetNamedFunction) body.addBefore(functionElement, anchor);
|
||||||
|
|
||||||
ShortenReferences.INSTANCE$.process(insertedFunctionElement);
|
ShortenReferences.DEFAULT.process(insertedFunctionElement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -35,8 +35,11 @@ public class KotlinShortenReferencesRefactoringHelper: RefactoringHelper<Any> {
|
|||||||
|
|
||||||
override fun performOperation(project: Project, operationData: Any?) {
|
override fun performOperation(project: Project, operationData: Any?) {
|
||||||
ApplicationManager.getApplication()!!.runWriteAction {
|
ApplicationManager.getApplication()!!.runWriteAction {
|
||||||
withElementsToShorten(project) { bindRequests ->
|
withElementsToShorten(project) { requests ->
|
||||||
ShortenReferences.process(bindRequests.map() { it.getElement() }.filterNotNull())
|
val elements = requests.map { it.pointer.getElement() }
|
||||||
|
val options = requests.map { it.options }
|
||||||
|
val elementToOptions = (elements zip options).toMap()
|
||||||
|
ShortenReferences({ elementToOptions[it] ?: ShortenReferences.Options.DEFAULT }).process(elements.filterNotNull())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
|||||||
elementsToCompact.add((JetElement) added);
|
elementsToCompact.add((JetElement) added);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortenReferences.INSTANCE$.process(elementsToCompact);
|
ShortenReferences.DEFAULT.process(elementsToCompact);
|
||||||
|
|
||||||
if (firstGenerated == null) return;
|
if (firstGenerated == null) return;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -86,7 +86,7 @@ public class MoveDeclarationsOutHelper {
|
|||||||
dummyFirstStatement.delete();
|
dummyFirstStatement.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortenReferences.INSTANCE$.process(propertiesDeclarations);
|
ShortenReferences.DEFAULT.process(propertiesDeclarations);
|
||||||
|
|
||||||
return PsiUtilCore.toPsiElementArray(resultStatements);
|
return PsiUtilCore.toPsiElementArray(resultStatements);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -99,7 +99,7 @@ public class KotlinRuntimeTypeCastSurrounder: KotlinExpressionSurrounder() {
|
|||||||
cast.getLeft().replace(myElement)
|
cast.getLeft().replace(myElement)
|
||||||
val expr = myElement.replace(parentCast) as JetExpression
|
val expr = myElement.replace(parentCast) as JetExpression
|
||||||
|
|
||||||
ShortenReferences.process(expr)
|
ShortenReferences.DEFAULT.process(expr)
|
||||||
|
|
||||||
val range = expr.getTextRange()
|
val range = expr.getTextRange()
|
||||||
myEditor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset())
|
myEditor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset())
|
||||||
|
|||||||
+1
-1
@@ -269,7 +269,7 @@ object CastReceiverInsertHandler : KotlinCallableInsertHandler() {
|
|||||||
|
|
||||||
val expr = receiver.replace(parentCast) as JetParenthesizedExpression
|
val expr = receiver.replace(parentCast) as JetParenthesizedExpression
|
||||||
|
|
||||||
ShortenReferences.process((expr.getExpression() as JetBinaryExpressionWithTypeRHS).getRight())
|
ShortenReferences.DEFAULT.process((expr.getExpression() as JetBinaryExpressionWithTypeRHS).getRight())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public object KotlinClassInsertHandler : BaseDeclarationInsertHandler() {
|
|||||||
val rangeMarker = document.createRangeMarker(classNameStart, classNameEnd)
|
val rangeMarker = document.createRangeMarker(classNameStart, classNameEnd)
|
||||||
val wholeRangeMarker = document.createRangeMarker(startOffset, classNameEnd + tempSuffix.length())
|
val wholeRangeMarker = document.createRangeMarker(startOffset, classNameEnd + tempSuffix.length())
|
||||||
|
|
||||||
ShortenReferences.process(file, classNameStart, classNameEnd)
|
ShortenReferences.DEFAULT.process(file, classNameStart, classNameEnd)
|
||||||
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document)
|
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document)
|
||||||
|
|
||||||
if (rangeMarker.isValid() && wholeRangeMarker.isValid()) {
|
if (rangeMarker.isValid() && wholeRangeMarker.isValid()) {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class ArtificialElementInsertHandler(
|
|||||||
|
|
||||||
fun shortenReferences(context: InsertionContext, startOffset: Int, endOffset: Int) {
|
fun shortenReferences(context: InsertionContext, startOffset: Int, endOffset: Int) {
|
||||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
||||||
ShortenReferences.process(context.getFile() as JetFile, startOffset, endOffset)
|
ShortenReferences.DEFAULT.process(context.getFile() as JetFile, startOffset, endOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mergeTails(tails: Collection<Tail?>): Tail? {
|
fun mergeTails(tails: Collection<Tail?>): Tail? {
|
||||||
|
|||||||
+1
-1
@@ -80,7 +80,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
|
|||||||
|
|
||||||
val replaced = replaceWithIfThenThrowExpression(element)
|
val replaced = replaceWithIfThenThrowExpression(element)
|
||||||
|
|
||||||
ShortenReferences.process(replaced.getThen()!!)
|
ShortenReferences.DEFAULT.process(replaced.getThen()!!)
|
||||||
|
|
||||||
fun replaceMessage() {
|
fun replaceMessage() {
|
||||||
val thrownExpression = ((replaced.getThen() as JetBlockExpression).getStatements().first() as JetThrowExpression).getThrownExpression()
|
val thrownExpression = ((replaced.getThen() as JetBlockExpression).getStatements().first() as JetThrowExpression).getThrownExpression()
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention<JetN
|
|||||||
kotlinCalls.forEach { it.replace(it.getCalleeExpression()) }
|
kotlinCalls.forEach { it.replace(it.getCalleeExpression()) }
|
||||||
foreignRefs.forEach { it.handleElementRename(getterName) }
|
foreignRefs.forEach { it.handleElementRename(getterName) }
|
||||||
|
|
||||||
ShortenReferences.process(elementsToShorten)
|
ShortenReferences.DEFAULT.process(elementsToShorten)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -86,7 +86,7 @@ public class ConvertIfWithThrowToAssertIntention :
|
|||||||
val assertExpr = psiFactory.createExpression(assertText)
|
val assertExpr = psiFactory.createExpression(assertText)
|
||||||
|
|
||||||
val newExpr = element.replace(assertExpr) as JetExpression
|
val newExpr = element.replace(assertExpr) as JetExpression
|
||||||
ShortenReferences.process(newExpr)
|
ShortenReferences.DEFAULT.process(newExpr)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSelector(element: JetExpression?): JetExpression? {
|
private fun getSelector(element: JetExpression?): JetExpression? {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
|
|||||||
if (callee == null) return
|
if (callee == null) return
|
||||||
|
|
||||||
element.addAfter(argumentList, callee)
|
element.addAfter(argumentList, callee)
|
||||||
ShortenReferences.process(element.getTypeArgumentList()!!)
|
ShortenReferences.DEFAULT.process(element.getTypeArgumentList()!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
|||||||
functionLiteral.addAfter(psiFactory.createNewLine(), openBraceElement)
|
functionLiteral.addAfter(psiFactory.createNewLine(), openBraceElement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShortenReferences.process(element.getValueParameters())
|
ShortenReferences.DEFAULT.process(element.getValueParameters())
|
||||||
|
|
||||||
// Step 2: make the return type explicit
|
// Step 2: make the return type explicit
|
||||||
val expectedReturnType = func.getReturnType()
|
val expectedReturnType = func.getReturnType()
|
||||||
@@ -90,7 +90,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
|||||||
val returnTypeExpr = psiFactory.createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(expectedReturnType))
|
val returnTypeExpr = psiFactory.createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(expectedReturnType))
|
||||||
functionLiteral.addAfter(returnTypeExpr, paramList)
|
functionLiteral.addAfter(returnTypeExpr, paramList)
|
||||||
functionLiteral.addAfter(returnTypeColon, paramList)
|
functionLiteral.addAfter(returnTypeColon, paramList)
|
||||||
ShortenReferences.process(functionLiteral.getTypeReference()!!)
|
ShortenReferences.DEFAULT.process(functionLiteral.getTypeReference()!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: make the receiver type explicit
|
// Step 3: make the receiver type explicit
|
||||||
@@ -99,7 +99,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
|||||||
val receiverTypeString = IdeDescriptorRenderers.SOURCE_CODE.renderType(expectedReceiverType)
|
val receiverTypeString = IdeDescriptorRenderers.SOURCE_CODE.renderType(expectedReceiverType)
|
||||||
val dot = functionLiteral.addBefore(psiFactory.createDot(), functionLiteral.getValueParameterList())
|
val dot = functionLiteral.addBefore(psiFactory.createDot(), functionLiteral.getValueParameterList())
|
||||||
functionLiteral.addBefore(psiFactory.createType(receiverTypeString), dot)
|
functionLiteral.addBefore(psiFactory.createType(receiverTypeString), dot)
|
||||||
ShortenReferences.process(functionLiteral.getReceiverTypeReference()!!)
|
ShortenReferences.DEFAULT.process(functionLiteral.getReceiverTypeReference()!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ import com.intellij.psi.util.PsiTreeUtil;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
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.util.ShortenReferences;
|
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
@@ -47,7 +47,7 @@ public class ReconstructTypeInCastOrIsAction extends PsiElementBaseIntentionActi
|
|||||||
JetType type = getReconstructedType(typeRef);
|
JetType type = getReconstructedType(typeRef);
|
||||||
JetTypeReference newType = JetPsiFactory(typeRef).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
JetTypeReference newType = JetPsiFactory(typeRef).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
||||||
JetTypeReference replaced = (JetTypeReference) typeRef.replace(newType);
|
JetTypeReference replaced = (JetTypeReference) typeRef.replace(newType);
|
||||||
ShortenReferences.INSTANCE$.process(replaced);
|
ShortenReferences.DEFAULT.process(replaced);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
|||||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||||
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.util.ShortenReferences;
|
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
@@ -182,7 +182,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
|
|||||||
public void templateFinished(Template template, boolean brokenOff) {
|
public void templateFinished(Template template, boolean brokenOff) {
|
||||||
JetTypeReference typeRef = declaration.getTypeReference();
|
JetTypeReference typeRef = declaration.getTypeReference();
|
||||||
if (typeRef != null) {
|
if (typeRef != null) {
|
||||||
ShortenReferences.INSTANCE$.process(typeRef);
|
ShortenReferences.DEFAULT.process(typeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ fun specifyTypeExplicitly(declaration: JetNamedFunction, type: JetType) {
|
|||||||
if (type.isError()) return
|
if (type.isError()) return
|
||||||
val typeReference = JetPsiFactory(declaration).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type))
|
val typeReference = JetPsiFactory(declaration).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type))
|
||||||
specifyTypeExplicitly(declaration, typeReference)
|
specifyTypeExplicitly(declaration, typeReference)
|
||||||
ShortenReferences.process(declaration.getTypeReference()!!)
|
ShortenReferences.DEFAULT.process(declaration.getTypeReference()!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeReference) {
|
fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeReference) {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import com.intellij.psi.PsiElement;
|
|||||||
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.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
@@ -82,7 +82,7 @@ public class DeclarationUtils {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (inferredType != null) {
|
if (inferredType != null) {
|
||||||
ShortenReferences.INSTANCE$.process(property.getTypeReference());
|
ShortenReferences.DEFAULT.process(property.getTypeReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
return newInitializer;
|
return newInitializer;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class KotlinShortenFQNamesProcessor : TemplateOptionalProcessor {
|
|||||||
PsiDocumentManager.getInstance(project).commitDocument(document)
|
PsiDocumentManager.getInstance(project).commitDocument(document)
|
||||||
|
|
||||||
val file = PsiUtilBase.getPsiFileInEditor(editor, project) as? JetFile ?: return
|
val file = PsiUtilBase.getPsiFileInEditor(editor, project) as? JetFile ?: return
|
||||||
ShortenReferences.process(file, templateRange.getStartOffset(), templateRange.getEndOffset())
|
ShortenReferences.DEFAULT.process(file, templateRange.getStartOffset(), templateRange.getEndOffset())
|
||||||
|
|
||||||
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document)
|
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
|
|||||||
|
|
||||||
JetTypeReference typeRef = castExpression.getRight();
|
JetTypeReference typeRef = castExpression.getRight();
|
||||||
assert typeRef != null;
|
assert typeRef != null;
|
||||||
ShortenReferences.INSTANCE$.process(typeRef);
|
ShortenReferences.DEFAULT.process(typeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
|||||||
assert typeReference != null;
|
assert typeReference != null;
|
||||||
|
|
||||||
newTypeReference = (JetTypeReference) typeReference.replace(newTypeReference);
|
newTypeReference = (JetTypeReference) typeReference.replace(newTypeReference);
|
||||||
ShortenReferences.INSTANCE$.process(newTypeReference);
|
ShortenReferences.DEFAULT.process(newTypeReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JetSingleIntentionActionFactory createFactory() {
|
public static JetSingleIntentionActionFactory createFactory() {
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
|
|||||||
if (functionLiteralReturnTypeRef != null) {
|
if (functionLiteralReturnTypeRef != null) {
|
||||||
JetTypeReference newTypeRef = JetPsiFactory(file).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
JetTypeReference newTypeRef = JetPsiFactory(file).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
||||||
newTypeRef = (JetTypeReference) functionLiteralReturnTypeRef.replace(newTypeRef);
|
newTypeRef = (JetTypeReference) functionLiteralReturnTypeRef.replace(newTypeRef);
|
||||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||||
}
|
}
|
||||||
if (appropriateQuickFix != null && appropriateQuickFix.isAvailable(project, editor, file)) {
|
if (appropriateQuickFix != null && appropriateQuickFix.isAvailable(project, editor, file)) {
|
||||||
appropriateQuickFix.invoke(project, editor, file);
|
appropriateQuickFix.invoke(project, editor, file);
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
|||||||
JetTypeReference newTypeRef = JetPsiFactory(project).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
JetTypeReference newTypeRef = JetPsiFactory(project).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
||||||
newTypeRef = element.setTypeReference(newTypeRef);
|
newTypeRef = element.setTypeReference(newTypeRef);
|
||||||
assert newTypeRef != null;
|
assert newTypeRef != null;
|
||||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
element.setTypeReference(null);
|
element.setTypeReference(null);
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ import org.jetbrains.kotlin.descriptors.*;
|
|||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||||
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.util.ShortenReferences;
|
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
@@ -376,11 +376,11 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
|
|||||||
|
|
||||||
JetTypeReference newTypeRef = function.setTypeReference(patternFunction.getTypeReference());
|
JetTypeReference newTypeRef = function.setTypeReference(patternFunction.getTypeReference());
|
||||||
if (newTypeRef != null) {
|
if (newTypeRef != null) {
|
||||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
JetParameterList newParameterList = (JetParameterList) function.getValueParameterList().replace(patternFunction.getValueParameterList());
|
JetParameterList newParameterList = (JetParameterList) function.getValueParameterList().replace(patternFunction.getValueParameterList());
|
||||||
ShortenReferences.INSTANCE$.process(newParameterList);
|
ShortenReferences.DEFAULT.process(newParameterList);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,6 @@ public class ChangeParameterTypeFix extends JetIntentionAction<JetParameter> {
|
|||||||
JetTypeReference newTypeRef = JetPsiFactory(file).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
JetTypeReference newTypeRef = JetPsiFactory(file).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
||||||
newTypeRef = element.setTypeReference(newTypeRef);
|
newTypeRef = element.setTypeReference(newTypeRef);
|
||||||
assert newTypeRef != null;
|
assert newTypeRef != null;
|
||||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
|
|||||||
@Override
|
@Override
|
||||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||||
JetTypeReference newTypeRef = (JetTypeReference) element.replace(JetPsiFactory(file).createType(renderedType));
|
JetTypeReference newTypeRef = (JetTypeReference) element.replace(JetPsiFactory(file).createType(renderedType));
|
||||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortenReferences.INSTANCE$.process(toShorten);
|
ShortenReferences.DEFAULT.process(toShorten);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+1
-1
@@ -201,7 +201,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
|||||||
runWriteAction { context.buildAndRunTemplate { buildNext(iterator) } }
|
runWriteAction { context.buildAndRunTemplate { buildNext(iterator) } }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ShortenReferences.process(elementsToShorten)
|
ShortenReferences.DEFAULT.process(elementsToShorten)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
|||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences.Options;
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.shorten.ShortenPackage;
|
import org.jetbrains.kotlin.idea.codeInsight.shorten.ShortenPackage;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil;
|
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringUtil;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.ChangeSignaturePackage;
|
import org.jetbrains.kotlin.idea.refactoring.changeSignature.ChangeSignaturePackage;
|
||||||
@@ -185,7 +186,10 @@ public class JetFunctionDefinitionUsage<T extends PsiElement> extends JetUsageIn
|
|||||||
|
|
||||||
//TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready
|
//TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready
|
||||||
if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) {
|
if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) {
|
||||||
ShortenPackage.addToShorteningWaitSet(function.setTypeReference(JetPsiFactory(function).createType(returnTypeText)));
|
ShortenPackage.addToShorteningWaitSet(
|
||||||
|
function.setTypeReference(JetPsiFactory(function).createType(returnTypeText)),
|
||||||
|
Options.DEFAULT
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +209,7 @@ public class JetFunctionDefinitionUsage<T extends PsiElement> extends JetUsageIn
|
|||||||
paramIndex++;
|
paramIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortenPackage.addToShorteningWaitSet(parameterList);
|
ShortenPackage.addToShorteningWaitSet(parameterList, Options.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changeInfo.isVisibilityChanged() && !JetPsiUtil.isLocal((JetDeclaration) element)) {
|
if (changeInfo.isVisibilityChanged() && !JetPsiUtil.isLocal((JetDeclaration) element)) {
|
||||||
@@ -284,7 +288,7 @@ public class JetFunctionDefinitionUsage<T extends PsiElement> extends JetUsageIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newParameterList != null) {
|
if (newParameterList != null) {
|
||||||
ShortenPackage.addToShorteningWaitSet(newParameterList);
|
ShortenPackage.addToShorteningWaitSet(newParameterList, Options.DEFAULT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ fun ExtractableCodeDescriptor.generateDeclaration(options: ExtractionGeneratorOp
|
|||||||
if (options.inTempFile) return ExtractionResult(declaration, Collections.emptyMap(), nameByOffset)
|
if (options.inTempFile) return ExtractionResult(declaration, Collections.emptyMap(), nameByOffset)
|
||||||
|
|
||||||
makeCall(this, declaration, controlFlow, extractionData.originalRange, parameters.map { it.argumentText })
|
makeCall(this, declaration, controlFlow, extractionData.originalRange, parameters.map { it.argumentText })
|
||||||
ShortenReferences.process(declaration)
|
ShortenReferences.DEFAULT.process(declaration)
|
||||||
|
|
||||||
val duplicateReplacers = duplicates.map { it.range to { makeCall(this, declaration, it.controlFlow, it.range, it.arguments) } }.toMap()
|
val duplicateReplacers = duplicates.map { it.range to { makeCall(this, declaration, it.controlFlow, it.range, it.arguments) } }.toMap()
|
||||||
return ExtractionResult(declaration, duplicateReplacers, nameByOffset)
|
return ExtractionResult(declaration, duplicateReplacers, nameByOffset)
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ import org.jetbrains.kotlin.diagnostics.Errors;
|
|||||||
import org.jetbrains.kotlin.idea.JetLanguage;
|
import org.jetbrains.kotlin.idea.JetLanguage;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade;
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||||
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
@@ -295,7 +295,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
|||||||
functionLiteral.addAfter(whitespaceToAdd, openBraceElement);
|
functionLiteral.addAfter(whitespaceToAdd, openBraceElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShortenReferences.INSTANCE$.process(functionLiteralExpression.getValueParameters());
|
ShortenReferences.DEFAULT.process(functionLiteralExpression.getValueParameters());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
|||||||
JetPsiFactory psiFactory = JetPsiFactory(containingFile);
|
JetPsiFactory psiFactory = JetPsiFactory(containingFile);
|
||||||
for (JetCallExpression call : callsToAddArguments) {
|
for (JetCallExpression call : callsToAddArguments) {
|
||||||
call.addAfter(psiFactory.createTypeArguments("<" + typeArguments + ">"), call.getCalleeExpression());
|
call.addAfter(psiFactory.createTypeArguments("<" + typeArguments + ">"), call.getCalleeExpression());
|
||||||
ShortenReferences.INSTANCE$.process(call.getTypeArgumentList());
|
ShortenReferences.DEFAULT.process(call.getTypeArgumentList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.analyzer.AnalyzerPackage;
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
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.util.ShortenReferences;
|
|
||||||
import org.jetbrains.kotlin.idea.intentions.ConvertToBlockBodyAction;
|
import org.jetbrains.kotlin.idea.intentions.ConvertToBlockBodyAction;
|
||||||
import org.jetbrains.kotlin.idea.intentions.RemoveCurlyBracesFromTemplateIntention;
|
import org.jetbrains.kotlin.idea.intentions.RemoveCurlyBracesFromTemplateIntention;
|
||||||
import org.jetbrains.kotlin.idea.refactoring.JetNameSuggester;
|
import org.jetbrains.kotlin.idea.refactoring.JetNameSuggester;
|
||||||
@@ -48,6 +47,7 @@ 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.KotlinIntroduceHandlerBase;
|
import org.jetbrains.kotlin.idea.refactoring.introduce.KotlinIntroduceHandlerBase;
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
||||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange;
|
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange;
|
||||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiUnifier;
|
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiUnifier;
|
||||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.PatternMatchingPackage;
|
import org.jetbrains.kotlin.idea.util.psi.patternMatching.PatternMatchingPackage;
|
||||||
@@ -425,7 +425,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
|||||||
}
|
}
|
||||||
propertyRef.set(property);
|
propertyRef.set(property);
|
||||||
if (noTypeInference) {
|
if (noTypeInference) {
|
||||||
ShortenReferences.INSTANCE$.process(property);
|
ShortenReferences.DEFAULT.process(property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ public abstract class AbstractShortenRefsTest : AbstractImportsTest() {
|
|||||||
override fun doTest(file: JetFile) {
|
override fun doTest(file: JetFile) {
|
||||||
val selectionModel = myFixture.getEditor().getSelectionModel()
|
val selectionModel = myFixture.getEditor().getSelectionModel()
|
||||||
if (!selectionModel.hasSelection()) error("No selection in input file")
|
if (!selectionModel.hasSelection()) error("No selection in input file")
|
||||||
ShortenReferences.process(file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())
|
ShortenReferences { ShortenReferences.Options(removeThis = true, removeThisLabels = true) }
|
||||||
|
.process(file, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd())
|
||||||
selectionModel.removeSelection()
|
selectionModel.removeSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user