当前位置: 首页>>代码示例>>Java>>正文


Java PsiDocumentManager类代码示例

本文整理汇总了Java中com.intellij.psi.PsiDocumentManager的典型用法代码示例。如果您正苦于以下问题:Java PsiDocumentManager类的具体用法?Java PsiDocumentManager怎么用?Java PsiDocumentManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PsiDocumentManager类属于com.intellij.psi包,在下文中一共展示了PsiDocumentManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: actionPerformed

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
    RefmtManager refmt = RefmtManager.getInstance();
    if (refmt != null) {
        PsiFile file = e.getData(PSI_FILE);
        Project project = e.getProject();
        if (project != null && file != null && (file instanceof OclFile || file instanceof RmlFile)) {
            String format = file instanceof OclFile ? "ml" : "re";
            Document document = PsiDocumentManager.getInstance(project).getDocument(file);
            if (document != null) {
                //WriteCommandAction.writeCommandAction(project).run(() -> refmt.refmt(project, format, document));
                WriteCommandAction.runWriteCommandAction(project, () -> refmt.refmt(project, format, document)); // idea#143
            }
        }
    }
}
 
开发者ID:reasonml-editor,项目名称:reasonml-idea-plugin,代码行数:17,代码来源:RefmtAction.java

示例2: execute

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
  myOriginalHandler.execute(editor, charTyped, dataContext);
  if (isMatchForClosingTag(editor, charTyped)) {
    int offset = editor.getCaretModel().getOffset();
    PsiFile file = dataContext.getData(LangDataKeys.PSI_FILE);
    if (file == null) {
      return;
    }
    PsiElement el = file.findElementAt(offset - 1);
    TagBlockElement block = (TagBlockElement) PsiTreeUtil
        .findFirstParent(el,
            parent -> parent instanceof TagBlockElement && !(parent instanceof SoyChoiceClause));
    if (block == null) {
      return;
    }
    String closingTag = block.getOpeningTag().generateClosingTag();
    insertClosingTag(editor, offset, closingTag);
    if (editor.getProject() != null) {
      PsiDocumentManager.getInstance(editor.getProject()).commitDocument(editor.getDocument());
      CodeStyleManager.getInstance(editor.getProject()).reformat(block);
    }
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:24,代码来源:ClosingTagHandler.java

示例3: applyFix

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    try {
        PsiElement element = descriptor.getPsiElement();
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        List<Integer> quotePositions = new ArrayList<>();

        int quotePosition = CsvIntentionHelper.getOpeningQuotePosition(element);
        if (quotePosition != -1) {
            quotePositions.add(quotePosition);
        }
        PsiElement endSeparatorElement = CsvIntentionHelper.findQuotePositionsUntilSeparator(element, quotePositions);
        if (endSeparatorElement == null) {
            quotePositions.add(document.getTextLength());
        } else {
            quotePositions.add(endSeparatorElement.getTextOffset());
        }
        String text = CsvIntentionHelper.addQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
开发者ID:SeeSharpSoft,项目名称:intellij-csv-validator,代码行数:24,代码来源:CsvValidationInspection.java

示例4: unquoteAll

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
public static void unquoteAll(@NotNull Project project, @NotNull PsiFile psiFile) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
        List<Integer> quotePositions = new ArrayList<>();
        Collection<PsiElement> fields = getAllFields(psiFile);
        for (PsiElement field : fields) {
            if (getChildren(field).stream().anyMatch(element -> getElementType(element) == CsvTypes.ESCAPED_TEXT)) {
                continue;
            }
            if (getElementType(field.getFirstChild()) == CsvTypes.QUOTE) {
                quotePositions.add(field.getFirstChild().getTextOffset());
            }
            if (getElementType(field.getLastChild()) == CsvTypes.QUOTE) {
                quotePositions.add(field.getLastChild().getTextOffset());
            }
        }
        String text = removeQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
开发者ID:SeeSharpSoft,项目名称:intellij-csv-validator,代码行数:23,代码来源:CsvIntentionHelper.java

示例5: quoteValue

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
public static void quoteValue(@NotNull Project project, @NotNull PsiElement element) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        List<Integer> quotePositions = new ArrayList<>();

        element = getParentFieldElement(element);
        int quotePosition = getOpeningQuotePosition(element.getFirstChild(), element.getLastChild());
        if (quotePosition != -1) {
            quotePositions.add(quotePosition);
        }
        PsiElement endSeparatorElement = findQuotePositionsUntilSeparator(element, quotePositions);
        if (endSeparatorElement == null) {
            quotePositions.add(document.getTextLength());
        } else {
            quotePositions.add(endSeparatorElement.getTextOffset());
        }
        String text = addQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
开发者ID:SeeSharpSoft,项目名称:intellij-csv-validator,代码行数:23,代码来源:CsvIntentionHelper.java

示例6: unquoteValue

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
public static void unquoteValue(@NotNull Project project, @NotNull PsiElement element) {
    try {
        Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
        List<Integer> quotePositions = new ArrayList<>();

        element = getParentFieldElement(element);
        if (getElementType(element.getFirstChild()) == CsvTypes.QUOTE) {
            quotePositions.add(element.getFirstChild().getTextOffset());
        }
        if (getElementType(element.getLastChild()) == CsvTypes.QUOTE) {
            quotePositions.add(element.getLastChild().getTextOffset());
        }
        String text = removeQuotes(document.getText(), quotePositions);
        document.setText(text);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
    }
}
 
开发者ID:SeeSharpSoft,项目名称:intellij-csv-validator,代码行数:19,代码来源:CsvIntentionHelper.java

示例7: updateForEditor

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
protected void updateForEditor(DataContext dataContext, Presentation presentation) {
  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  if (editor == null) {
    presentation.setVisible(false);
    return;
  }

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

  }
  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());

  PsiElement element = getTargetElement(editor, project);
  boolean result = element != null && CopyHandler.canCopy(new PsiElement[]{element});

  if (!result && file != null) {
    result = CopyHandler.canCopy(new PsiElement[]{file});
  }

  presentation.setEnabled(result);
  presentation.setVisible(true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:CopyElementAction.java

示例8: actionPerformed

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  DataContext dataContext = event.getDataContext();
  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  if (project == null || editor == null) {
    presentation.setEnabled(false);
    return;
  }

  PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (file == null || file.getVirtualFile() == null) {
    presentation.setEnabled(false);
    return;
  }

  boolean hasSelection = editor.getSelectionModel().hasSelection();
  LayoutCodeDialog dialog = new LayoutCodeDialog(project, file, hasSelection, HELP_ID);
  dialog.show();

  if (dialog.isOK()) {
    new FileInEditorProcessor(file, editor, dialog.getRunOptions()).processCode();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:ShowReformatFileDialog.java

示例9: handleMappingChange

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
private void handleMappingChange(Collection<VirtualFile> files, Collection<VirtualFile> oldFiles, boolean includeOpenFiles) {
  Project project = getProject();
  FilePropertyPusher<T> pusher = getFilePropertyPusher();
  if (project != null && pusher != null) {
    for (VirtualFile oldFile : oldFiles) {
      if (oldFile == null) continue; // project
      oldFile.putUserData(pusher.getFileDataKey(), null);
    }
    if (!project.isDefault()) {
      PushedFilePropertiesUpdater.getInstance(project).pushAll(pusher);
    }
  }
  if (shouldReparseFiles()) {
    Project[] projects = project == null ? ProjectManager.getInstance().getOpenProjects() : new Project[] { project };
    for (Project p : projects) {
      PsiDocumentManager.getInstance(p).reparseFiles(files, includeOpenFiles);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PerFileMappingsBase.java

示例10: createErrorAnnotations

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
private void createErrorAnnotations(PsiElement element, PsiFile file, AnnotationHolder holder, List<RuntimeException> annotationResult) {
    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if (document == null) {
        return;
    }
    PsiElement psiElementWithError = element;
    for (RuntimeException exception : annotationResult) {
        if (exception instanceof LocatedRuntimeException) {
            LocatedRuntimeException locatedException = (LocatedRuntimeException) exception;
            PsiElement childAtLine = file.findElementAt(document.getLineStartOffset(locatedException.getLineNumber() - 1));
            if (childAtLine != null) {
                psiElementWithError = childAtLine;
            }
        }
        holder.createErrorAnnotation(psiElementWithError, exception.getMessage());
    }
}
 
开发者ID:CloudSlang,项目名称:cs-intellij-plugin,代码行数:18,代码来源:ExecutableAnnotator.java

示例11: setStateImpl

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
@Override
protected void setStateImpl(final Project project, final Editor editor, final TextEditorState state) {
  super.setStateImpl(project, editor, state);
  // Folding
  final CodeFoldingState foldState = state.getFoldingState();
  if (project != null && foldState != null) {
    new WriteAction() {
      @Override
      protected void run(@NotNull Result result) throws Throwable {
        PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
        editor.getFoldingModel().runBatchFoldingOperation(
          new Runnable() {
            @Override
            public void run() {
              CodeFoldingManager.getInstance(project).restoreFoldingState(editor, foldState);
            }
          }
        );
      }
    }.execute();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PsiAwareTextEditorProvider.java

示例12: getPasses

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
@NotNull
List<TextEditorHighlightingPass> getPasses(@NotNull int[] passesToIgnore) {
  if (myProject.isDisposed()) return Collections.emptyList();
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();
  renewFile();
  if (myFile == null) return Collections.emptyList();
  if (myCompiled) {
    passesToIgnore = EXCEPT_OVERRIDDEN;
  }
  else if (!DaemonCodeAnalyzer.getInstance(myProject).isHighlightingAvailable(myFile)) {
    return Collections.emptyList();
  }

  TextEditorHighlightingPassRegistrarEx passRegistrar = TextEditorHighlightingPassRegistrarEx.getInstanceEx(myProject);

  return passRegistrar.instantiatePasses(myFile, myEditor, passesToIgnore);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:TextEditorBackgroundHighlighter.java

示例13: getDescription

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
@Override
public String getDescription(@NotNull final String refSuffix, @NotNull final Editor editor) {
  final Project project = editor.getProject();
  if (project == null) {
    LOG.error(editor);
    return null;
  }
  if (project.isDisposed()) return null;
  final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (file == null) {
    return null;
  }

  final InspectionProfile profile = (InspectionProfile)InspectionProfileManager.getInstance().getRootProfile();
  final InspectionToolWrapper toolWrapper = profile.getInspectionTool(refSuffix, file);
  if (toolWrapper == null) return null;

  String description = toolWrapper.loadDescription();
  if (description == null) {
    LOG.warn("No description for inspection '" + refSuffix + "'");
    description = InspectionsBundle.message("inspection.tool.description.under.construction.text");
  }
  return description;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:InspectionDescriptionLinkHandler.java

示例14: triggerAction

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
public static void triggerAction(Configuration config, SearchContext searchContext) {
  final Project project = searchContext.getProject();
  if (project == null) {
    return;
  }
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  //StructuralSearchPlugin.getInstance(searchContext.getProject());
  final SearchDialog searchDialog = new SearchDialog(searchContext);

  if (config!=null) {
    searchDialog.setUseLastConfiguration(true);
    searchDialog.setValuesFromConfig(config);
  }

  searchDialog.show();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:StructuralSearchAction.java

示例15: onProcessItemViewBinder

import com.intellij.psi.PsiDocumentManager; //导入依赖的package包/类
private void onProcessItemViewBinder(final PsiDirectory dir, final String typeName, final PsiClass itemClass) {
    PsiFile file = itemClass.getContainingFile();
    final PsiDocumentManager manager = PsiDocumentManager.getInstance(itemClass.getProject());
    final Document document = manager.getDocument(file);
    if (document == null) {
        return;
    }

    new WriteCommandAction.Simple(itemClass.getProject()) {
        @Override
        protected void run() throws Throwable {
            manager.doPostponedOperationsAndUnblockDocument(document);
            document.setText(document.getText()
                .replace("MTI_CLASS", typeName)
                .replace("MTI_LOWER_NAME", CaseFormat.UPPER_CAMEL.to(LOWER_UNDERSCORE, typeName))
                .replace("MTI_NAME", CaseFormat.UPPER_CAMEL.to(LOWER_CAMEL, typeName)));
            CodeStyleManager.getInstance(itemClass.getProject()).reformat(itemClass);
        }
    }.execute();
}
 
开发者ID:drakeet,项目名称:MultiTypeTemplates,代码行数:21,代码来源:CreateItemFilesAction.java


注:本文中的com.intellij.psi.PsiDocumentManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。