@NotNull
  public Collection<? extends DeclarationDescriptor> processImportReference(
      @NotNull JetImportDirective importDirective,
      @NotNull JetScope scope,
      @NotNull JetScope scopeToCheckVisibility,
      @NotNull Importer importer,
      @NotNull BindingTrace trace,
      @NotNull ModuleConfiguration moduleConfiguration,
      @NotNull LookupMode lookupMode) {
    if (importDirective.isAbsoluteInRootNamespace()) {
      trace.report(UNSUPPORTED.on(importDirective, "TypeHierarchyResolver")); // TODO
      return Collections.emptyList();
    }
    JetExpression importedReference = importDirective.getImportedReference();
    if (importedReference == null) {
      return Collections.emptyList();
    }

    Collection<? extends DeclarationDescriptor> descriptors;
    if (importedReference instanceof JetQualifiedExpression) {
      // store result only when we find all descriptors, not only classes on the second phase
      descriptors =
          lookupDescriptorsForQualifiedExpression(
              (JetQualifiedExpression) importedReference,
              scope,
              scopeToCheckVisibility,
              trace,
              lookupMode,
              lookupMode == LookupMode.EVERYTHING);
    } else {
      assert importedReference instanceof JetSimpleNameExpression;
      descriptors =
          lookupDescriptorsForSimpleNameReference(
              (JetSimpleNameExpression) importedReference,
              scope,
              scopeToCheckVisibility,
              trace,
              lookupMode,
              true,
              lookupMode == LookupMode.EVERYTHING);
    }

    JetSimpleNameExpression referenceExpression = JetPsiUtil.getLastReference(importedReference);
    if (importDirective.isAllUnder()) {
      if (referenceExpression == null
          || !canImportMembersFrom(descriptors, referenceExpression, trace, lookupMode)) {
        return Collections.emptyList();
      }

      for (DeclarationDescriptor descriptor : descriptors) {
        importer.addAllUnderImport(descriptor, moduleConfiguration.getPlatformToKotlinClassMap());
      }
      return Collections.emptyList();
    }

    Name aliasName = JetPsiUtil.getAliasName(importDirective);
    if (aliasName == null) {
      return Collections.emptyList();
    }

    for (DeclarationDescriptor descriptor : descriptors) {
      importer.addAliasImport(descriptor, aliasName);
    }

    return descriptors;
  }
예제 #2
0
 @Override
 public void visitTypedef(@NotNull JetTypedef typedef) {
   trace.report(UNSUPPORTED.on(typedef, "TypeHierarchyResolver"));
 }
 @Override
 public JetTypeInfo visitJetElement(JetElement element, ExpressionTypingContext context) {
   context.trace.report(UNSUPPORTED.on(element, "in a block"));
   return JetTypeInfo.create(null, context.dataFlowInfo);
 }