use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class ByLine method getBigLines.
@NotNull
private static Pair<List<Line>, TIntArrayList> getBigLines(@NotNull List<Line> lines, int threshold) {
List<Line> bigLines = new ArrayList<>(lines.size());
TIntArrayList indexes = new TIntArrayList(lines.size());
for (int i = 0; i < lines.size(); i++) {
Line line = lines.get(i);
if (line.getNonSpaceChars() > threshold) {
bigLines.add(line);
indexes.add(i);
}
}
return Pair.create(bigLines, indexes);
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class AddOnDemandStaticImportAction method invoke.
public static void invoke(final Project project, PsiFile file, final Editor editor, PsiElement element) {
final PsiJavaCodeReferenceElement refExpr = (PsiJavaCodeReferenceElement) element.getParent();
final PsiClass aClass = (PsiClass) refExpr.resolve();
if (aClass == null) {
return;
}
final PsiClass containingClass = PsiUtil.getTopLevelClass(refExpr);
if (aClass != containingClass) {
PsiImportList importList = ((PsiJavaFile) file).getImportList();
if (importList == null) {
return;
}
boolean alreadyImported = false;
for (PsiImportStaticStatement statement : importList.getImportStaticStatements()) {
if (!statement.isOnDemand())
continue;
PsiClass staticResolve = statement.resolveTargetClass();
if (aClass == staticResolve) {
alreadyImported = true;
break;
}
}
if (!alreadyImported) {
PsiImportStaticStatement importStaticStatement = JavaPsiFacade.getInstance(file.getProject()).getElementFactory().createImportStaticStatement(aClass, "*");
importList.add(importStaticStatement);
}
}
List<PsiFile> roots = file.getViewProvider().getAllFiles();
for (final PsiFile root : roots) {
PsiElement copy = root.copy();
final PsiManager manager = root.getManager();
final TIntArrayList expressionToDequalifyOffsets = new TIntArrayList();
copy.accept(new JavaRecursiveElementWalkingVisitor() {
int delta;
@Override
public void visitReferenceElement(PsiJavaCodeReferenceElement expression) {
if (isParameterizedReference(expression))
return;
PsiElement qualifierExpression = expression.getQualifier();
if (qualifierExpression instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement) qualifierExpression).isReferenceTo(aClass)) {
try {
PsiElement resolved = expression.resolve();
int end = expression.getTextRange().getEndOffset();
qualifierExpression.delete();
delta += end - expression.getTextRange().getEndOffset();
PsiElement after = expression.resolve();
if (manager.areElementsEquivalent(after, resolved)) {
expressionToDequalifyOffsets.add(expression.getTextRange().getStartOffset() + delta);
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
super.visitElement(expression);
}
});
expressionToDequalifyOffsets.forEachDescending(new TIntProcedure() {
@Override
public boolean execute(int offset) {
PsiJavaCodeReferenceElement expression = PsiTreeUtil.findElementOfClassAtOffset(root, offset, PsiJavaCodeReferenceElement.class, false);
if (expression == null) {
return false;
}
PsiElement qualifierExpression = expression.getQualifier();
if (qualifierExpression instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement) qualifierExpression).isReferenceTo(aClass)) {
qualifierExpression.delete();
if (editor != null) {
HighlightManager.getInstance(project).addRangeHighlight(editor, expression.getTextRange().getStartOffset(), expression.getTextRange().getEndOffset(), EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES), false, null);
}
}
return true;
}
});
}
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class ControlFlowAnalyzer method getEmptyIntArray.
@NotNull
private TIntArrayList getEmptyIntArray() {
if (intArrayPool.isEmpty()) {
return new TIntArrayList(1);
}
TIntArrayList list = intArrayPool.pop();
list.clear();
return list;
}
use of gnu.trove.TIntArrayList 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());
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class InplaceIntroduceParameterPopup method performIntroduce.
protected void performIntroduce() {
boolean isDeleteLocalVariable = false;
PsiExpression parameterInitializer = myExpr;
if (getLocalVariable() != null) {
if (myPanel.isUseInitializer()) {
parameterInitializer = getLocalVariable().getInitializer();
}
isDeleteLocalVariable = myPanel.isDeleteLocalVariable();
}
final TIntArrayList parametersToRemove = myPanel.getParametersToRemove();
final IntroduceParameterProcessor processor = new IntroduceParameterProcessor(myProject, myMethod, myMethodToSearchFor, parameterInitializer, myExpr, (PsiLocalVariable) getLocalVariable(), isDeleteLocalVariable, getInputName(), myPanel.isReplaceAllOccurences(), myPanel.getReplaceFieldsWithGetters(), myMustBeFinal || myPanel.isGenerateFinal(), isGenerateDelegate(), getType(), parametersToRemove);
final Runnable runnable = () -> {
final Runnable performRefactoring = () -> {
processor.setPrepareSuccessfulSwingThreadCallback(() -> {
});
processor.run();
normalizeParameterIdxAccordingToRemovedParams(parametersToRemove);
final PsiParameter parameter = getParameter();
if (parameter != null) {
super.saveSettings(parameter);
}
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
performRefactoring.run();
} else {
TransactionGuard.getInstance().submitTransactionLater(myProject, performRefactoring);
}
};
CommandProcessor.getInstance().executeCommand(myProject, runnable, getCommandName(), null);
}
Aggregations