Exemplo n.º 1
0
  @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()]));
  }
Exemplo n.º 2
0
  private JetScope getDeclarationsScope(String path) throws IOException {
    ModuleDescriptor moduleDescriptor =
        LazyResolveTestUtil.resolve(
            getProject(),
            Collections.singletonList(JetTestUtils.loadJetFile(getProject(), new File(path))));

    FqName fqName = new FqName("testData");
    PackageViewDescriptor packageView = moduleDescriptor.getPackage(fqName);
    assertNotNull("Package " + fqName + " not found", packageView);
    return addImports(packageView.getMemberScope());
  }