mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Added test for TODOs in Django. Removed n^2 scan for merging comments.
This commit is contained in:
@@ -39,6 +39,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.QueryExecutor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.CharSequenceSubSequence;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -51,7 +52,8 @@ import java.util.regex.Pattern;
|
||||
* @author yole
|
||||
*/
|
||||
public class IndexPatternSearcher implements QueryExecutor<IndexPatternOccurrence, IndexPatternSearch.SearchParameters> {
|
||||
public boolean execute(@NotNull final IndexPatternSearch.SearchParameters queryParameters, @NotNull final Processor<IndexPatternOccurrence> consumer) {
|
||||
public boolean execute(@NotNull final IndexPatternSearch.SearchParameters queryParameters,
|
||||
@NotNull final Processor<IndexPatternOccurrence> consumer) {
|
||||
final PsiFile file = queryParameters.getFile();
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (file instanceof PsiBinaryFile || file instanceof PsiCompiledElement || virtualFile == null) {
|
||||
@@ -161,29 +163,16 @@ public class IndexPatternSearcher implements QueryExecutor<IndexPatternOccurrenc
|
||||
}
|
||||
|
||||
private static void mergeCommentLists(TIntArrayList commentStarts,
|
||||
TIntArrayList commentEnds,
|
||||
TIntArrayList commentStartsList,
|
||||
TIntArrayList commentEndsList) {
|
||||
TIntArrayList commentEnds,
|
||||
TIntArrayList commentStartsList,
|
||||
TIntArrayList commentEndsList) {
|
||||
if (commentStarts.size() == 0 && commentEnds.size() == 0) {
|
||||
commentStarts.add(commentStartsList.toNativeArray());
|
||||
commentEnds.add(commentEndsList.toNativeArray());
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: this is costly for large N !
|
||||
for (int i = 0; i < commentStartsList.size(); i++) {
|
||||
boolean found = false;
|
||||
for (int j = 0; j < commentStarts.size(); j++) {
|
||||
if (commentStarts.get(j) == commentStartsList.get(i) && commentEnds.get(j) == commentEndsList.get(i)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
commentStarts.add(commentStartsList.get(i));
|
||||
commentEnds.add(commentEndsList.get(i));
|
||||
}
|
||||
}
|
||||
ContainerUtil.mergeSortedArrays(commentStarts, commentEnds, commentStartsList, commentEndsList);
|
||||
}
|
||||
|
||||
private static void findComments(final Lexer lexer,
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Factory;
|
||||
import com.intellij.util.*;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -1001,6 +1002,57 @@ public class ContainerUtil {
|
||||
return (List<T>)EmptyList.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge sorted points, which are sorted by x and with equal x by y.
|
||||
* Result is put to x1 y1.
|
||||
*/
|
||||
public static void mergeSortedArrays(TIntArrayList x1,
|
||||
TIntArrayList y1,
|
||||
TIntArrayList x2,
|
||||
TIntArrayList y2) {
|
||||
TIntArrayList newX = new TIntArrayList();
|
||||
TIntArrayList newY = new TIntArrayList();
|
||||
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
while (i < x1.size() && j < x2.size()) {
|
||||
if (x1.get(i) < x2.get(j) || (x1.get(i) == x2.get(j) && y1.get(i) < y2.get(j))) {
|
||||
newX.add(x1.get(i));
|
||||
newY.add(y1.get(i));
|
||||
i++;
|
||||
}
|
||||
else if (x1.get(i) > x2.get(j) || (x1.get(i) == x2.get(j) && y1.get(i) > y2.get(j))) {
|
||||
newX.add(x2.get(j));
|
||||
newY.add(y2.get(j));
|
||||
j++;
|
||||
}
|
||||
else { //equals
|
||||
newX.add(x1.get(i));
|
||||
newY.add(y1.get(i));
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
while (i < x1.size()) {
|
||||
newX.add(x1.get(i));
|
||||
newY.add(y1.get(i));
|
||||
i++;
|
||||
}
|
||||
|
||||
while (j < x2.size()) {
|
||||
newX.add(x2.get(j));
|
||||
newY.add(y2.get(j));
|
||||
j++;
|
||||
}
|
||||
|
||||
x1.clear();
|
||||
y1.clear();
|
||||
x1.add(newX.toNativeArray());
|
||||
y1.add(newY.toNativeArray());
|
||||
}
|
||||
|
||||
private static class EmptyList extends AbstractList<Object> implements RandomAccess, Serializable {
|
||||
private static final EmptyList INSTANCE = new EmptyList();
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.intellij.util.containers;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import gnu.trove.TIntArrayList;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -90,4 +91,25 @@ public class ContainerUtilTest extends junit.framework.TestCase {
|
||||
|
||||
assertEquals("abccba", log);
|
||||
}
|
||||
|
||||
public void testMergeSortedArrays() {
|
||||
TIntArrayList x1 = new TIntArrayList(new int[]{0, 2, 4, 6});
|
||||
TIntArrayList y1 = new TIntArrayList(new int[]{0, 2, 4, 6});
|
||||
TIntArrayList x2 = new TIntArrayList(new int[]{1, 2, 2});
|
||||
TIntArrayList y2 = new TIntArrayList(new int[]{1, 2, 3});
|
||||
ContainerUtil.mergeSortedArrays(x1, y1, x2, y2);
|
||||
assertEquals(new TIntArrayList(new int[]{0, 1, 2, 2, 4, 6}), x1);
|
||||
assertEquals(new TIntArrayList(new int[]{0, 1, 2, 3, 4, 6}), y1);
|
||||
x2 = new TIntArrayList(new int[]{1, 2, 2});
|
||||
y2 = new TIntArrayList(new int[]{1, 2, 3});
|
||||
ContainerUtil.mergeSortedArrays(x1, y1, x2, y2);
|
||||
assertEquals(new TIntArrayList(new int[]{0, 1, 2, 2, 4, 6}), x1);
|
||||
assertEquals(new TIntArrayList(new int[]{0, 1, 2, 3, 4, 6}), y1);
|
||||
|
||||
x2 = new TIntArrayList(new int[]{-1, -1, -2});
|
||||
y2 = new TIntArrayList(new int[]{-1, -2, -3});
|
||||
ContainerUtil.mergeSortedArrays(x1, y1, x2, y2);
|
||||
assertEquals(new TIntArrayList(new int[]{-1, -1, -2, 0, 1, 2, 2, 4, 6}), x1);
|
||||
assertEquals(new TIntArrayList(new int[]{-1, -2, -3, 0, 1, 2, 3, 4, 6}), y1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user