本文整理汇总了Java中com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.openEditorFor方法的典型用法代码示例。如果您正苦于以下问题:Java InjectedLanguageUtil.openEditorFor方法的具体用法?Java InjectedLanguageUtil.openEditorFor怎么用?Java InjectedLanguageUtil.openEditorFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
的用法示例。
在下文中一共展示了InjectedLanguageUtil.openEditorFor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addOccurrenceHighlights
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void addOccurrenceHighlights(@NotNull Editor editor,
@NotNull PsiReference[] occurrences,
@NotNull TextAttributes attributes,
boolean hideByTextChange,
Collection<RangeHighlighter> outHighlighters) {
if (occurrences.length == 0) return;
int flags = HIDE_BY_ESCAPE;
if (hideByTextChange) {
flags |= HIDE_BY_TEXT_CHANGE;
}
Color scrollmarkColor = getScrollMarkColor(attributes);
int oldOffset = editor.getCaretModel().getOffset();
int horizontalScrollOffset = editor.getScrollingModel().getHorizontalScrollOffset();
int verticalScrollOffset = editor.getScrollingModel().getVerticalScrollOffset();
for (PsiReference occurrence : occurrences) {
PsiElement element = occurrence.getElement();
int startOffset = element.getTextRange().getStartOffset();
int start = startOffset + occurrence.getRangeInElement().getStartOffset();
int end = startOffset + occurrence.getRangeInElement().getEndOffset();
PsiFile containingFile = element.getContainingFile();
Project project = element.getProject();
// each reference can reside in its own injected editor
Editor textEditor = InjectedLanguageUtil.openEditorFor(containingFile, project);
if (textEditor != null) {
addOccurrenceHighlight(textEditor, start, end, attributes, flags, outHighlighters, scrollmarkColor);
}
}
editor.getCaretModel().moveToOffset(oldOffset);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getScrollingModel().scrollHorizontally(horizontalScrollOffset);
editor.getScrollingModel().scrollVertically(verticalScrollOffset);
}
示例2: invoke
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
if (!FileModificationService.getInstance().preparePsiElementForWrite(element)) return;
element = findJavaCodeUpThere(element);
PsiFile file = element.getContainingFile();
editor = InjectedLanguageUtil.openEditorFor(file, project);
int endOffset = element.getTextRange().getEndOffset();
int line = editor.getDocument().getLineNumber(endOffset);
int lineEndOffset = editor.getDocument().getLineEndOffset(line);
PsiComment comment = PsiTreeUtil.findElementOfClassAtOffset(file, lineEndOffset-1, PsiComment.class, false);
String prefix = "";
boolean prefixFound = false;
if (comment != null) {
IElementType tokenType = comment.getTokenType();
if (tokenType == JavaTokenType.END_OF_LINE_COMMENT) {
prefix = StringUtil.trimStart(comment.getText(),"//") + " ";
prefixFound = true;
}
}
String commentText = "//" + prefix + nonNlsCommentPattern;
if (prefixFound) {
PsiComment newcom = JavaPsiFacade.getElementFactory(project).createCommentFromText(commentText, element);
comment.replace(newcom);
}
else {
editor.getDocument().insertString(lineEndOffset, " " + commentText);
}
DaemonCodeAnalyzer.getInstance(project).restart(); //comment replacement not necessarily rehighlights
}
示例3: addOccurrenceHighlights
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void addOccurrenceHighlights(@Nonnull Editor editor,
@Nonnull PsiReference[] occurrences,
@Nonnull TextAttributes attributes,
boolean hideByTextChange,
Collection<RangeHighlighter> outHighlighters) {
if (occurrences.length == 0) return;
int flags = HIDE_BY_ESCAPE;
if (hideByTextChange) {
flags |= HIDE_BY_TEXT_CHANGE;
}
Color scrollmarkColor = getScrollMarkColor(attributes);
int oldOffset = editor.getCaretModel().getOffset();
int horizontalScrollOffset = editor.getScrollingModel().getHorizontalScrollOffset();
int verticalScrollOffset = editor.getScrollingModel().getVerticalScrollOffset();
for (PsiReference occurrence : occurrences) {
PsiElement element = occurrence.getElement();
int startOffset = element.getTextRange().getStartOffset();
int start = startOffset + occurrence.getRangeInElement().getStartOffset();
int end = startOffset + occurrence.getRangeInElement().getEndOffset();
PsiFile containingFile = element.getContainingFile();
Project project = element.getProject();
// each reference can reside in its own injected editor
Editor textEditor = InjectedLanguageUtil.openEditorFor(containingFile, project);
if (textEditor != null) {
addOccurrenceHighlight(textEditor, start, end, attributes, flags, outHighlighters, scrollmarkColor);
}
}
editor.getCaretModel().moveToOffset(oldOffset);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getScrollingModel().scrollHorizontally(horizontalScrollOffset);
editor.getScrollingModel().scrollVertically(verticalScrollOffset);
}
示例4: applyFix
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@SuppressWarnings({"SSBasedInspection"})
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
Runnable fix = new Runnable() {
public void run() {
DictionarySuggestionProvider provider = findProvider();
if (provider != null) {
provider.setActive(true);
}
Editor editor = getEditorFromFocus();
HashMap<String, Object> map = new HashMap<String, Object>();
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null) return;
PsiFile containingFile = psiElement.getContainingFile();
if (editor == null) {
editor = InjectedLanguageUtil.openEditorFor(containingFile, project);
}
if (editor == null) return;
if (editor instanceof EditorWindow) {
map.put(CommonDataKeys.EDITOR.getName(), editor);
map.put(CommonDataKeys.PSI_ELEMENT.getName(), psiElement);
} else if (ApplicationManager.getApplication().isUnitTestMode()) { // TextEditorComponent / FiledEditorManagerImpl give away the data in real life
map.put(
CommonDataKeys.PSI_ELEMENT.getName(),
new TextEditorPsiDataProvider().getData(CommonDataKeys.PSI_ELEMENT.getName(), editor, editor.getCaretModel().getCurrentCaret())
);
}
final Boolean selectAll = editor.getUserData(RenameHandlerRegistry.SELECT_ALL);
try {
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, true);
DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent()));
AnAction action = new RenameElementAction();
AnActionEvent event = AnActionEvent.createFromAnAction(action, null, "", dataContext);
action.actionPerformed(event);
if (provider != null) {
provider.setActive(false);
}
}
finally {
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, selectAll);
}
}
};
if (ApplicationManager.getApplication().isUnitTestMode()) fix.run();
else SwingUtilities.invokeLater(fix); // TODO [shkate] this is hard to test!
}
示例5: applyFix
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@SuppressWarnings({"SSBasedInspection"})
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
Runnable fix = new Runnable() {
public void run() {
ElementNameSuggestionProvider provider = findProvider();
if (provider != null) {
provider.setActive(true);
}
Editor editor = getEditorFromFocus();
HashMap<String, Object> map = new HashMap<String, Object>();
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null) return;
PsiFile containingFile = psiElement.getContainingFile();
if (editor == null) {
editor = InjectedLanguageUtil.openEditorFor(containingFile, project);
}
if (editor == null) return;
if (editor instanceof EditorWindow) {
map.put(CommonDataKeys.EDITOR.getName(), editor);
map.put(CommonDataKeys.PSI_ELEMENT.getName(), psiElement);
} else if (ApplicationManager.getApplication().isUnitTestMode()) { // TextEditorComponent / FiledEditorManagerImpl give away the data in real life
map.put(
CommonDataKeys.PSI_ELEMENT.getName(),
new TextEditorPsiDataProvider().getData(CommonDataKeys.PSI_ELEMENT.getName(), editor, editor.getCaretModel().getCurrentCaret())
);
}
final Boolean selectAll = editor.getUserData(RenameHandlerRegistry.SELECT_ALL);
try {
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, true);
DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent()));
AnAction action = new RenameElementAction();
AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
action.actionPerformed(event);
if (provider != null) {
provider.setActive(false);
}
} finally {
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, selectAll);
}
}
};
if (ApplicationManager.getApplication().isUnitTestMode()) fix.run();
else SwingUtilities.invokeLater(fix); // TODO [shkate] this is hard to test!
}
示例6: applyFix
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@SuppressWarnings({"SSBasedInspection"})
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
Runnable fix = new Runnable() {
public void run() {
DictionarySuggestionProvider provider = findProvider();
if (provider != null) {
provider.setActive(true);
}
Editor editor = getEditorFromFocus();
HashMap<String, Object> map = new HashMap<String, Object>();
PsiElement psiElement = descriptor.getPsiElement();
if (psiElement == null) return;
PsiFile containingFile = psiElement.getContainingFile();
if (editor == null) {
editor = InjectedLanguageUtil.openEditorFor(containingFile, project);
}
if (editor == null) return;
if (editor instanceof EditorWindow) {
map.put(PlatformDataKeys.EDITOR.getName(), editor);
map.put(LangDataKeys.PSI_ELEMENT.getName(), psiElement);
} else if (ApplicationManager.getApplication().isUnitTestMode()) { // TextEditorComponent / FiledEditorManagerImpl give away the data in real life
map.put(
LangDataKeys.PSI_ELEMENT.getName(),
new TextEditorPsiDataProvider().getData(
LangDataKeys.PSI_ELEMENT.getName(),
editor,
containingFile.getVirtualFile()
)
);
}
final Boolean selectAll = editor.getUserData(RenameHandlerRegistry.SELECT_ALL);
try {
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, true);
DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext(editor.getComponent()));
AnAction action = new RenameElementAction();
AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
action.actionPerformed(event);
if (provider != null) {
provider.setActive(false);
}
}
finally {
editor.putUserData(RenameHandlerRegistry.SELECT_ALL, selectAll);
}
}
};
if (ApplicationManager.getApplication().isUnitTestMode()) fix.run();
else SwingUtilities.invokeLater(fix); // TODO [shkate] this is hard to test!
}