Search in sources :

Example 1 with HttpVirtualFile

use of com.intellij.openapi.vfs.impl.http.HttpVirtualFile in project intellij-community by JetBrains.

the class HtmlFileImpl method resolveFileReference.

@Nullable
@Override
public PsiFileSystemItem resolveFileReference(@NotNull FileReference reference, @NotNull String name) {
    VirtualFile file = getVirtualFile();
    if (!(file instanceof HttpVirtualFile)) {
        return null;
    }
    VirtualFile parent = file;
    if (!parent.isDirectory()) {
        parent = parent.getParent();
        if (parent == null) {
            parent = file;
        }
    }
    VirtualFile childFile = parent.findChild(name);
    HttpFileSystem fileSystem = (HttpFileSystem) parent.getFileSystem();
    if (childFile == null) {
        childFile = fileSystem.createChild(parent, name, !reference.isLast());
    }
    if (childFile.isDirectory()) {
        // pre create children
        VirtualFile childParent = childFile;
        FileReference[] references = reference.getFileReferenceSet().getAllReferences();
        for (int i = reference.getIndex() + 1, n = references.length; i < n; i++) {
            FileReference childReference = references[i];
            childParent = fileSystem.createChild(childParent, childReference.decode(childReference.getText()), i != (n - 1));
        }
        return getManager().findDirectory(childFile);
    } else {
        return getManager().findFile(childFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HttpVirtualFile(com.intellij.openapi.vfs.impl.http.HttpVirtualFile) HttpVirtualFile(com.intellij.openapi.vfs.impl.http.HttpVirtualFile) HttpFileSystem(com.intellij.openapi.vfs.ex.http.HttpFileSystem) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with HttpVirtualFile

use of com.intellij.openapi.vfs.impl.http.HttpVirtualFile in project intellij-community by JetBrains.

the class XSourcePositionImpl method create.

/**
   * do not call this method from plugins, use {@link XDebuggerUtil#createPosition(VirtualFile, int, int)} instead
   */
@Nullable
public static XSourcePositionImpl create(@Nullable VirtualFile file, int line, int column) {
    if (file == null) {
        return null;
    }
    AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock();
    try {
        int offset;
        if (file instanceof LightVirtualFile || file instanceof HttpVirtualFile) {
            offset = -1;
        } else {
            Document document = file.isValid() ? FileDocumentManager.getInstance().getDocument(file) : null;
            if (document == null) {
                return null;
            }
            if (line < 0) {
                line = 0;
            }
            if (column < 0) {
                column = 0;
            }
            offset = line < document.getLineCount() ? document.getLineStartOffset(line) + column : -1;
            if (offset >= document.getTextLength()) {
                offset = document.getTextLength() - 1;
            }
        }
        return new XSourcePositionImpl(file, line, offset);
    } finally {
        lock.finish();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) HttpVirtualFile(com.intellij.openapi.vfs.impl.http.HttpVirtualFile) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HttpVirtualFile (com.intellij.openapi.vfs.impl.http.HttpVirtualFile)2 Nullable (org.jetbrains.annotations.Nullable)2 AccessToken (com.intellij.openapi.application.AccessToken)1 Document (com.intellij.openapi.editor.Document)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HttpFileSystem (com.intellij.openapi.vfs.ex.http.HttpFileSystem)1 FileReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference)1 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1