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();
}
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());
}
}
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()]);
}
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()]);
}
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;
}
};
}
};
}
Aggregations