Package com.jetbrains.lang.dart.util

Examples of com.jetbrains.lang.dart.util.DartUrlResolver


    final VirtualFile customPack1 =
      myFixture.addFileToProject("custom_pack1/RootProject/rootlib.dart", "").getVirtualFile().getParent().getParent();
    final VirtualFile customPack2 =
      myFixture.addFileToProject("custom_pack2/SomePackage/somepack.dart", "").getVirtualFile().getParent().getParent();

    DartUrlResolver resolver = DartUrlResolver.getInstance(getProject(), nestedPubspec);
    VirtualFile file;

    file = resolver.findFileByDartUrl("dart:collection");
    assertNotNull(file);
    assertEquals(DartTestUtils.SDK_HOME_PATH + "/lib/collection/collection.dart", file.getPath());
    assertEquals("dart:collection", resolver.getDartUrlForFile(file));

    file = resolver.findFileByDartUrl("dart:collection/hash_map.dart");
    assertNotNull(file);
    assertEquals(DartTestUtils.SDK_HOME_PATH + "/lib/collection/hash_map.dart", file.getPath());
    assertEquals("dart:collection/hash_map.dart", resolver.getDartUrlForFile(file));

    file = resolver.findFileByDartUrl("package:NestedProject/src/nestedlib.dart");
    assertNotNull(file);
    assertEquals(rootPath + "/example/lib/src/nestedlib.dart", file.getPath());
    assertEquals("package:NestedProject/src/nestedlib.dart", resolver.getDartUrlForFile(file));

    file = resolver.findFileByDartUrl("package:RootProject/rootlib.dart");
    assertNotNull(file);
    assertEquals(rootPath + "/lib/rootlib.dart", file.getPath());
    assertEquals("package:RootProject/rootlib.dart", resolver.getDartUrlForFile(file));

    file = resolver.findFileByDartUrl("package:SomePackage/somepack.dart");
    assertNotNull(file);
    assertEquals(rootPath + "/example/packages/SomePackage/somepack.dart", file.getPath());
    assertEquals("package:SomePackage/somepack.dart", resolver.getDartUrlForFile(file));

    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      public void run() {
        final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
        try {
          final Library library = modifiableModel.getModuleLibraryTable().createLibrary("Dart custom package roots");
          final Library.ModifiableModel libModel = library.getModifiableModel();
          libModel.addRoot(customPack1.getUrl(), OrderRootType.CLASSES);
          libModel.addRoot(customPack2.getUrl(), OrderRootType.CLASSES);
          libModel.commit();
          modifiableModel.commit();
        }
        catch (Exception e) {
          if (!modifiableModel.isDisposed()) modifiableModel.dispose();
        }
      }
    });

    resolver = DartUrlResolver.getInstance(getProject(), nestedPubspec);

    file = resolver.findFileByDartUrl("package:NestedProject/src/nestedlib.dart");
    assertNull(file);

    file = resolver.findFileByDartUrl("package:RootProject/rootlib.dart");
    assertNotNull(file);
    assertEquals(rootPath + "/custom_pack1/RootProject/rootlib.dart", file.getPath());
    assertEquals("package:RootProject/rootlib.dart", resolver.getDartUrlForFile(file));

    file = resolver.findFileByDartUrl("package:SomePackage/somepack.dart");
    assertNotNull(file);
    assertEquals(rootPath + "/custom_pack2/SomePackage/somepack.dart", file.getPath());
    assertEquals("package:SomePackage/somepack.dart", resolver.getDartUrlForFile(file));
  }
View Full Code Here


    final String url = StringUtil.unquoteString(getText());
    if (url.startsWith(PACKAGE_PREFIX)) {
      final VirtualFile file = DartResolveUtil.getRealVirtualFile(getContainingFile());
      if (file == null) return PsiReference.EMPTY_ARRAY;

      final DartUrlResolver dartUrlResolver = DartUrlResolver.getInstance(getProject(), file);

      final int slashIndex = url.indexOf('/');
      if (slashIndex > 0) {
        final String packageName = url.substring(PACKAGE_PREFIX.length(), slashIndex);
        final VirtualFile packageDir = dartUrlResolver.getPackageDirIfLivePackageOrFromPubListPackageDirs(packageName);
        if (packageDir != null) {
          return getPackageReferences(file, packageDir, url.substring(slashIndex + 1), slashIndex + 1);
        }
      }

      final String relPath = url.substring(PACKAGE_PREFIX.length());
      final VirtualFile[] packageRoots = dartUrlResolver.getPackageRoots();

      if (packageRoots.length == 0) return PsiReference.EMPTY_ARRAY;
      if (packageRoots.length == 1) return getPackageReferences(file, packageRoots[0], relPath, PACKAGE_PREFIX.length());

      final Collection<PsiReference> result = new SmartList<PsiReference>();
View Full Code Here

    final int slashIndex = info.path.indexOf('/');
    if (slashIndex > 0) {
      final String packageName = info.path.substring(0, slashIndex);
      final String relPath = info.path.substring(slashIndex + 1);
      final DartUrlResolver urlResolver = DartUrlResolver.getInstance(context.getProject(), contextFile);
      final VirtualFile packageDir = urlResolver.getPackageDirIfLivePackageOrFromPubListPackageDirs(packageName);
      if (packageDir != null) {
        targetFile = packageDir.findFileByRelativePath(relPath);
      }
    }
View Full Code Here

    if (path.startsWith(PACKAGES_FOLDER_NAME + "/") || path.contains("/" + PACKAGES_FOLDER_NAME + "/")) {
      final VirtualFile contextFile = DartResolveUtil.getRealVirtualFile(getElement().getContainingFile());
      final VirtualFile targetFile = DartResolveUtil.getRealVirtualFile(element.getContainingFile());

      if (contextFile != null && targetFile != null) {
        final DartUrlResolver urlResolver = DartUrlResolver.getInstance(element.getProject(), contextFile);
        final String newUrl = urlResolver.getDartUrlForFile(targetFile);

        if (newUrl.startsWith(PACKAGE_PREFIX)) {
          final int index = path.startsWith(PACKAGES_FOLDER_NAME + "/") ? 0 : (path.indexOf("/" + PACKAGES_FOLDER_NAME + "/") + 1);
          final String newName = path.substring(0, index) + PACKAGES_FOLDER_NAME + "/" + newUrl.substring(PACKAGE_PREFIX.length());
          return rename(newName);
View Full Code Here

                                        : null;

    if (pubspecYamlFile != null && !pubspecYamlFile.isDirectory()) {
      final ArrayList<AbstractTreeNode> modifiedChildren = new ArrayList<AbstractTreeNode>(children);

      final DartUrlResolver resolver = DartUrlResolver.getInstance(project, pubspecYamlFile);
      resolver.processLivePackages(new PairConsumer<String, VirtualFile>() {
        public void consume(final @NotNull String packageName, final @NotNull VirtualFile packageDir) {
          final VirtualFile folder = packagesDir.findChild(packageName);
          if (folder != null) {
            final AbstractTreeNode node = getFolderNode(children, folder);
            if (node == null) {
View Full Code Here

  @NotNull
  public AnalysisContext getAnalysisContext(final @NotNull VirtualFile annotatedFile,
                                            final @NotNull String sdkPath) {
    AnalysisContext analysisContext = SoftReference.dereference(myAnalysisContextRef);

    final DartUrlResolver dartUrlResolver = DartUrlResolver.getInstance(myProject, annotatedFile);
    final VirtualFile yamlFile = dartUrlResolver.getPubspecYamlFile();
    final Document cachedDocument = yamlFile == null ? null : FileDocumentManager.getInstance().getCachedDocument(yamlFile);
    final long pubspecYamlTimestamp = yamlFile == null ? -1
                                                       : cachedDocument == null ? yamlFile.getModificationCount()
                                                                                : cachedDocument.getModificationStamp();

    final VirtualFile[] packageRoots = dartUrlResolver.getPackageRoots();

    final VirtualFile contentRoot = ProjectRootManager.getInstance(myProject).getFileIndex().getContentRootForFile(annotatedFile);
    final Module module = ModuleUtilCore.findModuleForFile(annotatedFile, myProject);

    final boolean useExplicitPackageUriResolver = !ApplicationManager.getApplication().isUnitTestMode() &&
View Full Code Here

    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("tool"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("web"), fileIndex);

    // Folders like packages/PathPackage and packages/ThisProject (where ThisProject is the name specified in pubspec.yaml) are symlinks to local 'lib' folders. Exclude it in order not to have duplicates. Resolve goes to local 'lib' folder.
    // Empty nodes like 'ThisProject (ThisProject/lib)' are added to Project Structure by DartTreeStructureProvider
    final DartUrlResolver resolver = DartUrlResolver.getInstance(module.getProject(), pubspecYamlFile);
    resolver.processLivePackages(new PairConsumer<String, VirtualFile>() {
      public void consume(final String packageName, final VirtualFile packageDir) {
        newExcludedPackagesUrls.add(root.getUrl() + "/packages/" + packageName);
      }
    });
View Full Code Here

                                                  final @NotNull ConfigurationContext context,
                                                  final @NotNull Ref<PsiElement> sourceElement) {
    final VirtualFile dartFile = DartCommandLineRuntimeConfigurationProducer.getRunnableDartFileFromContext(context);
    if (dartFile == null) return false;

    final DartUrlResolver urlResolver = DartUrlResolver.getInstance(context.getProject(), dartFile);
    final VirtualFile dartUnitLib = urlResolver.findFileByDartUrl("package:unittest/unittest.dart");
    if (dartUnitLib == null) return false;

    final VirtualFile yamlFile = urlResolver.getPubspecYamlFile();
    if (yamlFile != null) {
      final VirtualFile parent = yamlFile.getParent();
      final VirtualFile testFolder = parent == null ? null : parent.findChild("test");
      if (testFolder == null || !testFolder.isDirectory() || !VfsUtilCore.isAncestor(testFolder, dartFile, true)) {
        return false;
View Full Code Here

TOP

Related Classes of com.jetbrains.lang.dart.util.DartUrlResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.