@SuppressWarnings("ConstantConditions")
  private JetScope addImports(JetScope scope) {
    WritableScopeImpl writableScope =
        new WritableScopeImpl(
            scope,
            scope.getContainingDeclaration(),
            RedeclarationHandler.DO_NOTHING,
            "JetTypeCheckerTest.addImports");
    List<JetScope> scopeChain = new ArrayList<JetScope>();
    scopeChain.add(writableScope);

    ModuleDescriptor module = LazyResolveTestUtil.resolveProject(getProject());
    for (ImportPath defaultImport : module.getDefaultImports()) {
      FqName fqName = defaultImport.fqnPart();
      if (defaultImport.isAllUnder()) {
        scopeChain.add(module.getPackage(fqName).getMemberScope());
      } else {
        Name shortName = fqName.shortName();
        assert shortName.equals(defaultImport.getImportedName());
        writableScope.addClassifierDescriptor(
            module.getPackage(fqName.parent()).getMemberScope().getClassifier(shortName));
      }
    }
    scopeChain.add(module.getPackage(FqName.ROOT).getMemberScope());
    writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
    return new ChainedScope(
        scope.getContainingDeclaration(),
        "JetTypeCheckerTest.addImports scope with imports",
        scopeChain.toArray(new JetScope[scopeChain.size()]));
  }
Example #2
0
 @NotNull
 @Override
 public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
   ArrayList<DeclarationDescriptor> result = new ArrayList<DeclarationDescriptor>();
   for (JetScope jetScope : scopeChain) {
     result.addAll(jetScope.getDeclarationsByLabel(labelName));
   }
   result.trimToSize();
   return result;
 }
  @NotNull
  @Override
  public Set<VariableDescriptor> getProperties(@NotNull Name name) {
    checkMayRead();

    Set<VariableDescriptor> properties = Sets.newLinkedHashSet();
    for (JetScope imported : getImports()) {
      properties.addAll(imported.getProperties(name));
    }
    return properties;
  }
Example #4
0
 @NotNull
 @Override
 public Collection<DeclarationDescriptor> getAllDescriptors() {
   if (allDescriptors == null) {
     allDescriptors = new HashSet<DeclarationDescriptor>();
     for (JetScope scope : scopeChain) {
       allDescriptors.addAll(scope.getAllDescriptors());
     }
   }
   return allDescriptors;
 }
  @Override
  public ClassifierDescriptor getClassifier(@NotNull Name name) {
    checkMayRead();

    for (JetScope imported : getImports()) {
      ClassifierDescriptor importedClassifier = imported.getClassifier(name);
      if (importedClassifier != null) {
        return importedClassifier;
      }
    }
    return null;
  }
  @Override
  public ClassDescriptor getObjectDescriptor(@NotNull Name name) {
    checkMayRead();

    for (JetScope imported : getImports()) {
      ClassDescriptor objectDescriptor = imported.getObjectDescriptor(name);
      if (objectDescriptor != null) {
        return objectDescriptor;
      }
    }
    return null;
  }
  @Override
  public NamespaceDescriptor getNamespace(@NotNull Name name) {
    checkMayRead();

    for (JetScope imported : getImports()) {
      NamespaceDescriptor importedDescriptor = imported.getNamespace(name);
      if (importedDescriptor != null) {
        return importedDescriptor;
      }
    }
    return null;
  }
Example #8
0
  @Override
  public void printScopeStructure(@NotNull Printer p) {
    p.println(getClass().getSimpleName(), ": ", debugName, " {");
    p.pushIndent();

    for (JetScope scope : scopeChain) {
      scope.printScopeStructure(p);
    }

    p.popIndent();
    p.println("}");
  }
Example #9
0
 @NotNull
 @Override
 public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
   if (implicitReceiverHierarchy == null) {
     ArrayList<ReceiverParameterDescriptor> result = new ArrayList<ReceiverParameterDescriptor>();
     for (JetScope jetScope : scopeChain) {
       result.addAll(jetScope.getImplicitReceiversHierarchy());
     }
     result.trimToSize();
     implicitReceiverHierarchy = result;
   }
   return implicitReceiverHierarchy;
 }
  @Override
  public VariableDescriptor getLocalVariable(@NotNull Name name) {
    checkMayRead();

    // Meaningful lookup goes here
    for (JetScope imported : getImports()) {
      VariableDescriptor importedDescriptor = imported.getLocalVariable(name);
      if (importedDescriptor != null) {
        return importedDescriptor;
      }
    }
    return null;
  }
  @NotNull
  @Override
  public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
    checkMayRead();

    if (getImports().isEmpty()) {
      return Collections.emptySet();
    }
    Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
    for (JetScope imported : getImports()) {
      result.addAll(imported.getFunctions(name));
    }
    return result;
  }
  @Override
  public void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result) {
    checkMayRead();

    super.getImplicitReceiversHierarchy(result);
    // Imported scopes come with their receivers
    // Example: class member resolution scope imports a scope of it's class object
    //          members of the class object must be able to find it as an implicit receiver
    for (JetScope scope : getImports()) {
      ReceiverDescriptor definedReceiver = scope.getImplicitReceiver();
      if (definedReceiver.exists()) {
        result.add(0, definedReceiver);
      }
    }
  }
Example #13
0
 @NotNull
 @Override
 public Collection<DeclarationDescriptor> getAllDescriptors() {
   if (allDescriptors == null) {
     allDescriptors = substitute(workerScope.getAllDescriptors());
   }
   return allDescriptors;
 }
Example #14
0
  @TestOnly
  @Override
  public void printScopeStructure(@NotNull Printer p) {
    p.println(getClass().getSimpleName(), " {");
    p.pushIndent();

    p.println("substitutor = ");
    p.pushIndent();
    p.println(substitutor);
    p.popIndent();

    p.print("workerScope = ");
    workerScope.printScopeStructure(p.withholdIndentOnce());

    p.popIndent();
    p.println("}");
  }
Example #15
0
 @SuppressWarnings("ConstantConditions")
 private WritableScopeImpl addImports(JetScope scope) {
   WritableScopeImpl writableScope =
       new WritableScopeImpl(
           scope,
           scope.getContainingDeclaration(),
           RedeclarationHandler.DO_NOTHING,
           "JetTypeCheckerTest.addImports");
   InjectorForJavaDescriptorResolver injector =
       new InjectorForJavaDescriptorResolver(getProject(), new BindingTraceContext());
   JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
   writableScope.importScope(
       javaDescriptorResolver
           .resolveNamespace(FqName.ROOT, INCLUDE_KOTLIN_SOURCES)
           .getMemberScope());
   writableScope.importScope(
       javaDescriptorResolver
           .resolveNamespace(new FqName("java.lang"), IGNORE_KOTLIN_SOURCES)
           .getMemberScope());
   writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
   writableScope.importScope(builtIns.getBuiltInsScope());
   return writableScope;
 }
Example #16
0
 @NotNull
 @Override
 public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
   return substitute(workerScope.getFunctions(name));
 }
Example #17
0
 @NotNull
 @Override
 public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
   return substitute(workerScope.getProperties(name));
 }
Example #18
0
 @Override
 public VariableDescriptor getLocalVariable(@NotNull Name name) {
   return substitute(workerScope.getLocalVariable(name));
 }
Example #19
0
 @NotNull
 @Override
 public DeclarationDescriptor getContainingDeclaration() {
   return workerScope.getContainingDeclaration();
 }
Example #20
0
 @Override
 public ClassifierDescriptor getClassifier(@NotNull Name name) {
   return substitute(workerScope.getClassifier(name));
 }
Example #21
0
 @Override
 public PackageViewDescriptor getPackage(@NotNull Name name) {
   return workerScope.getPackage(name);
 }
Example #22
0
 @NotNull
 @Override
 public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
   return substitute(workerScope.getOwnDeclaredDescriptors());
 }