Search in sources :

Example 31 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.

the class PsiFieldImpl method getDetachedInitializer.

// avoids stub-to-AST switch if possible,
// returns the light generated initializer literal expression if stored in stubs, the regular initializer if wasn't
public PsiExpression getDetachedInitializer() {
    final PsiFieldStub stub = getGreenStub();
    PsiExpression initializer;
    if (stub == null) {
        initializer = getInitializer();
    } else {
        String initializerText = stub.getInitializerText();
        if (StringUtil.isEmpty(initializerText) || PsiFieldStub.INITIALIZER_NOT_STORED.equals(initializerText) || PsiFieldStub.INITIALIZER_TOO_LONG.equals(initializerText)) {
            initializer = getInitializer();
        } else {
            PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
            initializer = parserFacade.createExpressionFromText(initializerText, this);
            ((LightVirtualFile) initializer.getContainingFile().getViewProvider().getVirtualFile()).setWritable(false);
        }
    }
    return initializer;
}
Also used : PsiFieldStub(com.intellij.psi.impl.java.stubs.PsiFieldStub) LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 32 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.

the class InjectedLanguageUtil method findInjectionHost.

@Nullable
public static PsiLanguageInjectionHost findInjectionHost(@Nullable PsiElement psi) {
    if (psi == null)
        return null;
    // * formatting
    PsiFile containingFile = psi.getContainingFile().getOriginalFile();
    // * quick-edit-handler
    PsiElement fileContext = containingFile.getContext();
    if (fileContext instanceof PsiLanguageInjectionHost)
        return (PsiLanguageInjectionHost) fileContext;
    // * injection-registrar
    Place shreds = getShreds(containingFile.getViewProvider());
    if (shreds == null) {
        VirtualFile virtualFile = PsiUtilCore.getVirtualFile(containingFile);
        if (virtualFile instanceof LightVirtualFile) {
            // * dynamic files-from-text
            virtualFile = ((LightVirtualFile) virtualFile).getOriginalFile();
        }
        if (virtualFile instanceof VirtualFileWindow) {
            shreds = getShreds(((VirtualFileWindow) virtualFile).getDocumentWindow());
        }
    }
    return shreds != null ? shreds.getHostPointer().getElement() : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-plugins by JetBrains.

the class CPUSnapshotNode method getNavigatable.

@Override
public Navigatable getNavigatable() {
    if (navigatableCache == null) {
        final String name = runConfigurationName + " " + getTitle();
        VirtualFile virtualFile = new LightVirtualFile(name, new CpuSnapshotFileType(), "") {

            @NotNull
            @Override
            public String getPath() {
                return getName();
            }
        };
        virtualFile.putUserData(ProfileData.CALL_TREE_KEY, callTree);
        navigatableCache = new OpenFileDescriptor(module.getProject(), virtualFile);
    }
    return navigatableCache;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) CpuSnapshotFileType(com.jetbrains.actionscript.profiler.file.CpuSnapshotFileType)

Example 34 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-plugins by JetBrains.

the class DartExpressionCodeFragmentImpl method clone.

protected DartExpressionCodeFragmentImpl clone() {
    final DartExpressionCodeFragmentImpl clone = (DartExpressionCodeFragmentImpl) cloneImpl((FileElement) calcTreeElement().clone());
    clone.myPhysical = false;
    clone.myOriginalFile = this;
    final FileManager fileManager = ((PsiManagerEx) getManager()).getFileManager();
    final SingleRootFileViewProvider cloneViewProvider = (SingleRootFileViewProvider) fileManager.createFileViewProvider(new LightVirtualFile(getName(), getLanguage(), getText()), false);
    clone.myViewProvider = cloneViewProvider;
    cloneViewProvider.forceCachedPsi(clone);
    clone.init(getContentElementType(), getContentElementType());
    return clone;
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) FileElement(com.intellij.psi.impl.source.tree.FileElement) SingleRootFileViewProvider(com.intellij.psi.SingleRootFileViewProvider) FileManager(com.intellij.psi.impl.file.impl.FileManager) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx)

Example 35 with LightVirtualFile

use of com.intellij.testFramework.LightVirtualFile in project intellij-plugins by JetBrains.

the class DartVmServiceDebugProcess method getSourcePosition.

@Nullable
public XSourcePosition getSourcePosition(@NotNull final String isolateId, @NotNull final ScriptRef scriptRef, int tokenPos) {
    VirtualFile file = ReadAction.compute(() -> {
        String uri = scriptRef.getUri();
        if (myDASExecutionContextId != null && !isDartPatchUri(uri)) {
            final String path = DartAnalysisServerService.getInstance(getSession().getProject()).execution_mapUri(myDASExecutionContextId, null, uri);
            if (path != null) {
                return LocalFileSystem.getInstance().findFileByPath(path);
            }
        }
        final VirtualFile pubspec = myDartUrlResolver.getPubspecYamlFile();
        if (myRemoteProjectRootUri != null && uri.startsWith(myRemoteProjectRootUri) && pubspec != null) {
            final String localRootUri = StringUtil.trimEnd(myDartUrlResolver.getDartUrlForFile(pubspec.getParent()), '/');
            LOG.assertTrue(localRootUri.startsWith(DartUrlResolver.FILE_PREFIX), localRootUri);
            uri = localRootUri + uri.substring(myRemoteProjectRootUri.length());
        }
        return myDartUrlResolver.findFileByDartUrl(uri);
    });
    if (file == null) {
        file = myScriptIdToContentMap.get(scriptRef.getId());
    }
    TIntObjectHashMap<Pair<Integer, Integer>> tokenPosToLineAndColumn = myScriptIdToLinesAndColumnsMap.get(scriptRef.getId());
    if (file != null && tokenPosToLineAndColumn != null) {
        final Pair<Integer, Integer> lineAndColumn = tokenPosToLineAndColumn.get(tokenPos);
        if (lineAndColumn == null)
            return XDebuggerUtil.getInstance().createPositionByOffset(file, 0);
        return XDebuggerUtil.getInstance().createPosition(file, lineAndColumn.first, lineAndColumn.second);
    }
    final Script script = myVmServiceWrapper.getScriptSync(isolateId, scriptRef.getId());
    if (script == null)
        return null;
    if (file == null) {
        file = new LightVirtualFile(PathUtil.getFileName(script.getUri()), DartFileType.INSTANCE, script.getSource());
        ((LightVirtualFile) file).setWritable(false);
        myScriptIdToContentMap.put(scriptRef.getId(), (LightVirtualFile) file);
    }
    if (tokenPosToLineAndColumn == null) {
        tokenPosToLineAndColumn = createTokenPosToLineAndColumnMap(script.getTokenPosTable());
        myScriptIdToLinesAndColumnsMap.put(scriptRef.getId(), tokenPosToLineAndColumn);
    }
    final Pair<Integer, Integer> lineAndColumn = tokenPosToLineAndColumn.get(tokenPos);
    if (lineAndColumn == null)
        return XDebuggerUtil.getInstance().createPositionByOffset(file, 0);
    return XDebuggerUtil.getInstance().createPosition(file, lineAndColumn.first, lineAndColumn.second);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LightVirtualFile (com.intellij.testFramework.LightVirtualFile)69 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 NotNull (org.jetbrains.annotations.NotNull)10 Nullable (org.jetbrains.annotations.Nullable)10 IpnbFile (org.jetbrains.plugins.ipnb.format.IpnbFile)7 Document (com.intellij.openapi.editor.Document)6 FileElement (com.intellij.psi.impl.source.tree.FileElement)6 FileType (com.intellij.openapi.fileTypes.FileType)5 PsiManagerEx (com.intellij.psi.impl.PsiManagerEx)5 FileManager (com.intellij.psi.impl.file.impl.FileManager)5 Project (com.intellij.openapi.project.Project)4 SingleRootFileViewProvider (com.intellij.psi.SingleRootFileViewProvider)4 Language (com.intellij.lang.Language)3 FileViewProvider (com.intellij.psi.FileViewProvider)3 PsiFile (com.intellij.psi.PsiFile)3 PsiFileFactoryImpl (com.intellij.psi.impl.PsiFileFactoryImpl)3 File (java.io.File)3 IpnbCell (org.jetbrains.plugins.ipnb.format.cells.IpnbCell)3 VirtualFileWindow (com.intellij.injected.editor.VirtualFileWindow)2 MockDocument (com.intellij.mock.MockDocument)2