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


Java ControlFlowUtil.VariableInfo方法代码示例

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


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

示例1: isReassigned

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
public static boolean isReassigned(@NotNull PsiVariable variable, @NotNull Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems)
{
	if(variable instanceof PsiLocalVariable)
	{
		final PsiElement parent = variable.getParent();
		if(parent == null)
		{
			return false;
		}
		final PsiElement declarationScope = parent.getParent();
		if(declarationScope == null)
		{
			return false;
		}
		Collection<ControlFlowUtil.VariableInfo> codeBlockProblems = getFinalVariableProblemsInBlock(finalVarProblems, declarationScope);
		return codeBlockProblems.contains(new ControlFlowUtil.VariableInfo(variable, null));
	}
	if(variable instanceof PsiParameter)
	{
		final PsiParameter parameter = (PsiParameter) variable;
		return isAssigned(parameter);
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:25,代码来源:HighlightControlFlowUtil.java

示例2: getFinalVariableProblemsInBlock

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
@NotNull
private static Collection<ControlFlowUtil.VariableInfo> getFinalVariableProblemsInBlock(@NotNull Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems,
		@NotNull PsiElement codeBlock)
{
	Collection<ControlFlowUtil.VariableInfo> codeBlockProblems = finalVarProblems.get(codeBlock);
	if(codeBlockProblems == null)
	{
		try
		{
			final ControlFlow controlFlow = getControlFlowNoConstantEvaluate(codeBlock);
			codeBlockProblems = ControlFlowUtil.getInitializedTwice(controlFlow);
		}
		catch(AnalysisCanceledException e)
		{
			codeBlockProblems = Collections.emptyList();
		}
		finalVarProblems.put(codeBlock, codeBlockProblems);
	}
	return codeBlockProblems;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:HighlightControlFlowUtil.java

示例3: canBeFinal

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
private static boolean canBeFinal(@NotNull PsiVariable variable, @NotNull List<PsiReferenceExpression> references) {
  // if there is at least one assignment to this variable, it cannot be final
  Map<PsiElement, Collection<PsiReferenceExpression>> uninitializedVarProblems = new THashMap<PsiElement, Collection<PsiReferenceExpression>>();
  Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems = new THashMap<PsiElement, Collection<ControlFlowUtil.VariableInfo>>();
  for (PsiReferenceExpression expression : references) {
    if (ControlFlowUtil.isVariableAssignedInLoop(expression, variable)) return false;
    HighlightInfo highlightInfo = HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, variable, uninitializedVarProblems,
                                                                                               variable.getContainingFile());
    if (highlightInfo != null) return false;
    highlightInfo = HighlightControlFlowUtil.checkFinalVariableMightAlreadyHaveBeenAssignedTo(variable, expression, finalVarProblems);
    if (highlightInfo != null) return false;
    if (variable instanceof PsiParameter && PsiUtil.isAccessedForWriting(expression)) return false;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:VariableAccessFromInnerClassFix.java

示例4: canBeFinal

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
private static boolean canBeFinal(PsiVariable variable, List<PsiReferenceExpression> references) {
  // if there is at least one assignment to this variable, it cannot be final
  Map<PsiElement, Collection<PsiReferenceExpression>> uninitializedVarProblems = new THashMap<PsiElement, Collection<PsiReferenceExpression>>();
  Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems = new THashMap<PsiElement, Collection<ControlFlowUtil.VariableInfo>>();
  for (PsiReferenceExpression expression : references) {
    if (ControlFlowUtil.isVariableAssignedInLoop(expression, variable)) return false;
    HighlightInfo highlightInfo = HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, variable, uninitializedVarProblems,
                                                                                               variable.getContainingFile());
    if (highlightInfo != null) return false;
    highlightInfo = HighlightControlFlowUtil.checkFinalVariableMightAlreadyHaveBeenAssignedTo(variable, expression, finalVarProblems);
    if (highlightInfo != null) return false;
    if (variable instanceof PsiParameter && PsiUtil.isAccessedForWriting(expression)) return false;
  }
  return true;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:VariableAccessFromInnerClassFix.java

示例5: declareLocalVariables

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
private void declareLocalVariables() throws IncorrectOperationException {
  final PsiElement codeFragment = ControlFlowUtil.findCodeFragment(getMatchStart());
  try {
    final Project project = getMatchStart().getProject();
    final ControlFlow controlFlow = ControlFlowFactory.getInstance(project)
      .getControlFlow(codeFragment, new LocalsControlFlowPolicy(codeFragment));
    final int endOffset = controlFlow.getEndOffset(getMatchEnd());
    final int startOffset = controlFlow.getStartOffset(getMatchStart());
    final List<PsiVariable> usedVariables = ControlFlowUtil.getUsedVariables(controlFlow, endOffset, controlFlow.getSize());
    Collection<ControlFlowUtil.VariableInfo> reassigned = ControlFlowUtil.getInitializedTwice(controlFlow, endOffset, controlFlow.getSize());
    final Collection<PsiVariable> outVariables = ControlFlowUtil.getWrittenVariables(controlFlow, startOffset, endOffset, false);
    for (PsiVariable variable : usedVariables) {
      if (!outVariables.contains(variable)) {
        final PsiIdentifier identifier = variable.getNameIdentifier();
        if (identifier != null) {
          final TextRange textRange = checkRange(identifier);
          final TextRange startRange = checkRange(getMatchStart());
          final TextRange endRange = checkRange(getMatchEnd());
          if (textRange.getStartOffset() >= startRange.getStartOffset() && textRange.getEndOffset() <= endRange.getEndOffset()) {
            final String name = variable.getName();
            LOG.assertTrue(name != null);
            PsiDeclarationStatement statement =
              JavaPsiFacade.getInstance(project).getElementFactory().createVariableDeclarationStatement(name, variable.getType(), null);
            if (reassigned.contains(new ControlFlowUtil.VariableInfo(variable, null))) {
              final PsiElement[] psiElements = statement.getDeclaredElements();
              final PsiModifierList modifierList = ((PsiVariable)psiElements[0]).getModifierList();
              LOG.assertTrue(modifierList != null);
              modifierList.setModifierProperty(PsiModifier.FINAL, false);
            }
            getMatchStart().getParent().addBefore(statement, getMatchStart());
          }
        }
      }
    }
  }
  catch (AnalysisCanceledException e) {
    //skip match
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:40,代码来源:Match.java

示例6: isEffectivelyFinal

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的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:consulo,项目名称:consulo-java,代码行数:43,代码来源:HighlightControlFlowUtil.java

示例7: getInitializedTwice

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
public Collection<ControlFlowUtil.VariableInfo> getInitializedTwice(int start)
{
	return ControlFlowUtil.getInitializedTwice(myControlFlow, start, myControlFlow.getSize());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:5,代码来源:ControlFlowWrapper.java


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