本文整理汇总了Java中com.intellij.psi.PsiDocumentManager.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java PsiDocumentManager.getInstance方法的具体用法?Java PsiDocumentManager.getInstance怎么用?Java PsiDocumentManager.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiDocumentManager
的用法示例。
在下文中一共展示了PsiDocumentManager.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forcePsiPostprocessAndRestoreElement
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
public static <T extends PsiElement> T forcePsiPostprocessAndRestoreElement(@NotNull T element,
boolean useFileLanguage) {
final PsiFile psiFile = element.getContainingFile();
final Document document = psiFile.getViewProvider().getDocument();
//if (document == null) return element;
final Language language = useFileLanguage ? psiFile.getLanguage() : PsiUtilCore.getDialect(element);
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(psiFile.getProject());
final RangeMarker rangeMarker = document.createRangeMarker(element.getTextRange());
documentManager.doPostponedOperationsAndUnblockDocument(document);
documentManager.commitDocument(document);
T elementInRange = findElementInRange(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(),
(Class<? extends T>)element.getClass(),
language);
rangeMarker.dispose();
return elementInRange;
}
示例2: resolveURI
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
public static String resolveURI(PsiFile descriptorFile, String s) {
final PsiFile file = XmlUtil.findXmlFile(descriptorFile, s);
if (file != null) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
final PsiDocumentManager dm = PsiDocumentManager.getInstance(file.getProject());
final Document d = dm.getCachedDocument(file);
if (d != null) {
// TODO: fix. write action + saving -> deadlock
// dm.commitDocument(d);
// FileDocumentManager.getInstance().saveDocument(d);
}
s = reallyFixIDEAUrl(virtualFile.getUrl());
}
}
return s;
}
示例3: addOrReplaceSelectionForEditor
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
protected final void addOrReplaceSelectionForEditor(final String selection, Editor editor) {
final Project project = searchContext.getProject();
UIUtil.setContent(editor, selection, 0, -1, project);
final Document document = editor.getDocument();
editor.getSelectionModel().setSelection(0, document.getTextLength());
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(document);
final PsiFile file = documentManager.getPsiFile(document);
if (file == null) return;
new WriteCommandAction(project, file) {
@Override protected void run(@NotNull Result result) throws Throwable {
CodeStyleManager.getInstance(project).adjustLineIndent(file, new TextRange(0, document.getTextLength()));
}
}.execute();
}
示例4: testXmlDeclDtd
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
public void testXmlDeclDtd() throws Exception {
PsiFile file = createFile("x.xml", "<!DOCTYPE name [\n" +
" <!ELEMENT name (" + marker+ "a b c d" + marker+ ")>\n" +
" <!ELEMENT name2 (" + marker+ "%entity;" + marker+ ")>\n" +
"]>\n" +
"<name></name>");
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
Document document = documentManager.getDocument(file);
removeGarbage(document);
documentManager.commitAllDocuments();
String myFullDataPath = getTestDataPath() + "psi/";
ParsingTestCase.doCheckResult(myFullDataPath, file, true, "testXmlDeclDtd", false, false);
}
示例5: iterateOverCarets
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
private static void iterateOverCarets(@NotNull final Project project,
@NotNull final Editor hostEditor,
@NotNull final MultiCaretCodeInsightActionHandler handler) {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
final PsiFile psiFile = documentManager.getCachedPsiFile(hostEditor.getDocument());
documentManager.commitAllDocuments();
hostEditor.getCaretModel().runForEachCaret(new CaretAction() {
@Override
public void perform(Caret caret) {
Editor editor = hostEditor;
if (psiFile != null) {
Caret injectedCaret = InjectedLanguageUtil.getCaretForInjectedLanguageNoCommit(caret, psiFile);
if (injectedCaret != null) {
caret = injectedCaret;
editor = caret.getEditor();
}
}
final PsiFile file = PsiUtilBase.getPsiFileInEditor(caret, project);
if (file != null) {
handler.invoke(project, editor, caret, file);
}
}
});
}
示例6: reinitDocumentIndentOptions
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
private void reinitDocumentIndentOptions() {
if (myEditor == null) return;
final Project project = myEditor.getProject();
final DocumentEx document = myEditor.getDocument();
if (project == null || project.isDisposed()) return;
final PsiDocumentManager psiManager = PsiDocumentManager.getInstance(project);
final PsiFile file = psiManager.getPsiFile(document);
if (file == null) return;
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptionsByFile(file);
if (CodeStyleSettings.isRecalculateForCommittedDocument(options)) {
PsiDocumentManager.getInstance(project).performForCommittedDocument(document, new Runnable() {
@Override
public void run() {
CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
}
});
}
else {
CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
}
}
示例7: indentBlock
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
static void indentBlock(Project project, Editor editor, final int startOffset, final int endOffset, int originalCaretCol) {
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitAllDocuments();
final Document document = editor.getDocument();
PsiFile file = documentManager.getPsiFile(document);
if (file == null) {
return;
}
if (LanguageFormatting.INSTANCE.forContext(file) != null) {
indentBlockWithFormatter(project, document, startOffset, endOffset, file);
}
else {
indentPlainTextBlock(document, startOffset, endOffset, originalCaretCol);
}
}
示例8: isEnabled
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
if (editor.isViewer() || editor.isOneLineMode()) return false;
final Project project = editor.getProject();
if (project == null || project.isDisposed()) return false;
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
final Document document = editor.getDocument();
documentManager.commitDocument(document);
PsiFile psiFile = documentManager.getPsiFile(document);
PsiFile file = getRoot(psiFile, editor);
if (file == null) return false;
final MoverWrapper mover = getSuitableMover(editor, file);
if (mover == null || mover.getInfo().toMove2 == null) return false;
final int maxLine = editor.offsetToLogicalPosition(editor.getDocument().getTextLength()).line;
final LineRange range = mover.getInfo().toMove;
if (range.startLine == 0 && !isDown) return false;
return range.endLine <= maxLine || !isDown;
}
示例9: createProperty
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
public static void createProperty(final Project project,
final Collection<PropertiesFile> propertiesFiles,
final String key,
final String value) throws IncorrectOperationException {
for (PropertiesFile file : propertiesFiles) {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(documentManager.getDocument(file.getContainingFile()));
IProperty existingProperty = file.findPropertyByKey(key);
if (existingProperty == null) {
file.addProperty(key, value);
}
}
}
示例10: actionPerformed
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
if (project == null) {
return;
}
final Editor editor = e.getData(CommonDataKeys.EDITOR);
if (editor == null) {
return;
}
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
Document document = editor.getDocument();
documentManager.commitDocument(document);
final PsiFile file = documentManager.getPsiFile(document);
if (file == null) {
return;
}
SelectionModel model = editor.getSelectionModel();
if (model.hasSelection()) {
new RearrangeCodeProcessor(file, model).run();
}
else {
new RearrangeCodeProcessor(file).run();
}
}
示例11: buildLiveRearrangerData
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
/**
* must be called from within an IDEA read-action thread.
*
* @param project
* @param document
* @param psiFile
*/
void buildLiveRearrangerData(final Project project,
final Document document,
final PsiFile psiFile,
final int cursorOffset)
{
/**
* Per instructions from IntelliJ, we have to commit any changes to the document to the Psi
* tree.
*/
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(document);
final RearrangerSettings settings = new RearrangerSettings(); // use default settings with no rules
settings.setAskBeforeRearranging(true);
final Runnable task = new Runnable()
{
public void run()
{
logger.debug("liveRearrangeDocument task started");
liveRearrangeDocument(project, psiFile, settings, document, cursorOffset);
}
};
Thread t = new Thread(new Runnable()
{
public void run()
{
logger.debug("started thread " + Thread.currentThread().getName());
final Application application = ApplicationManager.getApplication();
application.runReadAction(new Runnable() {
public void run() {
logger.debug("enter application.runReadAction() on thread " + Thread.currentThread().getName());
task.run();
logger.debug("exit application.runReadAction() on thread " + Thread.currentThread().getName());
}});
}
}, "Live Rearranger parser");
t.start();
logger.debug("exit buildLiveRearrangerData on thread " + Thread.currentThread().getName());
}
示例12: autoPopupParameterInfo
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
public void autoPopupParameterInfo(@NotNull final Editor editor, @Nullable final PsiElement highlightedMethod){
if (ApplicationManager.getApplication().isUnitTestMode()) return;
if (DumbService.isDumb(myProject)) return;
if (PowerSaveMode.isEnabled()) return;
ApplicationManager.getApplication().assertIsDispatchThread();
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
if (settings.AUTO_POPUP_PARAMETER_INFO) {
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
PsiFile file = documentManager.getPsiFile(editor.getDocument());
if (file == null) return;
if (!documentManager.isUncommited(editor.getDocument())) {
file = documentManager.getPsiFile(InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file).getDocument());
if (file == null) return;
}
final PsiFile file1 = file;
final Runnable request = new Runnable(){
@Override
public void run(){
if (myProject.isDisposed() || DumbService.isDumb(myProject)) return;
documentManager.commitAllDocuments();
if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
int lbraceOffset = editor.getCaretModel().getOffset() - 1;
try {
ShowParameterInfoHandler.invoke(myProject, editor, file1, lbraceOffset, highlightedMethod);
}
catch (IndexNotReadyException ignored) { //anything can happen on alarm
}
}
};
addRequest(request, settings.PARAMETER_INFO_DELAY);
}
}
示例13: getInjectedEditor
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
public static Editor getInjectedEditor(@NotNull Project project, final Editor editor, boolean commit) {
Editor injectedEditor = editor;
if (editor != null) {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
PsiFile psiFile = documentManager.getCachedPsiFile(editor.getDocument());
if (psiFile != null) {
if (commit) documentManager.commitAllDocuments();
injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, psiFile);
}
}
return injectedEditor;
}
示例14: testNestedEditValueText
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
public void testNestedEditValueText() throws Exception {
resetScanCounter();
VirtualFile file1 = myFixture.copyFileToProject(VALUES1, "res/values/myvalues.xml");
PsiFile psiFile1 = PsiManager.getInstance(getProject()).findFile(file1);
assertNotNull(psiFile1);
ResourceFolderRepository resources = createRepository();
assertNotNull(resources);
List<ResourceItem> labelList = resources.getResourceItem(ResourceType.STRING, "title_template_step");
assertNotNull(labelList);
assertEquals(1, labelList.size());
ResourceItem label = labelList.get(0);
ResourceValue resourceValue = label.getResourceValue(false);
assertNotNull(resourceValue);
assertEquals("Step ${step_number}: Lorem Ipsum", resourceValue.getValue());
long generation = resources.getModificationCount();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
final Document document = documentManager.getDocument(psiFile1);
assertNotNull(document);
// Edit value should cause update
final int textOffset = document.getText().indexOf("Lorem");
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
document.insertString(textOffset + 1, "l");
documentManager.commitDocument(document);
}
});
assertTrue(generation < resources.getModificationCount());
resourceValue = label.getResourceValue(false);
assertNotNull(resourceValue);
assertEquals("Step ${step_number}: Llorem Ipsum", resourceValue.getValue());
// Shouldn't have done any full file rescans during the above edits
ensureIncremental();
}
示例15: asyncCommitDocuments
import com.intellij.psi.PsiDocumentManager; //导入方法依赖的package包/类
@NotNull
public static ActionCallback asyncCommitDocuments(@NotNull Project project) {
if (project.isDisposed()) return ActionCallback.DONE;
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
if (!documentManager.hasUncommitedDocuments()) {
return ActionCallback.DONE;
}
final ActionCallback callback = new ActionCallback();
documentManager.performWhenAllCommitted(callback.createSetDoneRunnable());
return callback;
}