drop deprecated syntax for anonymous initializer blocks

This commit is contained in:
Dmitry Jemerov
2015-04-24 18:37:27 +02:00
parent 35e82d4574
commit 98b8784ab0
52 changed files with 61 additions and 816 deletions
@@ -1,72 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.quickfix
import org.jetbrains.kotlin.psi.*
import kotlin.platform.*
import org.jetbrains.kotlin.diagnostics.*
import com.intellij.codeInsight.intention.*
import org.jetbrains.kotlin.idea.*
import com.intellij.openapi.project.*
import com.intellij.openapi.editor.*
import com.intellij.psi.*
import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionForFirstParentOfType
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.psiUtil.*
import java.util.ArrayList
public class AddInitKeywordFix(element: JetClassInitializer) : JetIntentionAction<JetClassInitializer>(element) {
override fun getText() = JetBundle.message("add.init.keyword")
override fun getFamilyName() = JetBundle.message("add.init.keyword.family")
override fun invoke(project: Project, editor: Editor?, file: JetFile) {
addInitKeyword(element)
}
companion object Factory : JetSingleIntentionActionFactory() {
override fun createAction(diagnostic: Diagnostic) = diagnostic.createIntentionForFirstParentOfType(::AddInitKeywordFix)
public fun createWholeProjectFixFactory(): JetSingleIntentionActionFactory = createIntentionFactory {
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetClassInitializer>(
predicate = { !it.hasInitKeyword() },
taskProcessor = { addInitKeyword(it) },
modalTitle = JetBundle.message("add.init.keyword.in.whole.project.modal.title"),
name = JetBundle.message("add.init.keyword.in.whole.project"),
familyName = JetBundle.message("add.init.keyword.in.whole.project.family")
)
}
private fun addInitKeyword(element: JetClassInitializer) {
if (element.hasInitKeyword()) return
val psiFactory = JetPsiFactory(element)
val initKeyword = psiFactory.createInitKeyword()
val anchor = element.getBody() ?: return
element.addBefore(initKeyword, anchor)
element.addBefore(psiFactory.createWhiteSpace(), anchor)
val prevLeaf: PsiElement? = element.prevLeafSkipWhitespaces()
if (prevLeaf?.getNode()?.getElementType() == JetTokens.SEMICOLON) {
prevLeaf!!.delete()
}
}
}
}
@@ -1,82 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.quickfix;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.diagnostics.Diagnostic;
import org.jetbrains.kotlin.idea.JetBundle;
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil;
import org.jetbrains.kotlin.psi.JetCallExpression;
import org.jetbrains.kotlin.psi.JetExpression;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.psi.JetFunctionLiteralArgument;
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
public class AddSemicolonAfterFunctionCallFix extends JetIntentionAction<JetCallExpression> {
private final JetFunctionLiteralArgument functionLiteralArgument;
public AddSemicolonAfterFunctionCallFix(@NotNull JetCallExpression element, @NotNull JetFunctionLiteralArgument functionLiteralArgument) {
super(element);
this.functionLiteralArgument = functionLiteralArgument;
}
@NotNull
@Override
public String getText() {
JetExpression callee = element.getCalleeExpression();
assert callee != null;
return JetBundle.message("add.semicolon.after.invocation", callee.getText());
}
@NotNull
@Override
public String getFamilyName() {
return JetBundle.message("add.semicolon.family");
}
@Override
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
PsiElement argumentList = element.getValueArgumentList();
assert argumentList != null;
PsiElement afterArgumentList = argumentList.getNextSibling();
int caretOffset = editor.getCaretModel().getOffset();
element.getParent().addRangeAfter(afterArgumentList, functionLiteralArgument, element);
element.deleteChildRange(afterArgumentList, functionLiteralArgument);
element.getParent().addAfter(JetPsiFactory(file).createSemicolon(), element);
editor.getCaretModel().moveToOffset(caretOffset + 1);
}
public static JetSingleIntentionActionFactory createFactory() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public JetIntentionAction createAction(Diagnostic diagnostic) {
JetCallExpression callExpression = QuickFixUtil.getParentElementOfType(diagnostic, JetCallExpression.class);
JetFunctionLiteralArgument functionLiteralArgument =
QuickFixUtil.getParentElementOfType(diagnostic, JetFunctionLiteralArgument.class);
if (callExpression == null || functionLiteralArgument == null) return null;
return new AddSemicolonAfterFunctionCallFix(callExpression, functionLiteralArgument);
}
};
}
}
@@ -216,8 +216,6 @@ public class QuickFixRegistrar {
QuickFixes.factories.put(NOT_AN_ANNOTATION_CLASS, MakeClassAnAnnotationClassFix.createFactory());
QuickFixes.factories.put(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED, AddSemicolonAfterFunctionCallFix.createFactory());
JetIntentionActionsFactory changeVariableTypeFix = ChangeVariableTypeFix.createFactoryForPropertyOrReturnTypeMismatchOnOverride();
QuickFixes.factories.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
QuickFixes.factories.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
@@ -309,9 +307,6 @@ public class QuickFixRegistrar {
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateClassFromReferenceExpressionActionFactory.INSTANCE$);
QuickFixes.factories.put(UNRESOLVED_REFERENCE, CreateClassFromCallWithConstructorCalleeActionFactory.INSTANCE$);
QuickFixes.factories.put(INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED, AddInitKeywordFix.Factory);
QuickFixes.factories.put(INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED, AddInitKeywordFix.Factory.createWholeProjectFixFactory());
QuickFixes.factories.put(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, InsertDelegationCallQuickfix.InsertThisDelegationCallFactory.INSTANCE$);
QuickFixes.factories.put(EXPLICIT_DELEGATION_CALL_REQUIRED, InsertDelegationCallQuickfix.InsertThisDelegationCallFactory.INSTANCE$);
@@ -1,8 +0,0 @@
// "Add semicolon after invocation of 'foo'" "true"
fun foo() {}
fun foo(x : Int) {}
fun bar() {
foo(4);
{}<caret>
}
@@ -1,8 +0,0 @@
// "Add semicolon after invocation of 'foo'" "true"
fun foo() {}
fun foo(x : Int) {}
fun bar() {
foo(4)
{}<caret>
}
@@ -1,64 +0,0 @@
annotation class Ann3
annotation class Ann4
class D {
Ann3 init {
}
Ann4 init {
class Q {
init {
}
}
}
}
class E {
companion object {
init {
}
init {}
}
}
fun foo() = 1
class F {
val a1 = foo()
init {
}
val a2 = foo()
init {
}
val a3 = foo(); // el
/* abc */init {
}
val a4 = foo() // el
;/* abc */
init {
}
val a5 = foo()
/* abc */
init {
}
val a6 = foo();
init {
}
}
@@ -1,37 +0,0 @@
// "Add 'init' keyword in whole project" "true"
annotation class Ann1
annotation class Ann2
class A {
Ann1 Ann2 init {
class Q {
init {
}
Ann2 init {
}
}
}
Ann1 init {
}
}
class B {
Ann1 Ann2 init {
class Q {
init {
}
Ann2 init {
}
}
}
init {
}
}
@@ -1,37 +0,0 @@
// "Add 'init' keyword in whole project" "true"
annotation class Ann1
annotation class Ann2
class A {
Ann1 Ann2 <caret>{
class Q {
{
}
Ann2 {
}
}
}
Ann1 {
}
}
class B {
Ann1 Ann2 {
class Q {
init {
}
Ann2 {
}
}
}
{
}
}
@@ -1,60 +0,0 @@
annotation class Ann3
annotation class Ann4
class D {
Ann3 init {
}
Ann4 {
class Q {
{
}
}
}
}
class E {
companion object {
init {
}
{}
}
}
fun foo() = 1
class F {
val a1 = foo();
{
}
val a2 = foo()
;{
}
val a3 = foo(); // el
/* abc */{
}
val a4 = foo() // el
;/* abc */{
}
val a5 = foo()
/* abc */;{
}
val a6 = foo();
init {
}
}
@@ -1,6 +0,0 @@
// "Add 'init' keyword" "true"
class A {
init {
}
}
@@ -1,9 +0,0 @@
// "Add 'init' keyword" "true"
fun foo() = 1
class A {
val prop = foo()
init {
}
}
@@ -1,9 +0,0 @@
// "Add 'init' keyword" "true"
fun foo() = 1
class A {
val prop = foo()
init {
}
}
@@ -1,8 +0,0 @@
// "Add 'init' keyword" "true"
annotation class Ann1
annotation class Ann2
class A {
Ann1 Ann2 init {
}
}
@@ -1,6 +0,0 @@
// "Add 'init' keyword" "true"
class A {
<caret>{
}
}
@@ -1,9 +0,0 @@
// "Add 'init' keyword" "true"
fun foo() = 1
class A {
val prop = foo();
<caret>{
}
}
@@ -1,8 +0,0 @@
// "Add 'init' keyword" "true"
fun foo() = 1
class A {
val prop = foo()
;<caret>{
}
}
@@ -1,8 +0,0 @@
// "Add 'init' keyword" "true"
annotation class Ann1
annotation class Ann2
class A {
Ann1 Ann2 <caret>{
}
}
@@ -848,12 +848,6 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Migration extends AbstractQuickFixMultiFileTest {
@TestMetadata("addInitKeywordMultiple.before.Main.kt")
public void testAddInitKeywordMultiple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/addInitKeywordMultiple.before.Main.kt");
doTestWithExtraFile(fileName);
}
public void testAllFilesPresentInMigration() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
}
@@ -2866,12 +2866,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/expressions"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeDanglingFunctionLiteralArgument.kt")
public void testDanglingFunctionLiteralArgument() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeDanglingFunctionLiteralArgument.kt");
doTest(fileName);
}
@TestMetadata("beforeRemoveUselessCast.kt")
public void testRemoveUselessCast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeRemoveUselessCast.kt");
@@ -3130,30 +3124,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("beforeAddInitKeyword.kt")
public void testAddInitKeyword() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/beforeAddInitKeyword.kt");
doTest(fileName);
}
@TestMetadata("beforeAddInitKeywordRemoveSemicolon.kt")
public void testAddInitKeywordRemoveSemicolon() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolon.kt");
doTest(fileName);
}
@TestMetadata("beforeAddInitKeywordRemoveSemicolonSameLine.kt")
public void testAddInitKeywordRemoveSemicolonSameLine() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolonSameLine.kt");
doTest(fileName);
}
@TestMetadata("beforeAddInitKeywordWithModifiers.kt")
public void testAddInitKeywordWithModifiers() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/beforeAddInitKeywordWithModifiers.kt");
doTest(fileName);
}
@TestMetadata("beforeAddInnerModifier.kt")
public void testAddInnerModifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/modifiers/beforeAddInnerModifier.kt");