/**
   * Check that function or property with the given qualified name can be resolved in given scope
   * and called on given receiver
   *
   * @param callableFQN
   * @param project
   * @param scope
   * @return
   */
  public static List<CallableDescriptor> canFindSuitableCall(
      @NotNull FqName callableFQN,
      @NotNull Project project,
      @NotNull JetExpression receiverExpression,
      @NotNull JetType receiverType,
      @NotNull JetScope scope) {

    JetImportDirective importDirective =
        JetPsiFactory.createImportDirective(project, callableFQN.getFqName());

    Collection<? extends DeclarationDescriptor> declarationDescriptors =
        ImportsResolver.analyseImportReference(importDirective, scope, new BindingTraceContext());

    List<CallableDescriptor> callableExtensionDescriptors = new ArrayList<CallableDescriptor>();
    ReceiverDescriptor receiverDescriptor =
        new ExpressionReceiver(receiverExpression, receiverType);

    for (DeclarationDescriptor declarationDescriptor : declarationDescriptors) {
      if (declarationDescriptor instanceof CallableDescriptor) {
        CallableDescriptor callableDescriptor = (CallableDescriptor) declarationDescriptor;

        if (checkIsExtensionCallable(receiverDescriptor, callableDescriptor)) {
          callableExtensionDescriptors.add(callableDescriptor);
        }
      }
    }

    return callableExtensionDescriptors;
  }
  public void process(
      @NotNull TopDownAnalysisContext c,
      @NotNull JetScope outerScope,
      @NotNull PackageLikeBuilder owner,
      @NotNull Collection<? extends PsiElement> declarations) {

    {
      // TODO: Very temp code - main goal is to remove recursion from
      // collectPackageFragmentsAndClassifiers
      Queue<JetDeclarationContainer> forDeferredResolve = new LinkedList<JetDeclarationContainer>();
      forDeferredResolve.addAll(
          collectPackageFragmentsAndClassifiers(c, outerScope, owner, declarations));

      while (!forDeferredResolve.isEmpty()) {
        JetDeclarationContainer declarationContainer = forDeferredResolve.poll();
        assert declarationContainer != null;

        DeclarationDescriptor descriptorForDeferredResolve =
            c.forDeferredResolver.get(declarationContainer);
        JetScope scope = c.normalScope.get(declarationContainer);

        // Even more temp code
        if (descriptorForDeferredResolve instanceof MutableClassDescriptorLite) {
          forDeferredResolve.addAll(
              collectPackageFragmentsAndClassifiers(
                  c,
                  scope,
                  ((MutableClassDescriptorLite) descriptorForDeferredResolve).getBuilder(),
                  declarationContainer.getDeclarations()));
        } else if (descriptorForDeferredResolve instanceof MutablePackageFragmentDescriptor) {
          forDeferredResolve.addAll(
              collectPackageFragmentsAndClassifiers(
                  c,
                  scope,
                  ((MutablePackageFragmentDescriptor) descriptorForDeferredResolve).getBuilder(),
                  declarationContainer.getDeclarations()));
        } else {
          assert false;
        }
      }
    }

    importsResolver.processTypeImports(c);

    createTypeConstructors(
        c); // create type constructors for classes and generic parameters, supertypes are not
            // filled in
    resolveTypesInClassHeaders(
        c); // Generic bounds and types in supertype lists (no expressions or constructor
            // resolution)

    c.setClassesTopologicalOrder(topologicallySortClassesAndObjects(c));

    // Detect and disconnect all loops in the hierarchy
    detectAndDisconnectLoops(c);
  }
Beispiel #3
0
  public void process(@NotNull TopDownAnalysisContext c) {
    resolveAnnotationConstructors(c);
    resolveConstructorHeaders(c);
    resolveAnnotationStubsOnClassesAndConstructors(c);
    resolveFunctionAndPropertyHeaders(c);

    // SCRIPT: Resolve script declarations
    scriptHeaderResolver.resolveScriptDeclarations(c);

    createFunctionsForDataClasses(c);
    importsResolver.processMembersImports(c);
    checkRedeclarationsInPackages(c);
    checkRedeclarationsInInnerClassNames(c);
  }