Java Code Examples for com.intellij.testFramework.LightVirtualFile

The following examples show how to use com.intellij.testFramework.LightVirtualFile. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: CppTools   Source File: CppDebugProcess.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public XDebuggerEditorsProvider getEditorsProvider() {
  return new XDebuggerEditorsProvider() {
    @NotNull
    @Override
    public FileType getFileType() {
      return CppSupportLoader.CPP_FILETYPE;
    }

    @NotNull
    @Override
    public Document createDocument(@NotNull Project project, @NotNull String s, @Nullable XSourcePosition xSourcePosition, @NotNull EvaluationMode evaluationMode) {
      VirtualFile virtualFile = new LightVirtualFile("dummy.cpp", s);
      ICppCodeFragment file = new CppCodeFragment(new SingleRootFileViewProvider(PsiManager.getInstance(project), virtualFile, true));
      return PsiDocumentManager.getInstance(project).getDocument(file);
    }
  };
}
 
Example 2
Source Project: consulo   Source File: InjectedLanguageUtil.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source Project: intellij   Source File: GlobFindUsagesTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInMemoryFileHandledGracefully() {
  createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(['**/*.java'])");

  LightVirtualFile inMemoryFile =
      new LightVirtualFile("mockProjectViewFile", ProjectViewLanguage.INSTANCE, "");

  FileManager fileManager =
      ((PsiManagerEx) PsiManager.getInstance(getProject())).getFileManager();
  fileManager.setViewProvider(
      inMemoryFile, fileManager.createFileViewProvider(inMemoryFile, true));

  PsiFile psiFile = fileManager.findFile(inMemoryFile);

  FindUsages.findAllReferences(psiFile);
}
 
Example 4
Source Project: consulo   Source File: FileTemplateConfigurable.java    License: Apache License 2.0 6 votes vote down vote up
private EditorHighlighter createHighlighter() {
  if (myTemplate != null && myVelocityFileType != UnknownFileType.INSTANCE) {
    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 = PlainTextFileType.INSTANCE;
  }

  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;
}
 
Example 5
Source Project: consulo-csharp   Source File: CSharpFragmentFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static CSharpFragmentFileImpl createExpressionFragment(Project project, String text, @Nullable final PsiElement context)
{
	LightVirtualFile virtualFile = new LightVirtualFile("dummy.cs", CSharpFileType.INSTANCE, text, System.currentTimeMillis());
	SingleRootFileViewProvider viewProvider = new SingleRootFileViewProvider(PsiManager.getInstance(project), virtualFile, true)
	{
		@Nonnull
		@Override
		public SingleRootFileViewProvider createCopy(@Nonnull final VirtualFile copy)
		{
			SingleRootFileViewProvider provider = new SingleRootFileViewProvider(getManager(), copy, false);
			CSharpFragmentFileImpl psiFile = new CSharpFragmentFileImpl(ourExpressionFileElementType, ourExpressionFileElementType, provider, context);
			provider.forceCachedPsi(psiFile);
			psiFile.getNode();
			return provider;
		}
	};
	CSharpFragmentFileImpl file = new CSharpFragmentFileImpl(ourExpressionFileElementType, ourExpressionFileElementType, viewProvider, context);
	viewProvider.forceCachedPsi(file);
	file.getNode();
	return file;
}
 
Example 6
Source Project: consulo   Source File: TemplateDataElementType.java    License: Apache License 2.0 6 votes vote down vote up
protected PsiFile createPsiFileFromSource(final Language language, CharSequence sourceCode, PsiManager manager) {
  @NonNls final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), sourceCode, LocalTimeCounter.currentTime());

  FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {
    @Override
    @Nonnull
    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);
}
 
Example 7
@Nullable
@RequiredReadAction
public static Module findModuleByPsiDirectory(final PsiDirectory directory)
{
	LightVirtualFile l = new LightVirtualFile("test.cs", CSharpFileType.INSTANCE, "")
	{
		@Override
		public VirtualFile getParent()
		{
			return directory.getVirtualFile();
		}

		@Nonnull
		@Override
		public VirtualFileSystem getFileSystem()
		{
			return LocalFileSystem.getInstance();
		}
	};
	return CreateFileFromTemplateAction.ModuleResolver.EP_NAME.composite().resolveModule(directory, CSharpFileType.INSTANCE);
}
 
Example 8
public HaxeExpressionCodeFragmentImpl(Project project,
                                      @NonNls String name,
                                      CharSequence text,
                                      boolean isPhysical) {
  super(new SingleRootFileViewProvider(PsiManager.getInstance(project),
                                       new LightVirtualFile(name, FileTypeManager.getInstance().getFileTypeByFileName(name), text),
                                       isPhysical) {
    @Override
    public boolean supportsIncrementalReparse(@NotNull Language rootLanguage) {
      return false;
    }
  });

  myPhysical = isPhysical;
  ((SingleRootFileViewProvider)getViewProvider()).forceCachedPsi(this);
  final MyHaxeFileElementType type = new MyHaxeFileElementType();
  init(type, type);
}
 
Example 9
Source Project: consulo   Source File: DiffUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @Nonnull DocumentContent content) {
  FileType type = content.getContentType();
  VirtualFile file = content.getHighlightFile();
  Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);

  EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
  if (language != null) {
    SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file);
    return highlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme());
  }
  if (file != null) {
    if ((type == null || type == PlainTextFileType.INSTANCE) || file.getFileType() == type || file instanceof LightVirtualFile) {
      return highlighterFactory.createEditorHighlighter(project, file);
    }
  }
  if (type != null) {
    return highlighterFactory.createEditorHighlighter(project, type);
  }
  return null;
}
 
Example 10
Source Project: consulo   Source File: DiffContentFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static Document createPsiDocument(@Nonnull Project project,
                                          @Nonnull String content,
                                          @Nonnull FileType fileType,
                                          @Nonnull String fileName,
                                          boolean readOnly) {
  ThrowableComputable<Document,RuntimeException> action = () -> {
    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;
  };
  return AccessRule.read(action);
}
 
Example 11
Source Project: consulo   Source File: ParsingTestCase.java    License: Apache License 2.0 6 votes vote down vote up
protected void doTest(boolean checkResult) {
  String name = getTestName(false);
  try {
    String text = loadFile(name + "." + myExtension);
    myFile = createPsiFile(name, text);
    ensureParsed(myFile);
    FileViewProvider viewProvider = myFile.getViewProvider();
    VirtualFile virtualFile = viewProvider.getVirtualFile();
    if (virtualFile instanceof LightVirtualFile) {
      assertEquals("light virtual file text mismatch", text, ((LightVirtualFile)virtualFile).getContent());
    }
    assertEquals("virtual file text mismatch", text, LoadTextUtil.loadText(virtualFile));
    assertEquals("doc text mismatch", text, viewProvider.getDocument().getText());
    assertEquals("psi text mismatch", text, myFile.getText());
    if (checkResult) {
      checkResult(name, myFile);
    }
    else {
      toParseTreeText(myFile, skipSpaces(), includeRanges());
    }
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 12
Source Project: consulo   Source File: FileDocumentManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void doSaveDocument(@Nonnull final Document document, boolean isExplicit) throws IOException, SaveVetoException {
  VirtualFile file = getFile(document);
  if (LOG.isTraceEnabled()) LOG.trace("saving: " + file);

  if (file == null || file instanceof LightVirtualFile || file.isValid() && !isFileModified(file)) {
    removeFromUnsaved(document);
    return;
  }

  if (file.isValid() && needsRefresh(file)) {
    LOG.trace("  refreshing...");
    file.refresh(false, false);
    if (!myUnsavedDocuments.contains(document)) return;
  }

  if (!maySaveDocument(file, document, isExplicit)) {
    throw new SaveVetoException();
  }

  LOG.trace("  writing...");
  WriteAction.run(() -> doSaveDocumentInWriteAction(document, file));
  LOG.trace("  done");
}
 
Example 13
Source Project: consulo   Source File: LoadTextUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Loads content of given virtual file. If limit is {@value UNLIMITED} then full CharSequence will be returned. Else CharSequence
 * will be truncated by limit if it has bigger length.
 *
 * @param file  Virtual file for content loading
 * @param limit Maximum characters count or {@value UNLIMITED}
 * @return Full or truncated CharSequence with file content
 * @throws IllegalArgumentException for binary files
 */
@Nonnull
public static CharSequence loadText(@Nonnull final VirtualFile file, int limit) {
  FileType type = file.getFileType();
  if (type.isBinary()) throw new IllegalArgumentException("Attempt to load truncated text for binary file: " + file.getPresentableUrl() + ". File type: " + type.getName());

  if (file instanceof LightVirtualFile) {
    return limitCharSequence(((LightVirtualFile)file).getContent(), limit);
  }

  if (file.isDirectory()) {
    throw new AssertionError("'" + file.getPresentableUrl() + "' is a directory");
  }
  try {
    byte[] bytes = limit == UNLIMITED ? file.contentsToByteArray() : FileUtil.loadFirstAndClose(file.getInputStream(), limit);
    return getTextByBinaryPresentation(bytes, file);
  }
  catch (IOException e) {
    return ArrayUtil.EMPTY_CHAR_SEQUENCE;
  }
}
 
Example 14
Source Project: consulo   Source File: AbstractFileViewProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public CharSequence getText() {
  final VirtualFile virtualFile = getVirtualFile();
  if (virtualFile instanceof LightVirtualFile) {
    Document doc = getCachedDocument();
    if (doc != null) return getLastCommittedText(doc);
    return ((LightVirtualFile)virtualFile).getContent();
  }

  final Document document = getDocument();
  if (document == null) {
    return LoadTextUtil.loadText(virtualFile);
  }
  return getLastCommittedText(document);
}
 
Example 15
Source Project: consulo   Source File: FileManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setViewProvider(@Nonnull final VirtualFile virtualFile, @Nullable final FileViewProvider fileViewProvider) {
  FileViewProvider prev = getRawCachedViewProvider(virtualFile);
  if (prev == fileViewProvider) return;
  if (prev != null) {
    DebugUtil.performPsiModification(null, () -> markInvalidated(prev));
  }

  if (fileViewProvider == null) {
    getVFileToViewProviderMap().remove(virtualFile);
  }
  else if (virtualFile instanceof LightVirtualFile) {
    virtualFile.putUserData(myPsiHardRefKey, fileViewProvider);
  }
  else {
    getVFileToViewProviderMap().put(virtualFile, fileViewProvider);
  }
}
 
Example 16
Source Project: consulo   Source File: PsiFileFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public PsiFile createFileFromText(@Nonnull String name,
                                  @Nonnull Language language,
                                  @Nonnull LanguageVersion languageVersion,
                                  @Nonnull CharSequence text,
                                  boolean physical,
                                  boolean markAsCopy,
                                  boolean noSizeLimit) {
  LightVirtualFile virtualFile = new LightVirtualFile(name, language, text);
  virtualFile.putUserData(LanguageVersion.KEY, languageVersion);
  if (noSizeLimit) {
    SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
  }
  return trySetupPsiForFile(virtualFile, language, languageVersion, physical, markAsCopy);
}
 
Example 17
Source Project: consulo   Source File: PsiFileFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public PsiFile createFileFromText(@Nonnull String name,
                                  @Nonnull LanguageVersion languageVersion,
                                  @Nonnull CharSequence text,
                                  boolean physical,
                                  boolean markAsCopy,
                                  boolean noSizeLimit,
                                  @Nullable VirtualFile original) {
  LightVirtualFile virtualFile = new LightVirtualFile(name, languageVersion.getLanguage(), text);
  if (original != null) virtualFile.setOriginalFile(original);
  virtualFile.putUserData(LanguageVersion.KEY, languageVersion);
  if (noSizeLimit) {
    SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
  }
  return trySetupPsiForFile(virtualFile, languageVersion.getLanguage(), languageVersion, physical, markAsCopy);
}
 
Example 18
Source Project: consulo   Source File: PsiFileFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public PsiFile createFileFromText(@Nonnull String name,
                                  @Nonnull FileType fileType,
                                  @Nonnull CharSequence text,
                                  long modificationStamp,
                                  final boolean physical,
                                  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, LanguageVersionUtil.findDefaultVersion(language), physical, markAsCopy);
    if (file != null) return file;
  }
  final SingleRootFileViewProvider singleRootFileViewProvider = new SingleRootFileViewProvider(myManager, virtualFile, physical);
  final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
  if (markAsCopy) CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
  return plainTextFile;
}
 
Example 19
Source Project: consulo   Source File: PsiFileFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public PsiFile trySetupPsiForFile(final LightVirtualFile virtualFile,
                                  @Nonnull Language language,
                                  @Nonnull LanguageVersion languageVersion,
                                  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) {
      psiFile.putUserData(LanguageVersion.KEY, languageVersion);
      if (markAsCopy) {
        markGenerated(psiFile);
      }
      return psiFile;
    }
  }
  return null;
}
 
Example 20
Source Project: consulo   Source File: LineStatusTrackerManager.java    License: Apache License 2.0 6 votes vote down vote up
private boolean shouldBeInstalled(@javax.annotation.Nullable final VirtualFile virtualFile) {
  if (isDisabled()) return false;

  if (virtualFile == null || virtualFile instanceof LightVirtualFile) return false;
  final FileStatusManager statusManager = FileStatusManager.getInstance(myProject);
  if (statusManager == null) return false;
  if (!myStatusProvider.isSupported(virtualFile)) {
    log("shouldBeInstalled failed: no support found", virtualFile);
    return false;
  }
  final FileStatus status = statusManager.getStatus(virtualFile);
  if (status == FileStatus.NOT_CHANGED || status == FileStatus.ADDED || status == FileStatus.UNKNOWN || status == FileStatus.IGNORED) {
    log("shouldBeInstalled skipped: status=" + status, virtualFile);
    return false;
  }
  return true;
}
 
Example 21
Source Project: EasyCode   Source File: SaveFile.java    License: MIT License 5 votes vote down vote up
/**
 * 构建对象
 *
 * @param path     路径
 * @param fileName 文件没
 * @param reformat 是否重新格式化代码
 */
public SaveFile(Project project, String path, String fileName, String content, boolean reformat, boolean operateTitle) {
    this.path = path;
    this.project = project;
    // 构建文件对象
    PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
    LOG.assertTrue(content != null);
    FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
    // 换行符统一使用\n
    this.file = psiFileFactory.createFileFromText(fileName, fileType, content.replace("\r", ""));
    this.virtualFile = new LightVirtualFile(fileName, fileType, content.replace("\r", ""));
    this.reformat = reformat;
    this.operateTitle = operateTitle;
}
 
Example 22
Source Project: EasyCode   Source File: TemplateEditor.java    License: MIT License 5 votes vote down vote up
/**
 * 重置
 *
 * @param name    模板名称
 * @param content 文本内容
 */
public void reset(String name, String content) {
    if (content != null && this.editor != null) {
        // 重置语法高亮
        ((EditorEx) editor).setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(project, new LightVirtualFile(name + ".ft")));
        // 重置文本内容
        WriteCommandAction.runWriteCommandAction(project, () -> this.editor.getDocument().setText(content));
    }
}
 
Example 23
Source Project: litho   Source File: OnEventGenerateActionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void createHandler_generateOnEvent() {
  testHelper.getPsiClass(
      classes -> {
        final CodeInsightTestFixture fixture = testHelper.getFixture();
        final PsiFile psiFile = classes.get(0).getContainingFile();
        final LightVirtualFile virtualFile =
            new LightVirtualFile(psiFile.getName(), psiFile.getFileType(), psiFile.getText());
        final String generatedOnEvent =
            "@com.facebook.litho.annotations.OnEvent(TestClass.class)\n"
                + "    static void onTestClass(com.facebook.litho.ComponentContext c) {\n"
                + "    }";
        final PsiClass eventClass =
            JavaPsiFacade.getInstance(fixture.getProject())
                .getElementFactory()
                .createClass("TestClass");

        fixture.openFileInEditor(virtualFile);

        assertThat(fixture.getEditor().getDocument().getText()).doesNotContain(generatedOnEvent);

        TransactionGuard.getInstance()
            .submitTransactionAndWait(
                () ->
                    OnEventGenerateAction.createHandler(
                            (context, project) -> eventClass,
                            onEvent -> {
                              assertThat(onEvent.getName()).isEqualTo("onTestClass");
                              assertThat(onEvent.getAnnotations()[0].getQualifiedName())
                                  .isEqualTo("com.facebook.litho.annotations.OnEvent");
                            })
                        .invoke(fixture.getProject(), fixture.getEditor(), fixture.getFile()));

        assertThat(fixture.getEditor().getDocument().getText()).contains(generatedOnEvent);
        return true;
      },
      "LayoutSpec.java");
}
 
Example 24
Source Project: litho   Source File: OnEventCreateFixTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void invoke() {
  testHelper.getPsiClass(
      classes -> {
        final CodeInsightTestFixture fixture = testHelper.getFixture();
        final PsiMethodCallExpression call =
            PsiTreeUtil.findChildOfType(classes.get(0), PsiMethodCallExpression.class);
        final LightVirtualFile virtualFile = createVirtualFile(classes.get(0));
        final String generatedOnEvent =
            "@com.facebook.litho.annotations.OnEvent(TestClass.class)\n"
                + "    static void onTestClass(com.facebook.litho.ComponentContext c) {\n"
                + "    }";
        final PsiClass eventClass =
            JavaPsiFacade.getInstance(fixture.getProject())
                .getElementFactory()
                .createClass("TestClass");

        fixture.openFileInEditor(virtualFile);

        assertThat(fixture.getEditor().getDocument().getText()).doesNotContain(generatedOnEvent);

        AddArgumentFix.createNewMethodCallFix(
                call, "TestName", eventClass, Mockito.mock(PsiClass.class))
            .invoke(fixture.getProject(), fixture.getEditor(), fixture.getFile());

        assertThat(fixture.getEditor().getDocument().getText()).contains(generatedOnEvent);
        assertThat(call.getArgumentList().getExpressions()[0].getText())
            .isEqualTo("TestName.onTestClass()");
        return true;
      },
      "EventHandlerAnnotatorSpec.java");
}
 
Example 25
Source Project: idea-php-typo3-plugin   Source File: FluidLanguageSubstitutor.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public Language getLanguage(@NotNull VirtualFile file, @NotNull Project project) {
    if (FluidConfig.shouldOpenHtmlAsFluid(project) && file.getFileType() == HtmlFileType.INSTANCE) {
        if (file instanceof LightVirtualFile) {
            return null;
        }

        return FluidLanguage.INSTANCE;
    }

    return null;
}
 
Example 26
public BPMNFileEditor(@NotNull final Project project, @NotNull final VirtualFile file) {
    final VirtualFile vf = file instanceof LightVirtualFile ? ((LightVirtualFile) file).getOriginalFile() : file;
    final Module module = ModuleUtilCore.findModuleForFile(vf, project);
    if (module == null) {
        throw new IllegalArgumentException("No module for file " + file + " in project " + project);
    }
    this.myFile = file;
    this.myDocument = FileDocumentManager.getInstance().getDocument(file);
    this.myProject = project;
    this.editor = new BPMNEditorDiagramTab(this, project, module, file);
}
 
Example 27
@Nullable
public static Document lookupDocument(String path, Project project) {
  final String fileName = InspectorService.fromSourceLocationUri(path, project);

  final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(fileName);
  if (virtualFile != null && virtualFile.exists() &&
      !(virtualFile instanceof LightVirtualFile) && !(virtualFile instanceof HttpVirtualFile)) {
    return FileDocumentManager.getInstance().getDocument(virtualFile);
  }

  return null;
}
 
Example 28
public static boolean couldContainWidgets(@Nullable VirtualFile file) {
  // Skip temp file used to show things like files downloaded from the VM.
  if (file instanceof LightVirtualFile) {
    return false;
  }
  // TODO(jacobr): we might also want to filter for files not under the current project root.
  return file != null && isDartFile(file);
}
 
Example 29
@Nullable
public static Document lookupDocument(String path, Project project) {
  final String fileName = InspectorService.fromSourceLocationUri(path, project);

  final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(fileName);
  if (virtualFile != null && virtualFile.exists() &&
      !(virtualFile instanceof LightVirtualFile) && !(virtualFile instanceof HttpVirtualFile)) {
    return FileDocumentManager.getInstance().getDocument(virtualFile);
  }

  return null;
}
 
Example 30
@Nullable
private static LightVirtualFile createSnapshot(@NotNull Script script) {
  // LightVirtualFiles have no parent directory, so just use the filename.
  final String filename = PathUtil.getFileName(script.getUri());
  final String scriptSource = script.getSource();
  if (scriptSource == null) {
    return null;
  }

  final LightVirtualFile snapshot = new LightVirtualFile(filename, DartFileType.INSTANCE, scriptSource);
  snapshot.setWritable(false);
  return snapshot;
}