Search in sources :

Example 21 with IntArrayList

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;
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) IntArrayList(com.intellij.util.containers.IntArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with IntArrayList

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());
}
Also used : PsiCodeBlock(com.intellij.psi.PsiCodeBlock) PsiJavaFile(com.intellij.psi.PsiJavaFile) IntArrayList(com.intellij.util.containers.IntArrayList)

Example 23 with IntArrayList

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;
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList)

Example 24 with IntArrayList

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();
        }
    }
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList)

Example 25 with IntArrayList

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;
}
Also used : IntArrayList(com.intellij.util.containers.IntArrayList)

Aggregations

IntArrayList (com.intellij.util.containers.IntArrayList)31 ArrayList (java.util.ArrayList)5 PsiFile (com.intellij.psi.PsiFile)3 NotNull (org.jetbrains.annotations.NotNull)3 TextRange (com.intellij.openapi.util.TextRange)2 Nullable (org.jetbrains.annotations.Nullable)2 ExceptionUtil (com.intellij.codeInsight.ExceptionUtil)1 RadComponent (com.intellij.designer.model.RadComponent)1 LighterASTNode (com.intellij.lang.LighterASTNode)1 Logger (com.intellij.openapi.diagnostic.Logger)1 RangeMarker (com.intellij.openapi.editor.RangeMarker)1 Project (com.intellij.openapi.project.Project)1 com.intellij.psi (com.intellij.psi)1 PsiCodeBlock (com.intellij.psi.PsiCodeBlock)1 PsiElement (com.intellij.psi.PsiElement)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 DummyHolder (com.intellij.psi.impl.source.DummyHolder)1 MethodSignature (com.intellij.psi.util.MethodSignature)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 PsiUtil (com.intellij.psi.util.PsiUtil)1