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
@@ -162,7 +162,6 @@ public interface Errors {
DiagnosticFactory0<JetSecondaryConstructor> SECONDARY_CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetDelegatorToSuperCall> SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetConstructorDelegationCall> PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED =
DiagnosticFactory0.create(ERROR, PositioningStrategies.SECONDARY_CONSTRUCTOR_DELEGATION_CALL);
@@ -421,8 +420,6 @@ public interface Errors {
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> CANNOT_COMPLETE_RESOLVE = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> UNRESOLVED_REFERENCE_WRONG_RECEIVER = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<JetExpression> DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED = DiagnosticFactory0.create(WARNING);
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> TYPE_PARAMETER_AS_REIFIED = DiagnosticFactory1.create(ERROR);
DiagnosticFactory1<PsiElement, JetType> REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR);
@@ -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);
@@ -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)) {
@@ -55,10 +55,6 @@ public class JetClassInitializer extends JetDeclarationStub<KotlinPlaceHolderStu
return result != null ? result : this;
}
public boolean hasInitKeyword() {
return getInitKeyword() != null;
}
@Nullable
public PsiElement getInitKeyword() {
return findChildByType(JetTokens.INIT_KEYWORD);
@@ -472,10 +472,6 @@ public class BodyResolver {
@NotNull JetClassInitializer anonymousInitializer,
@NotNull ClassDescriptorWithResolutionScopes classDescriptor
) {
if (!anonymousInitializer.hasInitKeyword()) {
trace.report(INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED.on(anonymousInitializer.getOpenBraceNodeOrSelf()));
}
JetScope scopeForInitializers = classDescriptor.getScopeForInitializerResolution();
if (!classDescriptor.getConstructors().isEmpty()) {
JetExpression body = anonymousInitializer.getBody();
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.resolve.calls;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import org.jetbrains.annotations.NotNull;
@@ -39,7 +38,6 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.tasks.*;
import org.jetbrains.kotlin.resolve.calls.tasks.collectors.CallableDescriptorCollectors;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
@@ -59,7 +57,8 @@ import static org.jetbrains.kotlin.diagnostics.Errors.*;
import static org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo;
import static org.jetbrains.kotlin.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS;
import static org.jetbrains.kotlin.resolve.calls.CallResolverUtil.ResolveArgumentsMode.SHAPE_FUNCTION_ARGUMENTS;
import static org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults.Code.*;
import static org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults.Code.CANDIDATES_WITH_WRONG_RECEIVER;
import static org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults.Code.INCOMPLETE_TYPE_INFERENCE;
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
@SuppressWarnings("RedundantTypeArguments")
@@ -498,8 +497,8 @@ public class CallResolver {
TemporaryBindingTrace taskTrace =
TemporaryBindingTrace.create(context.trace, "trace to resolve a task for", task.call.getCalleeExpression());
OverloadResolutionResultsImpl<F> results = performResolutionGuardedForExtraFunctionLiteralArguments(
task.replaceBindingTrace(taskTrace), callTransformer);
OverloadResolutionResultsImpl<F> results = performResolution(task.replaceBindingTrace(taskTrace), callTransformer);
allCandidates.addAll(task.getResolvedCalls());
@@ -542,62 +541,6 @@ public class CallResolver {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@NotNull
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> performResolutionGuardedForExtraFunctionLiteralArguments(
@NotNull final ResolutionTask<D, F> task,
@NotNull CallTransformer<D, F> callTransformer
) {
OverloadResolutionResultsImpl<F> 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<OverloadResolutionResults.Code> 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<? extends ValueArgument> getValueArguments() {
return CallUtilPackage.getValueArgumentsInParentheses(task.call);
}
@NotNull
@Override
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
return Collections.emptyList();
}
};
TemporaryBindingTrace temporaryTrace =
TemporaryBindingTrace.create(task.trace, "trace for resolution guarded for extra function literal arguments");
ResolutionTask<D, F> newTask = task.replaceContext(task.toBasic()).
replaceBindingTrace(temporaryTrace).replaceCall(callWithoutFLArgs);
OverloadResolutionResultsImpl<F> resultsWithFunctionLiteralsStripped = performResolution(newTask, callTransformer);
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
task.tracing.danglingFunctionLiteralArgumentSuspected(task.trace, task.call.getFunctionLiteralArguments());
}
}
return results;
}
@NotNull
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> performResolution(
@NotNull ResolutionTask<D, F> task,
@@ -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<JetFunctionLiteralArgument> 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()));
@@ -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<JetFunctionLiteralArgument> 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<JetFunctionLiteralArgument> functionLiteralArguments);
void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor);
void typeInferenceFailed(@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData);
@@ -113,12 +113,6 @@ public class TracingStrategyForImplicitConstructorDelegationCall(
unexpectedError("unnecessarySafeCall")
}
override fun danglingFunctionLiteralArgumentSuspected(
trace: BindingTrace, functionLiteralArguments: MutableList<JetFunctionLiteralArgument>
) {
unexpectedError("danglingFunctionLiteralArgumentSuspected")
}
override fun missingReceiver(trace: BindingTrace, expectedReceiver: ReceiverParameterDescriptor) {
unexpectedError("missingReceiver")
}
@@ -508,13 +508,6 @@ public class ControlStructureTypingUtils {
logError();
}
@Override
public void danglingFunctionLiteralArgumentSuspected(
@NotNull BindingTrace trace, @NotNull List<JetFunctionLiteralArgument> functionLiteralArguments
) {
logError();
}
@Override
public void invisibleMember(
@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor
@@ -32,7 +32,7 @@ fun main(args : Array<String>) {
<!UNRESOLVED_REFERENCE!>a<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>foo1<!>()(<!UNRESOLVED_REFERENCE!>a<!>)
foo2()({})
foo2()<!TOO_MANY_ARGUMENTS, DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{}<!>
foo2()<!TOO_MANY_ARGUMENTS!>{}<!>
(foo2()){}
(foo2()){<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, CANNOT_INFER_PARAMETER_TYPE!>x<!> -> }
foo2()({<!EXPECTED_PARAMETERS_NUMBER_MISMATCH, CANNOT_INFER_PARAMETER_TYPE!>x<!> -> })
@@ -12,6 +12,6 @@ fun test() {
v1({}, {})
v1({}, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, {})
v1({}, {}, {<!UNUSED_EXPRESSION!>it<!>})
v1({}) <!VARARG_OUTSIDE_PARENTHESES, DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{}<!>
v1 <!VARARG_OUTSIDE_PARENTHESES, DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{}<!>
v1({}) <!VARARG_OUTSIDE_PARENTHESES!>{}<!>
v1 <!VARARG_OUTSIDE_PARENTHESES!>{}<!>
}
@@ -10,7 +10,7 @@ fun test() {
bar(<!UNRESOLVED_REFERENCE, TOO_MANY_ARGUMENTS!>xx<!>)
bar <!TOO_MANY_ARGUMENTS, DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{ }<!>
bar <!TOO_MANY_ARGUMENTS!>{ }<!>
foo(<!TYPE_MISMATCH!>""<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>, <!UNRESOLVED_REFERENCE, TOO_MANY_ARGUMENTS!>xx<!>)
@@ -1,28 +0,0 @@
class Foo() {
private val builder = StringBuilder("sdfsd")
init {
}
}
class Foo1() {
private val builder = <!NONE_APPLICABLE!>StringBuilder<!>("sdfsd")
<!DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{
}<!>
}
fun foo() = {
<!NONE_APPLICABLE!>println<!>(1)
<!DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{}<!>
}
fun foo1() = {
println(1);
{}
}
fun println(<!UNUSED_PARAMETER!>i<!> : Int) {}
fun println(<!UNUSED_PARAMETER!>s<!> : Byte) {}
fun println() {}
@@ -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
}
@@ -1,11 +0,0 @@
package baz
fun test() {
<!NONE_APPLICABLE!>foo<!>(1) <!DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{}<!>
foo( <!NONE_APPLICABLE!>foo<!>(1) {} ) //here
}
fun foo(<!UNUSED_PARAMETER!>i<!>: Int) {}
fun foo() : (i : () -> Unit) -> Unit = {}
@@ -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
}
@@ -7,4 +7,4 @@ object Obj {
}
}
val x = Obj.method<!TOO_MANY_ARGUMENTS, DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{ -> }<!>
val x = Obj.method<!TOO_MANY_ARGUMENTS!>{ -> }<!>
@@ -1,10 +0,0 @@
class A {
val x: Int
val y: Int
<!INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED!>{<!>
x = 1
}
init {
y = 1
}
}
@@ -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
}
@@ -1,6 +1,6 @@
class Foo {
{
init {
foo()
val c = f
}
@@ -10,6 +10,8 @@ JetFile: AnonymousInitializer.kt
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n\n ')
ANONYMOUS_INITIALIZER
PsiElement(init)('init')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
@@ -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
@@ -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 ')
@@ -17,7 +17,7 @@ class Foo {
foo bar(1) buzz<T>(1) zoo var v : Int = 0
foo bar(1) buzz<T>(1) zoo typealias T = Int
foo bar(1) buzz<T>(1) zoo {}
foo bar(1) buzz<T>(1) zoo init {}
}
fun test() {
@@ -896,6 +896,8 @@ JetFile: ShortAnnotations.kt
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('zoo')
PsiWhiteSpace(' ')
PsiElement(init)('init')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiElement(RBRACE)('}')
+3 -3
View File
@@ -13,11 +13,11 @@ class BinaryTree<T> : IMutableSet<T> {
// override var size : Int { get; private set; }
this(compare : Comparison<T>) {
constructor(compare : Comparison<T>) {
this.compare = asMatchableComparison(comparison)
}
this() : this(naturalOrder<T>()) {
constructor() : this(naturalOrder<T>()) {
}
private [operator] fun T.compareTo(other : T) : Int = compare(this, other)
@@ -135,7 +135,7 @@ class BinaryTree<T> : IMutableSet<T> {
val up = Stack<TreeNode>()
var lastNode : TreeNode
this() {
init {
if (root != null)
down.push(root)
}
+34 -53
View File
@@ -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
<empty list>
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 ')
@@ -7,12 +7,4 @@ class A {
init {
x = 1
}
val y = f()
{
x = 2
}
{
x = 3
}
}
@@ -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)('}')
@@ -9,7 +9,7 @@ enum class A {
abc3
constructor(x: Int): this() {}
{
init {
}
}
@@ -131,6 +131,8 @@ JetFile: enumParsing.kt
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n ')
ANONYMOUS_INITIALIZER
PsiElement(init)('init')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n\n ')
@@ -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");
@@ -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");