当前位置: 首页>>代码示例>>Java>>正文


Java InjectedLanguageUtil.findElementAtNoCommit方法代码示例

本文整理汇总了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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PsiViewerDialog.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FormattingDocumentModelImpl.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PsiElementRenameHandler.java

示例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)));
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:ImageOrColorPreviewManager.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:PsiElementRenameHandler.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo-xml,代码行数:22,代码来源:XmlTagNameSynchronizer.java

示例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);
    }
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:PsiViewerDialog.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:XmlTagNameSynchronizer.java

示例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;
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:EmmetEditPointUtil.java

示例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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:12,代码来源:PsiElementRenameHandler.java

示例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);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:50,代码来源:PsiViewerDialog.java

示例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);
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:51,代码来源:PsiViewerDialog.java

示例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);
    }
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:49,代码来源:PsiViewerDialog.java


注:本文中的com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.findElementAtNoCommit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。