@Nullable public static BinaryCall getRangeAsBinaryCall(@NotNull JetForExpression forExpression) { // We are looking for rangeTo() calls // Other binary operations will succeed too, but will be filtered out later (by examining a // resolvedCall) JetExpression rangeExpression = forExpression.getLoopRange(); assert rangeExpression != null; JetExpression loopRange = JetPsiUtil.deparenthesizeWithNoTypeResolution(rangeExpression); if (loopRange instanceof JetQualifiedExpression) { // a.rangeTo(b) JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) loopRange; JetExpression selector = qualifiedExpression.getSelectorExpression(); if (selector instanceof JetCallExpression) { JetCallExpression callExpression = (JetCallExpression) selector; List<? extends ValueArgument> arguments = callExpression.getValueArguments(); if (arguments.size() == 1) { return new BinaryCall( qualifiedExpression.getReceiverExpression(), callExpression.getCalleeExpression(), arguments.get(0).getArgumentExpression()); } } } else if (loopRange instanceof JetBinaryExpression) { // a rangeTo b // a .. b JetBinaryExpression binaryExpression = (JetBinaryExpression) loopRange; return new BinaryCall( binaryExpression.getLeft(), binaryExpression.getOperationReference(), binaryExpression.getRight()); } return null; }
private static void addNamesForExpression( ArrayList<String> result, JetExpression expression, JetNameValidator validator) { if (expression instanceof JetQualifiedExpression) { JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) expression; JetExpression selectorExpression = qualifiedExpression.getSelectorExpression(); addNamesForExpression(result, selectorExpression, validator); if (selectorExpression != null && selectorExpression instanceof JetCallExpression) { JetExpression calleeExpression = ((JetCallExpression) selectorExpression).getCalleeExpression(); if (calleeExpression != null && calleeExpression instanceof JetSimpleNameExpression) { String name = ((JetSimpleNameExpression) calleeExpression).getReferencedName(); if (name != null && name.equals("sure")) { addNamesForExpression(result, qualifiedExpression.getReceiverExpression(), validator); } } } } else if (expression instanceof JetSimpleNameExpression) { JetSimpleNameExpression reference = (JetSimpleNameExpression) expression; String referenceName = reference.getReferencedName(); if (referenceName == null) return; if (referenceName.equals(referenceName.toUpperCase())) { addName(result, referenceName, validator); } else { addCamelNames(result, referenceName, validator); } } else if (expression instanceof JetCallExpression) { JetCallExpression call = (JetCallExpression) expression; addNamesForExpression(result, call.getCalleeExpression(), validator); } }
@Nullable private static Name getCallerName(@NotNull JetFunctionLiteralExpression expression) { JetCallExpression callExpression = getContainingCallExpression(expression); if (callExpression == null) return null; JetExpression calleeExpression = callExpression.getCalleeExpression(); if (calleeExpression instanceof JetSimpleNameExpression) { JetSimpleNameExpression nameExpression = (JetSimpleNameExpression) calleeExpression; return nameExpression.getReferencedNameAsName(); } return null; }
@NotNull public TypeInfoForCall getCallExpressionTypeInfoForCallWithoutFinalTypeCheck( @NotNull JetCallExpression callExpression, @NotNull ReceiverValue receiver, @Nullable ASTNode callOperationNode, @NotNull ResolutionContext context, @NotNull ResolveMode resolveMode) { boolean[] result = new boolean[1]; Call call = CallMaker.makeCall(receiver, callOperationNode, callExpression); TemporaryBindingTrace traceForFunction = TemporaryBindingTrace.create( context.trace, "trace to resolve as function call", callExpression); ResolvedCall<FunctionDescriptor> resolvedCall = getResolvedCallForFunction( call, callExpression, receiver, context.replaceBindingTrace(traceForFunction), resolveMode, result); if (result[0]) { FunctionDescriptor functionDescriptor = resolvedCall != null ? resolvedCall.getResultingDescriptor() : null; traceForFunction.commit(); if (callExpression.getValueArgumentList() == null && callExpression.getFunctionLiteralArguments().isEmpty()) { // there are only type arguments boolean hasValueParameters = functionDescriptor == null || functionDescriptor.getValueParameters().size() > 0; context.trace.report( FUNCTION_CALL_EXPECTED.on(callExpression, callExpression, hasValueParameters)); } if (functionDescriptor == null) { return TypeInfoForCall.create(null, context.dataFlowInfo); } JetType type = functionDescriptor.getReturnType(); return TypeInfoForCall.create( type, resolvedCall.getDataFlowInfo(), resolvedCall, call, context, resolveMode); } JetExpression calleeExpression = callExpression.getCalleeExpression(); if (calleeExpression instanceof JetSimpleNameExpression && callExpression.getTypeArgumentList() == null) { TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create( context.trace, "trace to resolve as variable with 'invoke' call", callExpression); JetType type = getVariableType( (JetSimpleNameExpression) calleeExpression, receiver, callOperationNode, context.replaceBindingTrace(traceForVariable), result); if (result[0]) { traceForVariable.commit(); context.trace.report( FUNCTION_EXPECTED.on( (JetReferenceExpression) calleeExpression, calleeExpression, type != null ? type : ErrorUtils.createErrorType(""))); return TypeInfoForCall.create(null, context.dataFlowInfo); } } traceForFunction.commit(); return TypeInfoForCall.create(null, context.dataFlowInfo); }