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


Java PsiUtil.getVariableCodeBlock方法代码示例

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


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

示例1: isVariableAssignedInLoop

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static boolean isVariableAssignedInLoop(@NotNull PsiReferenceExpression expression, PsiElement resolved) {
  if (!(expression.getParent() instanceof PsiAssignmentExpression)
      || ((PsiAssignmentExpression)expression.getParent()).getLExpression() != expression) {
    return false;
  }
  PsiExpression qualifier = expression.getQualifierExpression();
  if (qualifier != null && !(qualifier instanceof PsiThisExpression)) return false;

  if (!(resolved instanceof PsiVariable)) return false;
  PsiVariable variable = (PsiVariable)resolved;

  final PsiElement codeBlock = PsiUtil.getVariableCodeBlock(variable, expression);
  if (codeBlock == null) return false;
  final ControlFlow flow;
  try {
    flow = ControlFlowFactory.getInstance(codeBlock.getProject()).getControlFlow(codeBlock, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(), false);
  }
  catch (AnalysisCanceledException e) {
    return false;
  }
  final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expression.getParent();
  int startOffset = flow.getStartOffset(assignmentExpression);
  return startOffset != -1 && isInstructionReachable(flow, startOffset, startOffset);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ControlFlowUtil.java

示例2: getStatementToInsertBefore

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private PsiElement getStatementToInsertBefore() {
  PsiElement declarationScope = myVariable instanceof PsiParameter
                                ? ((PsiParameter)myVariable).getDeclarationScope() : PsiUtil.getVariableCodeBlock(myVariable, null);
  if (declarationScope == null) return null;

  PsiElement statement = myContext;
  nextInnerClass:
  do {
    statement = RefactoringUtil.getParentStatement(statement, false);

    if (statement == null || statement.getParent() == null) {
      return null;
    }
    PsiElement element = statement;
    while (element != declarationScope && !(element instanceof PsiFile)) {
      if (element instanceof PsiClass) {
        statement = statement.getParent();
        continue nextInnerClass;
      }
      element = element.getParent();
    }
    return statement;
  }
  while (true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:VariableAccessFromInnerClassFix.java

示例3: isEffectivelyFinal

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static boolean isEffectivelyFinal(@NotNull PsiVariable variable, @NotNull PsiElement scope, @Nullable PsiJavaCodeReferenceElement context) {
  boolean effectivelyFinal;
  if (variable instanceof PsiParameter) {
    effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(((PsiParameter)variable).getDeclarationScope()));
  }
  else {
    final ControlFlow controlFlow;
    try {
      PsiElement codeBlock = PsiUtil.getVariableCodeBlock(variable, context);
      if (codeBlock == null) return true;
      controlFlow = getControlFlow(codeBlock);
    }
    catch (AnalysisCanceledException e) {
      return true;
    }

    final List<PsiReferenceExpression> readBeforeWriteLocals = ControlFlowUtil.getReadBeforeWriteLocals(controlFlow);
    for (PsiReferenceExpression expression : readBeforeWriteLocals) {
      if (expression.resolve() == variable) {
        return PsiUtil.isAccessedForReading(expression);
      }
    }

    final Collection<ControlFlowUtil.VariableInfo> initializedTwice = ControlFlowUtil.getInitializedTwice(controlFlow);
    effectivelyFinal = !initializedTwice.contains(new ControlFlowUtil.VariableInfo(variable, null));
    if (effectivelyFinal) {
      effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(scope));
    }
  }
  return effectivelyFinal;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:HighlightControlFlowUtil.java

示例4: getQuickFixType

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static int getQuickFixType(@NotNull PsiVariable variable) {
  PsiElement outerCodeBlock = PsiUtil.getVariableCodeBlock(variable, null);
  if (outerCodeBlock == null) return -1;
  List<PsiReferenceExpression> outerReferences = new ArrayList<PsiReferenceExpression>();
  collectReferences(outerCodeBlock, variable, outerReferences);

  int type = MAKE_FINAL;
  for (PsiReferenceExpression expression : outerReferences) {
    // if it happens that variable referenced from another inner class, make sure it can be make final from there
    PsiElement innerScope = HighlightControlFlowUtil.getInnerClassVariableReferencedFrom(variable, expression);

    if (innerScope != null) {
      int thisType = MAKE_FINAL;
      if (writtenInside(variable, innerScope)) {
        // cannot make parameter array
        if (variable instanceof PsiParameter) return -1;
        thisType = MAKE_ARRAY;
      }
      if (thisType == MAKE_FINAL
          && !canBeFinal(variable, outerReferences)) {
        thisType = COPY_TO_FINAL;
      }
      type = Math.max(type, thisType);
    }
  }
  return type;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:VariableAccessFromInnerClassFix.java

示例5: deferLocalVariable

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private void deferLocalVariable(PsiLocalVariable variable) throws IncorrectOperationException {
  PsiElement outerCodeBlock = PsiUtil.getVariableCodeBlock(variable, null);
  deferVariable(outerCodeBlock, variable, variable.getParent());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:DeferFinalAssignmentFix.java


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