Search in sources :

Example 81 with SmartList

use of com.intellij.util.SmartList in project intellij-plugins by JetBrains.

the class DartSdkLibUtil method disableDartSdk.

public static void disableDartSdk(@NotNull final Collection<Module> modules) {
    if (modules.isEmpty())
        return;
    final List<ModifiableRootModel> models = new SmartList<>();
    for (final Module module : modules) {
        final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
        for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
            if (isDartSdkOrderEntry(orderEntry)) {
                modifiableModel.removeOrderEntry(orderEntry);
            }
        }
        models.add(modifiableModel);
    }
    DartProjectComponent.commitModifiableModels(modules.iterator().next().getProject(), models);
}
Also used : SmartList(com.intellij.util.SmartList) Module(com.intellij.openapi.module.Module)

Example 82 with SmartList

use of com.intellij.util.SmartList in project intellij-plugins by JetBrains.

the class JstdDebugBrowserInfo method build.

@Nullable
public static JstdDebugBrowserInfo build(@NotNull JstdServer server, @NotNull JstdRunSettings runSettings) {
    Collection<JstdBrowserInfo> capturedBrowsers = server.getCapturedBrowsers();
    List<JstdDebugBrowserInfo> debugBrowserInfos = new SmartList<>();
    for (JstdBrowserInfo browserInfo : capturedBrowsers) {
        Pair<JavaScriptDebugEngine, WebBrowser> engine = JavaScriptDebugEngine.Companion.findByBrowserIdOrName(browserInfo.getName());
        if (engine != null) {
            debugBrowserInfos.add(new JstdDebugBrowserInfo(engine, server.getSettings(), browserInfo));
        }
    }
    if (debugBrowserInfos.size() == 1) {
        return debugBrowserInfos.get(0);
    }
    if (debugBrowserInfos.size() > 1) {
        WebBrowser preferredBrowser = runSettings.getPreferredDebugBrowser();
        for (JstdDebugBrowserInfo info : debugBrowserInfos) {
            if (preferredBrowser.equals(info.getBrowser())) {
                return info;
            }
        }
    }
    return null;
}
Also used : WebBrowser(com.intellij.ide.browsers.WebBrowser) SmartList(com.intellij.util.SmartList) JstdBrowserInfo(com.google.jstestdriver.idea.server.JstdBrowserInfo) JavaScriptDebugEngine(com.intellij.javascript.debugger.JavaScriptDebugEngine) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class XDebuggerUtilImpl method getAllCaretsPositions.

@NotNull
public static Collection<XSourcePosition> getAllCaretsPositions(@NotNull Project project, DataContext context) {
    Editor editor = getEditor(project, context);
    if (editor == null) {
        return Collections.emptyList();
    }
    VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
    List<XSourcePosition> res = new SmartList<>();
    for (Caret caret : editor.getCaretModel().getAllCarets()) {
        XSourcePositionImpl position = XSourcePositionImpl.createByOffset(file, caret.getOffset());
        if (position != null) {
            res.add(position);
        }
    }
    return res;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Editor(com.intellij.openapi.editor.Editor) SmartList(com.intellij.util.SmartList) Caret(com.intellij.openapi.editor.Caret) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class BaseInjection method getMatchingRanges.

private static List<TextRange> getMatchingRanges(Matcher matcher, final int length) {
    final List<TextRange> list = new SmartList<>();
    int start = 0;
    while (start < length && matcher.find(start)) {
        final int groupCount = matcher.groupCount();
        if (groupCount == 0) {
            start = matcher.end();
        } else {
            for (int i = 1; i <= groupCount; i++) {
                start = matcher.start(i);
                if (start == -1)
                    continue;
                list.add(new TextRange(start, matcher.end(i)));
            }
            if (start >= matcher.end())
                break;
            start = matcher.end();
        }
    }
    return list;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) SmartList(com.intellij.util.SmartList)

Example 85 with SmartList

use of com.intellij.util.SmartList in project intellij-community by JetBrains.

the class PathReferenceManagerImpl method doMerge.

private static List<PsiReference> doMerge(final PsiElement element, final List<PsiReference> references) {
    List<PsiReference> resolvingRefs = new ArrayList<>();
    List<PsiReference> nonResolvingRefs = new ArrayList<>();
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < references.size(); i++) {
        PsiReference reference = references.get(i);
        assert element.equals(reference.getElement());
        if (reference.resolve() != null) {
            resolvingRefs.add(reference);
        } else {
            nonResolvingRefs.add(reference);
        }
    }
    List<PsiReference> result = new ArrayList<>(5);
    while (!resolvingRefs.isEmpty()) {
        final List<PsiReference> list = new ArrayList<>(5);
        final TextRange range = getFirstIntersectingReferences(resolvingRefs, list);
        final TextRange textRange = addIntersectingReferences(nonResolvingRefs, list, range);
        addToResult(element, result, list, textRange);
    }
    while (!nonResolvingRefs.isEmpty()) {
        final SmartList<PsiReference> list = new SmartList<>();
        final TextRange range = getFirstIntersectingReferences(nonResolvingRefs, list);
        int endOffset = range.getEndOffset();
        for (final PsiReference reference : list) {
            endOffset = Math.min(endOffset, reference.getRangeInElement().getEndOffset());
        }
        addToResult(element, result, list, new TextRange(range.getStartOffset(), endOffset));
    }
    return result;
}
Also used : PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) SmartList(com.intellij.util.SmartList)

Aggregations

SmartList (com.intellij.util.SmartList)163 NotNull (org.jetbrains.annotations.NotNull)70 Nullable (org.jetbrains.annotations.Nullable)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)14 TextRange (com.intellij.openapi.util.TextRange)12 PsiElement (com.intellij.psi.PsiElement)12 List (java.util.List)12 Element (org.jdom.Element)12 File (java.io.File)11 THashSet (gnu.trove.THashSet)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)8 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)6 IOException (java.io.IOException)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 IElementType (com.intellij.psi.tree.IElementType)5