Search in sources :

Example 11 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class InvertedIndexUtil method collectInputIdsContainingAllKeys.

@NotNull
public static <K, V, I> TIntHashSet collectInputIdsContainingAllKeys(@NotNull InvertedIndex<K, V, I> index, @NotNull Collection<K> dataKeys, @Nullable Condition<K> keyChecker, @Nullable Condition<V> valueChecker, @Nullable ValueContainer.IntPredicate idChecker) throws StorageException {
    TIntHashSet mainIntersection = null;
    for (K dataKey : dataKeys) {
        if (keyChecker != null && !keyChecker.value(dataKey))
            continue;
        final TIntHashSet copy = new TIntHashSet();
        final ValueContainer<V> container = index.getData(dataKey);
        for (ValueContainer.ValueIterator<V> valueIt = container.getValueIterator(); valueIt.hasNext(); ) {
            final V value = valueIt.next();
            if (valueChecker != null && !valueChecker.value(value)) {
                continue;
            }
            ValueContainer.IntIterator iterator = valueIt.getInputIdsIterator();
            final ValueContainer.IntPredicate predicate;
            if (mainIntersection == null || iterator.size() < mainIntersection.size() || (predicate = valueIt.getValueAssociationPredicate()) == null) {
                while (iterator.hasNext()) {
                    final int id = iterator.next();
                    if (mainIntersection == null && (idChecker == null || idChecker.contains(id)) || mainIntersection != null && mainIntersection.contains(id)) {
                        copy.add(id);
                    }
                }
            } else {
                mainIntersection.forEach(new TIntProcedure() {

                    @Override
                    public boolean execute(int id) {
                        if (predicate.contains(id))
                            copy.add(id);
                        return true;
                    }
                });
            }
        }
        mainIntersection = copy;
        if (mainIntersection.isEmpty()) {
            return EmptyIntHashSet.INSTANCE;
        }
    }
    return mainIntersection == null ? EmptyIntHashSet.INSTANCE : mainIntersection;
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) TIntHashSet(gnu.trove.TIntHashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class IntroduceParameterProcessor method removeParametersFromCall.

private void removeParametersFromCall(final PsiExpressionList argList) {
    final PsiExpression[] exprs = argList.getExpressions();
    myParametersToRemove.forEachDescending(new TIntProcedure() {

        public boolean execute(final int paramNum) {
            if (paramNum < exprs.length) {
                try {
                    exprs[paramNum].delete();
                } catch (IncorrectOperationException e) {
                    LOG.error(e);
                }
            }
            return true;
        }
    });
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 13 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class JavaIntroduceParameterMethodUsagesProcessor method findConflicts.

public void findConflicts(IntroduceParameterData data, UsageInfo[] usages, final MultiMap<PsiElement, String> conflicts) {
    final PsiMethod method = data.getMethodToReplaceIn();
    final int parametersCount = method.getParameterList().getParametersCount();
    for (UsageInfo usage : usages) {
        final PsiElement element = usage.getElement();
        if (element instanceof PsiMethodReferenceExpression && !ApplicationManager.getApplication().isUnitTestMode()) {
            conflicts.putValue(element, RefactoringBundle.message("expand.method.reference.warning"));
        }
        if (!isMethodUsage(usage))
            continue;
        final PsiCall call = RefactoringUtil.getCallExpressionByMethodReference(element);
        final PsiExpressionList argList = call.getArgumentList();
        if (argList != null) {
            final int actualParamLength = argList.getExpressions().length;
            if ((method.isVarArgs() && actualParamLength + 1 < parametersCount) || (!method.isVarArgs() && actualParamLength < parametersCount)) {
                conflicts.putValue(call, "Incomplete call(" + call.getText() + "): " + parametersCount + " parameters expected but only " + actualParamLength + " found");
            }
            data.getParametersToRemove().forEach(new TIntProcedure() {

                public boolean execute(int paramNum) {
                    if (paramNum >= actualParamLength) {
                        conflicts.putValue(call, "Incomplete call(" + call.getText() + "): expected to delete the " + paramNum + " parameter but only " + actualParamLength + " parameters found");
                    }
                    return true;
                }
            });
        }
    }
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) UsageInfo(com.intellij.usageView.UsageInfo)

Example 14 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class LoopAnalyzer method calcInLoop.

static int[] calcInLoop(ControlFlow controlFlow) {
    // loop[i] = loop number(strongly connected component number) of i-th instruction or 0 if outside loop
    final int[] loop = new int[controlFlow.getInstructionCount()];
    MyGraph graph = new MyGraph(controlFlow);
    final DFSTBuilder<Instruction> builder = new DFSTBuilder<>(graph);
    TIntArrayList sccs = builder.getSCCs();
    sccs.forEach(new TIntProcedure() {

        private int myTNumber;

        private int component;

        @Override
        public boolean execute(int size) {
            int value = size > 1 ? ++component : 0;
            for (int i = 0; i < size; i++) {
                Instruction instruction = builder.getNodeByTNumber(myTNumber + i);
                loop[instruction.getIndex()] = value;
            }
            myTNumber += size;
            return true;
        }
    });
    return loop;
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) DFSTBuilder(com.intellij.util.graph.DFSTBuilder) ConditionalGotoInstruction(com.intellij.codeInspection.dataFlow.instructions.ConditionalGotoInstruction) GotoInstruction(com.intellij.codeInspection.dataFlow.instructions.GotoInstruction) Instruction(com.intellij.codeInspection.dataFlow.instructions.Instruction) TIntArrayList(gnu.trove.TIntArrayList)

Example 15 with TIntProcedure

use of gnu.trove.TIntProcedure in project intellij-community by JetBrains.

the class EqClass method getMemberValues.

List<DfaValue> getMemberValues() {
    final List<DfaValue> result = new ArrayList<>(size());
    forEach(new TIntProcedure() {

        @Override
        public boolean execute(int c1) {
            DfaValue value = myFactory.getValue(c1);
            result.add(value);
            return true;
        }
    });
    return result;
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) ArrayList(java.util.ArrayList) DfaValue(com.intellij.codeInspection.dataFlow.value.DfaValue)

Aggregations

TIntProcedure (gnu.trove.TIntProcedure)24 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 TIntArrayList (gnu.trove.TIntArrayList)5 NotNull (org.jetbrains.annotations.NotNull)3 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)3 PsiDocTag (com.intellij.psi.javadoc.PsiDocTag)2 MethodJavaDocHelper (com.intellij.refactoring.util.javadoc.MethodJavaDocHelper)2 DFSTBuilder (com.intellij.util.graph.DFSTBuilder)2 TIntHashSet (gnu.trove.TIntHashSet)2 ArrayList (java.util.ArrayList)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)2 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)2 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)2 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)2 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)2 GrParameterList (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList)2 ConditionalGotoInstruction (com.intellij.codeInspection.dataFlow.instructions.ConditionalGotoInstruction)1 GotoInstruction (com.intellij.codeInspection.dataFlow.instructions.GotoInstruction)1