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


Java ControlFlowUtil类代码示例

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


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

示例1: findSubmemberHidesFieldCollisions

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
private static void findSubmemberHidesFieldCollisions(final PsiField field, final String newName, final List<UsageInfo> result) {
  if (field.getContainingClass() == null) return;
  if (field.hasModifierProperty(PsiModifier.PRIVATE)) return;
  final PsiClass containingClass = field.getContainingClass();
  Collection<PsiClass> inheritors = ClassInheritorsSearch.search(containingClass, true).findAll();
  for (PsiClass inheritor : inheritors) {
    PsiField conflictingField = inheritor.findFieldByName(newName, false);
    if (conflictingField != null) {
      result.add(new SubmemberHidesMemberUsageInfo(conflictingField, field));
    } 
    else { //local class
      final PsiMember member = PsiTreeUtil.getParentOfType(inheritor, PsiMember.class);
      if (member != null) {
        final ArrayList<PsiVariable> variables = new ArrayList<PsiVariable>();
        ControlFlowUtil.collectOuterLocals(variables, inheritor, inheritor, member);
        for (PsiVariable variable : variables) {
          if (newName.equals(variable.getName())) {
            result.add(new FieldHidesLocalUsageInfo(variable, field));
          }
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:RenameJavaVariableProcessor.java

示例2: blockCompletesAbruptly

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
private static boolean blockCompletesAbruptly(@NotNull final PsiCodeBlock finallyBlock)
{
	try
	{
		ControlFlow flow = ControlFlowFactory.getInstance(finallyBlock.getProject()).getControlFlow(finallyBlock, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(), false);
		int completionReasons = ControlFlowUtil.getCompletionReasons(flow, 0, flow.getSize());
		if(!BitUtil.isSet(completionReasons, ControlFlowUtil.NORMAL_COMPLETION_REASON))
		{
			return true;
		}
	}
	catch(AnalysisCanceledException e)
	{
		return true;
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:ExceptionUtil.java

示例3: 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

示例4: 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

示例5: checkInitializerCompleteNormally

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
@Nullable
static HighlightInfo checkInitializerCompleteNormally(@NotNull PsiClassInitializer initializer)
{
	final PsiCodeBlock body = initializer.getBody();
	// unhandled exceptions already reported
	try
	{
		final ControlFlow controlFlow = getControlFlowNoConstantEvaluate(body);
		final int completionReasons = ControlFlowUtil.getCompletionReasons(controlFlow, 0, controlFlow.getSize());
		if((completionReasons & ControlFlowUtil.NORMAL_COMPLETION_REASON) == 0)
		{
			String description = JavaErrorMessages.message("initializer.must.be.able.to.complete.normally");
			return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(body).descriptionAndTooltip(description).create();
		}
	}
	catch(AnalysisCanceledException e)
	{
		// incomplete code
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:HighlightControlFlowUtil.java

示例6: declareNecessaryVariablesInsideBody

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
private void declareNecessaryVariablesInsideBody(PsiCodeBlock body) throws IncorrectOperationException
{
	List<PsiVariable> usedVariables = myControlFlowWrapper.getUsedVariablesInBody(ControlFlowUtil.findCodeFragment(myElements[0]), myOutputVariables);
	for(PsiVariable variable : usedVariables)
	{
		boolean toDeclare = !isDeclaredInside(variable) && myInputVariables.toDeclareInsideBody(variable);
		if(toDeclare)
		{
			String name = variable.getName();
			PsiDeclarationStatement statement = myElementFactory.createVariableDeclarationStatement(name, variable.getType(), null);
			body.add(statement);
		}
	}

	if(myArtificialOutputVariable instanceof PsiField && !myIsChainedConstructor)
	{
		body.add(myElementFactory.createVariableDeclarationStatement(myArtificialOutputVariable.getName(), myArtificialOutputVariable.getType(), null));
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:ExtractMethodProcessor.java

示例7: 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

示例8: makeFinalIfNeeded

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
public static void makeFinalIfNeeded(@NotNull InsertionContext context, @NotNull PsiVariable variable) {
  PsiElement place = context.getFile().findElementAt(context.getTailOffset() - 1);
  if (!Registry.is("java.completion.make.outer.variables.final") ||
      place == null || PsiUtil.isLanguageLevel8OrHigher(place) || JspPsiUtil.isInJspFile(place)) {
    return;
  }

  if (HighlightControlFlowUtil.getInnerClassVariableReferencedFrom(variable, place) != null &&
      !HighlightControlFlowUtil.isReassigned(variable, new HashMap<PsiElement, Collection<ControlFlowUtil.VariableInfo>>())) {
    PsiUtil.setModifierProperty(variable, PsiModifier.FINAL, true);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:VariableLookupItem.java

示例9: declareNecessaryVariablesInsideBody

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
private void declareNecessaryVariablesInsideBody(PsiCodeBlock body) throws IncorrectOperationException {
  List<PsiVariable> usedVariables = myControlFlowWrapper.getUsedVariablesInBody(ControlFlowUtil.findCodeFragment(myElements[0]), myOutputVariables);
  for (PsiVariable variable : usedVariables) {
    boolean toDeclare = !isDeclaredInside(variable) && myInputVariables.toDeclareInsideBody(variable);
    if (toDeclare) {
      String name = variable.getName();
      PsiDeclarationStatement statement = myElementFactory.createVariableDeclarationStatement(name, variable.getType(), null);
      body.add(statement);
    }
  }

  if (myArtificialOutputVariable instanceof PsiField && !myIsChainedConstructor) {
    body.add(myElementFactory.createVariableDeclarationStatement(myArtificialOutputVariable.getName(), myArtificialOutputVariable.getType(), null));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:ExtractMethodProcessor.java

示例10: 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

示例11: isValueCompatibleNoCache

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
private boolean isValueCompatibleNoCache()
{
	final PsiElement body = getBody();
	if(body instanceof PsiCodeBlock)
	{
		try
		{
			ControlFlow controlFlow = ControlFlowFactory.getInstance(getProject()).getControlFlow(body, ourPolicy, false, false);
			int startOffset = controlFlow.getStartOffset(body);
			int endOffset = controlFlow.getEndOffset(body);
			if(startOffset != -1 && endOffset != -1 && ControlFlowUtil.canCompleteNormally(controlFlow, startOffset, endOffset))
			{
				return false;
			}
		}
		//error would be shown inside body
		catch(AnalysisCanceledException ignore)
		{
		}

		for(PsiReturnStatement statement : PsiUtil.findReturnStatements((PsiCodeBlock) body))
		{
			if(statement.getReturnValue() == null)
			{
				return false;
			}
		}
	}
	return true;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:31,代码来源:PsiLambdaExpressionImpl.java

示例12: checkMissingReturnStatement

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
@Nullable
static HighlightInfo checkMissingReturnStatement(@Nullable PsiCodeBlock body, @Nullable PsiType returnType)
{
	if(body == null || returnType == null || PsiType.VOID.equals(returnType.getDeepComponentType()))
	{
		return null;
	}

	// do not compute constant expressions for if() statement condition
	// see JLS 14.20 Unreachable Statements
	try
	{
		ControlFlow controlFlow = getControlFlowNoConstantEvaluate(body);
		if(!ControlFlowUtil.returnPresent(controlFlow))
		{
			PsiJavaToken rBrace = body.getRBrace();
			PsiElement context = rBrace == null ? body.getLastChild() : rBrace;
			String message = JavaErrorMessages.message("missing.return.statement");
			HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(context).descriptionAndTooltip(message).create();
			PsiElement parent = body.getParent();
			if(parent instanceof PsiMethod)
			{
				PsiMethod method = (PsiMethod) parent;
				QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createAddReturnFix(method));
				QuickFixAction.registerQuickFixAction(info, QUICK_FIX_FACTORY.createMethodReturnFix(method, PsiType.VOID, true));
			}
			return info;
		}
	}
	catch(AnalysisCanceledException ignored)
	{
	}

	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:36,代码来源:HighlightControlFlowUtil.java

示例13: checkUnreachableStatement

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
static HighlightInfo checkUnreachableStatement(@Nullable PsiCodeBlock codeBlock)
{
	if(codeBlock == null)
	{
		return null;
	}
	// do not compute constant expressions for if() statement condition
	// see JLS 14.20 Unreachable Statements
	try
	{
		AllVariablesControlFlowPolicy policy = AllVariablesControlFlowPolicy.getInstance();
		final ControlFlow controlFlow = ControlFlowFactory.getInstance(codeBlock.getProject()).getControlFlow(codeBlock, policy, false, false);
		final PsiElement unreachableStatement = ControlFlowUtil.getUnreachableStatement(controlFlow);
		if(unreachableStatement != null)
		{
			String description = JavaErrorMessages.message("unreachable.statement");
			return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(unreachableStatement).descriptionAndTooltip(description).create();
		}
	}
	catch(AnalysisCanceledException e)
	{
		// incomplete code
	}
	catch(IndexNotReadyException ignored)
	{
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:29,代码来源:HighlightControlFlowUtil.java

示例14: variableDefinitelyAssignedIn

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
/**
 * see JLS chapter 16
 *
 * @return true if variable assigned (maybe more than once)
 */
private static boolean variableDefinitelyAssignedIn(@NotNull PsiVariable variable, @NotNull PsiElement context)
{
	try
	{
		ControlFlow controlFlow = getControlFlow(context);
		return ControlFlowUtil.isVariableDefinitelyAssigned(variable, controlFlow);
	}
	catch(AnalysisCanceledException e)
	{
		return false;
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:HighlightControlFlowUtil.java

示例15: variableDefinitelyNotAssignedIn

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入依赖的package包/类
private static boolean variableDefinitelyNotAssignedIn(@NotNull PsiVariable variable, @NotNull PsiElement context)
{
	try
	{
		ControlFlow controlFlow = getControlFlow(context);
		return ControlFlowUtil.isVariableDefinitelyNotAssigned(variable, controlFlow);
	}
	catch(AnalysisCanceledException e)
	{
		return false;
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:13,代码来源:HighlightControlFlowUtil.java


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