use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class BuildArtifactAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = getEventProject(e);
if (project == null)
return;
final List<Artifact> artifacts = ArtifactUtil.getArtifactWithOutputPaths(project);
if (artifacts.isEmpty())
return;
List<ArtifactPopupItem> items = new ArrayList<>();
if (artifacts.size() > 1) {
items.add(0, new ArtifactPopupItem(null, "All Artifacts", EmptyIcon.ICON_16));
}
Set<Artifact> selectedArtifacts = new HashSet<>(ArtifactsWorkspaceSettings.getInstance(project).getArtifactsToBuild());
TIntArrayList selectedIndices = new TIntArrayList();
if (Comparing.haveEqualElements(artifacts, selectedArtifacts) && selectedArtifacts.size() > 1) {
selectedIndices.add(0);
selectedArtifacts.clear();
}
for (Artifact artifact : artifacts) {
final ArtifactPopupItem item = new ArtifactPopupItem(artifact, artifact.getName(), artifact.getArtifactType().getIcon());
if (selectedArtifacts.contains(artifact)) {
selectedIndices.add(items.size());
}
items.add(item);
}
final ProjectSettingsService projectSettingsService = ProjectSettingsService.getInstance(project);
final ArtifactAwareProjectSettingsService settingsService = projectSettingsService instanceof ArtifactAwareProjectSettingsService ? (ArtifactAwareProjectSettingsService) projectSettingsService : null;
final ChooseArtifactStep step = new ChooseArtifactStep(items, artifacts.get(0), project, settingsService);
step.setDefaultOptionIndices(selectedIndices.toNativeArray());
final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance().createListPopup(step);
final KeyStroke editKeyStroke = KeymapUtil.getKeyStroke(CommonShortcuts.getEditSource());
if (settingsService != null && editKeyStroke != null) {
popup.registerAction("editArtifact", editKeyStroke, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Object[] values = popup.getSelectedValues();
popup.cancel();
settingsService.openArtifactSettings(values.length > 0 ? ((ArtifactPopupItem) values[0]).getArtifact() : null);
}
});
}
popup.showCenteredInCurrentWindow(project);
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class LowLevelSearchUtil method getTextOccurrences.
@NotNull
private static int[] getTextOccurrences(@NotNull CharSequence text, int startOffset, int endOffset, @NotNull StringSearcher searcher, @Nullable ProgressIndicator progress) {
if (endOffset > text.length()) {
throw new IllegalArgumentException("end: " + endOffset + " > length: " + text.length());
}
Map<StringSearcher, int[]> cachedMap = cache.get(text);
int[] cachedOccurrences = cachedMap == null ? null : cachedMap.get(searcher);
boolean hasCachedOccurrences = cachedOccurrences != null && cachedOccurrences[0] <= startOffset && cachedOccurrences[1] >= endOffset;
if (!hasCachedOccurrences) {
TIntArrayList occurrences = new TIntArrayList();
int newStart = Math.min(startOffset, cachedOccurrences == null ? startOffset : cachedOccurrences[0]);
int newEnd = Math.max(endOffset, cachedOccurrences == null ? endOffset : cachedOccurrences[1]);
occurrences.add(newStart);
occurrences.add(newEnd);
for (int index = newStart; index < newEnd; index++) {
if (progress != null)
progress.checkCanceled();
//noinspection AssignmentToForLoopParameter
index = searcher.scan(text, index, newEnd);
if (index < 0)
break;
if (checkJavaIdentifier(text, 0, text.length(), searcher, index)) {
occurrences.add(index);
}
}
cachedOccurrences = occurrences.toNativeArray();
if (cachedMap == null) {
cachedMap = ConcurrencyUtil.cacheOrGet(cache, text, ContainerUtil.createConcurrentSoftMap());
}
cachedMap.put(searcher, cachedOccurrences);
}
TIntArrayList offsets = new TIntArrayList(cachedOccurrences.length - 2);
for (int i = 2; i < cachedOccurrences.length; i++) {
int occurrence = cachedOccurrences[i];
if (occurrence > endOffset - searcher.getPatternLength())
break;
if (occurrence >= startOffset) {
offsets.add(occurrence);
}
}
return offsets.toNativeArray();
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class MethodUpDownUtil method offsetsFromElements.
public static int[] offsetsFromElements(final Collection<PsiElement> array) {
TIntArrayList offsets = new TIntArrayList(array.size());
for (PsiElement element : array) {
int offset = element.getTextOffset();
assert offset >= 0 : element + " (" + element.getClass() + "); offset: " + offset;
offsets.add(offset);
}
offsets.sort();
return offsets.toNativeArray();
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class MoveArrangementMatchingRuleDownAction method fillMappings.
@Override
protected void fillMappings(@NotNull ArrangementMatchingRulesControl control, @NotNull List<int[]> mappings) {
TIntArrayList rows = control.getSelectedModelRows();
int bottom = control.getModel().getSize();
for (int i = 0; i < rows.size(); i++) {
int row = rows.get(i);
if (row == bottom - 1) {
mappings.add(new int[] { row, row });
bottom--;
} else {
mappings.add(new int[] { row, row + 1 });
}
}
}
use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.
the class MoveArrangementMatchingRuleUpAction method fillMappings.
@Override
protected void fillMappings(@NotNull ArrangementMatchingRulesControl control, @NotNull List<int[]> mappings) {
TIntArrayList rows = control.getSelectedModelRows();
rows.reverse();
int top = -1;
for (int i = 0; i < rows.size(); i++) {
int row = rows.get(i);
if (row == top + 1) {
mappings.add(new int[] { row, row });
top++;
} else {
mappings.add(new int[] { row, row - 1 });
}
}
}
Aggregations