本文整理汇总了Java中com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.getInjectedEditorForInjectedFile方法的典型用法代码示例。如果您正苦于以下问题:Java InjectedLanguageUtil.getInjectedEditorForInjectedFile方法的具体用法?Java InjectedLanguageUtil.getInjectedEditorForInjectedFile怎么用?Java InjectedLanguageUtil.getInjectedEditorForInjectedFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
的用法示例。
在下文中一共展示了InjectedLanguageUtil.getInjectedEditorForInjectedFile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: injectedEditorIfCharTypedIsSignificant
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@NotNull
public static Editor injectedEditorIfCharTypedIsSignificant(final char charTyped, @NotNull Editor editor, @NotNull PsiFile oldFile) {
int offset = editor.getCaretModel().getOffset();
// even for uncommitted document try to retrieve injected fragment that has been there recently
// we are assuming here that when user is (even furiously) typing, injected language would not change
// and thus we can use its lexer to insert closing braces etc
for (DocumentWindow documentWindow : InjectedLanguageUtil.getCachedInjectedDocuments(oldFile)) {
if (documentWindow.isValid() && documentWindow.containsRange(offset, offset)) {
PsiFile injectedFile = PsiDocumentManager.getInstance(oldFile.getProject()).getPsiFile(documentWindow);
final Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile);
// IDEA-52375 fix: last quote sign should be handled by outer language quote handler
final CharSequence charsSequence = editor.getDocument().getCharsSequence();
if (injectedEditor.getCaretModel().getOffset() == injectedEditor.getDocument().getTextLength() &&
offset < charsSequence.length() && charTyped == charsSequence.charAt(offset)) {
return editor;
}
return injectedEditor;
}
}
return editor;
}
示例2: chooseBetweenHostAndInjected
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Nullable
public static Pair<PsiFile,Editor> chooseBetweenHostAndInjected(@NotNull PsiFile hostFile, @NotNull Editor hostEditor, @NotNull PairProcessor<PsiFile, Editor> predicate) {
Editor editorToApply = null;
PsiFile fileToApply = null;
int offset = hostEditor.getCaretModel().getOffset();
PsiFile injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, offset);
if (injectedFile != null) {
Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile);
if (predicate.process(injectedFile, injectedEditor)) {
editorToApply = injectedEditor;
fileToApply = injectedFile;
}
}
if (editorToApply == null && predicate.process(hostFile, hostEditor)) {
editorToApply = hostEditor;
fileToApply = hostFile;
}
if (editorToApply == null) return null;
return Pair.create(fileToApply, editorToApply);
}
示例3: injectedEditorIfCharTypedIsSignificant
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@NotNull
static Editor injectedEditorIfCharTypedIsSignificant(final char charTyped, Editor editor, PsiFile oldFile) {
int offset = editor.getCaretModel().getOffset();
// even for uncommitted document try to retrieve injected fragment that has been there recently
// we are assuming here that when user is (even furiously) typing, injected language would not change
// and thus we can use its lexer to insert closing braces etc
for (DocumentWindow documentWindow : InjectedLanguageUtil.getCachedInjectedDocuments(oldFile)) {
if (documentWindow.isValid() && documentWindow.containsRange(offset, offset)) {
PsiFile injectedFile = PsiDocumentManager.getInstance(oldFile.getProject()).getPsiFile(documentWindow);
final Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile);
// IDEA-52375 fix: last quote sign should be handled by outer language quote handler
final CharSequence charsSequence = editor.getDocument().getCharsSequence();
if (injectedEditor.getCaretModel().getOffset() == injectedEditor.getDocument().getTextLength() &&
offset < charsSequence.length() && charTyped == charsSequence.charAt(offset)) {
return editor;
}
return injectedEditor;
}
}
return editor;
}
示例4: injectedEditorIfCharTypedIsSignificant
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Nonnull
public static Editor injectedEditorIfCharTypedIsSignificant(final char charTyped, @Nonnull Editor editor, @Nonnull PsiFile oldFile) {
int offset = editor.getCaretModel().getOffset();
// even for uncommitted document try to retrieve injected fragment that has been there recently
// we are assuming here that when user is (even furiously) typing, injected language would not change
// and thus we can use its lexer to insert closing braces etc
for (DocumentWindow documentWindow : InjectedLanguageUtil.getCachedInjectedDocuments(oldFile)) {
if (documentWindow.isValid() && documentWindow.containsRange(offset, offset)) {
PsiFile injectedFile = PsiDocumentManager.getInstance(oldFile.getProject()).getPsiFile(documentWindow);
if (injectedFile != null) {
Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile);
// IDEA-52375/WEB-9105 fix: last quote in editable fragment should be handled by outer language quote handler
TextRange hostRange = documentWindow.getHostRange(offset);
CharSequence sequence = editor.getDocument().getCharsSequence();
if (sequence.length() > offset && charTyped != sequence.charAt(offset) || hostRange != null && hostRange.contains(offset)) {
return injectedEditor;
}
}
}
}
return editor;
}
示例5: chooseBetweenHostAndInjected
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Nullable
public static Pair<PsiFile, Editor> chooseBetweenHostAndInjected(@Nonnull PsiFile hostFile,
@Nonnull Editor hostEditor,
@Nonnull PairProcessor<PsiFile, Editor> predicate) {
Editor editorToApply = null;
PsiFile fileToApply = null;
int offset = hostEditor.getCaretModel().getOffset();
PsiFile injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, offset);
if (injectedFile != null) {
Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(hostEditor, injectedFile);
if (predicate.process(injectedFile, injectedEditor)) {
editorToApply = injectedEditor;
fileToApply = injectedFile;
}
}
if (editorToApply == null && predicate.process(hostFile, hostEditor)) {
editorToApply = hostEditor;
fileToApply = hostFile;
}
if (editorToApply == null) return null;
return Pair.create(fileToApply, editorToApply);
}
示例6: moveCaret
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private static boolean moveCaret(Editor editor, PsiElement current, int offset) {
editor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, current.getContainingFile());
final CaretModel caretModel = editor.getCaretModel();
if (caretModel.getOffset() == offset) return false;
caretModel.moveToOffset(offset);
final Caret caret = caretModel.getCurrentCaret();
ScrollingModel scrollingModel = editor.getScrollingModel();
if (caret == caretModel.getPrimaryCaret()) {
scrollingModel.scrollToCaret(ScrollType.RELATIVE);
}
return true;
}
示例7: doExtractFunction
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private void doExtractFunction() throws Throwable {
myFixture.configureByFile(getTestFileName() + ".xsl");
final Editor editor = myFixture.getEditor();
assertTrue("Selection required", editor.getSelectionModel().hasSelection());
editor.getCaretModel().moveToOffset(editor.getSelectionModel().getSelectionStart());
final XsltExtractFunctionAction action = new XsltExtractFunctionAction() {
@Override
protected RefactoringOptions getSettings(XPathExpression expression, Set<XPathExpression> matchingExpressions) {
return new RefactoringOptions() {
@Override
public boolean isCanceled() {
return false;
}
@Override
public String getName() {
return "f:foo";
}
};
}
};
final PsiFile file = InjectedLanguageUtil.findInjectedPsiNoCommit(myFixture.getFile(), editor.getCaretModel().getOffset());
final Editor editorWindow = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, file);
assertTrue(editorWindow instanceof EditorWindow);
action.invoke(myFixture.getProject(), editorWindow, file, null);
myFixture.checkResultByFile(getTestFileName() + "_after.xsl");
}
示例8: addAvailableActionsForGroups
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private static void addAvailableActionsForGroups(@NotNull HighlightInfo info,
@NotNull Editor editor,
@NotNull PsiFile file,
@NotNull List<HighlightInfo.IntentionActionDescriptor> outList,
int group,
int offset) {
if (info.quickFixActionMarkers == null) return;
if (group != -1 && group != info.getGroup()) return;
Editor injectedEditor = null;
PsiFile injectedFile = null;
for (Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker> pair : info.quickFixActionMarkers) {
HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
RangeMarker range = pair.second;
if (!range.isValid()) continue;
int start = range.getStartOffset();
int end = range.getEndOffset();
final Project project = file.getProject();
if (start > offset || offset > end) {
continue;
}
Editor editorToUse;
PsiFile fileToUse;
if (info.isFromInjection()) {
if (injectedEditor == null) {
injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(file, offset);
injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile);
}
editorToUse = injectedEditor;
fileToUse = injectedFile;
}
else {
editorToUse = editor;
fileToUse = file;
}
if (actionInGroup.getAction().isAvailable(project, editorToUse, fileToUse)) {
outList.add(actionInGroup);
}
}
}
示例9: getEditor
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
@Nonnull
public Editor getEditor() {
DocumentWindow documentWindow = getInjectedDocument(myEditor.getCaretModel().getOffset());
if (documentWindow != null) {
PsiFile injectedFile = PsiDocumentManager.getInstance(myProject).getPsiFile(documentWindow);
return InjectedLanguageUtil.getInjectedEditorForInjectedFile(myEditor, injectedFile);
}
return myEditor;
}
示例10: addAvailableActionsForGroups
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private static void addAvailableActionsForGroups(@NotNull HighlightInfo info,
@NotNull Editor editor,
@NotNull PsiFile file,
@NotNull List<HighlightInfo.IntentionActionDescriptor> outList,
int group,
int offset) {
if (info.quickFixActionMarkers == null) return;
if (group != -1 && group != info.getGroup()) return;
boolean fixRangeIsNotEmpty = !info.getFixTextRange().isEmpty();
Editor injectedEditor = null;
PsiFile injectedFile = null;
for (Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker> pair : info.quickFixActionMarkers) {
HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
RangeMarker range = pair.second;
if (!range.isValid() || fixRangeIsNotEmpty && isEmpty(range)) continue;
if (DumbService.isDumb(file.getProject()) && !DumbService.isDumbAware(actionInGroup.getAction())) {
continue;
}
int start = range.getStartOffset();
int end = range.getEndOffset();
final Project project = file.getProject();
if (start > offset || offset > end) {
continue;
}
Editor editorToUse;
PsiFile fileToUse;
if (info.isFromInjection()) {
if (injectedEditor == null) {
injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(file, offset);
injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile);
}
editorToUse = injectedEditor;
fileToUse = injectedFile;
}
else {
editorToUse = editor;
fileToUse = file;
}
if (actionInGroup.getAction().isAvailable(project, editorToUse, fileToUse)) {
outList.add(actionInGroup);
}
}
}
示例11: addAvailableFixesForGroups
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private static void addAvailableFixesForGroups(@Nonnull HighlightInfo info,
@Nonnull Editor editor,
@Nonnull PsiFile file,
@Nonnull List<HighlightInfo.IntentionActionDescriptor> outList,
int group,
int offset) {
if (info.quickFixActionMarkers == null) return;
if (group != -1 && group != info.getGroup()) return;
boolean fixRangeIsNotEmpty = !info.getFixTextRange().isEmpty();
Editor injectedEditor = null;
PsiFile injectedFile = null;
for (Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker> pair : info.quickFixActionMarkers) {
HighlightInfo.IntentionActionDescriptor actionInGroup = pair.first;
RangeMarker range = pair.second;
if (!range.isValid() || fixRangeIsNotEmpty && isEmpty(range)) continue;
if (DumbService.isDumb(file.getProject()) && !DumbService.isDumbAware(actionInGroup.getAction())) {
continue;
}
int start = range.getStartOffset();
int end = range.getEndOffset();
final Project project = file.getProject();
if (start > offset || offset > end) {
continue;
}
Editor editorToUse;
PsiFile fileToUse;
if (info.isFromInjection()) {
if (injectedEditor == null) {
injectedFile = InjectedLanguageUtil.findInjectedPsiNoCommit(file, offset);
injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile);
}
editorToUse = injectedEditor;
fileToUse = injectedFile;
}
else {
editorToUse = editor;
fileToUse = file;
}
if (actionInGroup.getAction().isAvailable(project, editorToUse, fileToUse)) {
outList.add(actionInGroup);
}
}
}