use of gnu.trove.TIntIterator in project intellij-community by JetBrains.
the class RichControlFlow method reducible.
// Tarjan. Testing flow graph reducibility.
// Journal of Computer and System Sciences 9.3 (1974): 355-365.
public boolean reducible() {
if (dfsTree.back.isEmpty()) {
return true;
}
int size = controlFlow.transitions.length;
boolean[] loopEnters = dfsTree.loopEnters;
TIntHashSet[] cycleIncomings = new TIntHashSet[size];
// really this may be array, since dfs already ensures no duplicates
TIntArrayList[] nonCycleIncomings = new TIntArrayList[size];
int[] collapsedTo = new int[size];
int[] queue = new int[size];
int top;
for (int i = 0; i < size; i++) {
if (loopEnters[i]) {
cycleIncomings[i] = new TIntHashSet();
}
nonCycleIncomings[i] = new TIntArrayList();
collapsedTo[i] = i;
}
// from whom back connections
for (Edge edge : dfsTree.back) {
cycleIncomings[edge.to].add(edge.from);
}
// from whom ordinary connections
for (Edge edge : dfsTree.nonBack) {
nonCycleIncomings[edge.to].add(edge.from);
}
for (int w = size - 1; w >= 0; w--) {
top = 0;
// NB - it is modified later!
TIntHashSet p = cycleIncomings[w];
if (p == null) {
continue;
}
TIntIterator iter = p.iterator();
while (iter.hasNext()) {
queue[top++] = iter.next();
}
while (top > 0) {
int x = queue[--top];
TIntArrayList incoming = nonCycleIncomings[x];
for (int i = 0; i < incoming.size(); i++) {
int y1 = collapsedTo[incoming.getQuick(i)];
if (!dfsTree.isDescendant(y1, w)) {
return false;
}
if (y1 != w && p.add(y1)) {
queue[top++] = y1;
}
}
}
iter = p.iterator();
while (iter.hasNext()) {
collapsedTo[iter.next()] = w;
}
}
return true;
}
use of gnu.trove.TIntIterator in project intellij-community by JetBrains.
the class Util method findParametersToRemove.
// returns parameters that are used solely in specified expression
@NotNull
public static TIntArrayList findParametersToRemove(@NotNull PsiMethod method, @NotNull final PsiExpression expr, @Nullable final PsiExpression[] occurences) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length == 0)
return new TIntArrayList();
PsiMethod[] overridingMethods = OverridingMethodsSearch.search(method).toArray(PsiMethod.EMPTY_ARRAY);
final PsiMethod[] allMethods = ArrayUtil.append(overridingMethods, method);
final TIntHashSet suspects = new TIntHashSet();
expr.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceExpression(final PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
PsiElement resolved = expression.resolve();
if (resolved instanceof PsiParameter) {
int i = ArrayUtil.find(parameters, resolved);
if (i != -1) {
suspects.add(i);
}
}
}
});
final TIntIterator iterator = suspects.iterator();
while (iterator.hasNext()) {
final int paramNum = iterator.next();
for (PsiMethod psiMethod : allMethods) {
PsiParameter[] psiParameters = psiMethod.getParameterList().getParameters();
if (paramNum >= psiParameters.length)
continue;
PsiParameter parameter = psiParameters[paramNum];
if (!ReferencesSearch.search(parameter, parameter.getResolveScope(), false).forEach(reference -> {
PsiElement element = reference.getElement();
boolean stillCanBeRemoved = false;
if (element != null) {
stillCanBeRemoved = isAncestor(expr, element, false) || PsiUtil.isInsideJavadocComment(getPhysical(element));
if (!stillCanBeRemoved && occurences != null) {
for (PsiExpression occurence : occurences) {
if (isAncestor(occurence, element, false)) {
stillCanBeRemoved = true;
break;
}
}
}
}
if (!stillCanBeRemoved) {
iterator.remove();
return false;
}
return true;
}))
break;
}
}
return new TIntArrayList(suspects.toArray());
}
Aggregations