use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class JavaParsingTestCase method createPsiFile.
private PsiFile createPsiFile(final String name, final String text, final TestParser parser) {
if (TEST_FILE_ELEMENT_TYPE == null) {
TEST_FILE_ELEMENT_TYPE = new MyIFileElementType();
}
TEST_PARSER = parser;
final LightVirtualFile virtualFile = new LightVirtualFile(name + '.' + myFileExt, StdFileTypes.JAVA, text, -1);
final FileViewProvider viewProvider = new SingleRootFileViewProvider(PsiManager.getInstance(getProject()), virtualFile, true);
return new PsiJavaFileImpl(viewProvider) {
@NotNull
@Override
protected FileElement createFileElement(@NotNull final CharSequence text) {
return new FileElement(TEST_FILE_ELEMENT_TYPE, text);
}
};
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class LightVirtualFileLeaksTest method queryExternalAnnotations.
private void queryExternalAnnotations() {
LightVirtualFile vFile = createLightFile();
assertEmpty(AnnotationUtil.getAllAnnotations(((PsiJavaFile) getPsiManager().findFile(vFile)).getClasses()[0], true, null));
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class DiffContentFactoryImpl method createPsiDocument.
@Nullable
private static Document createPsiDocument(@NotNull Project project, @NotNull String content, @NotNull FileType fileType, @NotNull String fileName, boolean readOnly) {
return ReadAction.compute(() -> {
LightVirtualFile file = new LightVirtualFile(fileName, fileType, content);
file.setWritable(!readOnly);
file.putUserData(DiffPsiFileSupport.KEY, true);
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document == null)
return null;
PsiDocumentManager.getInstance(project).getPsiFile(document);
return document;
});
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class FileBasedIndexTest method testLargeFile.
public void testLargeFile() throws Exception {
char[] text = new char[FileUtilRt.LARGE_FOR_CONTENT_LOADING + 42];
final String clazz = "class Foo { String bar; }";
for (int i = 0; i < text.length; i++) {
text[i] = i < clazz.length() ? clazz.charAt(i) : ' ';
}
final LightVirtualFile file = new LightVirtualFile("Foo.java", new CharArrayCharSequence(text));
assertFalse(((FileBasedIndexImpl) FileBasedIndex.getInstance()).isIndexingCandidate(file, StubUpdatingIndex.INDEX_ID));
}
use of com.intellij.testFramework.LightVirtualFile in project intellij-community by JetBrains.
the class PsiUtilCore method getPsiFile.
/**
* Tries to find PSI file for a virtual file and throws assertion error with debug info if it is null.
*/
@NotNull
public static PsiFile getPsiFile(@NotNull Project project, @NotNull VirtualFile file) {
PsiManager psiManager = PsiManager.getInstance(project);
PsiFile psi = psiManager.findFile(file);
if (psi != null)
return psi;
FileType fileType = file.getFileType();
FileViewProvider viewProvider = psiManager.findViewProvider(file);
Document document = FileDocumentManager.getInstance().getDocument(file);
boolean ignored = !(file instanceof LightVirtualFile) && FileTypeRegistry.getInstance().isFileIgnored(file);
VirtualFile vDir = file.getParent();
PsiDirectory psiDir = vDir == null ? null : PsiManager.getInstance(project).findDirectory(vDir);
FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
StringBuilder sb = new StringBuilder();
sb.append("valid=").append(file.isValid()).append(" isDirectory=").append(file.isDirectory()).append(" hasDocument=").append(document != null).append(" length=").append(file.getLength());
sb.append("\nproject=").append(project.getName()).append(" default=").append(project.isDefault()).append(" open=").append(project.isOpen());
sb.append("\nfileType=").append(fileType.getName()).append("/").append(fileType.getClass().getName());
sb.append("\nisIgnored=").append(ignored);
sb.append(" underIgnored=").append(indexFacade.isUnderIgnored(file));
sb.append(" inLibrary=").append(indexFacade.isInLibrarySource(file) || indexFacade.isInLibraryClasses(file));
sb.append(" parentDir=").append(vDir == null ? "no-vfs" : vDir.isDirectory() ? "has-vfs-dir" : "has-vfs-file").append("/").append(psiDir == null ? "no-psi" : "has-psi");
sb.append("\nviewProvider=").append(viewProvider == null ? "null" : viewProvider.getClass().getName());
if (viewProvider != null) {
List<PsiFile> files = viewProvider.getAllFiles();
sb.append(" language=").append(viewProvider.getBaseLanguage().getID());
sb.append(" physical=").append(viewProvider.isPhysical());
sb.append(" rootCount=").append(files.size());
for (PsiFile o : files) {
sb.append("\n root=").append(o.getLanguage().getID()).append("/").append(o.getClass().getName());
}
}
LOG.error("no PSI for file '" + file.getName() + "'", new Attachment(file.getPresentableUrl(), sb.toString()));
throw new AssertionError();
}
Aggregations