@Nullable
  private NamespaceType lookupNamespaceType(
      @NotNull JetSimpleNameExpression expression, @NotNull ResolutionContext context) {
    Name name = expression.getReferencedNameAsName();
    NamespaceDescriptor namespace = context.scope.getNamespace(name);
    if (namespace == null) {
      return null;
    }
    context.trace.record(REFERENCE_TARGET, expression, namespace);

    // Construct a NamespaceType with everything from the namespace and with nested classes of the
    // corresponding class (if any)
    JetScope scope;
    ClassifierDescriptor classifier = context.scope.getClassifier(name);
    if (classifier instanceof ClassDescriptor) {
      scope =
          new ChainedScope(
              namespace,
              namespace.getMemberScope(),
              getStaticNestedClassesScope((ClassDescriptor) classifier));
    } else {
      scope = namespace.getMemberScope();
    }
    return new NamespaceType(name, scope);
  }
Ejemplo n.º 2
0
  @Nullable
  private JetType getExtendedClassObjectType(
      @NotNull JetType classObjectType,
      @NotNull Name referencedName,
      @NotNull ClassifierDescriptor classifier,
      @NotNull ResolutionContext context) {
    if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT
        && classifier instanceof ClassDescriptor) {
      List<JetScope> scopes = new ArrayList<JetScope>(3);

      scopes.add(classObjectType.getMemberScope());
      scopes.add(getStaticNestedClassesScope((ClassDescriptor) classifier));

      NamespaceDescriptor namespace = context.scope.getNamespace(referencedName);
      if (namespace != null) {
        scopes.add(namespace.getMemberScope());
      }

      JetScope scope = new ChainedScope(classifier, scopes.toArray(new JetScope[scopes.size()]));
      return new NamespaceType(referencedName, scope);
    } else if (context.expressionPosition == ExpressionPosition.LHS_OF_DOT
        || classifier.isClassObjectAValue()) {
      return classObjectType;
    } else {
      return null;
    }
  }