Example #1
0
  @NotNull
  public static Pair<FunctionDescriptor, PsiElement> getContainingFunctionSkipFunctionLiterals(
      @Nullable DeclarationDescriptor startDescriptor, boolean strict) {
    FunctionDescriptor containingFunctionDescriptor =
        DescriptorUtils.getParentOfType(startDescriptor, FunctionDescriptor.class, strict);
    PsiElement containingFunction =
        containingFunctionDescriptor != null
            ? DescriptorToSourceUtils.getSourceFromDescriptor(containingFunctionDescriptor)
            : null;
    while (containingFunction instanceof JetFunctionLiteral) {
      containingFunctionDescriptor =
          DescriptorUtils.getParentOfType(containingFunctionDescriptor, FunctionDescriptor.class);
      containingFunction =
          containingFunctionDescriptor != null
              ? DescriptorToSourceUtils.getSourceFromDescriptor(containingFunctionDescriptor)
              : null;
    }

    return new Pair<FunctionDescriptor, PsiElement>(
        containingFunctionDescriptor, containingFunction);
  }
Example #2
0
 public static void reportAmbiguousLabel(
     @NotNull BindingTrace trace,
     @NotNull JetSimpleNameExpression targetLabel,
     @NotNull Collection<DeclarationDescriptor> declarationsByLabel) {
   Collection<PsiElement> targets = Lists.newArrayList();
   for (DeclarationDescriptor descriptor : declarationsByLabel) {
     PsiElement element = DescriptorToSourceUtils.descriptorToDeclaration(descriptor);
     assert element != null : "Label can only point to something in the same lexical scope";
     targets.add(element);
   }
   if (!targets.isEmpty()) {
     trace.record(AMBIGUOUS_LABEL_TARGET, targetLabel, targets);
   }
   trace.report(AMBIGUOUS_LABEL.on(targetLabel));
 }
Example #3
0
  private void reportEachConstructorOnCycle(@NotNull ConstructorDescriptor startConstructor) {
    ConstructorDescriptor currentConstructor = startConstructor;
    do {
      PsiElement constructorToReport =
          DescriptorToSourceUtils.descriptorToDeclaration(currentConstructor);
      if (constructorToReport != null) {
        JetConstructorDelegationCall call =
            ((JetSecondaryConstructor) constructorToReport).getDelegationCall();
        assert call.getCalleeExpression() != null
            : "Callee expression of delegation call should not be null on cycle as there should be explicit 'this' calls";
        trace.report(CYCLIC_CONSTRUCTOR_DELEGATION_CALL.on(call.getCalleeExpression()));
      }

      currentConstructor = getDelegatedConstructor(currentConstructor);
      assert currentConstructor != null : "Delegated constructor should not be null in cycle";
    } while (startConstructor != currentConstructor);
  }