use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.
the class JavaNullMethodArgumentIndex method getNullParameterIndices.
@Nullable
private static IntArrayList getNullParameterIndices(LighterAST lighterAst, @NotNull LighterASTNode methodCall) {
final LighterASTNode node = LightTreeUtil.firstChildOfType(lighterAst, methodCall, EXPRESSION_LIST);
if (node == null)
return null;
final List<LighterASTNode> parameters = JavaLightTreeUtil.getExpressionChildren(lighterAst, node);
IntArrayList indices = new IntArrayList(1);
for (int idx = 0; idx < parameters.size(); idx++) {
if (isNullLiteral(lighterAst, parameters.get(idx))) {
indices.add(idx);
}
}
return indices;
}
use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.
the class ControlFlowTest method testMethodWithOnlyDoWhileStatementHasExitPoints.
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());
}
use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.
the class DuplicatesFinder method checkPostVariableUsages.
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;
}
use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.
the class DesignerEditorPanel method storeState.
protected void storeState() {
if (myRootComponent != null && myExpandedState == null && mySelectionState == null) {
myExpandedState = new int[myExpandedComponents == null ? 0 : myExpandedComponents.size()][];
for (int i = 0; i < myExpandedState.length; i++) {
IntArrayList path = new IntArrayList();
componentToPath((RadComponent) myExpandedComponents.get(i), path);
myExpandedState[i] = path.toArray();
}
mySelectionState = getSelectionState();
myExpandedComponents = null;
InputTool tool = myToolProvider.getActiveTool();
if (!(tool instanceof MarqueeTracker) && !(tool instanceof CreationTool) && !(tool instanceof PasteTool)) {
myToolProvider.loadDefaultTool();
}
}
}
use of com.intellij.util.containers.IntArrayList in project intellij-community by JetBrains.
the class ControlFlowWrapper method prepareExitStatements.
public Collection<PsiStatement> prepareExitStatements(@NotNull final PsiElement[] elements, @NotNull final PsiElement enclosingCodeFragment) throws ExitStatementsNotSameException {
myExitPoints = new IntArrayList();
myExitStatements = ControlFlowUtil.findExitPointsAndStatements(myControlFlow, myFlowStart, myFlowEnd, myExitPoints, ControlFlowUtil.DEFAULT_EXIT_STATEMENTS_CLASSES);
if (ControlFlowUtil.hasObservableThrowExitPoints(myControlFlow, myFlowStart, myFlowEnd, elements, enclosingCodeFragment)) {
throw new ExitStatementsNotSameException();
}
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;
}
Aggregations