本文整理汇总了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());
}
示例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;
}
示例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());
}
示例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)
{
}
}
示例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;
}