當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiFile.findElementAt方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiFile.findElementAt方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiFile.findElementAt方法的具體用法?Java PsiFile.findElementAt怎麽用?Java PsiFile.findElementAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiFile的用法示例。


在下文中一共展示了PsiFile.findElementAt方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
public void execute(@NotNull Editor editor, char charTyped, @NotNull DataContext dataContext) {
  myOriginalHandler.execute(editor, charTyped, dataContext);
  if (isMatchForClosingTag(editor, charTyped)) {
    int offset = editor.getCaretModel().getOffset();
    PsiFile file = dataContext.getData(LangDataKeys.PSI_FILE);
    if (file == null) {
      return;
    }
    PsiElement el = file.findElementAt(offset - 1);
    TagBlockElement block = (TagBlockElement) PsiTreeUtil
        .findFirstParent(el,
            parent -> parent instanceof TagBlockElement && !(parent instanceof SoyChoiceClause));
    if (block == null) {
      return;
    }
    String closingTag = block.getOpeningTag().generateClosingTag();
    insertClosingTag(editor, offset, closingTag);
    if (editor.getProject() != null) {
      PsiDocumentManager.getInstance(editor.getProject()).commitDocument(editor.getDocument());
      CodeStyleManager.getInstance(editor.getProject()).reformat(block);
    }
  }
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:24,代碼來源:ClosingTagHandler.java

示例2: postProcessEnter

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Override
public Result postProcessEnter(
    @NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
  if (file.getFileType() != SoyFileType.INSTANCE) {
    return Result.Continue;
  }

  int caretOffset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(caretOffset);
  Document document = editor.getDocument();

  int lineNumber = document.getLineNumber(caretOffset) - 1;
  int lineStartOffset = document.getLineStartOffset(lineNumber);
  String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset));

  if (element instanceof PsiComment && element.getTextOffset() < caretOffset) {
    handleEnterInComment(element, file, editor);
  } else if (lineTextBeforeCaret.startsWith("/*")) {
    insertText(file, editor, " * \n ", 3);
  }

  return Result.Continue;
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:24,代碼來源:EnterHandler.java

示例3: handleNoUsageTargets

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
/**
     * {@link com.intellij.codeInsight.highlighting.HighlightUsagesHandler#handleNoUsageTargets(PsiFile,
     * Editor, SelectionModel, Project)}
     */
    private static void handleNoUsageTargets(PsiFile file, @NotNull Editor editor,
            @NotNull Project project) {
        if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) {
            return;
        }
        final SelectionModel selectionModel = editor.getSelectionModel();
        selectionModel.selectWordAtCaret(false);
        String selection = selectionModel.getSelectedText();
//        LOG.assertTrue(selection != null);
        if (selection != null) {
            for (int i = 0; i < selection.length(); i++) {
                if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
                    selectionModel.removeSelection();
                }
            }
            
            searchSelection(editor, project);
            selectionModel.removeSelection();
        }
    }
 
開發者ID:huoguangjin,項目名稱:MultiHighlight,代碼行數:25,代碼來源:MultiHighlightHandler.java

示例4: getPsiClassFromContext

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
private PsiClass getPsiClassFromContext(AnActionEvent e) {
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);

    if (psiFile == null || editor == null) {
        return null;
    }

    int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);

    return PsiTreeUtil.getParentOfType(element, PsiClass.class);
}
 
開發者ID:LightSun,項目名稱:intellij-plugin-tools,代碼行數:14,代碼來源:BuilderClassAction.java

示例5: isInContext

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Override
public boolean isInContext(@NotNull PsiFile file, int offset) {
  if (file.getFileType() != SoyFileType.INSTANCE) return false;

  PsiElement element = file.findElementAt(offset);
  return psiElement()
      .andOr(
          psiElement().inside(Matchers.templateBlockMatcher),
          psiElement().withAncestor(2, Matchers.templateCallStatementMatcher))
      .accepts(element);
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:12,代碼來源:CallBlockContext.java

示例6: isInContext

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Override
public boolean isInContext(@NotNull PsiFile file, int offset) {
  if (file.getFileType() != SoyFileType.INSTANCE) return false;

  PsiElement element = file.findElementAt(offset);
  return psiElement()
      .inside(Matchers.templateBlockMatcher)
      .andNot(psiElement().withAncestor(2, Matchers.templateCallStatementMatcher))
      .accepts(element);
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:11,代碼來源:TemplateBlockContext.java

示例7: isInContext

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Override
public boolean isInContext(@NotNull PsiFile file, int offset) {
  if (file.getFileType() != SoyFileType.INSTANCE) return false;

  PsiElement element = file.findElementAt(offset);
  return !psiElement().inside(Matchers.templateBlockMatcher).accepts(element);
}
 
開發者ID:google,項目名稱:bamboo-soy,代碼行數:8,代碼來源:TopLevelContext.java

示例8: getPsiClassFromContext

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
private PsiClass getPsiClassFromContext(AnActionEvent e) {
    PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
   // psiFile.getViewProvider().getVirtualFile()

    if (psiFile == null || editor == null) {
        return null;
    }
    int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);

    return PsiTreeUtil.getParentOfType(element, PsiClass.class);
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:14,代碼來源:ConvertAction.java

示例9: getPsiClass

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
/**
 * 獲取當前焦點下的類
 * @param anActionEvent
 * @return
 */
public static PsiClass getPsiClass(AnActionEvent anActionEvent) {

    PsiFile psiFile = anActionEvent.getData(LangDataKeys.PSI_FILE);
    Editor editor = anActionEvent.getData(PlatformDataKeys.EDITOR);

    if (psiFile == null || editor == null) {
        return null;
    }

    int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);

    return PsiTreeUtil.getParentOfType(element, PsiClass.class);
}
 
開發者ID:hykes,項目名稱:CodeGen,代碼行數:20,代碼來源:PsiUtil.java

示例10: collectExpressions

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
public static List<PsiElement> collectExpressions(final PsiFile file,
                                                  final Document document,
                                                  final int offset,
                                                  boolean acceptVoid) {
	CharSequence text = document.getCharsSequence();
	int correctedOffset = offset;
	int textLength = document.getTextLength();
	if (offset >= textLength) {
		correctedOffset = textLength - 1;
	} else if (!Character.isJavaIdentifierPart(text.charAt(offset))) {
		correctedOffset--;
	}
	if (correctedOffset < 0) {
		correctedOffset = offset;
	} else if (!Character.isJavaIdentifierPart(text.charAt(correctedOffset))) {
		if (text.charAt(correctedOffset) == ';') {//initially caret on the end of line
			correctedOffset--;
		}
		if (correctedOffset < 0 || text.charAt(correctedOffset) != ')') {
			correctedOffset = offset;
		}
	}
	final PsiElement elementAtCaret = file.findElementAt(correctedOffset);
	final List<PsiElement> expressions = new ArrayList<>();

	PsiElement expression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiElement.class);

	while (expression != null && expression.getTextRange().getEndOffset() == elementAtCaret.getTextRange().getEndOffset()) {
		//System.out.println(expression + " - " + expression.getText() + " - " + expression.getTextRange());
		final PsiElement finalExpression = expression;

		if (expression.getPrevSibling() == null || expression.getPrevSibling().getNode().getElementType() == TokenType.WHITE_SPACE) {
			if (expressions.stream().noneMatch(pe -> finalExpression.getTextRange().equals(pe.getTextRange()))) {
				expressions.add(expression);
			}
		} else {
			//System.out.println("prevSilbing: " + expression.getPrevSibling().getNode().getElementType());
		}

		//expression = PsiTreeUtil.getParentOfType(expression, KtExpression.class);
		expression = expression.getParent();
	}

	// TODO: For an unknown reason this code completion works only with a single expression and not with multiple ones.
	// TODO: Therefore we have to cut our list to a singleton list.
	if (expressions.isEmpty()) {
		return expressions;
	}
	ArrayList<PsiElement> es = new ArrayList<>();
	es.add(expressions.get(0));
	//es.add(expressions.get(expressions.size()-1));
	return es;
}
 
開發者ID:xylo,項目名稱:intellij-postfix-templates,代碼行數:54,代碼來源:CustomKotlinStringPostfixTemplate.java

示例11: accept

import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
/**
 * Override to filter errors related to type incompatibilities arising from a
 * manifold extension adding an interface to an existing classpath class (as opposed
 * to a source file).  Basically suppress "incompatible type errors" or similar
 * involving a structural interface extension.
 */
@Override
public boolean accept( @NotNull HighlightInfo hi, @Nullable PsiFile file )
{
  if( hi.getDescription() == null ||
      hi.getSeverity() != HighlightSeverity.ERROR ||
      file == null )
  {
    return true;
  }

  PsiElement firstElem = file.findElementAt( hi.getStartOffset() );
  if( firstElem == null )
  {
    return true;
  }

  PsiElement elem = firstElem.getParent();
  if( elem == null )
  {
    return true;
  }

  if( isInvalidStaticMethodOnInterface( hi ) )
  {
    PsiElement lhsType = ((PsiReferenceExpressionImpl)((PsiMethodCallExpressionImpl)elem.getParent()).getMethodExpression().getQualifierExpression()).resolve();
    if( lhsType instanceof ManifoldPsiClass || lhsType instanceof ManifoldExtendedPsiClass )
    {
      PsiMethod psiMethod = ((PsiMethodCallExpressionImpl)elem.getParent()).resolveMethod();
      if( psiMethod.getContainingClass().isInterface() )
      {
        // ignore "Static method may be invoked on containing interface class only" errors where the method really is directly on a the interface, albeit the delegate
        return false;
      }
    }
    return true;
  }

  //##
  //## structural interface extensions cannot be added to the psiClass, so for now we suppress "incompatible type errors" or similar involving a structural interface extension.
  //##
  Boolean x = acceptInterfaceError( hi, firstElem, elem );
  if( x != null ) return x;

  return true;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:52,代碼來源:ManHighlightInfoFilter.java


注:本文中的com.intellij.psi.PsiFile.findElementAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。