Search in sources :

Example 1 with PsiExtraFile

use of com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile in project netbeans-mmd-plugin by raydac.

the class IdeaUtils method findPsiFileLinksForProjectScope.

public static List<PsiExtraFile> findPsiFileLinksForProjectScope(final Project project) {
    List<PsiExtraFile> result = new ArrayList<PsiExtraFile>();
    Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, MindMapFileType.INSTANCE, GlobalSearchScope.allScope(project));
    for (VirtualFile virtualFile : virtualFiles) {
        final MMDFile simpleFile = (MMDFile) PsiManager.getInstance(project).findFile(virtualFile);
        if (simpleFile != null) {
            final PsiExtraFile[] fileLinks = PsiTreeUtil.getChildrenOfType(simpleFile, PsiExtraFile.class);
            if (fileLinks != null) {
                Collections.addAll(result, fileLinks);
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MMDFile(com.igormaznitsa.ideamindmap.lang.MMDFile) PsiExtraFile(com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile)

Example 2 with PsiExtraFile

use of com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile in project netbeans-mmd-plugin by raydac.

the class RefactoringUtils method replaceMMUriToNewFile.

@Nonnull
public static String replaceMMUriToNewFile(@Nonnull final PsiExtraFile mindMapFile, @Nonnull final MMapURI oldFile, @Nonnull final MMapURI newFile) throws IOException {
    final File projectFolder = IdeaUtils.findProjectFolder(mindMapFile);
    if (projectFolder == null)
        throw new NullPointerException("Project folder is not found for " + mindMapFile);
    final MindMap parsedMap = new MindMap(null, new StringReader(mindMapFile.getContainingFile().getText()));
    parsedMap.replaceAllLinksToFile(projectFolder, oldFile, newFile);
    return parsedMap.write(new StringWriter(16384)).toString();
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) PsiExtraFile(com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) Nonnull(javax.annotation.Nonnull)

Example 3 with PsiExtraFile

use of com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile in project netbeans-mmd-plugin by raydac.

the class PsiExtraFileReferenceProvider method getReferencesByElement.

@Nonnull
@Override
public PsiReference[] getReferencesByElement(@Nonnull PsiElement element, @Nonnull ProcessingContext context) {
    PsiReference[] result = PsiReference.EMPTY_ARRAY;
    final PsiExtraFile extraFile = (PsiExtraFile) element;
    final VirtualFile targetFile = extraFile.findTargetFile();
    if (targetFile != null) {
        final TextRange range = new TextRange(0, extraFile.getTextLength());
        result = new PsiReference[] { new PsiExtraFileReference(extraFile, range) };
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiExtraFile(com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) Nonnull(javax.annotation.Nonnull)

Aggregations

PsiExtraFile (com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nonnull (javax.annotation.Nonnull)2 MMDFile (com.igormaznitsa.ideamindmap.lang.MMDFile)1 MindMap (com.igormaznitsa.mindmap.model.MindMap)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiFile (com.intellij.psi.PsiFile)1 PsiReference (com.intellij.psi.PsiReference)1 File (java.io.File)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1