Fixed bug in join lines
This commit is contained in:
@@ -33,7 +33,6 @@ import org.jetbrains.jet.lexer.JetTokens;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.JetNodeTypes.PROPERTY_ACCESSOR;
|
|
||||||
import static org.jetbrains.jet.JetNodeTypes.PROPERTY_DELEGATE;
|
import static org.jetbrains.jet.JetNodeTypes.PROPERTY_DELEGATE;
|
||||||
import static org.jetbrains.jet.lexer.JetTokens.*;
|
import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||||
|
|
||||||
@@ -233,6 +232,34 @@ public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStu
|
|||||||
return hasDelegateExpression() || hasInitializer();
|
return hasDelegateExpression() || hasInitializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public JetExpression setInitializer(@Nullable JetExpression initializer) {
|
||||||
|
JetExpression oldInitializer = getInitializer();
|
||||||
|
|
||||||
|
if (oldInitializer != null) {
|
||||||
|
if (initializer != null) {
|
||||||
|
return (JetExpression) oldInitializer.replace(initializer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
deleteChildRange(findChildByType(EQ), oldInitializer);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (initializer != null) {
|
||||||
|
PsiElement addAfter = getTypeRef();
|
||||||
|
if (addAfter == null) {
|
||||||
|
addAfter = getNameIdentifier();
|
||||||
|
}
|
||||||
|
PsiElement eq = addAfter(new JetPsiFactory(getProject()).createEQ(), addAfter);
|
||||||
|
return (JetExpression) addAfter(initializer, eq);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetExpression getDelegateExpressionOrInitializer() {
|
public JetExpression getDelegateExpressionOrInitializer() {
|
||||||
JetExpression expression = getDelegateExpression();
|
JetExpression expression = getDelegateExpression();
|
||||||
|
|||||||
+5
-5
@@ -38,7 +38,8 @@ public class JetDeclarationJoinLinesHandler : JoinRawLinesHandlerDelegate {
|
|||||||
.firstOrNull() ?: return -1
|
.firstOrNull() ?: return -1
|
||||||
val (property, assignment) = pair
|
val (property, assignment) = pair
|
||||||
|
|
||||||
return doJoin(property, assignment).getTextRange()!!.getStartOffset()
|
doJoin(property, assignment)
|
||||||
|
return property.getTextRange()!!.getStartOffset()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tryJoinLines(document: Document, file: PsiFile, start: Int, end: Int)
|
override fun tryJoinLines(document: Document, file: PsiFile, start: Int, end: Int)
|
||||||
@@ -58,10 +59,9 @@ public class JetDeclarationJoinLinesHandler : JoinRawLinesHandlerDelegate {
|
|||||||
return property to assignment
|
return property to assignment
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doJoin(property: JetProperty, assignment: JetBinaryExpression): JetProperty {
|
private fun doJoin(property: JetProperty, assignment: JetBinaryExpression) {
|
||||||
val newProperty = DeclarationUtils.changePropertyInitializer(property, assignment.getRight())
|
property.setInitializer(assignment.getRight())
|
||||||
property.getParent()!!.deleteChildRange(property.getNextSibling(), assignment)
|
property.getParent()!!.deleteChildRange(property.getNextSibling(), assignment) //TODO: should we remove range?
|
||||||
return property.replace(newProperty) as JetProperty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>[volatile] var v: Int
|
||||||
|
v = 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>[volatile] var v: Int = 1
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fun foo(n: Int) {
|
fun foo(n: Int) {
|
||||||
// foo3
|
// foo3
|
||||||
<caret>val x: String = "" // bar3
|
<caret>val /* foo */ x: String = "" // bar3
|
||||||
/* baz */
|
/* baz */
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fun foo(n: Int) {
|
fun foo(n: Int) {
|
||||||
// foo3
|
// foo3
|
||||||
<caret>val x: String = "" // bar3
|
<caret>val /* foo */ x: String = "" // bar3
|
||||||
/* baz */
|
/* baz */
|
||||||
}
|
}
|
||||||
+7
-5
@@ -17,13 +17,9 @@
|
|||||||
package org.jetbrains.jet.plugin.intentions.declarations;
|
package org.jetbrains.jet.plugin.intentions.declarations;
|
||||||
|
|
||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.test.InnerTestClasses;
|
|
||||||
import org.jetbrains.jet.test.TestMetadata;
|
import org.jetbrains.jet.test.TestMetadata;
|
||||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -50,6 +46,12 @@ public class JoinLinesTestGenerated extends AbstractJoinLinesTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("propertyWithAnnotation.kt")
|
||||||
|
public void testPropertyWithAnnotation() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/joinLines/propertyWithAnnotation.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simpleInit.kt")
|
@TestMetadata("simpleInit.kt")
|
||||||
public void testSimpleInit() throws Exception {
|
public void testSimpleInit() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/joinLines/simpleInit.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/joinLines/simpleInit.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user