Java 类com.intellij.psi.FileViewProvider 实例源码

项目:lua-for-idea    文件:LuaPsiManager.java   
private void processRoot(final List<InferenceCapable> files, VirtualFile f) {
    LuaFileUtil.iterateLuaFilesRecursively(f, new ContentIterator() {
        @Override
        public boolean processFile(VirtualFile fileOrDir) {
            ProgressManager.checkCanceled();

            log.debug("process " + fileOrDir.getName());
            if (fileOrDir.isDirectory()) return true;

            indicator.setText2(fileOrDir.getPresentableName());
            final FileViewProvider viewProvider = p.findViewProvider(fileOrDir);
            if (viewProvider == null) return true;

            final PsiFile psiFile = viewProvider.getPsi(viewProvider.getBaseLanguage());
            if (!(psiFile instanceof InferenceCapable)) return true;

            indicator.setText2(fileOrDir.getName());
            log.debug("forcing inference for: " + fileOrDir.getName());

            files.add((InferenceCapable) psiFile);

            return true;
        }
    });
}
项目:intellij-ce-playground    文件:Divider.java   
public static void divideInsideAndOutside(@NotNull PsiFile file,
                                          int startOffset,
                                          int endOffset,
                                          @NotNull TextRange range,
                                          @NotNull List<PsiElement> inside,
                                          @NotNull List<ProperTextRange> insideRanges,
                                          @NotNull List<PsiElement> outside,
                                          @NotNull List<ProperTextRange> outsideRanges,
                                          boolean includeParents,
                                          @NotNull Condition<PsiFile> filter) {
  final FileViewProvider viewProvider = file.getViewProvider();
  for (Language language : viewProvider.getLanguages()) {
    final PsiFile psiRoot = viewProvider.getPsi(language);
    if (filter.value(psiRoot)) {
      divideInsideAndOutside(psiRoot, startOffset, endOffset, range, inside, insideRanges, outside, outsideRanges, includeParents);
    }
  }
}
项目:intellij-ce-playground    文件:TemplateLanguageFormattingModelBuilder.java   
protected Block getRootBlock(PsiElement element, FileViewProvider viewProvider, CodeStyleSettings settings) {
  ASTNode node = element.getNode();
  if (node == null) {
    return createDummyBlock(node);
  }
  if (viewProvider instanceof TemplateLanguageFileViewProvider) {
    final Language dataLanguage = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage();
    final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(dataLanguage);
    if (builder instanceof DelegatingFormattingModelBuilder && ((DelegatingFormattingModelBuilder)builder).dontFormatMyModel()) {
      return createDummyBlock(node);
    }
    if (builder != null) {
      final FormattingModel model = builder.createModel(viewProvider.getPsi(dataLanguage), settings);
      List<DataLanguageBlockWrapper> childWrappers = buildChildWrappers(model.getRootBlock());
      if (childWrappers.size() == 1) {
        childWrappers = buildChildWrappers(childWrappers.get(0).getOriginal());
      }
      return createTemplateLanguageBlock(node, Wrap.createWrap(WrapType.NONE, false), null,
                                         filterBlocksByRange(childWrappers, node.getTextRange()), settings);
    }
  }
  return createTemplateLanguageBlock(node,  Wrap.createWrap(WrapType.NONE, false), null, Collections.<DataLanguageBlockWrapper>emptyList(), settings);
}
项目:intellij-ce-playground    文件:LossyEncodingInspection.java   
@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
  if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) return null;
  if (!file.isPhysical()) return null;
  FileViewProvider viewProvider = file.getViewProvider();
  if (viewProvider.getBaseLanguage() != file.getLanguage()) return null;
  VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return null;
  if (!virtualFile.isInLocalFileSystem()) return null;
  CharSequence text = viewProvider.getContents();
  Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text);

  // no sense in checking transparently decoded file: all characters there are already safely encoded
  if (charset instanceof Native2AsciiCharset) return null;

  List<ProblemDescriptor> descriptors = new SmartList<ProblemDescriptor>();
  boolean ok = checkFileLoadedInWrongEncoding(file, manager, isOnTheFly, virtualFile, charset, descriptors);
  if (ok) {
    checkIfCharactersWillBeLostAfterSave(file, manager, isOnTheFly, text, charset, descriptors);
  }

  return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
项目:intellij-ce-playground    文件:SlowLineMarkersPass.java   
@Override
public void doCollectInformation(@NotNull ProgressIndicator progress) {
  final FileViewProvider viewProvider = myFile.getViewProvider();
  final Set<Language> relevantLanguages = viewProvider.getLanguages();
  List<LineMarkerInfo> markers = new SmartList<LineMarkerInfo>();
  for (Language language : relevantLanguages) {
    PsiElement psiRoot = viewProvider.getPsi(language);
    if (psiRoot == null || !HighlightingLevelManager.getInstance(myProject).shouldHighlight(psiRoot)) continue;
    List<PsiElement> elements = CollectHighlightsUtil.getElementsInRange(psiRoot, myBounds.getStartOffset(), myBounds.getEndOffset());
    final List<LineMarkerProvider> providers = LineMarkersPass.getMarkerProviders(language, myProject);
    addLineMarkers(elements, providers, markers, progress);
    LineMarkersPass.collectLineMarkersForInjected(markers, elements, this, myFile, progress);
  }

  myMarkers = LineMarkersPass.mergeLineMarkers(markers, myEditor);
}
项目:intellij-ce-playground    文件:ChangeTemplateDataLanguageAction.java   
@Override
public void update(final AnActionEvent e) {
  e.getPresentation().setVisible(false);

  VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
  VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
  if (files != null && files.length > 1) {
    virtualFile = null;
  }
  if (virtualFile == null || virtualFile.isDirectory()) return;

  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return;

  final FileViewProvider provider = PsiManager.getInstance(project).findViewProvider(virtualFile);
  if (provider instanceof ConfigurableTemplateLanguageFileViewProvider) {
    final TemplateLanguageFileViewProvider viewProvider = (TemplateLanguageFileViewProvider)provider;

    e.getPresentation().setText(LangBundle.message("quickfix.change.template.data.language.text", viewProvider.getTemplateDataLanguage().getDisplayName()));
    e.getPresentation().setEnabled(true);
    e.getPresentation().setVisible(true);
  }

}
项目:intellij-ce-playground    文件:InjectedPsiCachedValueProvider.java   
@Override
public CachedValueProvider.Result<MultiHostRegistrarImpl> compute(PsiElement element) {
  PsiFile hostPsiFile = element.getContainingFile();
  if (hostPsiFile == null) return null;
  FileViewProvider viewProvider = hostPsiFile.getViewProvider();
  final DocumentEx hostDocument = (DocumentEx)viewProvider.getDocument();
  if (hostDocument == null) return null;

  PsiManager psiManager = viewProvider.getManager();
  final Project project = psiManager.getProject();
  InjectedLanguageManagerImpl injectedManager = InjectedLanguageManagerImpl.getInstanceImpl(project);

  final MultiHostRegistrarImpl result = doCompute(element, injectedManager, project, hostPsiFile);

  return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT, hostDocument);
}
项目:bamboo-soy    文件:SoyFileViewProviderFactory.java   
@NotNull
@Override
public FileViewProvider createFileViewProvider(
    @NotNull VirtualFile virtualFile,
    Language language,
    @NotNull PsiManager psiManager,
    boolean eventSystemEnabled) {
  assert language.isKindOf(SoyLanguage.INSTANCE);
  return new SoyFileViewProvider(psiManager, virtualFile, eventSystemEnabled);
}
项目:mule-intellij-plugins    文件:MelParserDefinition.java   
@Override
public PsiFile createFile(FileViewProvider fileViewProvider) {
    if (fileViewProvider != null) {
        return new MelFile(fileViewProvider);
    } else {
        throw new RuntimeException("Invalid file viewer null!!!");
    }
}
项目:mule-intellij-plugins    文件:WeaveParserDefinition.java   
@Override
public PsiFile createFile(FileViewProvider viewProvider) {
    if (viewProvider != null) {
        return new WeaveFile(viewProvider);
    } else {
        throw new RuntimeException("Invalid file viewer null!!!");
    }
}
项目:intellij-ce-playground    文件:XmlAutoPopupHandler.java   
public static void autoPopupXmlLookup(final Project project, final Editor editor){
  AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, new Condition<PsiFile>() {
    @Override
    public boolean value(PsiFile file) {
      int offset = editor.getCaretModel().getOffset();

      PsiElement lastElement = InjectedLanguageUtil.findElementAtNoCommit(file, offset - 1);
      if (lastElement instanceof PsiFile) { //the very end of an injected file
        lastElement = file.findElementAt(offset - 1);
      }
      if (lastElement == null || !lastElement.isValid()) return false;

      if (doCompleteIfNeeded(offset, file, lastElement)) {
        return true;
      }

      FileViewProvider fileViewProvider = file.getViewProvider();
      Language templateDataLanguage;

      final PsiElement parent = lastElement.getParent();
      if (fileViewProvider instanceof TemplateLanguageFileViewProvider &&
          (templateDataLanguage = ((TemplateLanguageFileViewProvider)fileViewProvider).getTemplateDataLanguage()) != parent.getLanguage()) {
        lastElement = fileViewProvider.findElementAt(offset - 1, templateDataLanguage);
        if (lastElement == null || !lastElement.isValid()) return false;
        return doCompleteIfNeeded(offset, file, lastElement);
      }
      return false;
    }
  });
}
项目:rythm_plugin    文件:RythmFileViewProviderFactory.java   
@NotNull
@Override
public FileViewProvider createFileViewProvider(@NotNull VirtualFile virtualFile,
                                               Language language,
                                               @NotNull PsiManager psiManager,
                                               boolean eventSystemEnabled){
  assert language.isKindOf(RythmLanguage.INSTANCE);
    return new RythmFileViewProvider(psiManager, virtualFile, eventSystemEnabled, language);
}
项目:epigraph    文件:SchemaRetroTagLinePainter.java   
@Override
public Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project, @NotNull VirtualFile file, int lineNumber) {
  List<LineExtensionInfo> res = ContainerUtil.newSmartList();

  PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
  final Document doc = FileDocumentManager.getInstance().getDocument(file);
  if (doc != null && lineNumber < doc.getLineCount()) {
    PsiFile psiFile = psiDocumentManager.getPsiFile(doc);
    if (psiFile != null) {
      int offset = doc.getLineStartOffset(lineNumber);
      FileViewProvider viewProvider = psiFile.getViewProvider();

      PsiElement element = viewProvider.findElementAt(offset);
      while (element != null) {
        int startOffset = element.getTextRange().getStartOffset();
        if (startOffset >= doc.getTextLength()) break;

        int startOffsetLine = doc.getLineNumber(startOffset);

        if (startOffsetLine < lineNumber) {
          element = PsiTreeUtil.nextVisibleLeaf(element);
          continue;
        }

        if (startOffsetLine > lineNumber) break;

        try {
          element = addExtensions(res, element);
        } catch (IndexNotReadyException ignored) { element = null; }
      }
    }
  }

  return res;
}
项目:intellij-ce-playground    文件:BuiltInWebBrowserUrlProvider.java   
@Override
public boolean canHandleElement(@NotNull OpenInBrowserRequest request) {
  if (request.getVirtualFile() instanceof HttpVirtualFile) {
    return true;
  }

  // we must use base language because we serve file - not part of file, but the whole file
  // handlebars, for example, contains HTML and HBS psi trees, so, regardless of context, we should not handle such file
  FileViewProvider viewProvider = request.getFile().getViewProvider();
  return viewProvider.isPhysical() &&
         !(request.getVirtualFile() instanceof LightVirtualFile) &&
         isMyLanguage(viewProvider.getBaseLanguage());
}
项目:intellij-ce-playground    文件:PsiFileBase.java   
protected PsiFileBase(@NotNull FileViewProvider viewProvider, @NotNull Language language) {
  super(viewProvider);
  myLanguage = findLanguage(language, viewProvider);
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(myLanguage);
  if (parserDefinition == null) {
    throw new RuntimeException("PsiFileBase: language.getParserDefinition() returned null for: "+myLanguage);
  }
  myParserDefinition = parserDefinition;
  final IFileElementType nodeType = parserDefinition.getFileNodeType();
  assert nodeType.getLanguage() == myLanguage: nodeType.getLanguage() + " != " + myLanguage;
  init(nodeType, nodeType);
}
项目:intellij-ce-playground    文件:EmptyFileManager.java   
@Override
public void setViewProvider(@NotNull final VirtualFile virtualFile, final FileViewProvider singleRootFileViewProvider) {
  if (!(virtualFile instanceof VirtualFileWindow)) {
    if (singleRootFileViewProvider == null) {
      myVFileToViewProviderMap.remove(virtualFile);
    }
    else {
      myVFileToViewProviderMap.put(virtualFile, singleRootFileViewProvider);
    }
  }
}
项目:intellij-ce-playground    文件:XPathUsageSearcher.java   
protected void processXmlFile(VirtualFile t) {
    myIndicator.setText(findBundleMessage("find.searching.for.string.in.file.progress", myExpression.expression, t.getPresentableUrl()));

    final PsiFile psiFile = myManager.findFile(t);
    if (psiFile instanceof XmlFile) {
        final XmlFile t1 = (XmlFile)psiFile;
        final XmlDocument document;
        FileViewProvider fileViewProvider = t1.getViewProvider();

        if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
            final PsiFile root = fileViewProvider.getPsi(((TemplateLanguageFileViewProvider)fileViewProvider).getTemplateDataLanguage());

            if (root instanceof XmlFile) {
                document = ((XmlFile)root).getDocument();
            } else {
                document = null;
            }
        } else {
            document = t1.getDocument();
        }
        if (document != null) {
            process(document);
        }
    }

    myIndicator.setFraction(++myFileCount / (double)myTotalFileCount);
}
项目:intellij-ce-playground    文件:SelectWordUtil.java   
public static void processRanges(@Nullable PsiElement element,
                                 CharSequence text,
                                 int cursorOffset,
                                 Editor editor,
                                 Processor<TextRange> consumer) {
  if (element == null) return;

  PsiFile file = element.getContainingFile();

  FileViewProvider viewProvider = file.getViewProvider();

  processInFile(element, consumer, text, cursorOffset, editor);

  for (PsiFile psiFile : viewProvider.getAllFiles()) {
    if (psiFile == file) continue;

    FileASTNode fileNode = psiFile.getNode();
    if (fileNode == null) continue;

    ASTNode nodeAt = fileNode.findLeafElementAt(element.getTextOffset());
    if (nodeAt == null) continue;

    PsiElement elementAt = nodeAt.getPsi();

    while (!(elementAt instanceof PsiFile) && elementAt != null) {
      if (elementAt.getTextRange().contains(element.getTextRange())) break;

      elementAt = elementAt.getParent();
    }

    if (elementAt == null) continue;

    processInFile(elementAt, consumer, text, cursorOffset, editor);
  }
}
项目:intellij-ce-playground    文件:PsiDocumentManagerImpl.java   
@Override
public void doPostponedOperationsAndUnblockDocument(@NotNull Document doc) {
  if (doc instanceof DocumentWindow) doc = ((DocumentWindow)doc).getDelegate();
  final PostprocessReformattingAspect component = myProject.getComponent(PostprocessReformattingAspect.class);
  final FileViewProvider viewProvider = getCachedViewProvider(doc);
  if (viewProvider != null && component != null) component.doPostponedFormatting(viewProvider);
}
项目:intellij-ce-playground    文件:TemplateLanguageErrorQuickFixProvider.java   
@Override
public void registerErrorQuickFix(@NotNull final PsiErrorElement errorElement, @NotNull final HighlightInfo highlightInfo) {
  final PsiFile psiFile = errorElement.getContainingFile();
  final FileViewProvider provider = psiFile.getViewProvider();
  if (!(provider instanceof TemplateLanguageFileViewProvider)) return;
  if (psiFile.getLanguage() != ((TemplateLanguageFileViewProvider) provider).getTemplateDataLanguage()) return;

  QuickFixAction.registerQuickFixAction(highlightInfo, createChangeTemplateDataLanguageFix(errorElement));

}
项目:intellij-ce-playground    文件:SimpleTemplateLanguageFormattingModelBuilder.java   
@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
  if (element instanceof PsiFile) {
    final FileViewProvider viewProvider = ((PsiFile)element).getViewProvider();
    if (viewProvider instanceof TemplateLanguageFileViewProvider) {
      final Language language = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage();
      FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(language);
      if (builder != null) {
        return builder.createModel(viewProvider.getPsi(language), settings);
      }
    }
  }

  final PsiFile file = element.getContainingFile();
  return new DocumentBasedFormattingModel(new AbstractBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) {
    @Override
    protected List<Block> buildChildren() {
      return Collections.emptyList();
    }

    @Override
    public Spacing getSpacing(final Block child1, @NotNull final Block child2) {
      return Spacing.getReadOnlySpacing();
    }

    @Override
    public boolean isLeaf() {
      return true;
    }
  }, element.getProject(), settings, file.getFileType(), file);
}
项目:TS-IJ    文件:TSParserDefinition.java   
@Override
public PsiFile createFile(FileViewProvider fileViewProvider) {
    return new TSFile(fileViewProvider);
}
项目:TS-IJ    文件:TSFile.java   
protected TSFile(@NotNull FileViewProvider viewProvider) {
    super(viewProvider, TSLanguage.INSTANCE);
}
项目:AppleScript-IDEA    文件:AppleScriptFile.java   
public AppleScriptFile(@NotNull FileViewProvider viewProvider) {
  super(viewProvider, com.intellij.plugin.applescript.AppleScriptLanguage.INSTANCE);
}
项目:AppleScript-IDEA    文件:AppleScriptParserDefinition.java   
public PsiFile createFile(FileViewProvider viewProvider) {
  return new AppleScriptFile(viewProvider);
}
项目:reasonml-idea-plugin    文件:RmlParserDefinition.java   
public PsiFile createFile(FileViewProvider viewProvider) {
    return new RmlFile(viewProvider);
}
项目:reasonml-idea-plugin    文件:OclP4ParserDefinition.java   
public PsiFile createFile(FileViewProvider viewProvider) {
    return new Ml4File(viewProvider);
}
项目:reasonml-idea-plugin    文件:OclParserDefinition.java   
public PsiFile createFile(FileViewProvider viewProvider) {
    return new OclFile(viewProvider);
}
项目:reasonml-idea-plugin    文件:RmlFile.java   
public RmlFile(@NotNull FileViewProvider viewProvider) {
    super(viewProvider, RmlLanguage.INSTANCE);
}
项目:reasonml-idea-plugin    文件:FileBase.java   
FileBase(@NotNull FileViewProvider viewProvider, @NotNull Language language) {
    super(viewProvider, language);
    m_moduleName = RmlPsiUtil.fileNameToModuleName(getName());
}
项目:reasonml-idea-plugin    文件:Ml4File.java   
public Ml4File(@NotNull FileViewProvider viewProvider) {
    super(viewProvider, OclLanguage.INSTANCE);
}
项目:reasonml-idea-plugin    文件:OclFile.java   
public OclFile(@NotNull FileViewProvider viewProvider) {
    super(viewProvider, OclLanguage.INSTANCE);
}
项目:greycat-idea-plugin    文件:GCMParserDefinition.java   
public PsiFile createFile(FileViewProvider viewProvider) {
    return new GCMFile(viewProvider);
}
项目:greycat-idea-plugin    文件:GCMFile.java   
public GCMFile(@NotNull FileViewProvider viewProvider) {
    super(viewProvider, GCMLanguage.INSTANCE);
}
项目:bamboo-soy    文件:SoyParserDefinition.java   
public PsiFile createFile(FileViewProvider viewProvider) {
  return new SoyFile(viewProvider);
}
项目:bamboo-soy    文件:SoyFile.java   
public SoyFile(@NotNull FileViewProvider viewProvider) {
  super(viewProvider, SoyLanguage.INSTANCE);
}
项目:idea-php-dotenv-plugin    文件:DotEnvFile.java   
public DotEnvFile(@NotNull FileViewProvider viewProvider) {
    super(viewProvider, DotEnvLanguage.INSTANCE);
}
项目:EmojiPrefix    文件:EmojiResourceFile.java   
protected EmojiResourceFile(@NotNull FileViewProvider viewProvider) {
    super(viewProvider, EmojiResourceLanguage.INSTANCE);
}
项目:EmojiPrefix    文件:EmojiResourceParserDefinition.java   
@Override
public PsiFile createFile(FileViewProvider fileViewProvider) {
    return new EmojiResourceFile(fileViewProvider);
}
项目:intellij-postfix-templates    文件:CptFile.java   
public CptFile(@NotNull FileViewProvider viewProvider) {
    super(viewProvider, CptLanguage.INSTANCE);
}