Function literal expression outside the parentheses wrapped into JetFunctionLiteralArgument
Extracted JetFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith util function
This commit is contained in:
@@ -61,6 +61,7 @@ public interface JetNodeTypes {
|
||||
IElementType TYPE_ARGUMENT_LIST = JetStubElementTypes.TYPE_ARGUMENT_LIST;
|
||||
JetNodeType VALUE_ARGUMENT_LIST = new JetNodeType("VALUE_ARGUMENT_LIST", JetValueArgumentList.class);
|
||||
JetNodeType VALUE_ARGUMENT = new JetNodeType("VALUE_ARGUMENT", JetValueArgument.class);
|
||||
JetNodeType FUNCTION_LITERAL_ARGUMENT = new JetNodeType("FUNCTION_LITERAL_ARGUMENT", JetFunctionLiteralArgument.class);
|
||||
JetNodeType VALUE_ARGUMENT_NAME = new JetNodeType("VALUE_ARGUMENT_NAME", JetValueArgumentName.class);
|
||||
IElementType TYPE_REFERENCE = JetStubElementTypes.TYPE_REFERENCE;
|
||||
|
||||
|
||||
@@ -1113,10 +1113,6 @@ public class JetControlFlowProcessor {
|
||||
inputExpressions.add(argumentExpression);
|
||||
}
|
||||
}
|
||||
for (JetExpression functionLiteral : expression.getFunctionLiteralArguments()) {
|
||||
generateInstructions(functionLiteral);
|
||||
inputExpressions.add(functionLiteral);
|
||||
}
|
||||
JetExpression calleeExpression = expression.getCalleeExpression();
|
||||
generateInstructions(calleeExpression);
|
||||
inputExpressions.add(calleeExpression);
|
||||
@@ -1490,8 +1486,7 @@ public class JetControlFlowProcessor {
|
||||
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
|
||||
Map<PseudoValue, ReceiverValue> receivers = getReceiverValues(resolvedCall);
|
||||
SmartFMap<PseudoValue, ValueParameterDescriptor> parameterValues = SmartFMap.emptyMap();
|
||||
List<ValueArgument> valueArguments = CallUtilPackage.getAllValueArguments(resolvedCall.getCall());
|
||||
for (ValueArgument argument : valueArguments) {
|
||||
for (ValueArgument argument : resolvedCall.getCall().getValueArguments()) {
|
||||
ArgumentMapping argumentMapping = resolvedCall.getArgumentMapping(argument);
|
||||
JetExpression argumentExpression = argument.getArgumentExpression();
|
||||
if (argumentMapping instanceof ArgumentMatch) {
|
||||
|
||||
@@ -516,6 +516,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
protected boolean parseCallWithClosure() {
|
||||
boolean success = false;
|
||||
while ((at(LBRACE) || at(LABEL_IDENTIFIER) && lookahead(1) == LBRACE)) {
|
||||
PsiBuilder.Marker argument = mark();
|
||||
if (!at(LBRACE)) {
|
||||
assert _at(LABEL_IDENTIFIER);
|
||||
parseLabeledExpression();
|
||||
@@ -523,6 +524,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
else {
|
||||
parseFunctionLiteral();
|
||||
}
|
||||
argument.done(FUNCTION_LITERAL_ARGUMENT);
|
||||
success = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@ public interface Call {
|
||||
@NotNull
|
||||
List<? extends ValueArgument> getValueArguments();
|
||||
|
||||
@KotlinSignature("fun getFunctionLiteralArguments(): List<JetExpression>")
|
||||
@KotlinSignature("fun getFunctionLiteralArguments(): List<JetFunctionLiteralArgument>")
|
||||
@NotNull
|
||||
List<JetExpression> getFunctionLiteralArguments();
|
||||
List<JetFunctionLiteralArgument> getFunctionLiteralArguments();
|
||||
|
||||
@KotlinSignature("fun getTypeArguments(): List<JetTypeProjection>")
|
||||
@NotNull
|
||||
|
||||
@@ -73,7 +73,7 @@ public class JetAnnotationEntry extends JetElementImplStub<PsiJetAnnotationEntry
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public interface JetCallElement extends JetElement {
|
||||
List<? extends ValueArgument> getValueArguments();
|
||||
|
||||
@NotNull
|
||||
List<JetExpression> getFunctionLiteralArguments();
|
||||
List<JetFunctionLiteralArgument> getFunctionLiteralArguments();
|
||||
|
||||
@NotNull
|
||||
List<JetTypeProjection> getTypeArguments();
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -49,6 +47,7 @@ public class JetCallExpression extends JetExpressionImpl implements JetCallEleme
|
||||
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetTypeArgumentList getTypeArgumentList() {
|
||||
return (JetTypeArgumentList) findChildByType(JetNodeTypes.TYPE_ARGUMENT_LIST);
|
||||
@@ -61,40 +60,26 @@ public class JetCallExpression extends JetExpressionImpl implements JetCallEleme
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
JetExpression calleeExpression = getCalleeExpression();
|
||||
ASTNode node;
|
||||
if (calleeExpression instanceof JetFunctionLiteralExpression) {
|
||||
node = calleeExpression.getNode().getTreeNext();
|
||||
}
|
||||
else {
|
||||
node = getNode().getFirstChildNode();
|
||||
}
|
||||
List<JetExpression> result = new SmartList<JetExpression>();
|
||||
while (node != null) {
|
||||
PsiElement psi = node.getPsi();
|
||||
if (psi instanceof JetFunctionLiteralExpression) {
|
||||
result.add((JetFunctionLiteralExpression) psi);
|
||||
}
|
||||
else if (psi instanceof JetLabeledExpression) {
|
||||
JetLabeledExpression labeledExpression = (JetLabeledExpression) psi;
|
||||
JetExpression baseExpression = labeledExpression.getBaseExpression();
|
||||
if (baseExpression instanceof JetFunctionLiteralExpression) {
|
||||
result.add(labeledExpression);
|
||||
}
|
||||
}
|
||||
node = node.getTreeNext();
|
||||
}
|
||||
return result;
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return findChildrenByType(JetNodeTypes.FUNCTION_LITERAL_ARGUMENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<? extends ValueArgument> getValueArguments() {
|
||||
JetValueArgumentList list = getValueArgumentList();
|
||||
return list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
|
||||
List<JetValueArgument> valueArgumentsInParentheses = list != null ? list.getArguments() : Collections.<JetValueArgument>emptyList();
|
||||
List<JetFunctionLiteralArgument> functionLiteralArguments = getFunctionLiteralArguments();
|
||||
if (functionLiteralArguments.isEmpty()) {
|
||||
return valueArgumentsInParentheses;
|
||||
}
|
||||
List<ValueArgument> allValueArguments = Lists.newArrayList();
|
||||
allValueArguments.addAll(valueArgumentsInParentheses);
|
||||
allValueArguments.addAll(functionLiteralArguments);
|
||||
return allValueArguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JetTypeProjection> getTypeArguments() {
|
||||
JetTypeArgumentList list = getTypeArgumentList();
|
||||
|
||||
@@ -46,11 +46,13 @@ public class JetDelegatorToSuperCall extends JetDelegationSpecifier implements J
|
||||
return getRequiredStubOrPsiChild(JetStubElementTypes.CONSTRUCTOR_CALLEE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetValueArgumentList getValueArgumentList() {
|
||||
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<? extends ValueArgument> getValueArguments() {
|
||||
JetValueArgumentList list = getValueArgumentList();
|
||||
@@ -59,7 +61,7 @@ public class JetDelegatorToSuperCall extends JetDelegationSpecifier implements J
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
@@ -47,11 +46,13 @@ public class JetDelegatorToThisCall extends JetDelegationSpecifier implements Je
|
||||
return getThisReference();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JetValueArgumentList getValueArgumentList() {
|
||||
return (JetValueArgumentList) findChildByType(JetNodeTypes.VALUE_ARGUMENT_LIST);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<? extends ValueArgument> getValueArguments() {
|
||||
JetValueArgumentList list = getValueArgumentList();
|
||||
@@ -60,7 +61,7 @@ public class JetDelegatorToThisCall extends JetDelegationSpecifier implements Je
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.psi
|
||||
|
||||
import com.intellij.lang.ASTNode
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
|
||||
public class JetFunctionLiteralArgument(node: ASTNode) : JetValueArgument(node) {
|
||||
|
||||
private fun assertFL() = throw AssertionError("Function literal argument doesn't contain function literal expression: " +
|
||||
"${super.getArgumentExpression()?.getText()} (it should be guaranteed by parser)")
|
||||
|
||||
override fun getArgumentExpression() = super.getArgumentExpression() ?: assertFL()
|
||||
|
||||
public fun getFunctionLiteral(): JetFunctionLiteralExpression {
|
||||
val expression = getArgumentExpression()
|
||||
|
||||
return when (expression) {
|
||||
is JetLabeledExpression -> expression.getBaseExpression() as? JetFunctionLiteralExpression ?: assertFL()
|
||||
else -> expression as? JetFunctionLiteralExpression ?: assertFL()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,8 +279,13 @@ public class JetPsiFactory(private val project: Project) {
|
||||
return createExpression(JetPsiUnparsingUtils.toIf(condition, thenExpr, elseExpr)) as JetIfExpression
|
||||
}
|
||||
|
||||
public fun createArgumentWithName(name: String, argumentExpression: JetExpression): JetValueArgument {
|
||||
return createCallArguments("(" + name + " = " + argumentExpression.getText() + ")").getArguments().first()
|
||||
public fun createArgumentWithName(name: String?, argumentExpression: JetExpression): JetValueArgument {
|
||||
val argumentText = (if (name != null) "$name = " else "") + argumentExpression.getText()
|
||||
return createCallArguments("($argumentText)").getArguments().first()
|
||||
}
|
||||
|
||||
public fun createArgument(argumentExpression: JetExpression): JetValueArgument {
|
||||
return createArgumentWithName(null, argumentExpression)
|
||||
}
|
||||
|
||||
public inner class IfChainBuilder() {
|
||||
|
||||
@@ -318,4 +318,13 @@ public fun JetSimpleNameExpression.isImportDirectiveExpression(): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
public fun JetElement.getTextWithLocation(): String = "'${this.getText()}' at ${DiagnosticUtils.atLocation(this)}"
|
||||
public fun JetElement.getTextWithLocation(): String = "'${this.getText()}' at ${DiagnosticUtils.atLocation(this)}"
|
||||
|
||||
public fun JetExpression.isFunctionLiteralOutsideParentheses(): Boolean {
|
||||
val parent = getParent()
|
||||
return when (parent) {
|
||||
is JetFunctionLiteralArgument -> true
|
||||
is JetLabeledExpression -> parent.isFunctionLiteralOutsideParentheses()
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -116,14 +116,10 @@ public class ArgumentTypeResolver {
|
||||
|
||||
for (ValueArgument valueArgument : context.call.getValueArguments()) {
|
||||
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
||||
if (argumentExpression != null && (argumentExpression instanceof JetFunctionLiteralExpression)) {
|
||||
if (argumentExpression != null && isFunctionLiteralArgument(argumentExpression)) {
|
||||
checkArgumentTypeWithNoCallee(context, argumentExpression);
|
||||
}
|
||||
}
|
||||
|
||||
for (JetExpression expression : context.call.getFunctionLiteralArguments()) {
|
||||
checkArgumentTypeWithNoCallee(context, expression);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkArgumentTypeWithNoCallee(CallResolutionContext<?> context, JetExpression argumentExpression) {
|
||||
|
||||
@@ -211,10 +211,8 @@ public class CallCompleter(
|
||||
getDataFlowInfoForArgument = { context.dataFlowInfo }
|
||||
}
|
||||
|
||||
val arguments = context.call.getAllValueArguments()
|
||||
|
||||
for (valueArgument in arguments) {
|
||||
val argumentMapping = getArgumentMapping(valueArgument)
|
||||
for (valueArgument in context.call.getValueArguments()) {
|
||||
val argumentMapping = getArgumentMapping(valueArgument!!)
|
||||
val expectedType = when (argumentMapping) {
|
||||
is ArgumentMatch -> CandidateResolver.getEffectiveExpectedType(argumentMapping.valueParameter, valueArgument)
|
||||
else -> TypeUtils.NO_EXPECTED_TYPE
|
||||
|
||||
@@ -20,12 +20,16 @@ import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.MutableResolvedCall;
|
||||
@@ -49,7 +53,6 @@ import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NOT_A_CLASS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NO_CONSTRUCTOR;
|
||||
@@ -484,7 +487,7 @@ public class CallResolver {
|
||||
|
||||
@NotNull
|
||||
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> performResolutionGuardedForExtraFunctionLiteralArguments(
|
||||
@NotNull ResolutionTask<D, F> task,
|
||||
@NotNull final ResolutionTask<D, F> task,
|
||||
@NotNull CallTransformer<D, F> callTransformer
|
||||
) {
|
||||
OverloadResolutionResultsImpl<F> results = performResolution(task, callTransformer);
|
||||
@@ -514,7 +517,13 @@ public class CallResolver {
|
||||
DelegatingCall callWithoutFLArgs = new DelegatingCall(task.call) {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<? extends ValueArgument> getValueArguments() {
|
||||
return CallUtilPackage.getValueArgumentsInParentheses(task.call);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -166,7 +166,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
+10
-12
@@ -25,13 +25,10 @@ import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.ValueArgument;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
|
||||
@@ -192,9 +189,9 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
|
||||
public void process() {
|
||||
ProcessorState state = positionedOnly;
|
||||
List<? extends ValueArgument> arguments = call.getValueArguments();
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
ValueArgument valueArgument = arguments.get(i);
|
||||
List<? extends ValueArgument> argumentsInParentheses = CallUtilPackage.getValueArgumentsInParentheses(call);
|
||||
for (int i = 0; i < argumentsInParentheses.size(); i++) {
|
||||
ValueArgument valueArgument = argumentsInParentheses.get(i);
|
||||
if (valueArgument.isNamed()) {
|
||||
state = state.processNamedArgument(valueArgument);
|
||||
}
|
||||
@@ -219,9 +216,10 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
D candidate = candidateCall.getCandidateDescriptor();
|
||||
List<ValueParameterDescriptor> valueParameters = candidate.getValueParameters();
|
||||
|
||||
List<JetExpression> functionLiteralArguments = call.getFunctionLiteralArguments();
|
||||
List<JetFunctionLiteralArgument> functionLiteralArguments = call.getFunctionLiteralArguments();
|
||||
if (!functionLiteralArguments.isEmpty()) {
|
||||
JetExpression possiblyLabeledFunctionLiteral = functionLiteralArguments.get(0);
|
||||
JetFunctionLiteralArgument functionLiteralArgument = functionLiteralArguments.get(0);
|
||||
JetExpression possiblyLabeledFunctionLiteral = functionLiteralArgument.getArgumentExpression();
|
||||
|
||||
if (valueParameters.isEmpty()) {
|
||||
report(TOO_MANY_ARGUMENTS.on(possiblyLabeledFunctionLiteral, candidate));
|
||||
@@ -239,13 +237,13 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
setStatus(WEAK_ERROR);
|
||||
}
|
||||
else {
|
||||
putVararg(valueParameterDescriptor, CallMaker.makeValueArgument(possiblyLabeledFunctionLiteral));
|
||||
putVararg(valueParameterDescriptor, functionLiteralArgument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < functionLiteralArguments.size(); i++) {
|
||||
JetExpression argument = functionLiteralArguments.get(i);
|
||||
JetExpression argument = functionLiteralArguments.get(i).getArgumentExpression();
|
||||
report(MANY_FUNCTION_LITERAL_ARGUMENTS.on(argument));
|
||||
setStatus(WEAK_ERROR);
|
||||
}
|
||||
|
||||
+3
-4
@@ -25,7 +25,6 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.codeFragmentUtil.CodeFragmentUtilPackage;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
@@ -167,9 +166,9 @@ public abstract class AbstractTracingStrategy implements TracingStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List<JetExpression> functionLiteralArguments) {
|
||||
for (JetExpression functionLiteralArgument : functionLiteralArguments) {
|
||||
trace.report(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED.on(functionLiteralArgument));
|
||||
public void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List<JetFunctionLiteralArgument> functionLiteralArguments) {
|
||||
for (JetFunctionLiteralArgument functionLiteralArgument : functionLiteralArguments) {
|
||||
trace.report(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED.on(functionLiteralArgument.getArgumentExpression()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralArgument;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
@@ -90,7 +90,7 @@ public interface TracingStrategy {
|
||||
public void unnecessarySafeCall(@NotNull BindingTrace trace, @NotNull JetType type) {}
|
||||
|
||||
@Override
|
||||
public void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List<JetExpression> functionLiteralArguments) {}
|
||||
public void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List<JetFunctionLiteralArgument> functionLiteralArguments) {}
|
||||
|
||||
@Override
|
||||
public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor) {}
|
||||
@@ -136,7 +136,7 @@ public interface TracingStrategy {
|
||||
|
||||
void unnecessarySafeCall(@NotNull BindingTrace trace, @NotNull JetType type);
|
||||
|
||||
void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List<JetExpression> functionLiteralArguments);
|
||||
void danglingFunctionLiteralArgumentSuspected(@NotNull BindingTrace trace, @NotNull List<JetFunctionLiteralArgument> functionLiteralArguments);
|
||||
|
||||
void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor);
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ public class CallMaker {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@NotNull
|
||||
@@ -301,7 +301,7 @@ public class CallMaker {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return callElement.getFunctionLiteralArguments();
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class DelegatingCall implements Call {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return delegate.getFunctionLiteralArguments();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ import org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL
|
||||
import org.jetbrains.kotlin.util.sure
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getTextWithLocation
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralArgument
|
||||
|
||||
// resolved call
|
||||
|
||||
@@ -84,12 +86,12 @@ public fun Call.hasUnresolvedArguments(context: BindingContext): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
public fun Call.getAllValueArguments(): List<ValueArgument> {
|
||||
val arguments = getValueArguments() +
|
||||
getFunctionLiteralArguments().map { functionLiteral -> CallMaker.makeValueArgument(functionLiteral) }
|
||||
[suppress("UNCHECKED_CAST")]
|
||||
return arguments as List<ValueArgument>
|
||||
}
|
||||
public fun Call.getValueArgumentsInParentheses(): List<ValueArgument> = getValueArguments().filterArgsInParentheses()
|
||||
|
||||
public fun JetCallExpression.getValueArgumentsInParentheses(): List<ValueArgument> = getValueArguments().filterArgsInParentheses()
|
||||
|
||||
[suppress("UNCHECKED_CAST")]
|
||||
private fun List<ValueArgument?>.filterArgsInParentheses() = filter { it !is JetFunctionLiteralArgument } as List<ValueArgument>
|
||||
|
||||
// Get call / resolved call from binding context
|
||||
|
||||
|
||||
+2
-2
@@ -206,7 +206,7 @@ public class ControlStructureTypingUtils {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
public List<JetFunctionLiteralArgument> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -470,7 +470,7 @@ public class ControlStructureTypingUtils {
|
||||
|
||||
@Override
|
||||
public void danglingFunctionLiteralArgumentSuspected(
|
||||
@NotNull BindingTrace trace, @NotNull List<JetExpression> functionLiteralArguments
|
||||
@NotNull BindingTrace trace, @NotNull List<JetFunctionLiteralArgument> functionLiteralArguments
|
||||
) {
|
||||
throwError();
|
||||
}
|
||||
|
||||
+1
-26
@@ -156,12 +156,7 @@ public class ExpressionTypingUtils {
|
||||
|
||||
PsiElement parent = scopeDeclaration.getParent();
|
||||
assert parent instanceof JetFunctionLiteralExpression : "parent of JetFunctionLiteral is " + parent;
|
||||
JetCallExpression callExpression = getCallExpression((JetFunctionLiteralExpression) parent);
|
||||
if (callExpression == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ResolvedCall<?> resolvedCall = CallUtilPackage.getResolvedCall(callExpression, context);
|
||||
ResolvedCall<?> resolvedCall = CallUtilPackage.getParentResolvedCall((JetFunctionLiteralExpression) parent, context, true);
|
||||
if (resolvedCall == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -177,26 +172,6 @@ public class ExpressionTypingUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JetCallExpression getCallExpression(@NotNull JetFunctionLiteralExpression functionLiteralExpression) {
|
||||
PsiElement parent = functionLiteralExpression.getParent();
|
||||
if (parent instanceof JetValueArgument) {
|
||||
// foo({ ... }) or foo(f = { ... })
|
||||
|
||||
PsiElement valueArgumentList = parent.getParent();
|
||||
assert valueArgumentList instanceof JetValueArgumentList : "parent of value argument is " + valueArgumentList;
|
||||
|
||||
if (valueArgumentList.getParent() instanceof JetCallExpression) { // may be argument list of annotation
|
||||
return (JetCallExpression) valueArgumentList.getParent();
|
||||
}
|
||||
}
|
||||
else if (parent instanceof JetCallExpression) {
|
||||
// foo { ... }
|
||||
|
||||
return (JetCallExpression) parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void checkCapturingInClosure(JetSimpleNameExpression expression, BindingTrace trace, JetScope scope) {
|
||||
VariableDescriptor variable = BindingContextUtils.extractVariableDescriptorIfAny(trace.getBindingContext(), expression, true);
|
||||
if (variable != null) {
|
||||
|
||||
@@ -94,9 +94,12 @@ public class LabelResolver {
|
||||
@Nullable
|
||||
private JetCallExpression getContainingCallExpression(@NotNull JetFunctionLiteralExpression expression) {
|
||||
PsiElement parent = expression.getParent();
|
||||
if (parent instanceof JetCallExpression) {
|
||||
if (parent instanceof JetFunctionLiteralArgument) {
|
||||
// f {}
|
||||
return (JetCallExpression) parent;
|
||||
PsiElement call = parent.getParent();
|
||||
if (call instanceof JetCallExpression) {
|
||||
return (JetCallExpression) call;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof JetValueArgument) {
|
||||
|
||||
Reference in New Issue
Block a user