Search in sources :

Example 51 with SmartList

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

the class GotoTestOrCodeHandler method getSourceAndTargetElements.

@Override
@Nullable
protected GotoData getSourceAndTargetElements(final Editor editor, final PsiFile file) {
    PsiElement selectedElement = getSelectedElement(editor, file);
    PsiElement sourceElement = TestFinderHelper.findSourceElement(selectedElement);
    if (sourceElement == null)
        return null;
    List<AdditionalAction> actions = new SmartList<>();
    Collection<PsiElement> candidates;
    if (TestFinderHelper.isTest(selectedElement)) {
        candidates = TestFinderHelper.findClassesForTest(selectedElement);
    } else {
        candidates = TestFinderHelper.findTestsForClass(selectedElement);
        final TestCreator creator = LanguageTestCreators.INSTANCE.forLanguage(file.getLanguage());
        if (creator != null && creator.isAvailable(file.getProject(), editor, file)) {
            actions.add(new AdditionalAction() {

                @NotNull
                @Override
                public String getText() {
                    return "Create New Test...";
                }

                @Override
                public Icon getIcon() {
                    return AllIcons.Actions.IntentionBulb;
                }

                @Override
                public void execute() {
                    creator.createTest(file.getProject(), editor, file);
                }
            });
        }
    }
    return new GotoData(sourceElement, PsiUtilCore.toPsiElementArray(candidates), actions);
}
Also used : SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 52 with SmartList

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

the class FirefoxUtil method computeProfiles.

@NotNull
public static List<FirefoxProfile> computeProfiles(@Nullable File profilesFile) {
    if (profilesFile == null || !profilesFile.isFile()) {
        return Collections.emptyList();
    }
    try {
        BufferedReader reader;
        reader = new BufferedReader(new FileReader(profilesFile));
        try {
            final List<FirefoxProfile> profiles = new SmartList<>();
            boolean insideProfile = false;
            String currentName = null;
            String currentPath = null;
            boolean isDefault = false;
            boolean isRelative = false;
            boolean eof = false;
            while (!eof) {
                String line = reader.readLine();
                if (line == null) {
                    eof = true;
                    line = "[]";
                } else {
                    line = line.trim();
                }
                if (line.startsWith("[") && line.endsWith("]")) {
                    if (!StringUtil.isEmpty(currentPath) && !StringUtil.isEmpty(currentName)) {
                        profiles.add(new FirefoxProfile(currentName, currentPath, isDefault, isRelative));
                    }
                    currentName = null;
                    currentPath = null;
                    isDefault = false;
                    isRelative = false;
                    insideProfile = StringUtil.startsWithIgnoreCase(line, "[Profile");
                    continue;
                }
                final int i = line.indexOf('=');
                if (i != -1 && insideProfile) {
                    String name = line.substring(0, i).trim();
                    String value = line.substring(i + 1).trim();
                    if (name.equalsIgnoreCase("path")) {
                        currentPath = value;
                    } else if (name.equalsIgnoreCase("name")) {
                        currentName = value;
                    } else if (name.equalsIgnoreCase("default") && value.equals("1")) {
                        isDefault = true;
                    } else //noinspection SpellCheckingInspection
                    if (name.equalsIgnoreCase("isrelative") && value.equals("1")) {
                        isRelative = true;
                    }
                }
            }
            return profiles;
        } finally {
            reader.close();
        }
    } catch (IOException e) {
        LOG.info(e);
        return Collections.emptyList();
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with SmartList

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

the class AbstractModuleDataService method removeData.

@Override
public void removeData(@NotNull final Computable<Collection<Module>> toRemoveComputable, @NotNull final Collection<DataNode<E>> toIgnore, @NotNull final ProjectData projectData, @NotNull final Project project, @NotNull final IdeModifiableModelsProvider modelsProvider) {
    final Collection<Module> toRemove = toRemoveComputable.compute();
    final List<Module> modules = new SmartList<>(toRemove);
    for (DataNode<E> moduleDataNode : toIgnore) {
        final Module module = modelsProvider.findIdeModule(moduleDataNode.getData());
        ContainerUtil.addIfNotNull(modules, module);
    }
    if (modules.isEmpty()) {
        return;
    }
    ContainerUtil.removeDuplicates(modules);
    for (Module module : modules) {
        if (module.isDisposed())
            continue;
        unlinkModuleFromExternalSystem(module);
    }
    ruleOrphanModules(modules, project, projectData.getOwner(), modules1 -> {
        for (Module module : modules1) {
            if (module.isDisposed())
                continue;
            String path = module.getModuleFilePath();
            final ModifiableModuleModel moduleModel = modelsProvider.getModifiableModuleModel();
            moduleModel.disposeModule(module);
            ModuleBuilder.deleteModuleFile(path);
        }
    });
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList)

Example 54 with SmartList

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

the class CompletionLookupArranger method getExactMatches.

private List<LookupElement> getExactMatches(LookupImpl lookup, List<LookupElement> items) {
    String selectedText = lookup.getTopLevelEditor().getSelectionModel().getSelectedText();
    List<LookupElement> exactMatches = new SmartList<>();
    for (int i = 0; i < items.size(); i++) {
        LookupElement item = items.get(i);
        boolean isSuddenLiveTemplate = isSuddenLiveTemplate(item);
        if (isPrefixItem(item, true) && !isSuddenLiveTemplate || item.getLookupString().equals(selectedText)) {
            if (item instanceof LiveTemplateLookupElement) {
                // prefer most recent live template lookup item
                return Collections.singletonList(item);
            }
            exactMatches.add(item);
        } else if (i == 0 && isSuddenLiveTemplate && items.size() > 1 && !CompletionServiceImpl.isStartMatch(items.get(1), this)) {
            return Collections.singletonList(item);
        }
    }
    return exactMatches;
}
Also used : LiveTemplateLookupElement(com.intellij.codeInsight.template.impl.LiveTemplateLookupElement) SmartList(com.intellij.util.SmartList) LiveTemplateLookupElement(com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)

Example 55 with SmartList

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

the class FindPopupPanel method getSelectedUsages.

@Nullable
private Usage[] getSelectedUsages() {
    int[] rows = myResultsPreviewTable.getSelectedRows();
    List<Usage> usages = null;
    for (int row : rows) {
        Object valueAt = myResultsPreviewTable.getModel().getValueAt(row, 0);
        if (valueAt instanceof Usage) {
            if (usages == null)
                usages = new SmartList<>();
            Usage at = (Usage) valueAt;
            usages.add(at);
        }
    }
    return usages != null ? ContainerUtil.toArray(usages, Usage.EMPTY_ARRAY) : null;
}
Also used : Usage(com.intellij.usages.Usage) SmartList(com.intellij.util.SmartList) RelativePoint(com.intellij.ui.awt.RelativePoint) Nullable(org.jetbrains.annotations.Nullable)

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