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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations