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