Java Code Examples for com.intellij.openapi.vfs.VirtualFile#getUrl()

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#getUrl() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void actionPerformed(AnActionEvent anActionEvent)
{
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(anActionEvent.getDataContext());
    final Project project = anActionEvent.getProject();

    Xsd2Raml xsd2Raml = new Xsd2Raml(file.getUrl());
    String raml = xsd2Raml.getRaml();

    PsiFile psiFile = PsiFileFactory.getInstance(anActionEvent.getProject()).createFileFromText(RamlLanguage.INSTANCE, raml);

    new WriteCommandAction.Simple(project, psiFile) {
        @Override
        protected void run() throws Throwable {
            psiFile.setName(file.getNameWithoutExtension() + "." + RamlFileType.INSTANCE.getDefaultExtension());

            PsiDirectory directory = CommonDataKeys.PSI_FILE.getData(anActionEvent.getDataContext()).getContainingDirectory();
            directory.add(psiFile);
        }
    }.execute();

}
 
Example 2
private void handleChange(@Nonnull VirtualFile virtualFile)
{
	if(!myActive.get())
	{
		return;
	}

	if(!mySourceFileTypes.contains(virtualFile.getFileType()))
	{
		return;
	}

	String url = virtualFile.getUrl();
	if(url.startsWith(myAssetsDirPointer.getUrl()))
	{
		myDataBlock.myFiles.add(virtualFile);
	}
}
 
Example 3
public HaxeClasspathEntry(@Nullable String name, @NotNull String url) {
  myName = name;
  myUrl = url;

  // Try to fix the URL if it wasn't correct.
  if (!url.contains(URLUtil.SCHEME_SEPARATOR)) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Fixing malformed URL passed by " + HaxeDebugUtil.printCallers(5));
    }
    VirtualFileSystem vfs = VirtualFileManager.getInstance().getFileSystem(LocalFileSystem.PROTOCOL);
    VirtualFile file = vfs.findFileByPath(url);
    if (null != file) {
      myUrl = file.getUrl();
    }
  }

  if (null != myName) {
    if (HaxelibNameUtil.isManagedLibrary(myName)) {
      myName = HaxelibNameUtil.parseHaxelib(myName);
      myIsManagedEntry = true;
    }
  }
}
 
Example 4
@RequiredReadAction
public Map<String, Couple<String>> buildOutputRootsLayout() {
  Map<String, Couple<String>> map = new LinkedHashMap<>();

  for (Module module : ModuleManager.getInstance(myProject).getModules()) {
    ModuleCompilerPathsManager moduleCompilerPathsManager = ModuleCompilerPathsManager.getInstance(module);

    final VirtualFile output = moduleCompilerPathsManager.getCompilerOutput(ProductionContentFolderTypeProvider.getInstance());
    final String outputUrl = output == null ? null : output.getUrl();
    final VirtualFile testsOutput = moduleCompilerPathsManager.getCompilerOutput(TestContentFolderTypeProvider.getInstance());
    final String testoutUrl = testsOutput == null ? null : testsOutput.getUrl();
    map.put(module.getName(), Couple.of(outputUrl, testoutUrl));
  }

  return map;
}
 
Example 5
Source Project: consulo   File: NewLibraryEditor.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public VirtualFile[] getFiles(@Nonnull OrderRootType rootType) {
  List<VirtualFile> result = new ArrayList<>();
  for (LightFilePointer pointer : myRoots.get(rootType)) {
    final VirtualFile file = pointer.getFile();
    if (file == null) {
      continue;
    }

    if (file.isDirectory()) {
      final String url = file.getUrl();
      if (isJarDirectory(url, rootType)) {
        boolean recursive = myJarDirectoryRecursiveUrls.get(rootType).contains(url);
        collectJarFiles(file, result, recursive);
        continue;
      }
    }
    result.add(file);
  }
  return VfsUtilCore.toVirtualFileArray(result);
}
 
Example 6
@Nullable
public static List<String> getHttpRoots(final String[] roots, String relPath) {
  final ArrayList<String> result = new ArrayList<String>();
  for (String root : roots) {
    final VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(root);
    if (virtualFile != null) {
      if (virtualFile.getFileSystem() instanceof HttpFileSystem) {
        String url = virtualFile.getUrl();
        if (!url.endsWith("/")) url += "/";
        result.add(url + relPath);
      }
      else {
        VirtualFile file = virtualFile.findFileByRelativePath(relPath);
        if (file != null) result.add(file.getUrl());
      }
    }
  }

  return result.isEmpty() ? null : result;
}
 
Example 7
Source Project: consulo   File: VcsRootIterator.java    License: Apache License 2.0 6 votes vote down vote up
private void init(final VcsRoot[] allRoots) {
  final String ourPath = myRoot.getUrl();

  for (VcsRoot root : allRoots) {
    final AbstractVcs vcs = root.getVcs();
    if (vcs == null || Comparing.equal(vcs.getName(), myVcsName)) continue;
    final VirtualFile path = root.getPath();
    if (path != null) {
      final String url = path.getUrl();
      if (url.startsWith(ourPath)) {
        myExcludedByOthers.add(url);
      }
    }
  }

  Collections.sort(myExcludedByOthers, StringLenComparator.getDescendingInstance());
}
 
Example 8
Source Project: intellij-haxe   File: HaxeLibrary.java    License: Apache License 2.0 5 votes vote down vote up
private HaxeLibrary(@NotNull String name, @NotNull VirtualFile libraryRoot, @NotNull HaxelibLibraryCache owner) {
  myCache = owner;
  myLibraryRoot = libraryRoot.getUrl();

  myMetadata = HaxelibMetadata.load(libraryRoot);
  HaxeLibraryInfo pathInfo = HaxelibUtil.deriveLibraryInfoFromPath(owner.getSdk(), libraryRoot.getPath());

  String mdname = myMetadata.getName();
  if (null != mdname && !mdname.isEmpty()) {
    myName = mdname;
  } else if (!name.isEmpty()) {
    myName = name;
  } else {
    myName = pathInfo == null ? "" : pathInfo.getName();
  }

  HaxelibSemVer semVer = HaxelibSemVer.create(myMetadata.getVersion());
  if (HaxelibSemVer.ZERO_VERSION == semVer && pathInfo != null) {
    semVer = pathInfo.getVersion();
  }
  mySemVer = semVer;

  String cp = myMetadata.getClasspath();
  if ((null == cp || cp.isEmpty()) && pathInfo != null) {
      cp = pathInfo.getClasspath();
  }
  if (null != cp && !cp.isEmpty()) {
    myRelativeClasspath = cp;
  } else {
    myRelativeClasspath = CURRENT_DIR;
  }
}
 
Example 9
Source Project: intellij-haxe   File: HaxeCompilerError.java    License: Apache License 2.0 5 votes vote down vote up
public String getUrl() {

    VirtualFileSystem vfs = VirtualFileManager.getInstance().getFileSystem(LocalFileSystem.PROTOCOL);
    VirtualFile file = vfs.findFileByPath(getPath());

    StringBuilder msg = new StringBuilder(file.getUrl());
    msg.append('#');
    msg.append(getLine());
    msg.append(':');
    msg.append(getColumn());
    return msg.toString();
  }
 
Example 10
Source Project: consulo   File: ArtifactUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static String getDefaultArtifactOutputPath(@Nonnull String artifactName, final @Nonnull Project project) {
  final CompilerConfiguration extension = CompilerConfiguration.getInstance(project);
  String outputUrl = extension.getCompilerOutputUrl();
  if (outputUrl == null || outputUrl.length() == 0) {
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir == null) return null;
    outputUrl = baseDir.getUrl() + "/out";
  }
  return VfsUtil.urlToPath(outputUrl) + "/artifacts/" + FileUtil.sanitizeFileName(artifactName);
}
 
Example 11
Source Project: consulo   File: PsiFileUrl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public AbstractUrl createUrlByElement(Object element) {
  if (element instanceof PsiFile) {
    VirtualFile file = ((PsiFile)element).getVirtualFile();
    if (file != null){
      return new PsiFileUrl(file.getUrl());
    }
  }
  return null;
}
 
Example 12
Source Project: consulo   File: RefElementImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public String getURL() {
  final PsiElement element = getPsiElement();
  if (element == null || !element.isPhysical()) return null;
  final PsiFile containingFile = element.getContainingFile();
  if (containingFile == null) return null;
  final VirtualFile virtualFile = containingFile.getVirtualFile();
  if (virtualFile == null) return null;
  return virtualFile.getUrl() + "#" + element.getTextOffset();
}
 
Example 13
Source Project: consulo   File: VcsRootIterator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean acceptFolderUnderVcs(final VirtualFile vcsRoot, final VirtualFile file) {
  final String vcsUrl = vcsRoot.getUrl();
  final MyRootFilter rootFilter = myOtherVcsFolders.get(vcsUrl);
  if ((rootFilter != null) && (! rootFilter.accept(file))) {
    return false;
  }
  final Boolean excluded = isExcluded(myExcludedFileIndex, file);
  if (excluded) return false;
  return true;
}
 
Example 14
Source Project: consulo   File: VcsRootIterator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean accept(final VirtualFile vf) {
  final String url = vf.getUrl();
  for (String excludedByOtherVcs : myExcludedByOthers) {
    // use the fact that they are sorted
    if (url.length() > excludedByOtherVcs.length()) return true;
    if (url.startsWith(excludedByOtherVcs)) return false;
  }
  return true;
}
 
Example 15
Source Project: consulo   File: ExcludeEntryDescription.java    License: Apache License 2.0 4 votes vote down vote up
public ExcludeEntryDescription(VirtualFile virtualFile, boolean includeSubdirectories, boolean isFile, Disposable parent) {
  this(virtualFile.getUrl(), includeSubdirectories, isFile, parent);
}
 
Example 16
Source Project: consulo   File: ContentEntryImpl.java    License: Apache License 2.0 4 votes vote down vote up
public ContentEntryImpl(@Nonnull VirtualFile file, @Nonnull ModuleRootLayerImpl m) {
  this(file.getUrl(), m);
}
 
Example 17
Source Project: consulo   File: LightFilePointer.java    License: Apache License 2.0 4 votes vote down vote up
public LightFilePointer(@Nonnull VirtualFile file) {
  myUrl = file.getUrl();
  myFile = file;
}
 
Example 18
public OneProjectItemCompileScope(Project project, VirtualFile file) {
  myProject = project;
  myFile = file;
  final String url = file.getUrl();
  myUrl = file.isDirectory()? url + "/" : url;
}
 
Example 19
Source Project: consulo   File: RefFileImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String getExternalName() {
  final PsiFile psiFile = getPsiElement();
  final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() : null;
  return virtualFile != null ? virtualFile.getUrl() : getName();
}
 
Example 20
Source Project: consulo   File: DirectoryUrl.java    License: Apache License 2.0 4 votes vote down vote up
public static DirectoryUrl create(PsiDirectory directory) {
  Project project = directory.getProject();
  final VirtualFile virtualFile = directory.getVirtualFile();
  final Module module = ModuleUtil.findModuleForFile(virtualFile, project);
  return new DirectoryUrl(virtualFile.getUrl(), module != null ? module.getName() : null);
}