本文整理汇总了Java中com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.findElementAtNoCommit方法的典型用法代码示例。如果您正苦于以下问题:Java InjectedLanguageUtil.findElementAtNoCommit方法的具体用法?Java InjectedLanguageUtil.findElementAtNoCommit怎么用?Java InjectedLanguageUtil.findElementAtNoCommit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
的用法示例。
在下文中一共展示了InjectedLanguageUtil.findElementAtNoCommit方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: caretPositionChanged
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void caretPositionChanged(CaretEvent e) {
if (!available() || myEditor.getSelectionModel().hasSelection()) return;
final ViewerTreeStructure treeStructure = (ViewerTreeStructure)myPsiTreeBuilder.getTreeStructure();
final PsiElement rootPsiElement = treeStructure.getRootPsiElement();
if (rootPsiElement == null) return;
final PsiElement rootElement = ((ViewerTreeStructure)myPsiTreeBuilder.getTreeStructure()).getRootPsiElement();
int baseOffset = rootPsiElement.getTextRange().getStartOffset();
final int offset = myEditor.getCaretModel().getOffset() + baseOffset;
final PsiElement element = InjectedLanguageUtil.findElementAtNoCommit(rootElement.getContainingFile(), offset);
if (element != null && myBlockTreeBuilder != null) {
TextRange rangeInHostFile = InjectedLanguageManager.getInstance(myProject).injectedToHost(element, element.getTextRange());
selectBlockNode(findBlockNode(rangeInHostFile, true));
}
myPsiTreeBuilder.select(element);
}
示例2: containsWhiteSpaceSymbolsOnly
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public boolean containsWhiteSpaceSymbolsOnly(int startOffset, int endOffset) {
WhiteSpaceFormattingStrategy strategy = myWhiteSpaceStrategy;
if (strategy.check(myDocument.getCharsSequence(), startOffset, endOffset) >= endOffset) {
return true;
}
PsiElement injectedElement = myFile != null ? InjectedLanguageUtil.findElementAtNoCommit(myFile, startOffset) : null;
if (injectedElement != null) {
Language injectedLanguage = injectedElement.getLanguage();
if (!injectedLanguage.equals(myFile.getLanguage())) {
WhiteSpaceFormattingStrategy localStrategy = WhiteSpaceFormattingStrategyFactory.getStrategy(injectedLanguage);
if (localStrategy != null) {
return localStrategy.check(myDocument.getCharsSequence(), startOffset, endOffset) >= endOffset;
}
}
}
return false;
}
示例3: invoke
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
PsiElement element = getElement(dataContext);
if (element == null) {
element = BaseRefactoringAction.getElementAtCaret(editor, file);
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
final String newName = DEFAULT_NAME.getData(dataContext);
if (newName != null) {
rename(element, project, element, editor, newName);
return;
}
}
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final PsiElement nameSuggestionContext = InjectedLanguageUtil.findElementAtNoCommit(file, editor.getCaretModel().getOffset());
invoke(element, project, nameSuggestionContext, editor);
}
示例4: getPsiElementAt
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Nullable
private static PsiElement getPsiElementAt(Point point, Editor editor) {
if (editor.isDisposed()) {
return null;
}
Project project = editor.getProject();
if (project == null || project.isDisposed()) {
return null;
}
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null || psiFile instanceof PsiCompiledElement || !psiFile.isValid()) {
return null;
}
return InjectedLanguageUtil.findElementAtNoCommit(psiFile, editor.logicalPositionToOffset(editor.xyToLogicalPosition(point)));
}
示例5: invoke
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void invoke(@Nonnull Project project, Editor editor, PsiFile file, DataContext dataContext) {
PsiElement element = getElement(dataContext);
if (element == null) {
element = BaseRefactoringAction.getElementAtCaret(editor, file);
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
final String newName = dataContext.getData(DEFAULT_NAME);
if (newName != null) {
rename(element, project, element, editor, newName);
return;
}
}
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final PsiElement nameSuggestionContext = InjectedLanguageUtil.findElementAtNoCommit(file, editor.getCaretModel().getOffset());
invoke(element, project, nameSuggestionContext, editor);
}
示例6: findSupport
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@RequiredReadAction
private RangeMarker findSupport(RangeMarker leader, PsiFile file, Document document)
{
final int offset = leader.getStartOffset();
PsiElement element = InjectedLanguageUtil.findElementAtNoCommit(file, offset);
PsiElement support = findSupportElement(element);
if(support == null && file.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider)
{
element = file.getViewProvider().findElementAt(offset, myLanguage);
support = findSupportElement(element);
}
if(support == null)
{
return null;
}
final TextRange range = support.getTextRange();
TextRange realRange = InjectedLanguageManager.getInstance(file.getProject()).injectedToHost(element.getContainingFile(), range);
return document.createRangeMarker(realRange.getStartOffset(), realRange.getEndOffset(), true);
}
示例7: initMap
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private void initMap(BlockTreeNode rootBlockNode, PsiElement psiEl) {
PsiElement currentElem = null;
if (rootBlockNode.getBlock() instanceof ASTBlock) {
ASTNode node = ((ASTBlock)rootBlockNode.getBlock()).getNode();
if (node != null) {
currentElem = node.getPsi();
}
}
if (currentElem == null) {
currentElem =
InjectedLanguageUtil
.findElementAtNoCommit(psiEl.getContainingFile(), rootBlockNode.getBlock().getTextRange().getStartOffset());
}
myPsiToBlockMap.put(currentElem, rootBlockNode);
//nested PSI elements with same ranges will be mapped to one blockNode
// assert currentElem != null; //for Scala-language plugin etc it can be null, because formatterBlocks is not instance of ASTBlock
TextRange curTextRange = currentElem.getTextRange();
PsiElement parentElem = currentElem.getParent();
while (parentElem != null && parentElem.getTextRange().equals(curTextRange)) {
myPsiToBlockMap.put(parentElem, rootBlockNode);
parentElem = parentElem.getParent();
}
for (BlockTreeNode block : rootBlockNode.getChildren()) {
initMap(block, psiEl);
}
}
示例8: findSupport
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private RangeMarker findSupport(RangeMarker leader, PsiFile file, Document document) {
final int offset = leader.getStartOffset();
PsiElement element = InjectedLanguageUtil.findElementAtNoCommit(file, offset);
PsiElement support = findSupportElement(element);
if (support == null && file.getViewProvider() instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
element = file.getViewProvider().findElementAt(offset, myLanguage);
support = findSupportElement(element);
}
if (support == null) return null;
final TextRange range = support.getTextRange();
TextRange realRange = InjectedLanguageManager.getInstance(file.getProject()).injectedToHost(element.getContainingFile(), range);
return document.createRangeMarker(realRange.getStartOffset(), realRange.getEndOffset(), true);
}
示例9: moveToNextPoint
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
private static void moveToNextPoint(Editor editor, PsiFile file, int offset, int inc) {
final Document doc = editor.getDocument();
final TemplateLanguageFileViewProvider provider = ObjectUtils.tryCast(file.getViewProvider(), TemplateLanguageFileViewProvider.class);
final Language additionalLanguage = provider != null ? provider.getTemplateDataLanguage() : null;
PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc);
for (int i = offset + inc; i < doc.getTextLength() && i >= 0; i += inc) {
PsiElement current = InjectedLanguageUtil.findElementAtNoCommit(file, i);
if (checkAndMove(editor, doc, i, current)) return;
if (additionalLanguage != null) {
current = provider.findElementAt(i, additionalLanguage);
if (checkAndMove(editor, doc, i, current)) return;
}
}
}
示例10: invoke
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
PsiElement element = getElement(dataContext);
if (element == null) {
element = BaseRefactoringAction.getElementAtCaret(editor, file);
}
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final PsiElement nameSuggestionContext = InjectedLanguageUtil.findElementAtNoCommit(file, editor.getCaretModel().getOffset());
invoke(element, project, nameSuggestionContext, editor);
}
示例11: valueChanged
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void valueChanged(@NotNull TreeSelectionEvent e) {
if (myIgnoreBlockTreeSelectionMarker > 0 || myBlockTreeBuilder == null) {
return;
}
Set<?> blockElementsSet = myBlockTreeBuilder.getSelectedElements();
if (blockElementsSet.isEmpty()) return;
BlockTreeNode descriptor = (BlockTreeNode)blockElementsSet.iterator().next();
PsiElement rootPsi = ((ViewerTreeStructure)myPsiTreeBuilder.getTreeStructure()).getRootPsiElement();
int blockStart = descriptor.getBlock().getTextRange().getStartOffset();
PsiFile file = rootPsi.getContainingFile();
PsiElement currentPsiEl = InjectedLanguageUtil.findElementAtNoCommit(file, blockStart);
if (currentPsiEl == null) currentPsiEl = file;
int blockLength = descriptor.getBlock().getTextRange().getLength();
while (currentPsiEl.getParent() != null &&
currentPsiEl.getTextRange().getStartOffset() == blockStart &&
currentPsiEl.getTextLength() != blockLength) {
currentPsiEl = currentPsiEl.getParent();
}
final BlockTreeStructure treeStructure = (BlockTreeStructure)myBlockTreeBuilder.getTreeStructure();
BlockTreeNode rootBlockNode = treeStructure.getRootElement();
int baseOffset = 0;
if (rootBlockNode != null) {
baseOffset = rootBlockNode.getBlock().getTextRange().getStartOffset();
}
if (currentPsiEl != null) {
TextRange range = descriptor.getBlock().getTextRange();
range = range.shiftRight(-baseOffset);
int start = range.getStartOffset();
int end = range.getEndOffset();
final int textLength = myEditor.getDocument().getTextLength();
if (myBlockTree.hasFocus()) {
clearSelection();
if (end <= textLength) {
myHighlighter = myEditor.getMarkupModel()
.addRangeHighlighter(start, end, HighlighterLayer.LAST, myAttributes, HighlighterTargetArea.EXACT_RANGE);
myEditor.getCaretModel().moveToOffset(start);
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
}
updateReferences(currentPsiEl);
if (!myPsiTree.hasFocus()) {
myPsiTreeBuilder.select(currentPsiEl);
}
}
}
示例12: valueChanged
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void valueChanged(TreeSelectionEvent e) {
if (myIgnoreBlockTreeSelectionMarker > 0 || myBlockTreeBuilder == null) {
return;
}
Set<?> blockElementsSet = myBlockTreeBuilder.getSelectedElements();
if (blockElementsSet.isEmpty()) return;
BlockTreeNode descriptor = (BlockTreeNode)blockElementsSet.iterator().next();
PsiElement rootPsi = ((ViewerTreeStructure)myPsiTreeBuilder.getTreeStructure()).getRootPsiElement();
int blockStart = descriptor.getBlock().getTextRange().getStartOffset();
PsiFile file = rootPsi.getContainingFile();
PsiElement currentPsiEl = InjectedLanguageUtil.findElementAtNoCommit(file, blockStart);
if (currentPsiEl == null) currentPsiEl = file;
int blockLength = descriptor.getBlock().getTextRange().getLength();
while (currentPsiEl.getParent() != null &&
currentPsiEl.getTextRange().getStartOffset() == blockStart &&
currentPsiEl.getTextLength() != blockLength) {
currentPsiEl = currentPsiEl.getParent();
}
final BlockTreeStructure treeStructure = (BlockTreeStructure)myBlockTreeBuilder.getTreeStructure();
BlockTreeNode rootBlockNode = treeStructure.getRootElement();
int baseOffset = 0;
if (rootBlockNode != null) {
baseOffset = rootBlockNode.getBlock().getTextRange().getStartOffset();
}
if (currentPsiEl != null) {
TextRange range = descriptor.getBlock().getTextRange();
range = range.shiftRight(-baseOffset);
int start = range.getStartOffset();
int end = range.getEndOffset();
final int textLength = myEditor.getDocument().getTextLength();
if (myBlockTree.hasFocus()) {
clearSelection();
if (end <= textLength) {
myHighlighter = myEditor.getMarkupModel()
.addRangeHighlighter(start, end, HighlighterLayer.LAST, myAttributes, HighlighterTargetArea.EXACT_RANGE);
updateIntersectHighlighter(start, end);
myEditor.getCaretModel().moveToOffset(start);
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
}
updateReferences(currentPsiEl);
if (!myPsiTree.hasFocus()) {
myPsiTreeBuilder.select(currentPsiEl);
}
}
}
示例13: valueChanged
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; //导入方法依赖的package包/类
@Override
public void valueChanged(TreeSelectionEvent e) {
if (myIgnoreBlockTreeSelectionMarker > 0 || myBlockTreeBuilder == null) {
return;
}
Set<?> blockElementsSet = myBlockTreeBuilder.getSelectedElements();
if (blockElementsSet.isEmpty()) return;
BlockTreeNode descriptor = (BlockTreeNode)blockElementsSet.iterator().next();
PsiElement rootPsi = ((ViewerTreeStructure)myPsiTreeBuilder.getTreeStructure()).getRootPsiElement();
int blockStart = descriptor.getBlock().getTextRange().getStartOffset();
PsiElement currentPsiEl = InjectedLanguageUtil.findElementAtNoCommit(rootPsi.getContainingFile(), blockStart);
int blockLength = descriptor.getBlock().getTextRange().getLength();
while (currentPsiEl.getParent() != null &&
currentPsiEl.getTextRange().getStartOffset() == blockStart &&
currentPsiEl.getTextLength() != blockLength) {
currentPsiEl = currentPsiEl.getParent();
}
final BlockTreeStructure treeStructure = (BlockTreeStructure)myBlockTreeBuilder.getTreeStructure();
BlockTreeNode rootBlockNode = treeStructure.getRootElement();
int baseOffset = 0;
if (rootBlockNode != null) {
baseOffset = rootBlockNode.getBlock().getTextRange().getStartOffset();
}
if (currentPsiEl != null) {
TextRange range = descriptor.getBlock().getTextRange();
range = range.shiftRight(-baseOffset);
int start = range.getStartOffset();
int end = range.getEndOffset();
final int textLength = myEditor.getDocument().getTextLength();
if (myBlockTree.hasFocus()) {
clearSelection();
if (end <= textLength) {
myHighlighter = myEditor.getMarkupModel()
.addRangeHighlighter(start, end, HighlighterLayer.LAST, myAttributes, HighlighterTargetArea.EXACT_RANGE);
updateIntersectHighlighter(start, end);
myEditor.getCaretModel().moveToOffset(start);
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
}
updateReferences(currentPsiEl);
if (!myPsiTree.hasFocus()) {
myPsiTreeBuilder.select(currentPsiEl);
}
}
}