From 98b8784ab02e1d1032e2dfb6b3adefd663b604e9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 24 Apr 2015 18:37:27 +0200 Subject: [PATCH] drop deprecated syntax for anonymous initializer blocks --- .../jetbrains/kotlin/diagnostics/Errors.java | 3 - .../rendering/DefaultErrorMessages.java | 6 -- .../jetbrains/kotlin/parsing/JetParsing.java | 4 - .../kotlin/psi/JetClassInitializer.java | 4 - .../kotlin/resolve/BodyResolver.java | 4 - .../kotlin/resolve/calls/CallResolver.java | 65 +------------- .../calls/tasks/AbstractTracingStrategy.java | 8 -- .../resolve/calls/tasks/TracingStrategy.java | 7 -- ...egyForImplicitConstructorDelegationCall.kt | 6 -- .../ControlStructureTypingUtils.java | 7 -- .../tests/FunctionCalleeExpressions.kt | 2 +- .../testData/diagnostics/tests/Varargs.kt | 4 +- .../checkArguments/kt1897_diagnostic_part.kt | 2 +- .../DanglingFunctionLiteral.kt | 28 ------ .../DanglingFunctionLiteral.txt | 26 ------ ...NoDanglingFunctionLiteralForNestedCalls.kt | 11 --- ...oDanglingFunctionLiteralForNestedCalls.txt | 7 -- .../diagnostics/tests/regressions/kt1736.kt | 2 +- .../expectedInitKeywordOnInitializer.kt | 10 --- .../expectedInitKeywordOnInitializer.txt | 10 --- compiler/testData/psi/AnonymousInitializer.kt | 2 +- .../testData/psi/AnonymousInitializer.txt | 2 + .../psi/PropertiesFollowedByInitializers.kt | 4 +- .../psi/PropertiesFollowedByInitializers.txt | 4 + .../psi/annotation/ShortAnnotations.kt | 2 +- .../psi/annotation/ShortAnnotations.txt | 2 + compiler/testData/psi/examples/BinaryTree.kt | 6 +- compiler/testData/psi/examples/BinaryTree.txt | 87 ++++++++----------- .../anonymousInitializer.kt | 8 -- .../anonymousInitializer.txt | 50 ----------- .../psi/secondaryConstructors/enumParsing.kt | 2 +- .../psi/secondaryConstructors/enumParsing.txt | 2 + .../checkers/JetDiagnosticsTestGenerated.java | 18 ---- .../kotlin/idea/quickfix/AddInitKeywordFix.kt | 72 --------------- .../AddSemicolonAfterFunctionCallFix.java | 82 ----------------- .../idea/quickfix/QuickFixRegistrar.java | 5 -- .../afterDanglingFunctionLiteralArgument.kt | 8 -- .../beforeDanglingFunctionLiteralArgument.kt | 8 -- ...ddInitKeywordMultiple.after.data.Sample.kt | 64 -------------- .../migration/addInitKeywordMultiple.after.kt | 37 -------- .../addInitKeywordMultiple.before.Main.kt | 37 -------- ...dInitKeywordMultiple.before.data.Sample.kt | 60 ------------- .../quickfix/modifiers/afterAddInitKeyword.kt | 6 -- .../afterAddInitKeywordRemoveSemicolon.kt | 9 -- ...erAddInitKeywordRemoveSemicolonSameLine.kt | 9 -- .../afterAddInitKeywordWithModifiers.kt | 8 -- .../modifiers/beforeAddInitKeyword.kt | 6 -- .../beforeAddInitKeywordRemoveSemicolon.kt | 9 -- ...reAddInitKeywordRemoveSemicolonSameLine.kt | 8 -- .../beforeAddInitKeywordWithModifiers.kt | 8 -- .../QuickFixMultiFileTestGenerated.java | 6 -- .../idea/quickfix/QuickFixTestGenerated.java | 30 ------- 52 files changed, 61 insertions(+), 816 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt delete mode 100644 compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.txt delete mode 100644 compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt delete mode 100644 compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.txt delete mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt delete mode 100644 compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.txt delete mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/AddInitKeywordFix.kt delete mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/AddSemicolonAfterFunctionCallFix.java delete mode 100644 idea/testData/quickfix/expressions/afterDanglingFunctionLiteralArgument.kt delete mode 100644 idea/testData/quickfix/expressions/beforeDanglingFunctionLiteralArgument.kt delete mode 100644 idea/testData/quickfix/migration/addInitKeywordMultiple.after.data.Sample.kt delete mode 100644 idea/testData/quickfix/migration/addInitKeywordMultiple.after.kt delete mode 100644 idea/testData/quickfix/migration/addInitKeywordMultiple.before.Main.kt delete mode 100644 idea/testData/quickfix/migration/addInitKeywordMultiple.before.data.Sample.kt delete mode 100644 idea/testData/quickfix/modifiers/afterAddInitKeyword.kt delete mode 100644 idea/testData/quickfix/modifiers/afterAddInitKeywordRemoveSemicolon.kt delete mode 100644 idea/testData/quickfix/modifiers/afterAddInitKeywordRemoveSemicolonSameLine.kt delete mode 100644 idea/testData/quickfix/modifiers/afterAddInitKeywordWithModifiers.kt delete mode 100644 idea/testData/quickfix/modifiers/beforeAddInitKeyword.kt delete mode 100644 idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolon.kt delete mode 100644 idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolonSameLine.kt delete mode 100644 idea/testData/quickfix/modifiers/beforeAddInitKeywordWithModifiers.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index f71410e69dd..ea4daf612f3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -162,7 +162,6 @@ public interface Errors { DiagnosticFactory0 SECONDARY_CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED = DiagnosticFactory0.create(WARNING); DiagnosticFactory0 PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED = DiagnosticFactory0.create(ERROR, PositioningStrategies.SECONDARY_CONSTRUCTOR_DELEGATION_CALL); @@ -421,8 +420,6 @@ public interface Errors { DiagnosticFactory1>> CANNOT_COMPLETE_RESOLVE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1>> UNRESOLVED_REFERENCE_WRONG_RECEIVER = DiagnosticFactory1.create(ERROR); - DiagnosticFactory0 DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED = DiagnosticFactory0.create(WARNING); - DiagnosticFactory1 TYPE_PARAMETER_AS_REIFIED = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 7566d209cee..b996c98e725 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -403,8 +403,6 @@ public class DefaultErrorMessages { MAP.put(INSTANCE_ACCESS_BEFORE_SUPER_CALL, "Cannot access ''{0}'' before superclass constructor has been called", NAME); - MAP.put(INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED, "Expecting 'init' keyword before class initializer"); - MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", STRING); MAP.put(NO_TAIL_CALLS_FOUND, "A function is marked as tail-recursive but no tail calls are found"); @@ -549,10 +547,6 @@ public class DefaultErrorMessages { MAP.put(NO_TYPE_ARGUMENTS_ON_RHS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected. " + "Use ''{1}'' if you don''t want to pass type arguments", null, STRING); - MAP.put(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED, - "This expression is treated as an argument to the function call on the previous line. " + - "Separate it with a semicolon (;) if it is not intended to be an argument."); - MAP.put(TYPE_PARAMETER_AS_REIFIED, "Cannot use ''{0}'' as reified type parameter. Use a class instead.", NAME); MAP.put(REIFIED_TYPE_PARAMETER_NO_INLINE, "Only type parameters of inline functions can be reified"); MAP.put(REIFIED_TYPE_FORBIDDEN_SUBSTITUTION, "Cannot use ''{0}'' as reified type parameter", RENDER_TYPE); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index b23a78e16cf..fdafcc84f3b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -839,10 +839,6 @@ public class JetParsing extends AbstractJetParsing { parseObject(isDefault ? NameParsingMode.ALLOWED : NameParsingMode.REQUIRED, true); declType = OBJECT_DECLARATION; } - else if (keywordToken == LBRACE) { - parseBlock(); - declType = ANONYMOUS_INITIALIZER; - } else if (at(INIT_KEYWORD)) { advance(); // init if (at(LBRACE)) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassInitializer.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassInitializer.java index 2b3762fcdb1..07a912181f7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassInitializer.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassInitializer.java @@ -55,10 +55,6 @@ public class JetClassInitializer extends JetDeclarationStub results = performResolutionGuardedForExtraFunctionLiteralArguments( - task.replaceBindingTrace(taskTrace), callTransformer); + OverloadResolutionResultsImpl results = performResolution(task.replaceBindingTrace(taskTrace), callTransformer); + allCandidates.addAll(task.getResolvedCalls()); @@ -542,62 +541,6 @@ public class CallResolver { ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - @NotNull - private OverloadResolutionResultsImpl performResolutionGuardedForExtraFunctionLiteralArguments( - @NotNull final ResolutionTask task, - @NotNull CallTransformer callTransformer - ) { - OverloadResolutionResultsImpl results = performResolution(task, callTransformer); - - // If resolution fails, we should check for some of the following situations: - // class A { - // val foo = Bar() // The following is intended to be an anonymous initializer, - // // but is treated as a function literal argument - // { - // ... - // } - // } - // - // fun foo() { - // bar { - // buzz() - // {...} // intended to be a returned from the outer literal - // } - // } - ImmutableSet someFailed = ImmutableSet.of(MANY_FAILED_CANDIDATES, - SINGLE_CANDIDATE_ARGUMENT_MISMATCH); - if (someFailed.contains(results.getResultCode()) && !task.call.getFunctionLiteralArguments().isEmpty() - && task.contextDependency == ContextDependency.INDEPENDENT) { //For nested calls there are no such cases - // We have some candidates that failed for some reason - // And we have a suspect: the function literal argument - // Now, we try to remove this argument and see if it helps - DelegatingCall callWithoutFLArgs = new DelegatingCall(task.call) { - @NotNull - @Override - public List getValueArguments() { - return CallUtilPackage.getValueArgumentsInParentheses(task.call); - } - - @NotNull - @Override - public List getFunctionLiteralArguments() { - return Collections.emptyList(); - } - }; - TemporaryBindingTrace temporaryTrace = - TemporaryBindingTrace.create(task.trace, "trace for resolution guarded for extra function literal arguments"); - ResolutionTask newTask = task.replaceContext(task.toBasic()). - replaceBindingTrace(temporaryTrace).replaceCall(callWithoutFLArgs); - - OverloadResolutionResultsImpl resultsWithFunctionLiteralsStripped = performResolution(newTask, callTransformer); - if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) { - task.tracing.danglingFunctionLiteralArgumentSuspected(task.trace, task.call.getFunctionLiteralArguments()); - } - } - - return results; - } - @NotNull private OverloadResolutionResultsImpl performResolution( @NotNull ResolutionTask task, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/AbstractTracingStrategy.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/AbstractTracingStrategy.java index 195d26699da..cd809089781 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/AbstractTracingStrategy.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/AbstractTracingStrategy.java @@ -42,7 +42,6 @@ import org.jetbrains.kotlin.types.Variance; import org.jetbrains.kotlin.types.expressions.OperatorConventions; import java.util.Collection; -import java.util.List; import static org.jetbrains.kotlin.diagnostics.Errors.*; import static org.jetbrains.kotlin.resolve.BindingContext.AMBIGUOUS_REFERENCE_TARGET; @@ -193,13 +192,6 @@ public abstract class AbstractTracingStrategy implements TracingStrategy { trace.report(UNNECESSARY_SAFE_CALL.on(callOperationNode.getPsi(), type)); } - @Override - public void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List functionLiteralArguments) { - for (JetFunctionLiteralArgument functionLiteralArgument : functionLiteralArguments) { - trace.report(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED.on(functionLiteralArgument.getArgumentExpression())); - } - } - @Override public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor) { trace.report(INVISIBLE_MEMBER.on(call.getCallElement(), descriptor, descriptor.getVisibility(), descriptor.getContainingDeclaration())); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategy.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategy.java index 063e131c05e..751549e920b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategy.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategy.java @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.calls.tasks; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.psi.Call; -import org.jetbrains.kotlin.psi.JetFunctionLiteralArgument; import org.jetbrains.kotlin.resolve.BindingTrace; import org.jetbrains.kotlin.resolve.calls.inference.InferenceErrorData; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; @@ -27,7 +26,6 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.types.JetType; import java.util.Collection; -import java.util.List; public interface TracingStrategy { TracingStrategy EMPTY = new TracingStrategy() { @@ -96,9 +94,6 @@ public interface TracingStrategy { @Override public void unnecessarySafeCall(@NotNull BindingTrace trace, @NotNull JetType type) {} - @Override - public void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List functionLiteralArguments) {} - @Override public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor) {} @@ -151,8 +146,6 @@ public interface TracingStrategy { void unnecessarySafeCall(@NotNull BindingTrace trace, @NotNull JetType type); - void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List functionLiteralArguments); - void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor); void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForImplicitConstructorDelegationCall.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForImplicitConstructorDelegationCall.kt index 2a612f249e8..6d169519c38 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForImplicitConstructorDelegationCall.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForImplicitConstructorDelegationCall.kt @@ -113,12 +113,6 @@ public class TracingStrategyForImplicitConstructorDelegationCall( unexpectedError("unnecessarySafeCall") } - override fun danglingFunctionLiteralArgumentSuspected( - trace: BindingTrace, functionLiteralArguments: MutableList - ) { - unexpectedError("danglingFunctionLiteralArgumentSuspected") - } - override fun missingReceiver(trace: BindingTrace, expectedReceiver: ReceiverParameterDescriptor) { unexpectedError("missingReceiver") } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java index 137929a2775..e77814534ff 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingUtils.java @@ -508,13 +508,6 @@ public class ControlStructureTypingUtils { logError(); } - @Override - public void danglingFunctionLiteralArgumentSuspected( - @NotNull BindingTrace trace, @NotNull List functionLiteralArguments - ) { - logError(); - } - @Override public void invisibleMember( @NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt index 0ef267c2127..6673a17efb7 100644 --- a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt @@ -32,7 +32,7 @@ fun main(args : Array) { a.foo1()(a) foo2()({}) - foo2(){} + foo2(){} (foo2()){} (foo2()){x -> } foo2()({x -> }) diff --git a/compiler/testData/diagnostics/tests/Varargs.kt b/compiler/testData/diagnostics/tests/Varargs.kt index ce75543d839..7e20e4f40be 100644 --- a/compiler/testData/diagnostics/tests/Varargs.kt +++ b/compiler/testData/diagnostics/tests/Varargs.kt @@ -12,6 +12,6 @@ fun test() { v1({}, {}) v1({}, 1, {}) v1({}, {}, {it}) - v1({}) {} - v1 {} + v1({}) {} + v1 {} } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.kt b/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.kt index a5be87e48b3..62081dabbde 100644 --- a/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.kt +++ b/compiler/testData/diagnostics/tests/checkArguments/kt1897_diagnostic_part.kt @@ -10,7 +10,7 @@ fun test() { bar(xx) - bar { } + bar { } foo("", 1, xx) diff --git a/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt b/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt deleted file mode 100644 index 01e9a91f009..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt +++ /dev/null @@ -1,28 +0,0 @@ - -class Foo() { - private val builder = StringBuilder("sdfsd") - - init { - } -} - -class Foo1() { - private val builder = StringBuilder("sdfsd") - - { - } -} - -fun foo() = { - println(1) - {} -} - -fun foo1() = { - println(1); - {} -} - -fun println(i : Int) {} -fun println(s : Byte) {} -fun println() {} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.txt b/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.txt deleted file mode 100644 index e5eba5ec160..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.txt +++ /dev/null @@ -1,26 +0,0 @@ -package - -internal fun foo(): () -> ??? -internal fun foo1(): () -> () -> kotlin.Unit -internal fun println(): kotlin.Unit -internal fun println(/*0*/ s: kotlin.Byte): kotlin.Unit -internal fun println(/*0*/ i: kotlin.Int): kotlin.Unit - -internal final class Foo { - public constructor Foo() - private final val builder: java.lang.StringBuilder - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} - -internal final class Foo1 { - public constructor Foo1() - private final val builder: [ERROR : Type for StringBuilder("sdfsd") - - { - }] - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt b/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt deleted file mode 100644 index 655667c2aa3..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt +++ /dev/null @@ -1,11 +0,0 @@ -package baz - -fun test() { - foo(1) {} - - foo( foo(1) {} ) //here -} - -fun foo(i: Int) {} - -fun foo() : (i : () -> Unit) -> Unit = {} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.txt b/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.txt deleted file mode 100644 index 8b731b6bdbf..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.txt +++ /dev/null @@ -1,7 +0,0 @@ -package - -package baz { - internal fun foo(): (() -> kotlin.Unit) -> kotlin.Unit - internal fun foo(/*0*/ i: kotlin.Int): kotlin.Unit - internal fun test(): kotlin.Unit -} diff --git a/compiler/testData/diagnostics/tests/regressions/kt1736.kt b/compiler/testData/diagnostics/tests/regressions/kt1736.kt index 8214fc8e645..e659bdc9a3c 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt1736.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt1736.kt @@ -7,4 +7,4 @@ object Obj { } } -val x = Obj.method{ -> } \ No newline at end of file +val x = Obj.method{ -> } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt deleted file mode 100644 index 03df7843893..00000000000 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt +++ /dev/null @@ -1,10 +0,0 @@ -class A { - val x: Int - val y: Int - { - x = 1 - } - init { - y = 1 - } -} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.txt b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.txt deleted file mode 100644 index 4be4604d583..00000000000 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.txt +++ /dev/null @@ -1,10 +0,0 @@ -package - -internal final class A { - public constructor A() - internal final val x: kotlin.Int - internal final val y: kotlin.Int - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/psi/AnonymousInitializer.kt b/compiler/testData/psi/AnonymousInitializer.kt index ffb4cefb3c5..a94df5e5b92 100644 --- a/compiler/testData/psi/AnonymousInitializer.kt +++ b/compiler/testData/psi/AnonymousInitializer.kt @@ -1,6 +1,6 @@ class Foo { - { + init { foo() val c = f } diff --git a/compiler/testData/psi/AnonymousInitializer.txt b/compiler/testData/psi/AnonymousInitializer.txt index 6e9a7764c9c..939d6afb63d 100644 --- a/compiler/testData/psi/AnonymousInitializer.txt +++ b/compiler/testData/psi/AnonymousInitializer.txt @@ -10,6 +10,8 @@ JetFile: AnonymousInitializer.kt PsiElement(LBRACE)('{') PsiWhiteSpace('\n\n ') ANONYMOUS_INITIALIZER + PsiElement(init)('init') + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') diff --git a/compiler/testData/psi/PropertiesFollowedByInitializers.kt b/compiler/testData/psi/PropertiesFollowedByInitializers.kt index eaf68db97b6..3502844c45d 100644 --- a/compiler/testData/psi/PropertiesFollowedByInitializers.kt +++ b/compiler/testData/psi/PropertiesFollowedByInitializers.kt @@ -3,13 +3,13 @@ class Foo() { var b : Int get() = 1; set var b1 : Int get() = 1; set {1} val b2 : Int get - { + init { } val b3 : Int get { return 1 } - val b4 : Int get; { + val b4 : Int get; init { } var b5 : Int get abstract set diff --git a/compiler/testData/psi/PropertiesFollowedByInitializers.txt b/compiler/testData/psi/PropertiesFollowedByInitializers.txt index 8f78ca1da87..792c527ef1d 100644 --- a/compiler/testData/psi/PropertiesFollowedByInitializers.txt +++ b/compiler/testData/psi/PropertiesFollowedByInitializers.txt @@ -123,6 +123,8 @@ JetFile: PropertiesFollowedByInitializers.kt PsiElement(get)('get') PsiWhiteSpace('\n ') ANONYMOUS_INITIALIZER + PsiElement(init)('init') + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n\n ') @@ -177,6 +179,8 @@ JetFile: PropertiesFollowedByInitializers.kt PsiElement(SEMICOLON)(';') PsiWhiteSpace(' ') ANONYMOUS_INITIALIZER + PsiElement(init)('init') + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') diff --git a/compiler/testData/psi/annotation/ShortAnnotations.kt b/compiler/testData/psi/annotation/ShortAnnotations.kt index b71744aa0db..1d4d3c1c1a2 100644 --- a/compiler/testData/psi/annotation/ShortAnnotations.kt +++ b/compiler/testData/psi/annotation/ShortAnnotations.kt @@ -17,7 +17,7 @@ class Foo { foo bar(1) buzz(1) zoo var v : Int = 0 foo bar(1) buzz(1) zoo typealias T = Int - foo bar(1) buzz(1) zoo {} + foo bar(1) buzz(1) zoo init {} } fun test() { diff --git a/compiler/testData/psi/annotation/ShortAnnotations.txt b/compiler/testData/psi/annotation/ShortAnnotations.txt index 2b82edc2d13..cf553e9faa8 100644 --- a/compiler/testData/psi/annotation/ShortAnnotations.txt +++ b/compiler/testData/psi/annotation/ShortAnnotations.txt @@ -896,6 +896,8 @@ JetFile: ShortAnnotations.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('zoo') PsiWhiteSpace(' ') + PsiElement(init)('init') + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') diff --git a/compiler/testData/psi/examples/BinaryTree.kt b/compiler/testData/psi/examples/BinaryTree.kt index 8105a7a37ee..ef07d13acba 100644 --- a/compiler/testData/psi/examples/BinaryTree.kt +++ b/compiler/testData/psi/examples/BinaryTree.kt @@ -13,11 +13,11 @@ class BinaryTree : IMutableSet { // override var size : Int { get; private set; } - this(compare : Comparison) { + constructor(compare : Comparison) { this.compare = asMatchableComparison(comparison) } - this() : this(naturalOrder()) { + constructor() : this(naturalOrder()) { } private [operator] fun T.compareTo(other : T) : Int = compare(this, other) @@ -135,7 +135,7 @@ class BinaryTree : IMutableSet { val up = Stack() var lastNode : TreeNode - this() { + init { if (root != null) down.push(root) } diff --git a/compiler/testData/psi/examples/BinaryTree.txt b/compiler/testData/psi/examples/BinaryTree.txt index 867df7082cd..b0ab8cc927d 100644 --- a/compiler/testData/psi/examples/BinaryTree.txt +++ b/compiler/testData/psi/examples/BinaryTree.txt @@ -151,24 +151,15 @@ JetFile: BinaryTree.kt PsiWhiteSpace('\n\n') PsiComment(EOL_COMMENT)('// override var size : Int { get; private set; }') PsiWhiteSpace('\n\n ') - PsiErrorElement:Expecting member declaration - PsiElement(this)('this') - PsiErrorElement:Expecting member declaration - PsiElement(LPAR)('(') - MODIFIER_LIST - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('compare') - PsiWhiteSpace(' ') - PsiErrorElement:Expecting member declaration - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - MODIFIER_LIST - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE + SECONDARY_CONSTRUCTOR + PsiElement(constructor)('constructor') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('compare') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') TYPE_REFERENCE USER_TYPE REFERENCE_EXPRESSION @@ -181,10 +172,11 @@ JetFile: BinaryTree.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('T') PsiElement(GT)('>') - PsiErrorElement:Expecting member declaration - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - ANONYMOUS_INITIALIZER + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CONSTRUCTOR_DELEGATION_CALL + CONSTRUCTOR_DELEGATION_REFERENCE + BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') @@ -212,25 +204,21 @@ JetFile: BinaryTree.kt PsiWhiteSpace('\n ') PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n ') - PsiErrorElement:Expecting member declaration - PsiElement(this)('this') - PsiErrorElement:Expecting member declaration - PsiElement(LPAR)('(') - PsiErrorElement:Expecting member declaration - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiErrorElement:Expecting member declaration + SECONDARY_CONSTRUCTOR + PsiElement(constructor)('constructor') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') PsiElement(COLON)(':') - PsiWhiteSpace(' ') - PsiErrorElement:Expecting member declaration - PsiElement(this)('this') - PsiErrorElement:Expecting member declaration - PsiElement(LPAR)('(') - MODIFIER_LIST - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE + PsiWhiteSpace(' ') + CONSTRUCTOR_DELEGATION_CALL + CONSTRUCTOR_DELEGATION_REFERENCE + PsiElement(this)('this') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + CALL_EXPRESSION REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('naturalOrder') TYPE_ARGUMENT_LIST @@ -241,13 +229,11 @@ JetFile: BinaryTree.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('T') PsiElement(GT)('>') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') PsiElement(RPAR)(')') - PsiErrorElement:Expecting member declaration - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - ANONYMOUS_INITIALIZER + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') @@ -1819,14 +1805,9 @@ JetFile: BinaryTree.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('TreeNode') PsiWhiteSpace('\n\n ') - PsiErrorElement:Expecting member declaration - PsiElement(this)('this') - PsiErrorElement:Expecting member declaration - PsiElement(LPAR)('(') - PsiErrorElement:Expecting member declaration - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') ANONYMOUS_INITIALIZER + PsiElement(init)('init') + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') diff --git a/compiler/testData/psi/secondaryConstructors/anonymousInitializer.kt b/compiler/testData/psi/secondaryConstructors/anonymousInitializer.kt index 4fc48b41a3e..d37452470ec 100644 --- a/compiler/testData/psi/secondaryConstructors/anonymousInitializer.kt +++ b/compiler/testData/psi/secondaryConstructors/anonymousInitializer.kt @@ -7,12 +7,4 @@ class A { init { x = 1 } - - val y = f() - { - x = 2 - } - { - x = 3 - } } diff --git a/compiler/testData/psi/secondaryConstructors/anonymousInitializer.txt b/compiler/testData/psi/secondaryConstructors/anonymousInitializer.txt index 2f0b92cf3d1..e55fa80d6af 100644 --- a/compiler/testData/psi/secondaryConstructors/anonymousInitializer.txt +++ b/compiler/testData/psi/secondaryConstructors/anonymousInitializer.txt @@ -57,55 +57,5 @@ JetFile: anonymousInitializer.kt PsiElement(INTEGER_LITERAL)('1') PsiWhiteSpace('\n ') PsiElement(RBRACE)('}') - PsiWhiteSpace('\n\n ') - PROPERTY - PsiElement(val)('val') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('y') - PsiWhiteSpace(' ') - PsiElement(EQ)('=') - PsiWhiteSpace(' ') - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('f') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - PsiElement(RPAR)(')') - PsiWhiteSpace('\n ') - FUNCTION_LITERAL_ARGUMENT - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - PsiWhiteSpace('\n ') - BLOCK - BINARY_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('x') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(EQ)('=') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('2') - PsiWhiteSpace('\n ') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n ') - FUNCTION_LITERAL_ARGUMENT - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - PsiWhiteSpace('\n ') - BLOCK - BINARY_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('x') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(EQ)('=') - PsiWhiteSpace(' ') - INTEGER_CONSTANT - PsiElement(INTEGER_LITERAL)('3') - PsiWhiteSpace('\n ') - PsiElement(RBRACE)('}') PsiWhiteSpace('\n') PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/secondaryConstructors/enumParsing.kt b/compiler/testData/psi/secondaryConstructors/enumParsing.kt index 445c76e93ad..ef210829871 100644 --- a/compiler/testData/psi/secondaryConstructors/enumParsing.kt +++ b/compiler/testData/psi/secondaryConstructors/enumParsing.kt @@ -9,7 +9,7 @@ enum class A { abc3 constructor(x: Int): this() {} - { + init { } } diff --git a/compiler/testData/psi/secondaryConstructors/enumParsing.txt b/compiler/testData/psi/secondaryConstructors/enumParsing.txt index 1a29e8f0c9d..dc8290280ab 100644 --- a/compiler/testData/psi/secondaryConstructors/enumParsing.txt +++ b/compiler/testData/psi/secondaryConstructors/enumParsing.txt @@ -131,6 +131,8 @@ JetFile: enumParsing.kt PsiElement(RBRACE)('}') PsiWhiteSpace('\n ') ANONYMOUS_INITIALIZER + PsiElement(init)('init') + PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') PsiWhiteSpace('\n\n ') diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 933bb36fc7d..1240cfe16bf 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -4713,12 +4713,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } - @TestMetadata("DanglingFunctionLiteral.kt") - public void testDanglingFunctionLiteral() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt"); - doTest(fileName); - } - @TestMetadata("DeprecatedSyntax.kt") public void testDeprecatedSyntax() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.kt"); @@ -4779,12 +4773,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } - @TestMetadata("NoDanglingFunctionLiteralForNestedCalls.kt") - public void testNoDanglingFunctionLiteralForNestedCalls() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt"); - doTest(fileName); - } - @TestMetadata("returnNull.kt") public void testReturnNull() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt"); @@ -10590,12 +10578,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } - @TestMetadata("expectedInitKeywordOnInitializer.kt") - public void testExpectedInitKeywordOnInitializer() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt"); - doTest(fileName); - } - @TestMetadata("expectedPrimaryConstructorCall.kt") public void testExpectedPrimaryConstructorCall() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.kt"); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddInitKeywordFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddInitKeywordFix.kt deleted file mode 100644 index 56458826ef1..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddInitKeywordFix.kt +++ /dev/null @@ -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(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( - 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() - } - } - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddSemicolonAfterFunctionCallFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddSemicolonAfterFunctionCallFix.java deleted file mode 100644 index c7b93c0ded8..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddSemicolonAfterFunctionCallFix.java +++ /dev/null @@ -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 { - 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); - } - }; - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java index c9f3965513f..5dbfc6c3cbd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java @@ -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$); diff --git a/idea/testData/quickfix/expressions/afterDanglingFunctionLiteralArgument.kt b/idea/testData/quickfix/expressions/afterDanglingFunctionLiteralArgument.kt deleted file mode 100644 index 37759d163a7..00000000000 --- a/idea/testData/quickfix/expressions/afterDanglingFunctionLiteralArgument.kt +++ /dev/null @@ -1,8 +0,0 @@ -// "Add semicolon after invocation of 'foo'" "true" -fun foo() {} -fun foo(x : Int) {} -fun bar() { - foo(4); - - {} -} diff --git a/idea/testData/quickfix/expressions/beforeDanglingFunctionLiteralArgument.kt b/idea/testData/quickfix/expressions/beforeDanglingFunctionLiteralArgument.kt deleted file mode 100644 index da98f8937d4..00000000000 --- a/idea/testData/quickfix/expressions/beforeDanglingFunctionLiteralArgument.kt +++ /dev/null @@ -1,8 +0,0 @@ -// "Add semicolon after invocation of 'foo'" "true" -fun foo() {} -fun foo(x : Int) {} -fun bar() { - foo(4) - - {} -} diff --git a/idea/testData/quickfix/migration/addInitKeywordMultiple.after.data.Sample.kt b/idea/testData/quickfix/migration/addInitKeywordMultiple.after.data.Sample.kt deleted file mode 100644 index 24a6eb775f8..00000000000 --- a/idea/testData/quickfix/migration/addInitKeywordMultiple.after.data.Sample.kt +++ /dev/null @@ -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 { - - } -} diff --git a/idea/testData/quickfix/migration/addInitKeywordMultiple.after.kt b/idea/testData/quickfix/migration/addInitKeywordMultiple.after.kt deleted file mode 100644 index 9a721ff85c4..00000000000 --- a/idea/testData/quickfix/migration/addInitKeywordMultiple.after.kt +++ /dev/null @@ -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 { - - } -} - diff --git a/idea/testData/quickfix/migration/addInitKeywordMultiple.before.Main.kt b/idea/testData/quickfix/migration/addInitKeywordMultiple.before.Main.kt deleted file mode 100644 index a981b595b56..00000000000 --- a/idea/testData/quickfix/migration/addInitKeywordMultiple.before.Main.kt +++ /dev/null @@ -1,37 +0,0 @@ -// "Add 'init' keyword in whole project" "true" - -annotation class Ann1 -annotation class Ann2 - -class A { - Ann1 Ann2 { - class Q { - { - - } - Ann2 { - - } - } - } - Ann1 { - - } -} - -class B { - Ann1 Ann2 { - class Q { - init { - - } - Ann2 { - - } - } - } - { - - } -} - diff --git a/idea/testData/quickfix/migration/addInitKeywordMultiple.before.data.Sample.kt b/idea/testData/quickfix/migration/addInitKeywordMultiple.before.data.Sample.kt deleted file mode 100644 index 338ada07322..00000000000 --- a/idea/testData/quickfix/migration/addInitKeywordMultiple.before.data.Sample.kt +++ /dev/null @@ -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 { - - } -} diff --git a/idea/testData/quickfix/modifiers/afterAddInitKeyword.kt b/idea/testData/quickfix/modifiers/afterAddInitKeyword.kt deleted file mode 100644 index 3cc90b47262..00000000000 --- a/idea/testData/quickfix/modifiers/afterAddInitKeyword.kt +++ /dev/null @@ -1,6 +0,0 @@ -// "Add 'init' keyword" "true" -class A { - init { - - } -} diff --git a/idea/testData/quickfix/modifiers/afterAddInitKeywordRemoveSemicolon.kt b/idea/testData/quickfix/modifiers/afterAddInitKeywordRemoveSemicolon.kt deleted file mode 100644 index e9a3c91bd34..00000000000 --- a/idea/testData/quickfix/modifiers/afterAddInitKeywordRemoveSemicolon.kt +++ /dev/null @@ -1,9 +0,0 @@ -// "Add 'init' keyword" "true" -fun foo() = 1 -class A { - val prop = foo() - - init { - - } -} diff --git a/idea/testData/quickfix/modifiers/afterAddInitKeywordRemoveSemicolonSameLine.kt b/idea/testData/quickfix/modifiers/afterAddInitKeywordRemoveSemicolonSameLine.kt deleted file mode 100644 index e9a3c91bd34..00000000000 --- a/idea/testData/quickfix/modifiers/afterAddInitKeywordRemoveSemicolonSameLine.kt +++ /dev/null @@ -1,9 +0,0 @@ -// "Add 'init' keyword" "true" -fun foo() = 1 -class A { - val prop = foo() - - init { - - } -} diff --git a/idea/testData/quickfix/modifiers/afterAddInitKeywordWithModifiers.kt b/idea/testData/quickfix/modifiers/afterAddInitKeywordWithModifiers.kt deleted file mode 100644 index a977fa11aad..00000000000 --- a/idea/testData/quickfix/modifiers/afterAddInitKeywordWithModifiers.kt +++ /dev/null @@ -1,8 +0,0 @@ -// "Add 'init' keyword" "true" -annotation class Ann1 -annotation class Ann2 -class A { - Ann1 Ann2 init { - - } -} diff --git a/idea/testData/quickfix/modifiers/beforeAddInitKeyword.kt b/idea/testData/quickfix/modifiers/beforeAddInitKeyword.kt deleted file mode 100644 index 0b3dfafe2b3..00000000000 --- a/idea/testData/quickfix/modifiers/beforeAddInitKeyword.kt +++ /dev/null @@ -1,6 +0,0 @@ -// "Add 'init' keyword" "true" -class A { - { - - } -} diff --git a/idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolon.kt b/idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolon.kt deleted file mode 100644 index d8d9b260ea3..00000000000 --- a/idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolon.kt +++ /dev/null @@ -1,9 +0,0 @@ -// "Add 'init' keyword" "true" -fun foo() = 1 -class A { - val prop = foo(); - - { - - } -} diff --git a/idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolonSameLine.kt b/idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolonSameLine.kt deleted file mode 100644 index 0eb341e3a2c..00000000000 --- a/idea/testData/quickfix/modifiers/beforeAddInitKeywordRemoveSemicolonSameLine.kt +++ /dev/null @@ -1,8 +0,0 @@ -// "Add 'init' keyword" "true" -fun foo() = 1 -class A { - val prop = foo() - ;{ - - } -} diff --git a/idea/testData/quickfix/modifiers/beforeAddInitKeywordWithModifiers.kt b/idea/testData/quickfix/modifiers/beforeAddInitKeywordWithModifiers.kt deleted file mode 100644 index 6b8b63a91ae..00000000000 --- a/idea/testData/quickfix/modifiers/beforeAddInitKeywordWithModifiers.kt +++ /dev/null @@ -1,8 +0,0 @@ -// "Add 'init' keyword" "true" -annotation class Ann1 -annotation class Ann2 -class A { - Ann1 Ann2 { - - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index 071d46a5b9e..9a2171ed64e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -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); } diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 15029633345..0b28cabad60 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -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");