當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。