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


Java PsiUtil.isStatement方法代码示例

本文整理汇总了Java中com.intellij.psi.util.PsiUtil.isStatement方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.isStatement方法的具体用法?Java PsiUtil.isStatement怎么用?Java PsiUtil.isStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.PsiUtil的用法示例。


在下文中一共展示了PsiUtil.isStatement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getResult

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public PsiElement getResult() {
  for (int i = 0; i < processedInstructions.length; i++) {
    if (!processedInstructions[i]) {
      PsiElement element = myFlow.getElement(i);
      if (element == null || !PsiUtil.isStatement(element)) continue;
      if (element.getParent() instanceof PsiExpression) continue;

      // ignore for(;;) statement unreachable update
      while (element instanceof PsiExpression) {
        element = element.getParent();
      }
      if (element instanceof PsiStatement
          && element.getParent() instanceof PsiForStatement
          && element == ((PsiForStatement)element.getParent()).getUpdate()) {
        continue;
      }
      //filter out generated stmts
      final int endOffset = myFlow.getEndOffset(element);
      if (endOffset != i + 1) continue;
      final int startOffset = myFlow.getStartOffset(element);
      // this offset actually is a part of reachable statement
      if (0 <= startOffset && startOffset < processedInstructions.length && processedInstructions[startOffset]) continue;
      return element;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:ControlFlowUtil.java

示例2: sideEffectAwareRemove

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
protected static void sideEffectAwareRemove(Project project,
                                            PsiExpression psiInitializer,
                                            PsiElement elementToDelete,
                                            PsiVariable variable) {
  if (!FileModificationService.getInstance().prepareFileForWrite(elementToDelete.getContainingFile())) return;

  final PsiElement declaration = variable.getParent();
  final List<PsiElement> sideEffects = new ArrayList<PsiElement>();
  boolean hasSideEffects = RemoveUnusedVariableUtil.checkSideEffects(psiInitializer, variable, sideEffects);
  RemoveUnusedVariableUtil.RemoveMode res = RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL;
  if (hasSideEffects) {
    hasSideEffects = PsiUtil.isStatement(psiInitializer);
    res = RemoveUnusedVariableFix.showSideEffectsWarning(sideEffects, variable,
                                                         FileEditorManager.getInstance(project).getSelectedTextEditor(),
                                                         hasSideEffects, sideEffects.get(0).getText(),
                                                         variable.getTypeElement().getText() +
                                                         " " +
                                                         variable.getName() +
                                                         ";<br>" +
                                                         PsiExpressionTrimRenderer.render(psiInitializer)
    );
  }
  try {
    if (res == RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL) {
      elementToDelete.delete();
    }
    else if (res == RemoveUnusedVariableUtil.RemoveMode.MAKE_STATEMENT) {
      final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
      final PsiStatement statementFromText = factory.createStatementFromText(psiInitializer.getText() + ";", null);
      final PsiElement parent = elementToDelete.getParent();
      if (parent instanceof PsiExpressionStatement) {
        parent.replace(statementFromText);
      } else {
        declaration.getParent().addAfter(statementFromText, declaration);
        elementToDelete.delete();
      }
    }
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:43,代码来源:RemoveInitializerFix.java

示例3: inlineResultVariable

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private void inlineResultVariable(PsiVariable resultVar) throws IncorrectOperationException {
  PsiAssignmentExpression assignment = null;
  PsiReferenceExpression resultUsage = null;
  for (PsiReference ref1 : ReferencesSearch.search(resultVar, GlobalSearchScope.projectScope(myProject), false)) {
    PsiReferenceExpression ref = (PsiReferenceExpression)ref1;
    if (ref.getParent() instanceof PsiAssignmentExpression && ((PsiAssignmentExpression)ref.getParent()).getLExpression().equals(ref)) {
      if (assignment != null) {
        assignment = null;
        break;
      }
      else {
        assignment = (PsiAssignmentExpression)ref.getParent();
      }
    }
    else {
      LOG.assertTrue(resultUsage == null, "old:" + resultUsage + "; new:" + ref);
      resultUsage = ref;
    }
  }

  if (assignment == null) return;
  boolean condition = assignment.getParent() instanceof PsiExpressionStatement;
  LOG.assertTrue(condition);
  // SCR3175 fixed: inline only if declaration and assignment is in the same code block.
  if (!(assignment.getParent().getParent() == resultVar.getParent().getParent())) return;
  if (resultUsage != null) {
    String name = resultVar.getName();
    PsiDeclarationStatement declaration =
      myFactory.createVariableDeclarationStatement(name, resultVar.getType(), assignment.getRExpression());
    declaration = (PsiDeclarationStatement)assignment.getParent().replace(declaration);
    resultVar.getParent().delete();
    resultVar = (PsiVariable)declaration.getDeclaredElements()[0];

    PsiElement parentStatement = RefactoringUtil.getParentStatement(resultUsage, true);
    PsiElement next = declaration.getNextSibling();
    boolean canInline = false;
    while (true) {
      if (next == null) break;
      if (parentStatement.equals(next)) {
        canInline = true;
        break;
      }
      if (next instanceof PsiStatement) break;
      next = next.getNextSibling();
    }

    if (canInline) {
      InlineUtil.inlineVariable(resultVar, resultVar.getInitializer(), resultUsage);
      declaration.delete();
    }
  }
  else {
    PsiExpression rExpression = assignment.getRExpression();
    while (rExpression instanceof PsiReferenceExpression) rExpression = ((PsiReferenceExpression)rExpression).getQualifierExpression();
    if (rExpression == null || !PsiUtil.isStatement(rExpression)) {
      assignment.delete();
    }
    else {
      assignment.replace(rExpression);
    }
    resultVar.delete();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:64,代码来源:InlineMethodProcessor.java


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