Search in sources :

Example 6 with TIntArrayList

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);
}
Also used : ActionEvent(java.awt.event.ActionEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) TIntArrayList(gnu.trove.TIntArrayList) Artifact(com.intellij.packaging.artifacts.Artifact) TIntArrayList(gnu.trove.TIntArrayList) Project(com.intellij.openapi.project.Project) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) ProjectSettingsService(com.intellij.openapi.roots.ui.configuration.ProjectSettingsService)

Example 7 with TIntArrayList

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();
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) StringSearcher(com.intellij.util.text.StringSearcher) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with TIntArrayList

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();
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) PsiElement(com.intellij.psi.PsiElement)

Example 9 with TIntArrayList

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 });
        }
    }
}
Also used : TIntArrayList(gnu.trove.TIntArrayList)

Example 10 with TIntArrayList

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 });
        }
    }
}
Also used : TIntArrayList(gnu.trove.TIntArrayList)

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