Search in sources :

Example 56 with SmartList

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

the class ModuleRootManagerComponent method getStateModificationCount.

@Override
public long getStateModificationCount() {
    Module module = getModule();
    if (!module.isLoaded() || !(module instanceof ModuleEx)) {
        return myModificationCount;
    }
    final long[] result = { myModificationCount };
    result[0] += ((ModuleEx) module).getOptionsModificationCount();
    final List<String> handledLibraryTables = new SmartList<>();
    getRootModel().orderEntries().forEachLibrary(library -> {
        LibraryTable table = library.getTable();
        if (table instanceof LibraryTableBase && !handledLibraryTables.contains(table.getTableLevel())) {
            handledLibraryTables.add(table.getTableLevel());
            long count = ((LibraryTableBase) table).getStateModificationCount();
            if (count > 0) {
                if (Registry.is("store.track.module.root.manager.changes", false)) {
                    LOG.error("modification count changed due to library  " + library.getName() + " change (" + count + "), module " + getModule().getName());
                }
            }
            result[0] += count;
        }
        return true;
    });
    return result[0] + myRootModel.getStateModificationCount();
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModuleEx(com.intellij.openapi.module.impl.ModuleEx) LibraryTableBase(com.intellij.openapi.roots.impl.libraries.LibraryTableBase) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList)

Example 57 with SmartList

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

the class LogFileOptions method getPaths.

@NotNull
public Set<String> getPaths() {
    File logFile = new File(myPathPattern);
    if (logFile.exists()) {
        return Collections.singleton(myPathPattern);
    }
    int dirIndex = myPathPattern.lastIndexOf(File.separator);
    if (dirIndex == -1) {
        return Collections.emptySet();
    }
    List<File> files = new SmartList<>();
    collectMatchedFiles(new File(myPathPattern.substring(0, dirIndex)), Pattern.compile(FileUtil.convertAntToRegexp(myPathPattern.substring(dirIndex + File.separator.length()))), files);
    if (files.isEmpty()) {
        return Collections.emptySet();
    }
    if (myShowAll) {
        SmartHashSet<String> result = new SmartHashSet<>();
        result.ensureCapacity(files.size());
        for (File file : files) {
            result.add(file.getPath());
        }
        return result;
    } else {
        File lastFile = null;
        for (File file : files) {
            if (lastFile != null) {
                if (file.lastModified() > lastFile.lastModified()) {
                    lastFile = file;
                }
            } else {
                lastFile = file;
            }
        }
        assert lastFile != null;
        return Collections.singleton(lastFile.getPath());
    }
}
Also used : SmartHashSet(com.intellij.util.containers.SmartHashSet) SmartList(com.intellij.util.SmartList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with SmartList

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

the class LongLineInspection method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    final Project project = manager.getProject();
    final int codeStyleRightMargin = CodeStyleSettingsManager.getSettings(project).getRightMargin(file.getLanguage());
    final VirtualFile vFile = file.getVirtualFile();
    if (vFile instanceof VirtualFileWindow) {
        return null;
    }
    final Document document = FileDocumentManager.getInstance().getDocument(vFile);
    if (document == null) {
        return null;
    }
    final List<ProblemDescriptor> descriptors = new SmartList<>();
    for (int idx = 0; idx < document.getLineCount(); idx++) {
        final int startOffset = document.getLineStartOffset(idx);
        final int endOffset = document.getLineEndOffset(idx);
        if (endOffset - startOffset > codeStyleRightMargin) {
            final int maxOffset = startOffset + codeStyleRightMargin;
            descriptors.add(manager.createProblemDescriptor(file, new TextRange(maxOffset, endOffset), String.format("Line is longer than allowed by code style (> %s columns)", codeStyleRightMargin), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly));
        }
    }
    return descriptors.isEmpty() ? null : descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VirtualFileWindow(com.intellij.injected.editor.VirtualFileWindow) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) SmartList(com.intellij.util.SmartList) Nullable(org.jetbrains.annotations.Nullable)

Example 59 with SmartList

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

the class LossyEncodingInspection method checkFile.

@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    if (InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file))
        return null;
    if (!file.isPhysical())
        return null;
    FileViewProvider viewProvider = file.getViewProvider();
    if (viewProvider.getBaseLanguage() != file.getLanguage())
        return null;
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null)
        return null;
    if (!virtualFile.isInLocalFileSystem())
        return null;
    CharSequence text = viewProvider.getContents();
    Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text);
    // no sense in checking transparently decoded file: all characters there are already safely encoded
    if (charset instanceof Native2AsciiCharset)
        return null;
    List<ProblemDescriptor> descriptors = new SmartList<>();
    boolean ok = checkFileLoadedInWrongEncoding(file, manager, isOnTheFly, virtualFile, charset, descriptors);
    if (ok) {
        checkIfCharactersWillBeLostAfterSave(file, manager, isOnTheFly, text, charset, descriptors);
    }
    return descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileViewProvider(com.intellij.psi.FileViewProvider) Charset(java.nio.charset.Charset) Native2AsciiCharset(com.intellij.lang.properties.charset.Native2AsciiCharset) SmartList(com.intellij.util.SmartList) Native2AsciiCharset(com.intellij.lang.properties.charset.Native2AsciiCharset) Nullable(org.jetbrains.annotations.Nullable)

Example 60 with SmartList

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

the class RunLineMarkerProvider method getLineMarkerInfo.

@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
    List<RunLineMarkerContributor> contributors = RunLineMarkerContributor.EXTENSION.allForLanguage(element.getLanguage());
    Icon icon = null;
    List<Info> infos = null;
    for (RunLineMarkerContributor contributor : contributors) {
        Info info = contributor.getInfo(element);
        if (info == null) {
            continue;
        }
        if (icon == null) {
            icon = info.icon;
        }
        if (infos == null) {
            infos = new SmartList<>();
        }
        infos.add(info);
    }
    if (icon == null)
        return null;
    if (infos.size() > 1) {
        Collections.sort(infos, COMPARATOR);
        final Info first = infos.get(0);
        for (Iterator<Info> it = infos.iterator(); it.hasNext(); ) {
            Info info = it.next();
            if (info != first && first.shouldReplace(info)) {
                it.remove();
            }
        }
    }
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    for (Info info : infos) {
        for (AnAction action : info.actions) {
            actionGroup.add(new LineMarkerActionWrapper(element, action));
        }
        if (info != infos.get(infos.size() - 1)) {
            actionGroup.add(new Separator());
        }
    }
    List<Info> finalInfos = infos;
    Function<PsiElement, String> tooltipProvider = element1 -> {
        final StringBuilder tooltip = new StringBuilder();
        for (Info info : finalInfos) {
            if (info.tooltipProvider != null) {
                String string = info.tooltipProvider.apply(element1);
                if (string == null)
                    continue;
                if (tooltip.length() != 0) {
                    tooltip.append("\n");
                }
                tooltip.append(string);
            }
        }
        return tooltip.length() == 0 ? null : tooltip.toString();
    };
    return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, tooltipProvider, null, GutterIconRenderer.Alignment.CENTER) {

        @Nullable
        @Override
        public GutterIconRenderer createGutterRenderer() {
            return new LineMarkerGutterIconRenderer<PsiElement>(this) {

                @Override
                public AnAction getClickAction() {
                    return null;
                }

                @Override
                public boolean isNavigateAction() {
                    return true;
                }

                @Nullable
                @Override
                public ActionGroup getPopupMenuActions() {
                    return actionGroup;
                }
            };
        }
    };
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Pass(com.intellij.codeHighlighting.Pass) LineMarkerProviderDescriptor(com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor) Nullable(org.jetbrains.annotations.Nullable) SmartList(com.intellij.util.SmartList) Function(com.intellij.util.Function) PsiElement(com.intellij.psi.PsiElement) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) javax.swing(javax.swing) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) PsiElement(com.intellij.psi.PsiElement) 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