Search in sources :

Example 71 with TIntArrayList

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

the class MergeModelBase method executeMergeCommand.

public boolean executeMergeCommand(@Nullable String commandName, @Nullable String commandGroupId, @NotNull UndoConfirmationPolicy confirmationPolicy, boolean underBulkUpdate, @Nullable TIntArrayList affectedChanges, @NotNull Runnable task) {
    TIntArrayList allAffectedChanges = affectedChanges != null ? collectAffectedChanges(affectedChanges) : null;
    return DiffUtil.executeWriteCommand(myProject, myDocument, commandName, commandGroupId, confirmationPolicy, underBulkUpdate, () -> {
        LOG.assertTrue(!myInsideCommand);
        // We should restore states after changes in document (by DocumentUndoProvider) to avoid corruption by our onBeforeDocumentChange()
        // Undo actions are performed in backward order, while redo actions are performed in forward order.
        // Thus we should register two UndoableActions.
        myInsideCommand = true;
        enterBulkChangeUpdateBlock();
        try {
            registerUndoRedo(true, allAffectedChanges);
            try {
                task.run();
            } finally {
                registerUndoRedo(false, allAffectedChanges);
            }
        } finally {
            exitBulkChangeUpdateBlock();
            myInsideCommand = false;
        }
    });
}
Also used : TIntArrayList(gnu.trove.TIntArrayList)

Example 72 with TIntArrayList

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

the class ControlFlowAnalyzer method addElementOffsetLater.

// patch instruction currently added to control flow so that its jump offset corrected on getStartOffset(element) or getEndOffset(element)
//  when corresponding element offset become available
private void addElementOffsetLater(@NotNull PsiElement element, boolean atStart) {
    Map<PsiElement, TIntArrayList> offsetsAddElement = atStart ? offsetsAddElementStart : offsetsAddElementEnd;
    TIntArrayList offsets = offsetsAddElement.get(element);
    if (offsets == null) {
        offsets = getEmptyIntArray();
        offsetsAddElement.put(element, offsets);
    }
    int offset = myCurrentFlow.getSize() - 1;
    offsets.add(offset);
    if (myCurrentFlow.getEndOffset(element) != -1) {
        patchInstructionOffsets(element);
    }
}
Also used : TIntArrayList(gnu.trove.TIntArrayList)

Example 73 with TIntArrayList

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

the class ControlFlowAnalyzer method cleanup.

private void cleanup() {
    // make all non patched goto instructions jump to the end of control flow
    for (TIntArrayList offsets : offsetsAddElementStart.values()) {
        patchInstructionOffsets(offsets, myCurrentFlow.getEndOffset(myCodeFragment));
    }
    for (TIntArrayList offsets : offsetsAddElementEnd.values()) {
        patchInstructionOffsets(offsets, myCurrentFlow.getEndOffset(myCodeFragment));
    }
    // register all sub ranges
    for (Map.Entry<PsiElement, ControlFlowSubRange> entry : mySubRanges.entrySet()) {
        ProgressManager.checkCanceled();
        ControlFlowSubRange subRange = entry.getValue();
        PsiElement element = entry.getKey();
        myControlFlowFactory.registerSubRange(element, subRange, myEvaluateConstantIfCondition, myEnabledShortCircuit, myPolicy);
    }
}
Also used : THashMap(gnu.trove.THashMap) TIntArrayList(gnu.trove.TIntArrayList)

Example 74 with TIntArrayList

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

the class ByChar method getPunctuationChars.

@NotNull
private static CharOffsets getPunctuationChars(@NotNull CharSequence text) {
    TIntArrayList chars = new TIntArrayList(text.length());
    TIntArrayList offsets = new TIntArrayList(text.length());
    for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);
        if (isPunctuation(c)) {
            chars.add(c);
            offsets.add(i);
        }
    }
    return new CharOffsets(chars.toNativeArray(), offsets.toNativeArray());
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with TIntArrayList

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

the class ByLine method correctChangesSecondStep.

@NotNull
private static FairDiffIterable correctChangesSecondStep(@NotNull final List<Line> lines1, @NotNull final List<Line> lines2, @NotNull final FairDiffIterable changes) {
    /*
     * We want to fix invalid matching here:
     *
     * .{        ..{
     * ..{   vs  ...{
     * ...{
     *
     * first step will return matching (0,2)-(0,2). And we should adjust it to (1,3)-(0,2)
     *
     *
     * From the other hand, we don't want to reduce number of IW-matched lines.
     *
     * .{         ...{
     * ..{    vs  ..{
     * ...{       .{
     *
     * first step will return (0,3)-(0,3) and 'correcting' it to (0,1)-(2,3) is wrong (and it will break ByWord highlighting).
     *
     *
     * Idea:
     * 1. lines are matched at first step and equal -> match them
     * 2. lines are not matched at first step -> do not match them
     * 3. lines are matched at first step and not equal ->
     *   a. find all IW-equal lines in the same unmatched block
     *   b. find a maximum matching between them, maximising amount of equal pairs in it
     *   c. match equal lines using result of the previous step
     */
    final ExpandChangeBuilder builder = new ExpandChangeBuilder(lines1, lines2);
    new Object() {

        private CharSequence sample = null;

        private int last1 = 0;

        private int last2 = 0;

        public void run() {
            for (Range range : changes.iterateUnchanged()) {
                int count = range.end1 - range.start1;
                for (int i = 0; i < count; i++) {
                    int index1 = range.start1 + i;
                    int index2 = range.start2 + i;
                    Line line1 = lines1.get(index1);
                    Line line2 = lines2.get(index2);
                    if (!StringUtil.equalsIgnoreWhitespaces(sample, line1.getContent())) {
                        if (line1.equals(line2)) {
                            flush(index1, index2);
                            builder.markEqual(index1, index2);
                        } else {
                            flush(index1, index2);
                            sample = line1.getContent();
                        }
                    }
                }
            }
            flush(changes.getLength1(), changes.getLength2());
        }

        private void flush(int line1, int line2) {
            if (sample == null)
                return;
            int start1 = Math.max(last1, builder.getIndex1());
            int start2 = Math.max(last2, builder.getIndex2());
            TIntArrayList subLines1 = new TIntArrayList();
            TIntArrayList subLines2 = new TIntArrayList();
            for (int i = start1; i < line1; i++) {
                if (StringUtil.equalsIgnoreWhitespaces(sample, lines1.get(i).getContent())) {
                    subLines1.add(i);
                    last1 = i + 1;
                }
            }
            for (int i = start2; i < line2; i++) {
                if (StringUtil.equalsIgnoreWhitespaces(sample, lines2.get(i).getContent())) {
                    subLines2.add(i);
                    last2 = i + 1;
                }
            }
            assert subLines1.size() > 0 && subLines2.size() > 0;
            alignExactMatching(subLines1, subLines2);
            sample = null;
        }

        private void alignExactMatching(TIntArrayList subLines1, TIntArrayList subLines2) {
            int n = Math.max(subLines1.size(), subLines2.size());
            boolean skipAligning = // we use brute-force algorithm (C_n_k). This will limit search space by ~250 cases.
            n > 10 || // nothing to do
            subLines1.size() == subLines2.size();
            if (skipAligning) {
                int count = Math.min(subLines1.size(), subLines2.size());
                for (int i = 0; i < count; i++) {
                    int index1 = subLines1.get(i);
                    int index2 = subLines2.get(i);
                    if (lines1.get(index1).equals(lines2.get(index2))) {
                        builder.markEqual(index1, index2);
                    }
                }
                return;
            }
            if (subLines1.size() < subLines2.size()) {
                int[] matching = getBestMatchingAlignment(subLines1, subLines2, lines1, lines2);
                for (int i = 0; i < subLines1.size(); i++) {
                    int index1 = subLines1.get(i);
                    int index2 = subLines2.get(matching[i]);
                    if (lines1.get(index1).equals(lines2.get(index2))) {
                        builder.markEqual(index1, index2);
                    }
                }
            } else {
                int[] matching = getBestMatchingAlignment(subLines2, subLines1, lines2, lines1);
                for (int i = 0; i < subLines2.size(); i++) {
                    int index1 = subLines1.get(matching[i]);
                    int index2 = subLines2.get(i);
                    if (lines1.get(index1).equals(lines2.get(index2))) {
                        builder.markEqual(index1, index2);
                    }
                }
            }
        }
    }.run();
    return fair(builder.finish());
}
Also used : MergeRange(com.intellij.diff.util.MergeRange) Range(com.intellij.diff.util.Range) TIntArrayList(gnu.trove.TIntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TIntArrayList (gnu.trove.TIntArrayList)104 NotNull (org.jetbrains.annotations.NotNull)34 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Nullable (org.jetbrains.annotations.Nullable)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrangementMatchingRulesControl (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl)3 StringSearcher (com.intellij.util.text.StringSearcher)3 TIntHashSet (gnu.trove.TIntHashSet)3 TIntProcedure (gnu.trove.TIntProcedure)3 IOException (java.io.IOException)3 IDevice (com.android.ddmlib.IDevice)2 ArrangementMatchingRulesModel (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 ElementToWorkOn (com.intellij.refactoring.introduceField.ElementToWorkOn)2 IntroduceParameterProcessor (com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2