Created automatic labeling of function expression.
This commit is contained in:
@@ -65,6 +65,11 @@ public class LabelResolver {
|
||||
if (element instanceof JetFunctionLiteralExpression) {
|
||||
return getCallerName((JetFunctionLiteralExpression) element);
|
||||
}
|
||||
if (element instanceof JetNamedFunction) {
|
||||
Name name = ((JetNamedFunction) element).getNameAsName();
|
||||
if (name != null) return name;
|
||||
return getCallerName((JetNamedFunction) element);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -78,7 +83,7 @@ public class LabelResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Name getCallerName(@NotNull JetFunctionLiteralExpression expression) {
|
||||
private Name getCallerName(@NotNull JetExpression expression) {
|
||||
JetCallExpression callExpression = getContainingCallExpression(expression);
|
||||
if (callExpression == null) return null;
|
||||
|
||||
@@ -92,7 +97,7 @@ public class LabelResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetCallExpression getContainingCallExpression(@NotNull JetFunctionLiteralExpression expression) {
|
||||
private JetCallExpression getContainingCallExpression(@NotNull JetExpression expression) {
|
||||
PsiElement parent = expression.getParent();
|
||||
if (parent instanceof JetFunctionLiteralArgument) {
|
||||
// f {}
|
||||
@@ -103,7 +108,7 @@ public class LabelResolver {
|
||||
}
|
||||
|
||||
if (parent instanceof JetValueArgument) {
|
||||
// f ({}) or f(p = {})
|
||||
// f ({}) or f(p = {}) or f (fun () {})
|
||||
JetValueArgument argument = (JetValueArgument) parent;
|
||||
PsiElement argList = argument.getParent();
|
||||
if (argList == null) return null;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> = null!!
|
||||
|
||||
fun autolabel(l: List<Int>) = l.map (fun (i: Int): Int {
|
||||
return@map 4
|
||||
})
|
||||
|
||||
fun unresolvedMapLabel(l: List<Int>) = l.map (fun test(i: Int): Int {
|
||||
return<!UNRESOLVED_REFERENCE!>@map<!> 4
|
||||
})
|
||||
|
||||
fun labelToFunName(l: List<Int>) = l.map (fun test(i: Int): Int {
|
||||
return@test 4
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
internal fun autolabel(/*0*/ l: kotlin.List<kotlin.Int>): kotlin.List<kotlin.Int>
|
||||
internal fun labelToFunName(/*0*/ l: kotlin.List<kotlin.Int>): kotlin.List<kotlin.Int>
|
||||
internal fun unresolvedMapLabel(/*0*/ l: kotlin.List<kotlin.Int>): kotlin.List<kotlin.Int>
|
||||
internal fun </*0*/ T, /*1*/ R> kotlin.Iterable<T>.map(/*0*/ transform: (T) -> R): kotlin.List<R>
|
||||
@@ -4634,6 +4634,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/functionAsExpression"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("AutoLabels.kt")
|
||||
public void testAutoLabels() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Common.kt")
|
||||
public void testCommon() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionAsExpression/Common.kt");
|
||||
|
||||
Reference in New Issue
Block a user