@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()]));
  }
  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());
  }
 @NotNull
 private static PsiClass findClass(
     String qualifiedName, Project project, KotlinCoreEnvironment environment) {
   ModuleDescriptor module = LazyResolveTestUtil.resolveProject(project, environment);
   ClassDescriptor classDescriptor =
       DescriptorUtilsKt.resolveTopLevelClass(
           module, new FqName(qualifiedName), NoLookupLocation.FROM_TEST);
   assertNotNull("Class descriptor wasn't resolved: " + qualifiedName, classDescriptor);
   PsiClass psiClass = (PsiClass) DescriptorToSourceUtils.getSourceFromDescriptor(classDescriptor);
   assertNotNull("Class declaration wasn't found: " + classDescriptor, psiClass);
   return psiClass;
 }
Beispiel #4
0
  public static void resolveAllKotlinFiles(KotlinCoreEnvironment environment) throws IOException {
    List<ContentRoot> paths =
        environment.getConfiguration().get(CommonConfigurationKeys.CONTENT_ROOTS);
    if (paths == null) return;
    List<KtFile> jetFiles = Lists.newArrayList();
    for (ContentRoot root : paths) {
      if (!(root instanceof KotlinSourceRoot)) continue;

      String path = ((KotlinSourceRoot) root).getPath();
      File file = new File(path);
      if (file.isFile()) {
        jetFiles.add(loadJetFile(environment.getProject(), file));
      } else {
        //noinspection ConstantConditions
        for (File childFile : file.listFiles()) {
          if (childFile.getName().endsWith(".kt")) {
            jetFiles.add(loadJetFile(environment.getProject(), childFile));
          }
        }
      }
    }
    LazyResolveTestUtil.resolve(environment.getProject(), jetFiles, environment);
  }