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.psi.SmartPointerManager
|
||||
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"))
|
||||
|
||||
/*
|
||||
@@ -37,7 +40,7 @@ private var Project.elementsToShorten: MutableSet<SmartPsiElementPointer<JetElem
|
||||
public var Project.ensureElementsToShortenIsEmptyBeforeRefactoring: Boolean
|
||||
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
|
||||
if (elements == null) {
|
||||
elements = HashSet()
|
||||
@@ -47,16 +50,17 @@ private fun Project.getOrCreateElementsToShorten(): MutableSet<SmartPsiElementPo
|
||||
return elements!!
|
||||
}
|
||||
|
||||
public fun JetElement.addToShorteningWaitSet() {
|
||||
public fun JetElement.addToShorteningWaitSet(options: Options = Options.DEFAULT) {
|
||||
assert (ApplicationManager.getApplication()!!.isWriteAccessAllowed(), "Write access needed")
|
||||
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) {
|
||||
project.elementsToShorten?.let { bindRequests ->
|
||||
public fun withElementsToShorten(project: Project, f: (Set<ShorteningRequest>) -> Unit) {
|
||||
project.elementsToShorten?.let { requests ->
|
||||
project.elementsToShorten = null
|
||||
f(bindRequests)
|
||||
f(requests)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ public class JetSimpleNameReference(
|
||||
PsiTreeUtil.getParentOfType(expression, javaClass<JetImportDirective>(), javaClass<JetPackageDirective>()) == null
|
||||
if (needToShorten) {
|
||||
if (shorteningMode == ShorteningMode.FORCED_SHORTENING) {
|
||||
ShortenReferences.process(newQualifiedElement)
|
||||
ShortenReferences.DEFAULT.process(newQualifiedElement)
|
||||
}
|
||||
else {
|
||||
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.scopes.receivers.ExpressionReceiver
|
||||
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) {
|
||||
process(listOf(element))
|
||||
}
|
||||
@@ -158,6 +186,7 @@ public object ShortenReferences {
|
||||
|
||||
private fun analyzeReferences(elements: Iterable<JetElement>, visitor: ShorteningVisitor<*>): Set<DeclarationDescriptor> {
|
||||
for (element in elements) {
|
||||
visitor.options = options(element)
|
||||
element.accept(visitor)
|
||||
}
|
||||
return visitor.getDescriptorsToImport()
|
||||
@@ -168,6 +197,8 @@ public object ShortenReferences {
|
||||
protected val elementFilter: (PsiElement) -> FilterResult,
|
||||
protected val failedToImportDescriptors: Set<DeclarationDescriptor>
|
||||
) : JetVisitorVoid() {
|
||||
var options: Options = Options.DEFAULT
|
||||
|
||||
private val elementsToShorten = ArrayList<T>()
|
||||
private val descriptorsToImport = LinkedHashSet<DeclarationDescriptor>()
|
||||
|
||||
@@ -211,7 +242,6 @@ public object ShortenReferences {
|
||||
elementFilter: (PsiElement) -> FilterResult,
|
||||
failedToImportDescriptors: Set<DeclarationDescriptor>
|
||||
) : ShorteningVisitor<JetUserType>(file, elementFilter, failedToImportDescriptors) {
|
||||
|
||||
override fun visitUserType(userType: JetUserType) {
|
||||
val filterResult = elementFilter(userType)
|
||||
if (filterResult == FilterResult.SKIP) return
|
||||
@@ -272,8 +302,15 @@ public object ShortenReferences {
|
||||
val bindingContext = resolutionFacade.analyze(qualifiedExpression)
|
||||
|
||||
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(
|
||||
qualifiedExpression,
|
||||
javaClass<JetImportDirective>(), javaClass<JetPackageDirective>()) != null) return true
|
||||
@@ -327,7 +364,7 @@ public object ShortenReferences {
|
||||
private val simpleThis = JetPsiFactory(file).createExpression("this") as JetThisExpression
|
||||
|
||||
private fun process(thisExpression: JetThisExpression) {
|
||||
if (thisExpression.getTargetLabel() == null) return
|
||||
if (!options.removeThisLabels || thisExpression.getTargetLabel() == null) return
|
||||
|
||||
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)
|
||||
private class ImportInserter(val file: JetFile) {
|
||||
private var optimizeImports = true
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.Modality;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
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.ShortenReferences;
|
||||
import org.jetbrains.kotlin.psi.JetClass;
|
||||
import org.jetbrains.kotlin.psi.JetClassBody;
|
||||
import org.jetbrains.kotlin.psi.JetNamedFunction;
|
||||
@@ -105,7 +105,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
|
||||
PsiElement anchor = body.getRBrace();
|
||||
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?) {
|
||||
ApplicationManager.getApplication()!!.runWriteAction {
|
||||
withElementsToShorten(project) { bindRequests ->
|
||||
ShortenReferences.process(bindRequests.map() { it.getElement() }.filterNotNull())
|
||||
withElementsToShorten(project) { requests ->
|
||||
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);
|
||||
}
|
||||
|
||||
ShortenReferences.INSTANCE$.process(elementsToCompact);
|
||||
ShortenReferences.DEFAULT.process(elementsToCompact);
|
||||
|
||||
if (firstGenerated == null) return;
|
||||
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public class MoveDeclarationsOutHelper {
|
||||
dummyFirstStatement.delete();
|
||||
}
|
||||
|
||||
ShortenReferences.INSTANCE$.process(propertiesDeclarations);
|
||||
ShortenReferences.DEFAULT.process(propertiesDeclarations);
|
||||
|
||||
return PsiUtilCore.toPsiElementArray(resultStatements);
|
||||
}
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ public class KotlinRuntimeTypeCastSurrounder: KotlinExpressionSurrounder() {
|
||||
cast.getLeft().replace(myElement)
|
||||
val expr = myElement.replace(parentCast) as JetExpression
|
||||
|
||||
ShortenReferences.process(expr)
|
||||
ShortenReferences.DEFAULT.process(expr)
|
||||
|
||||
val range = expr.getTextRange()
|
||||
myEditor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset())
|
||||
|
||||
+1
-1
@@ -269,7 +269,7 @@ object CastReceiverInsertHandler : KotlinCallableInsertHandler() {
|
||||
|
||||
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 wholeRangeMarker = document.createRangeMarker(startOffset, classNameEnd + tempSuffix.length())
|
||||
|
||||
ShortenReferences.process(file, classNameStart, classNameEnd)
|
||||
ShortenReferences.DEFAULT.process(file, classNameStart, classNameEnd)
|
||||
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document)
|
||||
|
||||
if (rangeMarker.isValid() && wholeRangeMarker.isValid()) {
|
||||
|
||||
@@ -62,7 +62,7 @@ class ArtificialElementInsertHandler(
|
||||
|
||||
fun shortenReferences(context: InsertionContext, startOffset: Int, endOffset: Int) {
|
||||
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? {
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
|
||||
|
||||
val replaced = replaceWithIfThenThrowExpression(element)
|
||||
|
||||
ShortenReferences.process(replaced.getThen()!!)
|
||||
ShortenReferences.DEFAULT.process(replaced.getThen()!!)
|
||||
|
||||
fun replaceMessage() {
|
||||
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()) }
|
||||
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 newExpr = element.replace(assertExpr) as JetExpression
|
||||
ShortenReferences.process(newExpr)
|
||||
ShortenReferences.DEFAULT.process(newExpr)
|
||||
}
|
||||
|
||||
private fun getSelector(element: JetExpression?): JetExpression? {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class InsertExplicitTypeArguments : JetSelfTargetingIntention<JetCallExpr
|
||||
if (callee == null) return
|
||||
|
||||
element.addAfter(argumentList, callee)
|
||||
ShortenReferences.process(element.getTypeArgumentList()!!)
|
||||
ShortenReferences.DEFAULT.process(element.getTypeArgumentList()!!)
|
||||
}
|
||||
|
||||
class object {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
functionLiteral.addAfter(psiFactory.createNewLine(), openBraceElement)
|
||||
}
|
||||
}
|
||||
ShortenReferences.process(element.getValueParameters())
|
||||
ShortenReferences.DEFAULT.process(element.getValueParameters())
|
||||
|
||||
// Step 2: make the return type explicit
|
||||
val expectedReturnType = func.getReturnType()
|
||||
@@ -90,7 +90,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
val returnTypeExpr = psiFactory.createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(expectedReturnType))
|
||||
functionLiteral.addAfter(returnTypeExpr, paramList)
|
||||
functionLiteral.addAfter(returnTypeColon, paramList)
|
||||
ShortenReferences.process(functionLiteral.getTypeReference()!!)
|
||||
ShortenReferences.DEFAULT.process(functionLiteral.getTypeReference()!!)
|
||||
}
|
||||
|
||||
// Step 3: make the receiver type explicit
|
||||
@@ -99,7 +99,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
|
||||
val receiverTypeString = IdeDescriptorRenderers.SOURCE_CODE.renderType(expectedReceiverType)
|
||||
val dot = functionLiteral.addBefore(psiFactory.createDot(), functionLiteral.getValueParameterList())
|
||||
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.kotlin.idea.JetBundle;
|
||||
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.ShortenReferences;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
@@ -47,7 +47,7 @@ public class ReconstructTypeInCastOrIsAction extends PsiElementBaseIntentionActi
|
||||
JetType type = getReconstructedType(typeRef);
|
||||
JetTypeReference newType = JetPsiFactory(typeRef).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
||||
JetTypeReference replaced = (JetTypeReference) typeRef.replace(newType);
|
||||
ShortenReferences.INSTANCE$.process(replaced);
|
||||
ShortenReferences.DEFAULT.process(replaced);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
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.ShortenReferences;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
@@ -182,7 +182,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
|
||||
public void templateFinished(Template template, boolean brokenOff) {
|
||||
JetTypeReference typeRef = declaration.getTypeReference();
|
||||
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
|
||||
val typeReference = JetPsiFactory(declaration).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type))
|
||||
specifyTypeExplicitly(declaration, typeReference)
|
||||
ShortenReferences.process(declaration.getTypeReference()!!)
|
||||
ShortenReferences.DEFAULT.process(declaration.getTypeReference()!!)
|
||||
}
|
||||
|
||||
fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeReference) {
|
||||
|
||||
@@ -20,8 +20,8 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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.ShortenReferences;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
@@ -82,7 +82,7 @@ public class DeclarationUtils {
|
||||
);
|
||||
|
||||
if (inferredType != null) {
|
||||
ShortenReferences.INSTANCE$.process(property.getTypeReference());
|
||||
ShortenReferences.DEFAULT.process(property.getTypeReference());
|
||||
}
|
||||
|
||||
return newInitializer;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class KotlinShortenFQNamesProcessor : TemplateOptionalProcessor {
|
||||
PsiDocumentManager.getInstance(project).commitDocument(document)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
|
||||
|
||||
JetTypeReference typeRef = castExpression.getRight();
|
||||
assert typeRef != null;
|
||||
ShortenReferences.INSTANCE$.process(typeRef);
|
||||
ShortenReferences.DEFAULT.process(typeRef);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
||||
assert typeReference != null;
|
||||
|
||||
newTypeReference = (JetTypeReference) typeReference.replace(newTypeReference);
|
||||
ShortenReferences.INSTANCE$.process(newTypeReference);
|
||||
ShortenReferences.DEFAULT.process(newTypeReference);
|
||||
}
|
||||
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
|
||||
@@ -132,7 +132,7 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
|
||||
if (functionLiteralReturnTypeRef != null) {
|
||||
JetTypeReference newTypeRef = JetPsiFactory(file).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type));
|
||||
newTypeRef = (JetTypeReference) functionLiteralReturnTypeRef.replace(newTypeRef);
|
||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
||||
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||
}
|
||||
if (appropriateQuickFix != null && appropriateQuickFix.isAvailable(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));
|
||||
newTypeRef = element.setTypeReference(newTypeRef);
|
||||
assert newTypeRef != null;
|
||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
||||
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||
}
|
||||
else {
|
||||
element.setTypeReference(null);
|
||||
|
||||
@@ -40,8 +40,8 @@ import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
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.ShortenReferences;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
@@ -376,11 +376,11 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
|
||||
|
||||
JetTypeReference newTypeRef = function.setTypeReference(patternFunction.getTypeReference());
|
||||
if (newTypeRef != null) {
|
||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
||||
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||
}
|
||||
|
||||
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));
|
||||
newTypeRef = element.setTypeReference(newTypeRef);
|
||||
assert newTypeRef != null;
|
||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
||||
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetTypeReference newTypeRef = (JetTypeReference) element.replace(JetPsiFactory(file).createType(renderedType));
|
||||
ShortenReferences.INSTANCE$.process(newTypeRef);
|
||||
ShortenReferences.DEFAULT.process(newTypeRef);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -105,7 +105,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
||||
}
|
||||
}
|
||||
|
||||
ShortenReferences.INSTANCE$.process(toShorten);
|
||||
ShortenReferences.DEFAULT.process(toShorten);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -201,7 +201,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
runWriteAction { context.buildAndRunTemplate { buildNext(iterator) } }
|
||||
}
|
||||
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.impl.AnonymousFunctionDescriptor;
|
||||
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.refactoring.JetRefactoringUtil;
|
||||
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
|
||||
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++;
|
||||
}
|
||||
|
||||
ShortenPackage.addToShorteningWaitSet(parameterList);
|
||||
ShortenPackage.addToShorteningWaitSet(parameterList, Options.DEFAULT);
|
||||
}
|
||||
|
||||
if (changeInfo.isVisibilityChanged() && !JetPsiUtil.isLocal((JetDeclaration) element)) {
|
||||
@@ -284,7 +288,7 @@ public class JetFunctionDefinitionUsage<T extends PsiElement> extends JetUsageIn
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
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()
|
||||
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.caches.resolve.ResolutionFacade;
|
||||
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.ShortenReferences;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
@@ -295,7 +295,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
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);
|
||||
for (JetCallExpression call : callsToAddArguments) {
|
||||
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.idea.caches.resolve.ResolvePackage;
|
||||
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.RemoveCurlyBracesFromTemplateIntention;
|
||||
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.introduce.KotlinIntroduceHandlerBase;
|
||||
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.JetPsiUnifier;
|
||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.PatternMatchingPackage;
|
||||
@@ -425,7 +425,7 @@ public class KotlinIntroduceVariableHandler extends KotlinIntroduceHandlerBase {
|
||||
}
|
||||
propertyRef.set(property);
|
||||
if (noTypeInference) {
|
||||
ShortenReferences.INSTANCE$.process(property);
|
||||
ShortenReferences.DEFAULT.process(property);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ public abstract class AbstractShortenRefsTest : AbstractImportsTest() {
|
||||
override fun doTest(file: JetFile) {
|
||||
val selectionModel = myFixture.getEditor().getSelectionModel()
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user