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


Java ControlFlowUtil.findExitPointsAndStatements方法代码示例

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


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

示例1: highlightExitPoints

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
private void highlightExitPoints(final PsiStatement parent, final PsiCodeBlock body) throws AnalysisCanceledException
{
	final Project project = myTarget.getProject();
	ControlFlow flow = ControlFlowFactory.getInstance(project).getControlFlow(body, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(),
			false);

	Collection<PsiStatement> exitStatements = ControlFlowUtil.findExitPointsAndStatements(flow, 0, flow.getSize(), new IntArrayList(),
			PsiReturnStatement.class, PsiBreakStatement.class, PsiContinueStatement.class, PsiThrowStatement.class);
	if(!exitStatements.contains(parent))
	{
		return;
	}

	PsiElement originalTarget = getExitTarget(parent);

	final Iterator<PsiStatement> it = exitStatements.iterator();
	while(it.hasNext())
	{
		PsiStatement psiStatement = it.next();
		if(getExitTarget(psiStatement) != originalTarget)
		{
			it.remove();
		}
	}

	for(PsiElement e : exitStatements)
	{
		addOccurrence(e);
	}
	myStatusText = CodeInsightBundle.message("status.bar.exit.points.highlighted.message", exitStatements.size(), HighlightUsagesHandler.getShortcutText());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:HighlightExitPointsHandler.java

示例2: prepareExitStatements

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
public Collection<PsiStatement> prepareExitStatements(final PsiElement[] elements) throws ExitStatementsNotSameException
{
	myExitPoints = new IntArrayList();
	myExitStatements = ControlFlowUtil.findExitPointsAndStatements(myControlFlow, myFlowStart, myFlowEnd, myExitPoints, ControlFlowUtil.DEFAULT_EXIT_STATEMENTS_CLASSES);
	if(LOG.isDebugEnabled())
	{
		LOG.debug("exit points:");
		for(int i = 0; i < myExitPoints.size(); i++)
		{
			LOG.debug("  " + myExitPoints.get(i));
		}
		LOG.debug("exit statements:");
		for(PsiStatement exitStatement : myExitStatements)
		{
			LOG.debug("  " + exitStatement);
		}
	}
	if(myExitPoints.isEmpty())
	{
		// if the fragment never exits assume as if it exits in the end
		myExitPoints.add(myControlFlow.getEndOffset(elements[elements.length - 1]));
	}

	if(myExitPoints.size() != 1)
	{
		myGenerateConditionalExit = true;
		areExitStatementsTheSame();
	}
	return myExitStatements;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:31,代码来源:ControlFlowWrapper.java

示例3: testMethodWithOnlyDoWhileStatementHasExitPoints

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
public void testMethodWithOnlyDoWhileStatementHasExitPoints() throws Exception {
  configureFromFileText("a.java", "public class Foo {\n" +
                                  "  public void foo() {\n" +
                                  "    boolean f;\n" +
                                  "    do {\n" +
                                  "      f = something();\n" +
                                  "    } while (f);\n" +
                                  "  }\n" +
                                  "}");
  final PsiCodeBlock body = ((PsiJavaFile)getFile()).getClasses()[0].getMethods()[0].getBody();
  ControlFlow flow = ControlFlowFactory.getInstance(getProject()).getControlFlow(body, new LocalsControlFlowPolicy(body), false);
  IntArrayList exitPoints = new IntArrayList();
  ControlFlowUtil.findExitPointsAndStatements(flow, 0, flow.getSize() -1 , exitPoints, ControlFlowUtil.DEFAULT_EXIT_STATEMENTS_CLASSES);
  assertEquals(1, exitPoints.size());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:16,代码来源:ControlFlowTest.java

示例4: DuplicatesFinder

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
public DuplicatesFinder(PsiElement[] pattern, InputVariables parameters, @Nullable ReturnValue returnValue, @NotNull List<? extends PsiVariable> outputParameters)
{
	myReturnValue = returnValue;
	LOG.assertTrue(pattern.length > 0);
	myPattern = pattern;
	myPatternAsList = Arrays.asList(myPattern);
	myParameters = parameters;
	myOutputParameters = outputParameters;

	final PsiElement codeFragment = ControlFlowUtil.findCodeFragment(pattern[0]);
	try
	{
		final ControlFlow controlFlow = ControlFlowFactory.getInstance(codeFragment.getProject()).getControlFlow(codeFragment, new LocalsControlFlowPolicy(codeFragment), false);

		int startOffset;
		int i = 0;
		do
		{
			startOffset = controlFlow.getStartOffset(pattern[i++]);
		}
		while(startOffset < 0 && i < pattern.length);

		int endOffset;
		int j = pattern.length - 1;
		do
		{
			endOffset = controlFlow.getEndOffset(pattern[j--]);
		}
		while(endOffset < 0 && j >= 0);

		IntArrayList exitPoints = new IntArrayList();
		final Collection<PsiStatement> exitStatements = ControlFlowUtil.findExitPointsAndStatements(controlFlow, startOffset, endOffset, exitPoints,
				ControlFlowUtil.DEFAULT_EXIT_STATEMENTS_CLASSES);
		myMultipleExitPoints = exitPoints.size() > 1;

		if(myMultipleExitPoints)
		{
			myParameters.removeParametersUsedInExitsOnly(codeFragment, exitStatements, controlFlow, startOffset, endOffset);
		}
	}
	catch(AnalysisCanceledException e)
	{
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:45,代码来源:DuplicatesFinder.java

示例5: checkPostVariableUsages

import com.intellij.psi.controlFlow.ControlFlowUtil; //导入方法依赖的package包/类
private boolean checkPostVariableUsages(final ArrayList<PsiElement> candidates, final Match match)
{
	final PsiElement codeFragment = ControlFlowUtil.findCodeFragment(candidates.get(0));
	try
	{
		final ControlFlow controlFlow = ControlFlowFactory.getInstance(codeFragment.getProject()).getControlFlow(codeFragment, new LocalsControlFlowPolicy(codeFragment), false);

		int startOffset;
		int i = 0;
		do
		{
			startOffset = controlFlow.getStartOffset(candidates.get(i++));
		}
		while(startOffset < 0 && i < candidates.size());

		int endOffset;
		int j = candidates.size() - 1;
		do
		{
			endOffset = controlFlow.getEndOffset(candidates.get(j--));
		}
		while(endOffset < 0 && j >= 0);

		final IntArrayList exitPoints = new IntArrayList();
		ControlFlowUtil.findExitPointsAndStatements(controlFlow, startOffset, endOffset, exitPoints, ControlFlowUtil.DEFAULT_EXIT_STATEMENTS_CLASSES);
		final PsiVariable[] outVariables = ControlFlowUtil.getOutputVariables(controlFlow, startOffset, endOffset, exitPoints.toArray());

		if(outVariables.length > 0)
		{
			if(outVariables.length == 1)
			{
				ReturnValue returnValue = match.getReturnValue();
				if(returnValue == null)
				{
					returnValue = myReturnValue;
				}
				if(returnValue instanceof VariableReturnValue)
				{
					final ReturnValue value = match.getOutputVariableValue(((VariableReturnValue) returnValue).getVariable());
					if(value != null)
					{
						if(value.isEquivalent(new VariableReturnValue(outVariables[0])))
						{
							return false;
						}
						if(value instanceof ExpressionReturnValue)
						{
							final PsiExpression expression = ((ExpressionReturnValue) value).getExpression();
							if(expression instanceof PsiReferenceExpression)
							{
								final PsiElement variable = ((PsiReferenceExpression) expression).resolve();
								return variable == null || !PsiEquivalenceUtil.areElementsEquivalent(variable, outVariables[0]);
							}
						}
					}
				}
			}
			return true;
		}
	}
	catch(AnalysisCanceledException e)
	{
	}
	return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:66,代码来源:DuplicatesFinder.java


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