Minor code corrections after review

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