use of com.intellij.psi.impl.source.PsiFileImpl in project smali by JesusFreke.
the class LightCodeInsightParsingTestCase method doTest.
protected void doTest(boolean checkResult) {
String name = getTestName(false);
try {
String text = loadFile(name + "." + myFileExt);
PsiFile f = createPsiFile(name, text);
if (f instanceof PsiFileImpl) {
// Also want to test stub serialization/deserialization
StubTree stubTree = ((PsiFileImpl) f).calcStubTree();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SerializationManagerImpl.getInstanceEx().serialize(stubTree.getRoot(), baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
SerializationManagerImpl.getInstanceEx().deserialize(bais);
}
ensureParsed(f);
assertEquals("light virtual file text mismatch", text, ((LightVirtualFile) f.getVirtualFile()).getContent().toString());
assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(f.getVirtualFile()));
assertEquals("doc text mismatch", text, f.getViewProvider().getDocument().getText());
assertEquals("psi text mismatch", text, f.getText());
if (checkResult) {
checkResult(name, f);
} else {
toParseTreeText(f, skipSpaces(), includeRanges());
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (SerializerNotFoundException e) {
throw new RuntimeException(e);
}
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PsiFileGistImpl method getPsiFile.
private static PsiFile getPsiFile(@NotNull Project project, @NotNull VirtualFile file) {
PsiFile psi = PsiManager.getInstance(project).findFile(file);
if (psi == null || !(psi instanceof PsiFileImpl) || ((PsiFileImpl) psi).isContentsLoaded()) {
return psi;
}
FileType fileType = file.getFileType();
if (!(fileType instanceof LanguageFileType))
return null;
return FileContentImpl.createFileFromText(project, psi.getViewProvider().getContents(), (LanguageFileType) fileType, file, file.getName());
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class SrcRepositoryUseTest method testCopyableUserDataChild.
public void testCopyableUserDataChild() throws Exception {
final PsiClass aClass = myJavaFacade.findClass("pack.MyInterface1", GlobalSearchScope.allScope(myProject));
assertNotNull(aClass);
final PsiFile containingFile = aClass.getContainingFile();
final CompositeElement element = ((PsiFileImpl) containingFile).calcTreeElement();
aClass.putCopyableUserData(TEST_KEY, "TEST");
final PsiJavaFile fileCopy = (PsiJavaFile) containingFile.copy();
final PsiClass[] classesCopy = fileCopy.getClasses();
assertEquals(1, classesCopy.length);
assertNotNull(element);
assertEquals("TEST", classesCopy[0].getCopyableUserData(TEST_KEY));
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class StubTreeBuilder method getStubbedRoots.
/** Order is deterministic. First element matches {@link FileViewProvider#getStubBindingRoot()} */
@NotNull
public static List<Pair<IStubFileElementType, PsiFile>> getStubbedRoots(@NotNull FileViewProvider viewProvider) {
final List<Trinity<Language, IStubFileElementType, PsiFile>> roots = new SmartList<>();
final PsiFile stubBindingRoot = viewProvider.getStubBindingRoot();
for (Language language : viewProvider.getLanguages()) {
final PsiFile file = viewProvider.getPsi(language);
if (file instanceof PsiFileImpl) {
final IElementType type = ((PsiFileImpl) file).getElementTypeForStubBuilder();
if (type != null) {
roots.add(Trinity.create(language, (IStubFileElementType) type, file));
}
}
}
ContainerUtil.sort(roots, (o1, o2) -> {
if (o1.third == stubBindingRoot)
return o2.third == stubBindingRoot ? 0 : -1;
else if (o2.third == stubBindingRoot)
return 1;
else
return StringUtil.compare(o1.first.getID(), o2.first.getID(), false);
});
return ContainerUtil.map(roots, trinity -> Pair.create(trinity.second, trinity.third));
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class BlockSupportImpl method reparseRange.
@Override
public void reparseRange(@NotNull PsiFile file, int startOffset, int endOffset, @NotNull CharSequence newText) throws IncorrectOperationException {
LOG.assertTrue(file.isValid());
final PsiFileImpl psiFile = (PsiFileImpl) file;
final Document document = psiFile.getViewProvider().getDocument();
assert document != null;
document.replaceString(startOffset, endOffset, newText);
PsiDocumentManager.getInstance(psiFile.getProject()).commitDocument(document);
}
Aggregations