本文整理汇总了Java中com.intellij.testFramework.LightVirtualFile类的典型用法代码示例。如果您正苦于以下问题:Java LightVirtualFile类的具体用法?Java LightVirtualFile怎么用?Java LightVirtualFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LightVirtualFile类属于com.intellij.testFramework包,在下文中一共展示了LightVirtualFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFindInCommentsProperlyWorksWithOffsets
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
public void testFindInCommentsProperlyWorksWithOffsets() {
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
String prefix = "/*";
String text = prefix + "done*/";
findModel.setSearchContext(FindModel.SearchContext.IN_COMMENTS);
LightVirtualFile file = new LightVirtualFile("A.java", text);
FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file);
assertTrue(findResult.isStringFound());
findModel.setRegularExpressions(true);
findResult = myFindManager.findString(text, prefix.length(), findModel, file);
assertTrue(findResult.isStringFound());
}
示例2: testFindExceptComments
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
public void testFindExceptComments() {
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
String prefix = "/*";
String text = prefix + "done*/done";
findModel.setSearchContext(FindModel.SearchContext.EXCEPT_COMMENTS);
LightVirtualFile file = new LightVirtualFile("A.java", text);
FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file);
assertTrue(findResult.isStringFound());
assertTrue(findResult.getStartOffset() > prefix.length());
findModel.setRegularExpressions(true);
findResult = myFindManager.findString(text, prefix.length(), findModel, file);
assertTrue(findResult.isStringFound());
assertTrue(findResult.getStartOffset() > prefix.length());
}
示例3: testFindExceptLiterals
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
public void testFindExceptLiterals() {
FindModel findModel = FindManagerTestUtils.configureFindModel("done");
String prefix = "\"";
String text = prefix + "done\"done";
findModel.setSearchContext(FindModel.SearchContext.EXCEPT_STRING_LITERALS);
LightVirtualFile file = new LightVirtualFile("A.java", text);
FindResult findResult = myFindManager.findString(text, prefix.length(), findModel, file);
assertTrue(findResult.isStringFound());
assertTrue(findResult.getStartOffset() > prefix.length());
findModel.setRegularExpressions(true);
findResult = myFindManager.findString(text, prefix.length(), findModel, file);
assertTrue(findResult.isStringFound());
assertTrue(findResult.getStartOffset() > prefix.length());
}
示例4: calcBaseLanguage
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
private static Language calcBaseLanguage(@NotNull VirtualFile file, @NotNull Project project, @NotNull final FileType fileType) {
if (file instanceof LightVirtualFile) {
final Language language = ((LightVirtualFile)file).getLanguage();
if (language != null) {
return language;
}
}
if (fileType.isBinary()) return Language.ANY;
if (isTooLargeForIntelligence(file)) return PlainTextLanguage.INSTANCE;
if (fileType instanceof LanguageFileType) {
return LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), file, project);
}
return PlainTextLanguage.INSTANCE;
}
示例5: isInProject
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
@Override
public boolean isInProject(@NotNull PsiElement element) {
if (element instanceof PsiDirectoryContainer) {
PsiDirectory[] dirs = ((PsiDirectoryContainer)element).getDirectories();
for (PsiDirectory dir : dirs) {
if (!isInProject(dir)) return false;
}
return true;
}
PsiFile file = element.getContainingFile();
VirtualFile virtualFile = null;
if (file != null) {
virtualFile = file.getViewProvider().getVirtualFile();
}
else if (element instanceof PsiFileSystemItem) {
virtualFile = ((PsiFileSystemItem)element).getVirtualFile();
}
if (file != null && file.isPhysical() && virtualFile instanceof LightVirtualFile) return true;
if (virtualFile != null) {
return myFileIndex.isInContent(virtualFile);
}
return false;
}
示例6: createFileFromText
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
@Override
@NotNull
public PsiFile createFileFromText(@NotNull String name,
@NotNull FileType fileType,
@NotNull CharSequence text,
long modificationStamp,
final boolean eventSystemEnabled,
boolean markAsCopy) {
final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
if(fileType instanceof LanguageFileType){
final Language language =
LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), virtualFile, myManager.getProject());
final PsiFile file = trySetupPsiForFile(virtualFile, language, eventSystemEnabled, markAsCopy);
if (file != null) return file;
}
final SingleRootFileViewProvider singleRootFileViewProvider =
new SingleRootFileViewProvider(myManager, virtualFile, eventSystemEnabled);
final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
if(markAsCopy) CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
return plainTextFile;
}
示例7: trySetupPsiForFile
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
@Nullable
public PsiFile trySetupPsiForFile(@NotNull LightVirtualFile virtualFile,
@NotNull Language language,
final boolean physical, final boolean markAsCopy) {
final FileViewProviderFactory factory = LanguageFileViewProviders.INSTANCE.forLanguage(language);
FileViewProvider viewProvider = factory != null ? factory.createFileViewProvider(virtualFile, language, myManager, physical) : null;
if (viewProvider == null) viewProvider = new SingleRootFileViewProvider(myManager, virtualFile, physical);
language = viewProvider.getBaseLanguage();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
if (parserDefinition != null) {
final PsiFile psiFile = viewProvider.getPsi(language);
if (psiFile != null) {
if (markAsCopy) {
if (psiFile.getNode() == null) {
throw new AssertionError("No node for file " + psiFile + "; language=" + language);
}
markGenerated(psiFile);
}
return psiFile;
}
}
return null;
}
示例8: shouldBeInstalled
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
private boolean shouldBeInstalled(@Nullable final VirtualFile virtualFile) {
if (isDisabled()) return false;
if (virtualFile == null || virtualFile instanceof LightVirtualFile) return false;
if (!virtualFile.isInLocalFileSystem()) return false;
final FileStatusManager statusManager = FileStatusManager.getInstance(myProject);
if (statusManager == null) return false;
final AbstractVcs activeVcs = myVcsManager.getVcsFor(virtualFile);
if (activeVcs == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("shouldBeInstalled: for file " + virtualFile.getPath() + " failed: no active VCS");
}
return false;
}
final FileStatus status = statusManager.getStatus(virtualFile);
if (status == FileStatus.NOT_CHANGED || status == FileStatus.ADDED || status == FileStatus.UNKNOWN || status == FileStatus.IGNORED) {
if (LOG.isDebugEnabled()) {
LOG.debug("shouldBeInstalled: for file " + virtualFile.getPath() + " skipped: status=" + status);
}
return false;
}
return true;
}
示例9: GutteredLanguageConsole
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
public GutteredLanguageConsole(@NotNull String title,
@NotNull Project project,
@NotNull Language language,
@Nullable GutterContentProvider gutterContentProvider,
@Nullable final PairFunction<VirtualFile, Project, PsiFile> psiFileFactory) {
super(new Helper(project, new LightVirtualFile(title, language, "")) {
@NotNull
@Override
public PsiFile getFile() {
return psiFileFactory == null ? super.getFile() : psiFileFactory.fun(virtualFile, project);
}
});
this.gutterContentProvider = gutterContentProvider == null ? new BasicGutterContentProvider() : gutterContentProvider;
}
示例10: createFromText
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
protected PsiFile createFromText(final Language language, CharSequence text, PsiManager manager) {
@NonNls
final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), text, LocalTimeCounter.currentTime());
FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {
@Override
@NotNull
public Language getBaseLanguage() {
return language;
}
};
// Since we're already inside a template language PSI that was built regardless of the file size (for whatever reason),
// there should also be no file size checks for template data files.
SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
return viewProvider.getPsi(language);
}
示例11: findInjectionHost
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
@Nullable
public static PsiLanguageInjectionHost findInjectionHost(@Nullable PsiElement psi) {
if (psi == null) return null;
PsiFile containingFile = psi.getContainingFile().getOriginalFile(); // * formatting
PsiElement fileContext = containingFile.getContext(); // * quick-edit-handler
if (fileContext instanceof PsiLanguageInjectionHost) return (PsiLanguageInjectionHost)fileContext;
Place shreds = getShreds(containingFile.getViewProvider()); // * injection-registrar
if (shreds == null) {
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(containingFile);
if (virtualFile instanceof LightVirtualFile) {
virtualFile = ((LightVirtualFile)virtualFile).getOriginalFile(); // * dynamic files-from-text
}
if (virtualFile instanceof VirtualFileWindow) {
shreds = getShreds(((VirtualFileWindow)virtualFile).getDocumentWindow());
}
}
return shreds != null ? shreds.getHostPointer().getElement() : null;
}
示例12: createHighlighter
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
private EditorHighlighter createHighlighter() {
if (myTemplate != null && myVelocityFileType != FileTypes.UNKNOWN) {
return EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, new LightVirtualFile("aaa." + myTemplate.getExtension() + ".ft"));
}
FileType fileType = null;
if (myTemplate != null) {
fileType = FileTypeManager.getInstance().getFileTypeByExtension(myTemplate.getExtension());
}
if (fileType == null) {
fileType = FileTypes.PLAIN_TEXT;
}
SyntaxHighlighter originalHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(fileType, null, null);
if (originalHighlighter == null) {
originalHighlighter = new PlainSyntaxHighlighter();
}
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
LayeredLexerEditorHighlighter highlighter = new LayeredLexerEditorHighlighter(new TemplateHighlighter(), scheme);
highlighter.registerLayer(FileTemplateTokenType.TEXT, new LayerDescriptor(originalHighlighter, ""));
return highlighter;
}
示例13: CommandConsole
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
/**
* @param module module console runs on
* @param title console title
* @param commandsAndDefaultExecutor List of commands (to be injected into {@link CommandLineFile}) if any
* and executor to be used when user executes unknown command.
* Both may be null. Execution is passed to command if command exist, passed to default executor
* otherwise. With out of commands default executor will always be used.
* With out of executor, no execution would be possible at all.
*/
private CommandConsole(@NotNull final Module module,
@NotNull final String title,
@Nullable final Pair<List<Command>, CommandExecutor> commandsAndDefaultExecutor) {
super(new Helper(module.getProject(), new LightVirtualFile(title, CommandLineLanguage.INSTANCE, "")) {
@Override
public void setupEditor(@NotNull EditorEx editor) {
super.setupEditor(editor);
// We do not need spaces here, because it leads to PY-15557
EditorSettings editorSettings = editor.getSettings();
editorSettings.setAdditionalLinesCount(0);
editorSettings.setAdditionalColumnsCount(0);
}
});
myCommandsAndDefaultExecutor = commandsAndDefaultExecutor;
myModule = module;
}
示例14: testCodeCell
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
public void testCodeCell() throws IOException {
final String fileName = "testData/code.ipynb";
final String fileText = getFileText(fileName);
final IpnbFile ipnbFile = IpnbParser.parseIpnbFile(fileText, new LightVirtualFile());
assertNotNull(ipnbFile);
final List<IpnbCell> cells = ipnbFile.getCells();
assertEquals(1, cells.size());
final IpnbCell cell = cells.get(0);
assertTrue(cell instanceof IpnbCodeCell);
final List<IpnbOutputCell> outputs = ((IpnbCodeCell)cell).getCellOutputs();
assertEquals(0, outputs.size());
final List<String> source = ((IpnbCodeCell)cell).getSource();
final String joined = StringUtil.join(source, "");
assertEquals("e = x + 2*y", joined);
final String language = ((IpnbCodeCell)cell).getLanguage();
assertEquals("python", language);
final Integer number = ((IpnbCodeCell)cell).getPromptNumber();
assertEquals(new Integer(4), number);
}
示例15: testOutputs
import com.intellij.testFramework.LightVirtualFile; //导入依赖的package包/类
public void testOutputs() throws IOException {
final String fileName = "testData/outputs.ipynb";
final String fileText = getFileText(fileName);
final IpnbFile ipnbFile = IpnbParser.parseIpnbFile(fileText, new LightVirtualFile());
assertNotNull(ipnbFile);
final List<IpnbCell> cells = ipnbFile.getCells();
assertEquals(1, cells.size());
final IpnbCell cell = cells.get(0);
assertTrue(cell instanceof IpnbCodeCell);
final List<IpnbOutputCell> outputs = ((IpnbCodeCell)cell).getCellOutputs();
assertEquals(1, outputs.size());
final IpnbOutputCell output = outputs.get(0);
final List<String> text = output.getText();
assertNotNull(text);
final String joined = StringUtil.join(text, "");
assertEquals("\"Add(Symbol('x'), Mul(Integer(2), Symbol('y')))\"", joined);
}