Minor code corrections after review
This commit is contained in:
@@ -32,7 +32,7 @@ public object ShortenReferences {
|
|||||||
public fun process(file: JetFile, startOffset: Int, endOffset: Int) {
|
public fun process(file: JetFile, startOffset: Int, endOffset: Int) {
|
||||||
val smartPointerManager = SmartPointerManager.getInstance(file.getProject())
|
val smartPointerManager = SmartPointerManager.getInstance(file.getProject())
|
||||||
val pointer = smartPointerManager.createSmartPsiFileRangePointer(file, TextRange(startOffset, endOffset))
|
val pointer = smartPointerManager.createSmartPsiFileRangePointer(file, TextRange(startOffset, endOffset))
|
||||||
try{
|
try {
|
||||||
process(listOf(file), { element ->
|
process(listOf(file), { element ->
|
||||||
val segment = pointer.getRange()
|
val segment = pointer.getRange()
|
||||||
if (segment != null) {
|
if (segment != null) {
|
||||||
@@ -44,7 +44,7 @@ public object ShortenReferences {
|
|||||||
else -> FilterResult.SKIP
|
else -> FilterResult.SKIP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
FilterResult.SKIP
|
FilterResult.SKIP
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -102,9 +102,12 @@ public object ShortenReferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitUserType(userType: JetUserType) {
|
override fun visitUserType(userType: JetUserType) {
|
||||||
|
val filterResult = elementFilter(userType)
|
||||||
|
if (filterResult == FilterResult.SKIP) return
|
||||||
|
|
||||||
userType.getTypeArgumentList()?.accept(this)
|
userType.getTypeArgumentList()?.accept(this)
|
||||||
|
|
||||||
if (elementFilter(userType) == FilterResult.PROCESS && canShortenType(userType)) {
|
if (filterResult == FilterResult.PROCESS && canShortenType(userType)) {
|
||||||
typesToShorten.add(userType)
|
typesToShorten.add(userType)
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
@@ -59,17 +59,16 @@ class LambdaItems(val project: Project) {
|
|||||||
val offset = context.getStartOffset()
|
val offset = context.getStartOffset()
|
||||||
val placeholder = "{}"
|
val placeholder = "{}"
|
||||||
document.replaceString(offset, context.getTailOffset(), placeholder)
|
document.replaceString(offset, context.getTailOffset(), placeholder)
|
||||||
editor.getCaretModel().moveToOffset(offset + 1)
|
|
||||||
val rangeMarker = document.createRangeMarker(offset, offset + placeholder.length)
|
val rangeMarker = document.createRangeMarker(offset, offset + placeholder.length)
|
||||||
|
|
||||||
// we start template later to not interfere with insertion of tail type
|
// we start template later to not interfere with insertion of tail type
|
||||||
val commandProcessor = CommandProcessor.getInstance()
|
val commandProcessor = CommandProcessor.getInstance()
|
||||||
val commandName = commandProcessor.getCurrentCommandName()
|
val commandName = commandProcessor.getCurrentCommandName()
|
||||||
val commandGroupId = commandProcessor.getCurrentCommandGroupId()
|
val commandGroupId = commandProcessor.getCurrentCommandGroupId()
|
||||||
context.setLaterRunnable{
|
context.setLaterRunnable {
|
||||||
commandProcessor.executeCommand(project, {
|
commandProcessor.executeCommand(project, {
|
||||||
ApplicationManager.getApplication()!!.runWriteAction(Computable<Unit>{
|
ApplicationManager.getApplication()!!.runWriteAction(Computable<Unit> {
|
||||||
try{
|
try {
|
||||||
if (rangeMarker.isValid()) {
|
if (rangeMarker.isValid()) {
|
||||||
document.deleteString(rangeMarker.getStartOffset(), rangeMarker.getEndOffset())
|
document.deleteString(rangeMarker.getStartOffset(), rangeMarker.getEndOffset())
|
||||||
editor.getCaretModel().moveToOffset(rangeMarker.getStartOffset())
|
editor.getCaretModel().moveToOffset(rangeMarker.getStartOffset())
|
||||||
@@ -101,9 +100,9 @@ class LambdaItems(val project: Project) {
|
|||||||
template.addTextSegment("(")
|
template.addTextSegment("(")
|
||||||
}
|
}
|
||||||
|
|
||||||
var i = 0
|
for (i in parameterTypes.indices) {
|
||||||
for (parameterType in parameterTypes) {
|
val parameterType = parameterTypes[i]
|
||||||
if (i++ > 0) {
|
if (i > 0) {
|
||||||
template.addTextSegment(", ")
|
template.addTextSegment(", ")
|
||||||
}
|
}
|
||||||
template.addVariable(ParameterNameExpression(JetNameSuggester.suggestNames(parameterType, nameValidator, "p")), true)
|
template.addVariable(ParameterNameExpression(JetNameSuggester.suggestNames(parameterType, nameValidator, "p")), true)
|
||||||
|
|||||||
Reference in New Issue
Block a user