From faaf25d77bc56390678055f803685cb03c874db6 Mon Sep 17 00:00:00 2001 From: "Kirill.Safonov" Date: Fri, 8 Jul 2011 14:49:56 +0400 Subject: [PATCH 01/10] move CodeSmellDetector registration to RichPlatformPlugin (will fix IDEA-71759) --- resources/src/META-INF/IdeaPlugin.xml | 3 --- resources/src/idea/RichPlatformPlugin.xml | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index bcec8b75cd4a..a91e4902cab8 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -280,9 +280,6 @@ - - + + From 055912b73faf53d9a41d5bad490455f2af523a50 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 8 Jul 2011 14:52:59 +0400 Subject: [PATCH 02/10] extracted service for file downloading, downloading of db drivers migrated to new api --- .../libraries/DownloadingOptionsDialog.java | 8 +- .../ui/libraries/LibraryDownloadSettings.java | 10 +-- .../ui/libraries/LibraryOptionsPanel.java | 3 +- .../library/DownloadableLibraryService.java | 12 +-- .../impl/DownloadableLibraryEditor.java | 8 +- .../impl/DownloadableLibraryServiceImpl.java | 25 +++--- .../CustomLibraryDescriptionImpl.java | 9 --- .../OldCustomLibraryDescription.java | 7 +- .../impl/ui/libraries/LibraryDownloader.java | 2 +- .../DownloadableLibraryDescription.java | 15 +--- .../library/FrameworkLibraryVersion.java | 11 +-- .../DownloadableLibraryDescriptionImpl.java | 2 +- .../impl/FrameworkLibraryVersionImpl.java | 22 +---- .../library/impl/LibraryVersionsFetcher.java | 49 ++---------- .../DownloadableFileDescription.java | 2 +- .../download/DownloadableFileService.java | 39 +++++++++ .../DownloadableFileSetDescription.java | 34 ++++++++ .../download/DownloadableFileSetVersions.java | 34 ++++++++ .../impl/DownloadableFileDescriptionImpl.java | 4 +- .../impl/DownloadableFileServiceImpl.java | 55 +++++++++++++ .../DownloadableFileSetDescriptionImpl.java | 57 +++++++++++++ .../impl/FileSetVersionsFetcherBase.java | 80 +++++++++++++++++++ .../src/META-INF/LangExtensions.xml | 4 +- resources/src/META-INF/IdeaPlugin.xml | 3 + 24 files changed, 363 insertions(+), 132 deletions(-) rename platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryAssistant.java => java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryService.java (70%) rename platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryAssistantImpl.java => java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java (53%) rename platform/lang-impl/src/com/intellij/{framework/library => util/download}/DownloadableFileDescription.java (96%) create mode 100644 platform/lang-impl/src/com/intellij/util/download/DownloadableFileService.java create mode 100644 platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetDescription.java create mode 100644 platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetVersions.java rename platform/lang-impl/src/com/intellij/{framework/library => util/download}/impl/DownloadableFileDescriptionImpl.java (95%) create mode 100644 platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileServiceImpl.java create mode 100644 platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileSetDescriptionImpl.java create mode 100644 platform/lang-impl/src/com/intellij/util/download/impl/FileSetVersionsFetcherBase.java diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java index ed0dc71982b8..0e29d5520da8 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java @@ -15,7 +15,7 @@ */ package com.intellij.facet.impl.ui.libraries; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.DownloadableLibraryType; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.ide.ui.ListCellRendererWrapper; @@ -118,12 +118,12 @@ public class DownloadingOptionsDialog extends DialogWrapper { init(); } - private void onVersionChanged(final @Nullable List selected) { + private void onVersionChanged(final @Nullable List selected) { final FrameworkLibraryVersion version = getSelectedVersion(); if (Comparing.equal(myLastSelectedVersion, version)) return; if (version != null) { - final List downloads = version.getLibraryFiles(); + final List downloads = version.getFiles(); myFilesList.setModel(new CollectionListModel( ContainerUtil.map2Array(downloads, JCheckBox.class, new Function() { @Override @@ -169,7 +169,7 @@ public class DownloadingOptionsDialog extends DialogWrapper { private List getSelectedDownloads(FrameworkLibraryVersion version) { List selected = new ArrayList(); - List downloads = version.getLibraryFiles(); + List downloads = version.getFiles(); for (int i = 0; i < downloads.size(); i++) { if (myFilesList.isItemSelected(i)) { selected.add(downloads.get(i)); diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java index 76becb410536..c029cd626ac6 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java @@ -15,7 +15,7 @@ */ package com.intellij.facet.impl.ui.libraries; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.DownloadableLibraryType; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.framework.library.LibraryVersionProperties; @@ -40,19 +40,19 @@ public class LibraryDownloadSettings { private final boolean myDownloadSources; private final boolean myDownloadJavaDocs; private final LibrariesContainer.LibraryLevel myLibraryLevel; - private final List mySelectedDownloads; + private final List mySelectedDownloads; public LibraryDownloadSettings(@NotNull FrameworkLibraryVersion libraryVersion, @Nullable DownloadableLibraryType libraryType, final LibrariesContainer.LibraryLevel libraryLevel, final String downloadedLibrariesPath) { this(libraryVersion, libraryType, downloadedLibrariesPath, libraryVersion.getDefaultLibraryName(), libraryLevel, - libraryVersion.getLibraryFiles(), true, true); + libraryVersion.getFiles(), true, true); } public LibraryDownloadSettings(@NotNull FrameworkLibraryVersion libraryVersion, @Nullable DownloadableLibraryType libraryType, @NotNull String directoryForDownloadedLibrariesPath, @NotNull String libraryName, @NotNull LibrariesContainer.LibraryLevel libraryLevel, - @NotNull List selectedDownloads, + @NotNull List selectedDownloads, boolean downloadSources, boolean downloadJavaDocs) { myVersion = libraryVersion; myLibraryType = libraryType; @@ -85,7 +85,7 @@ public class LibraryDownloadSettings { return myDirectoryForDownloadedLibrariesPath; } - public List getSelectedDownloads() { + public List getSelectedDownloads() { return mySelectedDownloads; } diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java index e2489df17ff1..1fb0c6a62010 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java @@ -15,6 +15,7 @@ */ package com.intellij.facet.impl.ui.libraries; +import com.intellij.util.download.DownloadableFileSetVersions; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.ide.IdeBundle; @@ -100,7 +101,7 @@ public class LibraryOptionsPanel implements Disposable { final DownloadableLibraryDescription description = libraryDescription.getDownloadableDescription(); if (description != null) { showCard("loading"); - description.fetchLibraryVersions(new DownloadableLibraryDescription.LibraryVersionsCallback() { + description.fetchVersions(new DownloadableFileSetVersions.FileSetVersionsCallback() { @Override public void onSuccess(@NotNull final List versions) { //noinspection SSBasedInspection diff --git a/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryAssistant.java b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryService.java similarity index 70% rename from platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryAssistant.java rename to java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryService.java index d5b605e0dbb6..72fbbc61a828 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryAssistant.java +++ b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryService.java @@ -16,6 +16,7 @@ package com.intellij.framework.library; import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import org.jetbrains.annotations.NotNull; import java.net.URL; @@ -23,15 +24,14 @@ import java.net.URL; /** * @author nik */ -public abstract class DownloadableLibraryAssistant { - public static DownloadableLibraryAssistant getInstance() { - return ServiceManager.getService(DownloadableLibraryAssistant.class); +public abstract class DownloadableLibraryService { + public static DownloadableLibraryService getInstance() { + return ServiceManager.getService(DownloadableLibraryService.class); } - @NotNull - public abstract DownloadableFileDescription createFileDescription(@NotNull String downloadUrl, @NotNull String fileName); - @NotNull public abstract DownloadableLibraryDescription createLibraryDescription(@NotNull String groupId, @NotNull URL... localUrls); + @NotNull + public abstract CustomLibraryDescription createDescriptionForType(Class typeClass); } diff --git a/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryEditor.java b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryEditor.java index 8869844290bd..d35a9673146b 100644 --- a/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryEditor.java +++ b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryEditor.java @@ -17,10 +17,7 @@ package com.intellij.framework.library.impl; import com.intellij.facet.impl.ui.libraries.DownloadingOptionsDialog; import com.intellij.facet.impl.ui.libraries.LibraryDownloadSettings; -import com.intellij.framework.library.DownloadableLibraryDescription; -import com.intellij.framework.library.DownloadableLibraryType; -import com.intellij.framework.library.FrameworkLibraryVersion; -import com.intellij.framework.library.LibraryVersionProperties; +import com.intellij.framework.library.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent; @@ -29,6 +26,7 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorBa import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.download.DownloadableFileSetVersions; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -72,7 +70,7 @@ public class DownloadableLibraryEditor extends LibraryPropertiesEditor { private void changeVersion() { final ModalityState current = ModalityState.current(); - myDescription.fetchLibraryVersions(new DownloadableLibraryDescription.LibraryVersionsCallback() { + myDescription.fetchVersions(new DownloadableFileSetVersions.FileSetVersionsCallback() { @Override public void onSuccess(@NotNull final List versions) { ApplicationManager.getApplication().invokeLater(new Runnable() { diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryAssistantImpl.java b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java similarity index 53% rename from platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryAssistantImpl.java rename to java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java index bc3172d75b49..5f6a84ec2b9c 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryAssistantImpl.java +++ b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryServiceImpl.java @@ -15,10 +15,13 @@ */ package com.intellij.framework.library.impl; -import com.intellij.framework.library.DownloadableFileDescription; -import com.intellij.framework.library.DownloadableLibraryAssistant; import com.intellij.framework.library.DownloadableLibraryDescription; -import com.intellij.openapi.util.io.FileUtil; +import com.intellij.framework.library.DownloadableLibraryService; +import com.intellij.framework.library.DownloadableLibraryType; +import com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.roots.libraries.LibraryType; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import org.jetbrains.annotations.NotNull; import java.net.URL; @@ -26,16 +29,20 @@ import java.net.URL; /** * @author nik */ -public class DownloadableLibraryAssistantImpl extends DownloadableLibraryAssistant { - @NotNull - @Override - public DownloadableFileDescription createFileDescription(@NotNull String downloadUrl, @NotNull String fileName) { - return new DownloadableFileDescriptionImpl(downloadUrl, FileUtil.getNameWithoutExtension(fileName), FileUtil.getExtension(fileName)); - } +public class DownloadableLibraryServiceImpl extends DownloadableLibraryService { + private static final Logger LOG = Logger.getInstance("#com.intellij.framework.library.impl.DownloadableLibraryServiceImpl"); @NotNull @Override public DownloadableLibraryDescription createLibraryDescription(@NotNull String groupId, @NotNull URL... localUrls) { return new LibraryVersionsFetcher(groupId, localUrls); } + + @NotNull + @Override + public CustomLibraryDescription createDescriptionForType(Class typeClass) { + final DownloadableLibraryType libraryType = LibraryType.EP_NAME.findExtension(typeClass); + LOG.assertTrue(libraryType != null, typeClass); + return new CustomLibraryDescriptionImpl(libraryType); + } } diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java index 15cb3b424ddd..edad8b510c30 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java @@ -17,8 +17,6 @@ package com.intellij.ide.util.frameworkSupport; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.DownloadableLibraryType; -import com.intellij.framework.library.LibraryVersionProperties; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.roots.libraries.LibraryType; import com.intellij.openapi.roots.ui.configuration.libraries.LibraryFilter; import com.intellij.openapi.vfs.VirtualFile; @@ -31,7 +29,6 @@ import java.util.List; * @author nik */ public class CustomLibraryDescriptionImpl extends CustomLibraryDescriptionBase { - private static final Logger LOG = Logger.getInstance("#com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl"); private final DownloadableLibraryType myLibraryType; public CustomLibraryDescriptionImpl(@NotNull DownloadableLibraryType downloadableLibraryType) { @@ -60,10 +57,4 @@ public class CustomLibraryDescriptionImpl extends CustomLibraryDescriptionBase { } }; } - - public static CustomLibraryDescriptionImpl createDescription(Class typeClass) { - final DownloadableLibraryType libraryType = LibraryType.EP_NAME.findExtension(typeClass); - LOG.assertTrue(libraryType != null, typeClass); - return new CustomLibraryDescriptionImpl(libraryType); - } } diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java index 7955603b80d2..1d3406b1cad8 100644 --- a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/OldCustomLibraryDescription.java @@ -18,10 +18,10 @@ package com.intellij.ide.util.frameworkSupport; import com.intellij.facet.impl.ui.libraries.RequiredLibrariesInfo; import com.intellij.facet.ui.libraries.LibraryDownloadInfo; import com.intellij.facet.ui.libraries.LibraryInfo; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.FrameworkLibraryVersion; -import com.intellij.framework.library.impl.DownloadableFileDescriptionImpl; +import com.intellij.util.download.impl.DownloadableFileDescriptionImpl; import com.intellij.framework.library.impl.DownloadableLibraryDescriptionImpl; import com.intellij.framework.library.impl.FrameworkLibraryVersionImpl; import com.intellij.openapi.roots.libraries.LibraryType; @@ -54,7 +54,8 @@ public class OldCustomLibraryDescription extends CustomLibraryDescriptionBase { for (LibraryInfo info : version.getLibraries()) { final LibraryDownloadInfo downloadingInfo = info.getDownloadingInfo(); if (downloadingInfo != null) { - final DownloadableFileDescription element = new DownloadableFileDescriptionImpl(downloadingInfo.getDownloadUrl(), downloadingInfo.getFileNamePrefix(), downloadingInfo.getFileNameSuffix()); + final DownloadableFileDescription + element = new DownloadableFileDescriptionImpl(downloadingInfo.getDownloadUrl(), downloadingInfo.getFileNamePrefix(), downloadingInfo.getFileNameSuffix()); downloads.add(element); } } diff --git a/platform/lang-impl/src/com/intellij/facet/impl/ui/libraries/LibraryDownloader.java b/platform/lang-impl/src/com/intellij/facet/impl/ui/libraries/LibraryDownloader.java index bbcc872a5870..942e37dd99aa 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/ui/libraries/LibraryDownloader.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/ui/libraries/LibraryDownloader.java @@ -16,7 +16,7 @@ package com.intellij.facet.impl.ui.libraries; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.ide.IdeBundle; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.Result; diff --git a/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryDescription.java b/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryDescription.java index 48068b1a15a2..e1ac7d3836db 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryDescription.java +++ b/platform/lang-impl/src/com/intellij/framework/library/DownloadableLibraryDescription.java @@ -15,21 +15,10 @@ */ package com.intellij.framework.library; -import org.jetbrains.annotations.NotNull; - -import java.util.List; +import com.intellij.util.download.DownloadableFileSetVersions; /** * @author nik */ -public interface DownloadableLibraryDescription { - - void fetchLibraryVersions(@NotNull LibraryVersionsCallback callback); - - abstract class LibraryVersionsCallback { - public abstract void onSuccess(@NotNull List versions); - - public void onError(@NotNull String errorMessage) { - } - } +public interface DownloadableLibraryDescription extends DownloadableFileSetVersions { } diff --git a/platform/lang-impl/src/com/intellij/framework/library/FrameworkLibraryVersion.java b/platform/lang-impl/src/com/intellij/framework/library/FrameworkLibraryVersion.java index 17f7e891b91b..a336013b9a14 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/FrameworkLibraryVersion.java +++ b/platform/lang-impl/src/com/intellij/framework/library/FrameworkLibraryVersion.java @@ -16,22 +16,15 @@ package com.intellij.framework.library; import com.intellij.ide.util.frameworkSupport.FrameworkVersion; +import com.intellij.util.download.DownloadableFileSetDescription; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * @author nik */ -public interface FrameworkLibraryVersion { +public interface FrameworkLibraryVersion extends DownloadableFileSetDescription { @NotNull String getDefaultLibraryName(); - @NotNull - String getVersionString(); - - @NotNull - List getLibraryFiles(); - boolean isCompatibleWith(@NotNull FrameworkVersion frameworkVersion); } diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryDescriptionImpl.java b/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryDescriptionImpl.java index 5941809ddecc..ece1286b00b1 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryDescriptionImpl.java +++ b/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableLibraryDescriptionImpl.java @@ -36,7 +36,7 @@ public class DownloadableLibraryDescriptionImpl implements DownloadableLibraryDe } @Override - public void fetchLibraryVersions(@NotNull LibraryVersionsCallback callback) { + public void fetchVersions(@NotNull FileSetVersionsCallback callback) { callback.onSuccess(myVersions); } } diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/FrameworkLibraryVersionImpl.java b/platform/lang-impl/src/com/intellij/framework/library/impl/FrameworkLibraryVersionImpl.java index eff46bfde09b..171f1581e60f 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/FrameworkLibraryVersionImpl.java +++ b/platform/lang-impl/src/com/intellij/framework/library/impl/FrameworkLibraryVersionImpl.java @@ -15,9 +15,10 @@ */ package com.intellij.framework.library.impl; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.FrameworkLibraryVersion; import com.intellij.ide.util.frameworkSupport.FrameworkVersion; +import com.intellij.util.download.impl.DownloadableFileSetDescriptionImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,9 +27,7 @@ import java.util.List; /** * @author nik */ -public class FrameworkLibraryVersionImpl implements FrameworkLibraryVersion { - private final List myLibraryFiles; - private final String myVersionString; +public class FrameworkLibraryVersionImpl extends DownloadableFileSetDescriptionImpl implements FrameworkLibraryVersion { private final String myLibraryCategory; private final FrameworkVersion myFrameworkVersion; @@ -36,30 +35,17 @@ public class FrameworkLibraryVersionImpl implements FrameworkLibraryVersion { List libraryFiles, String category, @Nullable FrameworkVersion frameworkVersion) { - myVersionString = versionString; - myLibraryFiles = libraryFiles; + super(category, versionString, libraryFiles); myLibraryCategory = category; myFrameworkVersion = frameworkVersion; } - @NotNull - @Override - public String getVersionString() { - return myVersionString; - } - @NotNull @Override public String getDefaultLibraryName() { return myVersionString.length() > 0 ? myLibraryCategory + "-" + myVersionString : myLibraryCategory; } - @NotNull - @Override - public List getLibraryFiles() { - return myLibraryFiles; - } - @Override public boolean isCompatibleWith(@NotNull FrameworkVersion frameworkVersion) { return myFrameworkVersion == null || myFrameworkVersion.getVersionName().equals(frameworkVersion.getVersionName()); diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/LibraryVersionsFetcher.java b/platform/lang-impl/src/com/intellij/framework/library/impl/LibraryVersionsFetcher.java index 37f3915e3af3..9383d66d6306 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/LibraryVersionsFetcher.java +++ b/platform/lang-impl/src/com/intellij/framework/library/impl/LibraryVersionsFetcher.java @@ -15,64 +15,27 @@ */ package com.intellij.framework.library.impl; -import com.intellij.facet.frameworks.LibrariesDownloadAssistant; import com.intellij.facet.frameworks.beans.Artifact; -import com.intellij.facet.frameworks.beans.ArtifactItem; -import com.intellij.framework.library.DownloadableFileDescription; -import com.intellij.framework.library.DownloadableLibraryAssistant; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.framework.library.DownloadableLibraryDescription; import com.intellij.framework.library.FrameworkLibraryVersion; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.download.impl.FileSetVersionsFetcherBase; import org.jetbrains.annotations.NotNull; import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; /** * @author nik */ -public class LibraryVersionsFetcher implements DownloadableLibraryDescription { - private static final Comparator VERSIONS_COMPARATOR = new Comparator() { - @Override - public int compare(FrameworkLibraryVersion o1, FrameworkLibraryVersion o2) { - return -StringUtil.compareVersionNumbers(o1.getVersionString(), o2.getVersionString()); - } - }; - private final String myGroupId; - private final URL[] myLocalUrls; +public class LibraryVersionsFetcher extends FileSetVersionsFetcherBase implements DownloadableLibraryDescription { public LibraryVersionsFetcher(@NotNull String groupId, @NotNull URL[] localUrls) { - myGroupId = groupId; - myLocalUrls = localUrls; + super(groupId, localUrls); } @Override - public void fetchLibraryVersions(@NotNull final LibraryVersionsCallback callback) { - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override - public void run() { - final Artifact[] versions = LibrariesDownloadAssistant.getVersions(myGroupId, myLocalUrls); - final List result = new ArrayList(); - for (Artifact version : versions) { - final ArtifactItem[] items = version.getItems(); - final List files = new ArrayList(); - for (ArtifactItem item : items) { - String url = item.getUrl(); - final String prefix = version.getUrlPrefix(); - if (!url.startsWith("http://") && prefix != null) { - url = prefix + url; - } - files.add(DownloadableLibraryAssistant.getInstance().createFileDescription(url, item.getName())); - } - result.add(new FrameworkLibraryVersionImpl(version.getVersion(), files, myGroupId, null)); - } - Collections.sort(result, VERSIONS_COMPARATOR); - callback.onSuccess(result); - } - }); + protected FrameworkLibraryVersion createVersion(Artifact version, List files) { + return new FrameworkLibraryVersionImpl(version.getVersion(), files, myGroupId, null); } } diff --git a/platform/lang-impl/src/com/intellij/framework/library/DownloadableFileDescription.java b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileDescription.java similarity index 96% rename from platform/lang-impl/src/com/intellij/framework/library/DownloadableFileDescription.java rename to platform/lang-impl/src/com/intellij/util/download/DownloadableFileDescription.java index 6b7e25d1cc98..9276de81f94c 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/DownloadableFileDescription.java +++ b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileDescription.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.framework.library; +package com.intellij.util.download; import com.intellij.openapi.util.Condition; import org.jetbrains.annotations.NotNull; diff --git a/platform/lang-impl/src/com/intellij/util/download/DownloadableFileService.java b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileService.java new file mode 100644 index 000000000000..aa2aba45a14a --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileService.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download; + +import com.intellij.openapi.components.ServiceManager; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.net.URL; + +/** + * @author nik + */ +public abstract class DownloadableFileService { + public static DownloadableFileService getInstance() { + return ServiceManager.getService(DownloadableFileService.class); + } + + @NotNull + public abstract DownloadableFileDescription createFileDescription(@NotNull String downloadUrl, @NotNull String fileName); + + @NotNull + public abstract DownloadableFileSetVersions createFileSetVersions(@NotNull String groupId, @NotNull URL... localUrls); + + public abstract void loadVersionsToCombobox(@NotNull DownloadableFileSetVersions versions, @NotNull JComboBox comboBox); +} diff --git a/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetDescription.java b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetDescription.java new file mode 100644 index 000000000000..0940a2460650 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetDescription.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author nik + */ +public interface DownloadableFileSetDescription { + @NotNull + String getName(); + + @NotNull + String getVersionString(); + + @NotNull + List getFiles(); +} diff --git a/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetVersions.java b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetVersions.java new file mode 100644 index 000000000000..7cfda318183d --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/DownloadableFileSetVersions.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author nik + */ +public interface DownloadableFileSetVersions { + void fetchVersions(@NotNull FileSetVersionsCallback callback); + + abstract class FileSetVersionsCallback { + public abstract void onSuccess(@NotNull List versions); + + public void onError(@NotNull String errorMessage) { + } + } +} diff --git a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableFileDescriptionImpl.java b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileDescriptionImpl.java similarity index 95% rename from platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableFileDescriptionImpl.java rename to platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileDescriptionImpl.java index 97745cf459b2..fe49aa7e249c 100644 --- a/platform/lang-impl/src/com/intellij/framework/library/impl/DownloadableFileDescriptionImpl.java +++ b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileDescriptionImpl.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.framework.library.impl; +package com.intellij.util.download.impl; -import com.intellij.framework.library.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileDescription; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Conditions; import com.intellij.util.text.UniqueNameGenerator; diff --git a/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileServiceImpl.java b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileServiceImpl.java new file mode 100644 index 000000000000..ce496eca5a83 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileServiceImpl.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download.impl; + +import com.intellij.facet.frameworks.beans.Artifact; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.download.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileService; +import com.intellij.util.download.DownloadableFileSetDescription; +import com.intellij.util.download.DownloadableFileSetVersions; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.net.URL; +import java.util.List; + +/** + * @author nik + */ +public class DownloadableFileServiceImpl extends DownloadableFileService { + @NotNull + @Override + public DownloadableFileDescription createFileDescription(@NotNull String downloadUrl, @NotNull String fileName) { + return new DownloadableFileDescriptionImpl(downloadUrl, FileUtil.getNameWithoutExtension(fileName), FileUtil.getExtension(fileName)); + } + + @NotNull + @Override + public DownloadableFileSetVersions createFileSetVersions(@NotNull String groupId, + @NotNull URL... localUrls) { + return new FileSetVersionsFetcherBase(groupId, localUrls) { + @Override + protected DownloadableFileSetDescription createVersion(Artifact version, List files) { + return new DownloadableFileSetDescriptionImpl(version.getName(), version.getVersion(), files); + } + }; + } + + @Override + public void loadVersionsToCombobox(@NotNull DownloadableFileSetVersions versions, @NotNull JComboBox comboBox) { + } +} diff --git a/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileSetDescriptionImpl.java b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileSetDescriptionImpl.java new file mode 100644 index 000000000000..f9ebccbfcef6 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/impl/DownloadableFileSetDescriptionImpl.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download.impl; + +import com.intellij.util.download.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileSetDescription; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * @author nik + */ +public class DownloadableFileSetDescriptionImpl implements DownloadableFileSetDescription { + protected final List myFiles; + protected final String myVersionString; + private final String myName; + + public DownloadableFileSetDescriptionImpl(@NotNull String name, + @NotNull String versionString, + @NotNull List files) { + myName = name; + myVersionString = versionString; + myFiles = files; + } + + @NotNull + @Override + public String getName() { + return myName; + } + + @NotNull + @Override + public String getVersionString() { + return myVersionString; + } + + @NotNull + @Override + public List getFiles() { + return myFiles; + } +} diff --git a/platform/lang-impl/src/com/intellij/util/download/impl/FileSetVersionsFetcherBase.java b/platform/lang-impl/src/com/intellij/util/download/impl/FileSetVersionsFetcherBase.java new file mode 100644 index 000000000000..6001a7b54cef --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/download/impl/FileSetVersionsFetcherBase.java @@ -0,0 +1,80 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.util.download.impl; + +import com.intellij.facet.frameworks.LibrariesDownloadAssistant; +import com.intellij.facet.frameworks.beans.Artifact; +import com.intellij.facet.frameworks.beans.ArtifactItem; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.download.DownloadableFileDescription; +import com.intellij.util.download.DownloadableFileService; +import com.intellij.util.download.DownloadableFileSetDescription; +import com.intellij.util.download.DownloadableFileSetVersions; +import org.jetbrains.annotations.NotNull; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +/** + * @author nik + */ +public abstract class FileSetVersionsFetcherBase implements DownloadableFileSetVersions { + private static final Comparator VERSIONS_COMPARATOR = new Comparator() { + @Override + public int compare(DownloadableFileSetDescription o1, DownloadableFileSetDescription o2) { + return -StringUtil.compareVersionNumbers(o1.getVersionString(), o2.getVersionString()); + } + }; + protected final String myGroupId; + private final URL[] myLocalUrls; + + public FileSetVersionsFetcherBase(@NotNull String groupId, @NotNull URL[] localUrls) { + myLocalUrls = localUrls; + myGroupId = groupId; + } + + @Override + public void fetchVersions(@NotNull final FileSetVersionsCallback callback) { + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + final Artifact[] versions = LibrariesDownloadAssistant.getVersions(myGroupId, myLocalUrls); + final List result = new ArrayList(); + for (Artifact version : versions) { + final ArtifactItem[] items = version.getItems(); + final List files = new ArrayList(); + for (ArtifactItem item : items) { + String url = item.getUrl(); + final String prefix = version.getUrlPrefix(); + if (!url.startsWith("http://") && prefix != null) { + url = prefix + url; + } + files.add(DownloadableFileService.getInstance().createFileDescription(url, item.getName())); + } + result.add(createVersion(version, files)); + } + Collections.sort(result, VERSIONS_COMPARATOR); + callback.onSuccess(result); + } + }); + } + + protected abstract F createVersion(Artifact version, List files); +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 58fc5a616acb..449c59473376 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -141,8 +141,8 @@ - + diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index a91e4902cab8..398073393100 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -304,6 +304,9 @@ + + From 880fcba09d4c5fc3624a167a3bbfff65326fbea3 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 7 Jul 2011 15:53:33 +0200 Subject: [PATCH 03/10] undo/redo IdeActions --- .../src/com/intellij/openapi/actionSystem/IdeActions.java | 3 +++ .../src/com/intellij/ui/TextComponentUndoProvider.java | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java index 4615d2fe9f16..d4ca80de5b1a 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/IdeActions.java @@ -251,4 +251,7 @@ public interface IdeActions { String ACTION_MOVE_STATEMENT_DOWN_ACTION = "MoveStatementDown"; String ACTION_COMPARE_CLIPBOARD_WITH_SELECTION = "CompareClipboardWithSelection"; + + String ACTION_UNDO = "$Undo"; + String ACTION_REDO = "$Redo"; } diff --git a/platform/platform-api/src/com/intellij/ui/TextComponentUndoProvider.java b/platform/platform-api/src/com/intellij/ui/TextComponentUndoProvider.java index 693ae99049cd..abea57195d62 100644 --- a/platform/platform-api/src/com/intellij/ui/TextComponentUndoProvider.java +++ b/platform/platform-api/src/com/intellij/ui/TextComponentUndoProvider.java @@ -17,6 +17,7 @@ package com.intellij.ui; import com.intellij.openapi.Disposable; +import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.actionSystem.KeyboardShortcut; import com.intellij.openapi.actionSystem.Shortcut; import com.intellij.openapi.keymap.KeymapManager; @@ -50,8 +51,8 @@ public class TextComponentUndoProvider implements Disposable { myOldKeymap = myTextComponent.getKeymap(); Keymap keymap = JTextComponent.addKeymap(null, myOldKeymap); com.intellij.openapi.keymap.Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap(); - Shortcut[] undoShortcuts = activeKeymap.getShortcuts("$Undo"); - Shortcut[] redoShortcuts = activeKeymap.getShortcuts("$Redo"); + Shortcut[] undoShortcuts = activeKeymap.getShortcuts(IdeActions.ACTION_UNDO); + Shortcut[] redoShortcuts = activeKeymap.getShortcuts(IdeActions.ACTION_REDO); Action undoAction = new AbstractAction ("Undo") { public void actionPerformed(ActionEvent e) { From a6f874f22c7f30dcef9e85d42e8c7f05f1fb3af0 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 7 Jul 2011 16:06:49 +0200 Subject: [PATCH 04/10] continuation transform for completion: make copy commit a surface action in the control flow --- .../completion/CodeCompletionHandlerBase.java | 116 ++++++++++-------- 1 file changed, 68 insertions(+), 48 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 94525beb9d1b..73b5726498f4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -27,7 +27,9 @@ import com.intellij.ide.DataManager; import com.intellij.injected.editor.EditorWindow; import com.intellij.lang.Language; import com.intellij.lang.injection.InjectedLanguageManager; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.diagnostic.Logger; @@ -220,7 +222,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { CommandProcessor.getInstance().executeCommand(project, initCmd, null, null); } - doComplete(time, initializationContext[0], hasModifiers); + insertDummyIdentifier(initializationContext[0], hasModifiers, time); } @NotNull @@ -245,11 +247,15 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { return lookup; } - private void doComplete(final int invocationCount, CompletionInitializationContext initContext, boolean hasModifiers) { + private void doComplete(CompletionInitializationContext initContext, + boolean hasModifiers, + int invocationCount, + PsiFile hostFile, + int hostStartOffset, Editor hostEditor, OffsetMap hostMap) { + CompletionContext context = createCompletionContext(hostFile, hostStartOffset, hostEditor, hostMap); + CompletionParameters parameters = createCompletionParameters(invocationCount, initContext, context); + final Editor editor = initContext.getEditor(); - - final CompletionParameters parameters = createCompletionParameters(invocationCount, initContext); - final Semaphore freezeSemaphore = new Semaphore(); freezeSemaphore.down(); final CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, parameters, this, freezeSemaphore, @@ -331,21 +337,9 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { return data; } - - private CompletionParameters createCompletionParameters(int invocationCount, final CompletionInitializationContext initContext) { - final Ref ref = Ref.create(null); - CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { - @Override - public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - ref.set(insertDummyIdentifier(initContext)); - } - }); - } - }); - final CompletionContext newContext = ref.get(); + private CompletionParameters createCompletionParameters(int invocationCount, + CompletionInitializationContext initContext, + final CompletionContext newContext) { final int offset = newContext.getStartOffset(); final PsiFile fileCopy = newContext.file; @@ -459,10 +453,10 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { } } - private CompletionContext insertDummyIdentifier(CompletionInitializationContext initContext) { + private void insertDummyIdentifier(final CompletionInitializationContext initContext, boolean hasModifiers, int invocationCount) { final PsiFile originalFile = initContext.getFile(); - PsiFile fileCopy = createFileCopy(originalFile); - PsiFile hostFile = InjectedLanguageUtil.getTopLevelFile(fileCopy); + final PsiFile fileCopy = createFileCopy(originalFile); + final PsiFile hostFile = InjectedLanguageUtil.getTopLevelFile(fileCopy); final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(hostFile.getProject()); int hostStartOffset = injectedLanguageManager.injectedToHost(fileCopy, initContext.getStartOffset()); final Editor hostEditor = InjectedLanguageUtil.getTopLevelEditor(initContext.getEditor()); @@ -473,15 +467,35 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { hostMap.addOffset(key, injectedLanguageManager.injectedToHost(fileCopy, original.getOffset(key))); } - Document document = fileCopy.getViewProvider().getDocument(); + final Document document = fileCopy.getViewProvider().getDocument(); assert document != null : "no document"; - patchFileCopy(initContext, fileCopy, document); + + CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() { + @Override + public void run() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + patchFileCopy(initContext, fileCopy, document); + } + }); + } + }); final Document hostDocument = hostFile.getViewProvider().getDocument(); assert hostDocument != null : "no host document"; PsiDocumentManager.getInstance(hostFile.getProject()).commitDocument(hostDocument); + + doComplete(initContext, hasModifiers, invocationCount, hostFile, hostStartOffset, hostEditor, hostMap); + } + + private static CompletionContext createCompletionContext(PsiFile hostFile, + int hostStartOffset, + Editor hostEditor, + OffsetMap hostMap) { assert hostFile.isValid() : "file became invalid"; assert hostMap.getOffset(CompletionInitializationContext.START_OFFSET) < hostFile.getTextLength() : "startOffset outside the host file"; + InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(hostFile.getProject()); CompletionContext context; PsiFile injected = InjectedLanguageUtil.findInjectedPsiNoCommit(hostFile, hostStartOffset); if (injected != null) { @@ -494,10 +508,10 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { for (final OffsetKey key : new ArrayList(hostMap.keySet())) { map.addOffset(key, injectedEditor.logicalPositionToOffset(injectedEditor.hostToInjected(hostEditor.offsetToLogicalPosition(hostMap.getOffset(key))))); } - context = new CompletionContext(initContext.getProject(), injectedEditor, injected, map); + context = new CompletionContext(hostFile.getProject(), injectedEditor, injected, map); assert hostStartOffset == injectedLanguageManager.injectedToHost(injected, context.getStartOffset()) : "inconsistent injected offset translation"; } else { - context = new CompletionContext(initContext.getProject(), hostEditor, hostFile, hostMap); + context = new CompletionContext(hostFile.getProject(), hostEditor, hostFile, hostMap); } assert context.getStartOffset() < context.file.getTextLength() : "start outside the file"; @@ -591,31 +605,37 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { public static final Key>> FILE_COPY_KEY = Key.create("CompletionFileCopy"); protected PsiFile createFileCopy(PsiFile file) { - final VirtualFile virtualFile = file.getVirtualFile(); - if (file.isPhysical() && virtualFile != null && virtualFile.getFileSystem() == LocalFileSystem.getInstance() - // must not cache injected file copy, since it does not reflect changes in host document - && !InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) { - final SoftReference> reference = file.getUserData(FILE_COPY_KEY); - if (reference != null) { - final Pair pair = reference.get(); - if (pair != null && pair.first.isValid() && pair.first.getClass().equals(file.getClass())) { - final PsiFile copy = pair.first; - if (copy.getModificationStamp() > file.getModificationStamp()) { - ((PsiModificationTrackerImpl) file.getManager().getModificationTracker()).incCounter(); + AccessToken token = WriteAction.start(); + try { + final VirtualFile virtualFile = file.getVirtualFile(); + if (file.isPhysical() && virtualFile != null && virtualFile.getFileSystem() == LocalFileSystem.getInstance() + // must not cache injected file copy, since it does not reflect changes in host document + && !InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) { + final SoftReference> reference = file.getUserData(FILE_COPY_KEY); + if (reference != null) { + final Pair pair = reference.get(); + if (pair != null && pair.first.isValid() && pair.first.getClass().equals(file.getClass())) { + final PsiFile copy = pair.first; + if (copy.getModificationStamp() > file.getModificationStamp()) { + ((PsiModificationTrackerImpl) file.getManager().getModificationTracker()).incCounter(); + } + final Document document = pair.second; + assert document != null; + document.setText(file.getText()); + return copy; } - final Document document = pair.second; - assert document != null; - document.setText(file.getText()); - return copy; } } - } - final PsiFile copy = (PsiFile)file.copy(); - final Document document = copy.getViewProvider().getDocument(); - assert document != null; - file.putUserData(FILE_COPY_KEY, new SoftReference>(Pair.create(copy, document))); - return copy; + final PsiFile copy = (PsiFile)file.copy(); + final Document document = copy.getViewProvider().getDocument(); + assert document != null; + file.putUserData(FILE_COPY_KEY, new SoftReference>(Pair.create(copy, document))); + return copy; + } + finally { + token.finish(); + } } private static boolean isAutocompleteOnInvocation(final CompletionType type) { From 71415ffdfefc41e69ba9951285eb2f62f728f9d7 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 7 Jul 2011 17:28:39 +0200 Subject: [PATCH 05/10] a distinctive log console error color --- .../pages/ANSIColoredConsoleColorsPage.java | 12 +++++++++--- .../execution/ui/ConsoleViewContentType.java | 4 ++-- .../intellij/notification/EventLogConsole.java | 17 ++++++++++------- .../src/messages/OptionsBundle.properties | 3 ++- .../src/DefaultColorSchemesManager.xml | 7 ++++++- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ANSIColoredConsoleColorsPage.java b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ANSIColoredConsoleColorsPage.java index 5a4dec3eda31..d551c7a4773d 100644 --- a/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ANSIColoredConsoleColorsPage.java +++ b/platform/lang-impl/src/com/intellij/openapi/options/colors/pages/ANSIColoredConsoleColorsPage.java @@ -27,7 +27,9 @@ public class ANSIColoredConsoleColorsPage implements ColorSettingsPage { "- C:>\n" + "- help\n" + "Bad command or file name\n" + - "Log warning\n" + + "\n" + + "Log error\n" + + "Log warning\n" + "\n" + "# Process output highlighted using ANSI colors codes\n" + "ANSI: red\n" + @@ -42,10 +44,13 @@ public class ANSIColoredConsoleColorsPage implements ColorSettingsPage { private static final AttributesDescriptor[] ATTRS = new AttributesDescriptor[]{ new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.stdout"), ConsoleViewContentType.NORMAL_OUTPUT_KEY), - new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.warning"), ConsoleViewContentType.WARNING_OUTPUT_KEY), + new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.stderr"), ConsoleViewContentType.ERROR_OUTPUT_KEY), new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.stdin"), ConsoleViewContentType.USER_INPUT_KEY), new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.system.output"), ConsoleViewContentType.SYSTEM_OUTPUT_KEY), + new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.logError"), ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY), + new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.console.warning"), ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY), + new AttributesDescriptor(OptionsBundle.message("color.settings.console.red"), ConsoleHighlighter.RED), new AttributesDescriptor(OptionsBundle.message("color.settings.console.green"), ConsoleHighlighter.GREEN), new AttributesDescriptor(OptionsBundle.message("color.settings.console.yellow"), ConsoleHighlighter.YELLOW), @@ -61,7 +66,8 @@ public class ANSIColoredConsoleColorsPage implements ColorSettingsPage { ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("stdout", ConsoleViewContentType.NORMAL_OUTPUT_KEY); ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("stdin", ConsoleViewContentType.USER_INPUT_KEY); ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("stderr", ConsoleViewContentType.ERROR_OUTPUT_KEY); - ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("warning", ConsoleViewContentType.WARNING_OUTPUT_KEY); + ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("logError", ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY); + ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("logWarning", ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY); ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("red", ConsoleHighlighter.RED); ADDITIONAL_HIGHLIGHT_DESCRIPTORS.put("green", ConsoleHighlighter.GREEN); diff --git a/platform/platform-api/src/com/intellij/execution/ui/ConsoleViewContentType.java b/platform/platform-api/src/com/intellij/execution/ui/ConsoleViewContentType.java index 5243263df902..f80acefc295d 100644 --- a/platform/platform-api/src/com/intellij/execution/ui/ConsoleViewContentType.java +++ b/platform/platform-api/src/com/intellij/execution/ui/ConsoleViewContentType.java @@ -39,13 +39,13 @@ public class ConsoleViewContentType { public static final ColorKey CONSOLE_BACKGROUND_KEY = ColorKey.createColorKey("CONSOLE_BACKGROUND_KEY"); public static final TextAttributesKey NORMAL_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_NORMAL_OUTPUT"); - public static final TextAttributesKey WARNING_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_WARNING_OUTPUT"); + public static final TextAttributesKey LOG_WARNING_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("LOG_WARNING_OUTPUT"); public static final TextAttributesKey ERROR_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_ERROR_OUTPUT"); + public static final TextAttributesKey LOG_ERROR_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("LOG_ERROR_OUTPUT"); public static final TextAttributesKey USER_INPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_USER_INPUT"); public static final TextAttributesKey SYSTEM_OUTPUT_KEY = TextAttributesKey.createTextAttributesKey("CONSOLE_SYSTEM_OUTPUT"); public static final ConsoleViewContentType NORMAL_OUTPUT = new ConsoleViewContentType("NORMAL_OUTPUT", NORMAL_OUTPUT_KEY); - public static final ConsoleViewContentType WARNING_OUTPUT = new ConsoleViewContentType("ERROR_OUTPUT", WARNING_OUTPUT_KEY); public static final ConsoleViewContentType ERROR_OUTPUT = new ConsoleViewContentType("ERROR_OUTPUT", ERROR_OUTPUT_KEY); public static final ConsoleViewContentType USER_INPUT = new ConsoleViewContentType("USER_OUTPUT", USER_INPUT_KEY); public static final ConsoleViewContentType SYSTEM_OUTPUT = new ConsoleViewContentType("SYSTEM_OUTPUT", SYSTEM_OUTPUT_KEY); diff --git a/platform/platform-impl/src/com/intellij/notification/EventLogConsole.java b/platform/platform-impl/src/com/intellij/notification/EventLogConsole.java index 83de47d6647e..cba851865aa2 100644 --- a/platform/platform-impl/src/com/intellij/notification/EventLogConsole.java +++ b/platform/platform-impl/src/com/intellij/notification/EventLogConsole.java @@ -26,6 +26,8 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.ScrollType; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.editor.event.EditorMouseEvent; import com.intellij.openapi.editor.ex.EditorMarkupModel; import com.intellij.openapi.editor.markup.*; @@ -113,18 +115,19 @@ class EventLogConsole { Pair pair = EventLog.formatForLog(notification); final NotificationType type = notification.getType(); - ConsoleViewContentType contentType = type == NotificationType.ERROR - ? ConsoleViewContentType.ERROR_OUTPUT + TextAttributesKey key = type == NotificationType.ERROR + ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY : type == NotificationType.INFORMATION - ? ConsoleViewContentType.NORMAL_OUTPUT - : ConsoleViewContentType.WARNING_OUTPUT; + ? ConsoleViewContentType.NORMAL_OUTPUT_KEY + : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY; int msgStart = document.getTextLength(); String message = pair.first; append(document, message); - myLogEditor.getMarkupModel() - .addRangeHighlighter(msgStart, document.getTextLength(), HighlighterLayer.CARET_ROW + 1, contentType.getAttributes(), - HighlighterTargetArea.EXACT_RANGE); + + TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key); + int layer = HighlighterLayer.CARET_ROW + 1; + myLogEditor.getMarkupModel().addRangeHighlighter(msgStart, document.getTextLength(), layer, attributes, HighlighterTargetArea.EXACT_RANGE); if (pair.second) { String s = " "; diff --git a/platform/platform-resources-en/src/messages/OptionsBundle.properties b/platform/platform-resources-en/src/messages/OptionsBundle.properties index b3bfef5e37ce..b01256cf2be4 100644 --- a/platform/platform-resources-en/src/messages/OptionsBundle.properties +++ b/platform/platform-resources-en/src/messages/OptionsBundle.properties @@ -127,7 +127,8 @@ options.general.color.descriptor.modified.lines=Modified lines options.general.color.descriptor.console.background=Console background options.general.color.descriptor.console.stdout=Console standard output options.general.color.descriptor.console.stderr=Console error output -options.general.color.descriptor.console.warning=Console warning output +options.general.color.descriptor.console.warning=Log console warning +options.general.color.descriptor.console.logError=Log console error options.general.color.descriptor.console.stdin=Console user input options.general.color.descriptor.console.system.output=Console system output options.general.color.descriptor.hyperlink.new=Hyperlink diff --git a/platform/platform-resources/src/DefaultColorSchemesManager.xml b/platform/platform-resources/src/DefaultColorSchemesManager.xml index 7978c93214d1..a464da48aced 100644 --- a/platform/platform-resources/src/DefaultColorSchemesManager.xml +++ b/platform/platform-resources/src/DefaultColorSchemesManager.xml @@ -1139,11 +1139,16 @@ - +