use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class EditorTracker method editorsByWindow.
@NotNull
private List<Editor> editorsByWindow(Window window) {
List<Editor> list = myWindowToEditorsMap.get(window);
if (list == null)
return Collections.emptyList();
List<Editor> filtered = new SmartList<>();
for (Editor editor : list) {
if (editor.getContentComponent().isShowing()) {
filtered.add(editor);
}
}
return filtered;
}
use of com.intellij.util.SmartList in project intellij-community by JetBrains.
the class TemplateModuleBuilder method unzip.
private void unzip(@Nullable final String projectName, String path, final boolean moduleMode, @Nullable ProgressIndicator pI, boolean reportFailuresWithDialog) {
final WizardInputField basePackage = getBasePackageField();
try {
final File dir = new File(path);
class ExceptionConsumer implements Consumer<VelocityException> {
private String myPath;
private String myText;
private SmartList<Trinity<String, String, VelocityException>> myFailures = new SmartList<>();
@Override
public void consume(VelocityException e) {
myFailures.add(Trinity.create(myPath, myText, e));
}
private void setCurrentFile(String path, String text) {
myPath = path;
myText = text;
}
private void reportFailures() {
if (myFailures.isEmpty()) {
return;
}
if (reportFailuresWithDialog) {
String dialogMessage;
if (myFailures.size() == 1) {
dialogMessage = "Failed to decode file \'" + myFailures.get(0).getFirst() + "\'";
} else {
StringBuilder dialogMessageBuilder = new StringBuilder();
dialogMessageBuilder.append("Failed to decode files: \n");
for (Trinity<String, String, VelocityException> failure : myFailures) {
dialogMessageBuilder.append(failure.getFirst()).append("\n");
}
dialogMessage = dialogMessageBuilder.toString();
}
Messages.showErrorDialog(dialogMessage, "Decoding Template");
}
StringBuilder reportBuilder = new StringBuilder();
for (Trinity<String, String, VelocityException> failure : myFailures) {
reportBuilder.append("File: ").append(failure.getFirst()).append("\n");
reportBuilder.append("Exception:\n").append(ExceptionUtil.getThrowableText(failure.getThird())).append("\n");
reportBuilder.append("File content:\n\'").append(failure.getSecond()).append("\'\n");
reportBuilder.append("\n===========================================\n");
}
LOG.error(LogMessageEx.createEvent("Cannot decode files in template", "", new Attachment("Files in template", reportBuilder.toString())));
}
}
ExceptionConsumer consumer = new ExceptionConsumer();
List<File> filesToRefresh = new ArrayList<>();
myTemplate.processStream(new ArchivedProjectTemplate.StreamProcessor<Void>() {
@Override
public Void consume(@NotNull ZipInputStream stream) throws IOException {
ZipUtil.unzip(ProgressManager.getInstance().getProgressIndicator(), dir, stream, path1 -> {
if (moduleMode && path1.contains(Project.DIRECTORY_STORE_FOLDER)) {
return null;
}
if (basePackage != null) {
return path1.replace(getPathFragment(basePackage.getDefaultValue()), getPathFragment(basePackage.getValue()));
}
return path1;
}, new ZipUtil.ContentProcessor() {
@Override
public byte[] processContent(byte[] content, File file) throws IOException {
if (pI != null) {
pI.checkCanceled();
}
FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(FileUtilRt.getExtension(file.getName()));
String text = new String(content, CharsetToolkit.UTF8_CHARSET);
consumer.setCurrentFile(file.getName(), text);
return fileType.isBinary() ? content : processTemplates(projectName, text, file, consumer);
}
}, true);
myTemplate.handleUnzippedDirectories(dir, filesToRefresh);
return null;
}
});
if (pI != null) {
pI.setText("Refreshing...");
}
String iml = ContainerUtil.find(dir.list(), s -> s.endsWith(".iml"));
if (moduleMode) {
File from = new File(path, iml);
File to = new File(getModuleFilePath());
if (!from.renameTo(to)) {
throw new IOException("Can't rename " + from + " to " + to);
}
}
RefreshQueue refreshQueue = RefreshQueue.getInstance();
LOG.assertTrue(!filesToRefresh.isEmpty());
for (File file : filesToRefresh) {
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
if (virtualFile == null) {
throw new IOException("Can't find " + file);
}
refreshQueue.refresh(false, true, null, virtualFile);
}
consumer.reportFailures();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
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);
}
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();
}
}
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);
}
});
}
Aggregations