Search in sources :

Example 76 with SmartList

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

the class AbstractDartFileProcessingAction method getApplicableVirtualFiles.

@NotNull
private static List<VirtualFile> getApplicableVirtualFiles(@NotNull final Project project, @NotNull final VirtualFile[] filesAndDirs) {
    final List<VirtualFile> result = new SmartList<>();
    GlobalSearchScope dirScope = null;
    for (VirtualFile fileOrDir : filesAndDirs) {
        if (fileOrDir.isDirectory()) {
            if (dirScope == null) {
                dirScope = GlobalSearchScopesCore.directoryScope(project, fileOrDir, true);
            } else {
                dirScope = dirScope.union(GlobalSearchScopesCore.directoryScope(project, fileOrDir, true));
            }
        } else if (isApplicableFile(project, fileOrDir)) {
            result.add(fileOrDir);
        }
    }
    if (dirScope != null) {
        for (VirtualFile file : FileTypeIndex.getFiles(DartFileType.INSTANCE, GlobalSearchScope.projectScope(project).intersectWith(dirScope))) {
            if (isApplicableFile(project, file)) {
                result.add(file);
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with SmartList

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

the class DartRenameDialog method previewRefactoring.

@Override
protected void previewRefactoring() {
    final UsageViewPresentation presentation = new UsageViewPresentation();
    presentation.setTabText(RefactoringBundle.message("usageView.tabText"));
    presentation.setShowCancelButton(true);
    presentation.setTargetsNodeText(RefactoringBundle.message("0.to.be.renamed.to.1.2", myRefactoring.getElementKindName(), "", getNewName()));
    presentation.setNonCodeUsagesString(DartBundle.message("usages.in.comments.to.rename"));
    presentation.setCodeUsagesString(DartBundle.message("usages.in.code.to.rename"));
    presentation.setDynamicUsagesString(DartBundle.message("dynamic.usages.to.rename"));
    presentation.setUsageTypeFilteringAvailable(false);
    final List<UsageTarget> usageTargets = new SmartList<>();
    final Map<Usage, String> usageToEditIdMap = new THashMap<>();
    fillTargetsAndUsageToEditIdMap(usageTargets, usageToEditIdMap);
    final UsageTarget[] targets = usageTargets.toArray(new UsageTarget[usageTargets.size()]);
    final Set<Usage> usageSet = usageToEditIdMap.keySet();
    final Usage[] usages = usageSet.toArray(new Usage[usageSet.size()]);
    final UsageView usageView = UsageViewManager.getInstance(myProject).showUsages(targets, usages, presentation);
    final SourceChange sourceChange = myRefactoring.getChange();
    assert sourceChange != null;
    usageView.addPerformOperationAction(createRefactoringRunnable(usageView, usageToEditIdMap), sourceChange.getMessage(), DartBundle.message("rename.need.reRun"), RefactoringBundle.message("usageView.doAction"), false);
}
Also used : THashMap(gnu.trove.THashMap) SourceChange(org.dartlang.analysis.server.protocol.SourceChange) SmartList(com.intellij.util.SmartList)

Example 78 with SmartList

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

the class DartProjectComponent method convertOrderEntriesTargetingGlobalDartSdkLib.

private void convertOrderEntriesTargetingGlobalDartSdkLib() {
    final DartSdk correctSdk = DartSdk.getDartSdk(myProject);
    // already converted
    if (correctSdk != null)
        return;
    // for performance reasons avoid taking write action and modifiable models if not needed
    if (!hasIncorrectModuleDependencies())
        return;
    final String sdkPath = DartSdkUtil.getFirstKnownDartSdkPath();
    if (sdkPath == null)
        return;
    ApplicationManager.getApplication().runWriteAction(() -> {
        DartSdkLibUtil.ensureDartSdkConfigured(myProject, sdkPath);
        final Collection<ModifiableRootModel> modelsToCommit = new SmartList<>();
        for (final Module module : ModuleManager.getInstance(myProject).getModules()) {
            boolean hasCorrectDependency = false;
            boolean needsCorrectDependency = false;
            final List<OrderEntry> orderEntriesToRemove = new SmartList<>();
            final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
            for (final OrderEntry orderEntry : model.getOrderEntries()) {
                if (isOldGlobalDartSdkLibEntry(orderEntry)) {
                    needsCorrectDependency = true;
                    orderEntriesToRemove.add(orderEntry);
                } else if (DartSdkLibUtil.isDartSdkOrderEntry(orderEntry)) {
                    hasCorrectDependency = true;
                }
            }
            if (needsCorrectDependency && !hasCorrectDependency || !orderEntriesToRemove.isEmpty()) {
                if (needsCorrectDependency && !hasCorrectDependency) {
                    model.addInvalidLibrary(DartSdk.DART_SDK_LIB_NAME, LibraryTablesRegistrar.PROJECT_LEVEL);
                }
                for (OrderEntry entry : orderEntriesToRemove) {
                    model.removeOrderEntry(entry);
                }
                modelsToCommit.add(model);
            } else {
                model.dispose();
            }
        }
        commitModifiableModels(myProject, modelsToCommit);
    });
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) SmartList(com.intellij.util.SmartList) Module(com.intellij.openapi.module.Module)

Example 79 with SmartList

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

the class DartServerRootsHandler method updateRoots.

private void updateRoots() {
    final DartSdk sdk = DartSdk.getDartSdk(myProject);
    if (sdk == null || !DartAnalysisServerService.isDartSdkVersionSufficient(sdk)) {
        DartAnalysisServerService.getInstance(myProject).stopServer();
    }
    final List<String> newIncludedRoots = new SmartList<>();
    final List<String> newExcludedRoots = new SmartList<>();
    if (sdk != null) {
        @SuppressWarnings("ConstantConditions") final String dotIdeaPath = PathUtil.getParentPath(myProject.getProjectFilePath());
        if (dotIdeaPath.endsWith("/.idea")) {
            newExcludedRoots.add(FileUtil.toSystemDependentName(dotIdeaPath));
        }
        for (Module module : DartSdkLibUtil.getModulesWithDartSdkEnabled(myProject)) {
            final Set<String> excludedPackageSymlinkUrls = getExcludedPackageSymlinkUrls(module);
            for (ContentEntry contentEntry : ModuleRootManager.getInstance(module).getContentEntries()) {
                final String contentEntryUrl = contentEntry.getUrl();
                if (contentEntryUrl.startsWith(URLUtil.FILE_PROTOCOL + URLUtil.SCHEME_SEPARATOR)) {
                    newIncludedRoots.add(FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(contentEntryUrl)));
                    for (String excludedUrl : contentEntry.getExcludeFolderUrls()) {
                        if (excludedUrl.startsWith(contentEntryUrl) && !excludedPackageSymlinkUrls.contains(excludedUrl)) {
                            newExcludedRoots.add(FileUtil.toSystemDependentName(VfsUtilCore.urlToPath(excludedUrl)));
                        }
                    }
                }
            }
        }
    }
    if (!myIncludedRoots.equals(newIncludedRoots) || !myExcludedRoots.equals(newExcludedRoots)) {
        myIncludedRoots.clear();
        myExcludedRoots.clear();
        if (DartAnalysisServerService.getInstance(myProject).updateRoots(newIncludedRoots, newExcludedRoots)) {
            myIncludedRoots.addAll(newIncludedRoots);
            myExcludedRoots.addAll(newExcludedRoots);
        }
    }
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) ContentEntry(com.intellij.openapi.roots.ContentEntry) SmartList(com.intellij.util.SmartList) Module(com.intellij.openapi.module.Module)

Example 80 with SmartList

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

the class DartMultiHostInjector method injectHtmlIfNeeded.

private static void injectHtmlIfNeeded(@NotNull final MultiHostRegistrar registrar, @NotNull final DartStringLiteralExpression element) {
    final List<HtmlPlaceInfo> infos = new SmartList<>();
    final StringBuilder textBuf = new StringBuilder();
    PsiElement child = element.getFirstChild();
    while (child != null) {
        final IElementType type = child.getNode().getElementType();
        if (type == DartTokenTypes.REGULAR_STRING_PART) {
            textBuf.append(child.getText());
            String suffix = null;
            final PsiElement nextSibling = child.getNextSibling();
            if (nextSibling != null && nextSibling.getNode().getElementType() != DartTokenTypes.CLOSING_QUOTE) {
                // string template like $foo or ${foo}
                suffix = "placeholder";
                textBuf.append(suffix);
            }
            infos.add(new HtmlPlaceInfo(TextRange.from(child.getStartOffsetInParent(), child.getTextLength()), suffix));
        } else if (type == DartTokenTypes.RAW_SINGLE_QUOTED_STRING || type == DartTokenTypes.RAW_TRIPLE_QUOTED_STRING) {
            final Pair<String, TextRange> stringAndRange = DartPsiImplUtil.getUnquotedDartStringAndItsRange(child.getText());
            final String string = stringAndRange.first;
            final TextRange stringRange = stringAndRange.second;
            infos.add(new HtmlPlaceInfo(stringRange.shiftRight(child.getStartOffsetInParent()), null));
            textBuf.append(string);
        }
        child = child.getNextSibling();
    }
    if (textBuf.length() > 0 && looksLikeHtml(textBuf.toString())) {
        registrar.startInjecting(HTMLLanguage.INSTANCE);
        for (HtmlPlaceInfo info : infos) {
            registrar.addPlace(null, info.suffix, element, info.range);
        }
        registrar.doneInjecting();
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) TextRange(com.intellij.openapi.util.TextRange) SmartList(com.intellij.util.SmartList) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

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