From 090c63bce1b0fb500f61e07f79224e0b72368a00 Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 26 Oct 2009 11:19:34 +0300 Subject: [PATCH 01/21] obsolete code removed --- .../impl/ConfigFileFactoryImpl.java | 4 - .../impl/CustomConfigFileSetImpl.java | 99 ------------------- .../util/descriptors/ConfigFileFactory.java | 2 - .../util/descriptors/CustomConfigFileSet.java | 37 ------- 4 files changed, 142 deletions(-) delete mode 100644 java/idea-ui/src/com/intellij/util/descriptors/impl/CustomConfigFileSetImpl.java delete mode 100644 java/openapi/src/com/intellij/util/descriptors/CustomConfigFileSet.java diff --git a/java/idea-ui/src/com/intellij/util/descriptors/impl/ConfigFileFactoryImpl.java b/java/idea-ui/src/com/intellij/util/descriptors/impl/ConfigFileFactoryImpl.java index 1729b51869e8..e8a101647071 100644 --- a/java/idea-ui/src/com/intellij/util/descriptors/impl/ConfigFileFactoryImpl.java +++ b/java/idea-ui/src/com/intellij/util/descriptors/impl/ConfigFileFactoryImpl.java @@ -55,10 +55,6 @@ public class ConfigFileFactoryImpl extends ConfigFileFactory { return new ConfigFileContainerImpl(project, metaDataProvider, (ConfigFileInfoSetImpl)configuration); } - public CustomConfigFileSet createCustomConfigFileSet() { - return new CustomConfigFileSetImpl(); - } - private static String getText(final String templateName) throws IOException { final FileTemplateManager templateManager = FileTemplateManager.getInstance(); final FileTemplate template = templateManager.getJ2eeTemplate(templateName); diff --git a/java/idea-ui/src/com/intellij/util/descriptors/impl/CustomConfigFileSetImpl.java b/java/idea-ui/src/com/intellij/util/descriptors/impl/CustomConfigFileSetImpl.java deleted file mode 100644 index 2b715b33d15c..000000000000 --- a/java/idea-ui/src/com/intellij/util/descriptors/impl/CustomConfigFileSetImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2000-2009 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.descriptors.impl; - -import com.intellij.openapi.util.WriteExternalException; -import com.intellij.util.descriptors.CustomConfigFile; -import com.intellij.util.descriptors.CustomConfigFileSet; -import org.jdom.Element; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @author nik - */ -public class CustomConfigFileSetImpl implements CustomConfigFileSet { - @NonNls private static final String ELEMENT_NAME = "deploymentDescriptor"; - @NonNls private static final String URL_ATTRIBUTE = "url"; - @NonNls private static final String OPTION_ELEMENT_NAME = "option"; - @NonNls private static final String DEFAULT_DIR_OPTION = "DEFAULT_DIR"; - @NonNls private static final String NAME_ATTRIBUTE = "name"; - @NonNls private static final String VALUE_ATTRIBUTE = "value"; - - private final List myDescriptors = new ArrayList(); - - public void add(CustomConfigFile descriptor) { - myDescriptors.add(descriptor); - } - - public void remove(CustomConfigFile descriptor) { - myDescriptors.remove(descriptor); - } - - public CustomConfigFile[] getConfigFiles() { - return myDescriptors.toArray(new CustomConfigFile[myDescriptors.size()]); - } - - public void setConfigFiles(final Collection descriptors) { - myDescriptors.clear(); - myDescriptors.addAll(descriptors); - } - - public void readExternal(Element element) { - doReadExternal(element, new ArrayList()); - } - - public void doReadExternal(Element element, List descriptorElements) { - myDescriptors.clear(); - List descriptors = element.getChildren(ELEMENT_NAME); - for (Element descriptor : descriptors) { - String url = descriptor.getAttributeValue(URL_ATTRIBUTE); - String directory = getDefaultDirOption(descriptor); - if (directory != null) { - myDescriptors.add(new CustomConfigFile(url, directory)); - descriptorElements.add(descriptor); - } - } - } - - @Nullable - private static String getDefaultDirOption(final Element descriptor) { - List options = descriptor.getChildren(OPTION_ELEMENT_NAME); - for (Element option : options) { - if (DEFAULT_DIR_OPTION.equals(option.getAttributeValue(NAME_ATTRIBUTE))) { - return option.getAttributeValue(VALUE_ATTRIBUTE); - } - } - return null; - } - - public void writeExternal(Element element) throws WriteExternalException { - for (CustomConfigFile descriptor : myDescriptors) { - final Element child = new Element(ELEMENT_NAME); - child.setAttribute(URL_ATTRIBUTE, descriptor.getUrl()); - final Element option = new Element(OPTION_ELEMENT_NAME); - option.setAttribute(NAME_ATTRIBUTE, DEFAULT_DIR_OPTION); - option.setAttribute(VALUE_ATTRIBUTE, descriptor.getOutputDirectoryPath()); - child.addContent(option); - element.addContent(child); - } - } -} diff --git a/java/openapi/src/com/intellij/util/descriptors/ConfigFileFactory.java b/java/openapi/src/com/intellij/util/descriptors/ConfigFileFactory.java index aa81db0eaffa..34690fe90c48 100644 --- a/java/openapi/src/com/intellij/util/descriptors/ConfigFileFactory.java +++ b/java/openapi/src/com/intellij/util/descriptors/ConfigFileFactory.java @@ -40,8 +40,6 @@ public abstract class ConfigFileFactory { public abstract ConfigFileMetaDataRegistry createMetaDataRegistry(); - public abstract CustomConfigFileSet createCustomConfigFileSet(); - @Nullable public abstract VirtualFile createFile(@Nullable Project project, String url, ConfigFileVersion version, final boolean forceNew); diff --git a/java/openapi/src/com/intellij/util/descriptors/CustomConfigFileSet.java b/java/openapi/src/com/intellij/util/descriptors/CustomConfigFileSet.java deleted file mode 100644 index 5437ef8205fd..000000000000 --- a/java/openapi/src/com/intellij/util/descriptors/CustomConfigFileSet.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2000-2009 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.descriptors; - -import com.intellij.openapi.util.JDOMExternalizable; - -import java.util.Collection; - -/** - * @author nik - * - * todo[nik] delete - */ -public interface CustomConfigFileSet extends JDOMExternalizable { - - void add(CustomConfigFile descriptor); - - void remove(CustomConfigFile descriptor); - - CustomConfigFile[] getConfigFiles(); - - void setConfigFiles(Collection descriptors); -} From b1da624f5ce56f68cc78a71a82ceb7110d688fcf Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 23 Oct 2009 20:13:35 +0400 Subject: [PATCH 02/21] junit: do not pull statistics events if no statistics were read --- .../execution/junit2/FilterCache.java | 6 ++++++ .../intellij/execution/junit2/SuiteState.java | 2 +- .../intellij/execution/junit2/TestProxy.java | 16 ++++------------ .../execution/junit2/states/TestState.java | 2 +- .../junit2/states/TestStateUpdater.java | 2 +- .../execution/junit2/ui/StatisticsPanel.java | 14 +++----------- .../execution/junit2/ui/StatisticsTable.java | 8 ++++++-- .../ui/model/JUnitListenersNotifier.java | 19 +++++++++++-------- 8 files changed, 33 insertions(+), 36 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit2/FilterCache.java b/plugins/junit/src/com/intellij/execution/junit2/FilterCache.java index 7a3d3c067efb..8d00b0215661 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/FilterCache.java +++ b/plugins/junit/src/com/intellij/execution/junit2/FilterCache.java @@ -25,6 +25,7 @@ import java.util.*; class FilterCache { private final ArrayList myList = new ArrayList(4); + private final Set mySet = new HashSet(); private final Map> myCache = new THashMap>(); public TestProxy[] select(final Filter filter) { @@ -46,9 +47,14 @@ class FilterCache { public void add(final TestProxy test) { myList.add(test); + mySet.add(test); resetCache(); } + public boolean contains(TestProxy test) { + return mySet.contains(test); + } + public AbstractTestProxy detect(final Filter filter) { return filter.detectIn(myList); } diff --git a/plugins/junit/src/com/intellij/execution/junit2/SuiteState.java b/plugins/junit/src/com/intellij/execution/junit2/SuiteState.java index 7c335537db22..2c77fc3956c0 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/SuiteState.java +++ b/plugins/junit/src/com/intellij/execution/junit2/SuiteState.java @@ -83,7 +83,7 @@ public class SuiteState extends TestState { return myCache.get(ALL_TESTS); } - public void changeStateAfterAddingChaildTo(final TestProxy test, final TestProxy child) { + public void changeStateAfterAddingChildTo(final TestProxy test, final TestProxy child) { if (child.getState().getMagnitude() <= getMagnitude()) { test.onStatisticsChanged(); return; diff --git a/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java b/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java index 51d9bdf7f081..5cb86418e9e7 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java +++ b/plugins/junit/src/com/intellij/execution/junit2/TestProxy.java @@ -102,7 +102,6 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy, pullEvent(new StateChangedEvent(this)); if (myParent != null) myParent.onChanged(this); - fireStatisticsChanged(); myNotifier.onChanged(this); } @@ -163,7 +162,7 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy, } public void addChild(final TestProxy child) { - if (myChildren.getList().contains(child)) + if (myChildren.contains(child)) return; if (child.getParent() != null) return;//todo throw new RuntimeException("Test: "+child + " already has parent: " + child.getParent()); @@ -174,8 +173,7 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy, child.fireOnNewPrintable(child); } pullEvent(new NewChildEvent(this, child)); - fireStatisticsChanged(); - getState().changeStateAfterAddingChaildTo(this, child); + getState().changeStateAfterAddingChildTo(this, child); myNotifier.onChildAdded(this, child); } @@ -203,11 +201,6 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy, } public void onStatisticsChanged() { - myChildren.resetCache(); - fireStatisticsChanged(); - } - - private void fireStatisticsChanged() { myChildren.resetCache(); if (myParent != null) myParent.onStatisticsChanged(); @@ -220,12 +213,11 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy, } public void setStatistics(final Statistics statistics) { - myChildren.resetCache(); if (!myState.isFinal()) { - LOG.error("" + myState.getMagnitude()); + LOG.error(String.valueOf(myState.getMagnitude())); } myStatistics = statistics; - fireStatisticsChanged(); + onStatisticsChanged(); } public Statistics getStatisticsImpl() { diff --git a/plugins/junit/src/com/intellij/execution/junit2/states/TestState.java b/plugins/junit/src/com/intellij/execution/junit2/states/TestState.java index 6ee58b073e2f..4feaf2b46ae3 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/states/TestState.java +++ b/plugins/junit/src/com/intellij/execution/junit2/states/TestState.java @@ -65,7 +65,7 @@ public abstract class TestState implements Printable { return null; } - public void changeStateAfterAddingChaildTo(final TestProxy test, final TestProxy child) { + public void changeStateAfterAddingChildTo(final TestProxy test, final TestProxy child) { test.setState(new SuiteState(test)); } } diff --git a/plugins/junit/src/com/intellij/execution/junit2/states/TestStateUpdater.java b/plugins/junit/src/com/intellij/execution/junit2/states/TestStateUpdater.java index 014818de040e..958b05b0daea 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/states/TestStateUpdater.java +++ b/plugins/junit/src/com/intellij/execution/junit2/states/TestStateUpdater.java @@ -113,7 +113,7 @@ public class TestStateUpdater implements PacketConsumer { final List children = parent.getChildren(); final TestState parentState = parent.getState(); LOG.assertTrue(parentState instanceof SuiteState); - if (children.indexOf(child) == children.size() - 1) { + if (child.equals(children.get(children.size() - 1))) { ((SuiteState)parentState).setRunning(false); } ((SuiteState)parentState).updateMagnitude(magnitude); diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java index 9b792c789991..afe48a6e3dac 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsPanel.java @@ -16,8 +16,6 @@ package com.intellij.execution.junit2.ui; -import com.intellij.execution.junit2.NewChildEvent; -import com.intellij.execution.junit2.StatisticsChanged; import com.intellij.execution.junit2.TestEvent; import com.intellij.execution.junit2.TestProxy; import com.intellij.execution.junit2.ui.actions.TestContext; @@ -70,9 +68,9 @@ class StatisticsPanel extends JPanel implements DataProvider{ myTable.setVisible(true); // myTestCaseInfo.setVisible(false); if (myCurrentTest.isLeaf() && myCurrentTest.getParent() != null) { - myChildInfo.onSelectionChanged(myCurrentTest.getParent()); + myChildInfo.updateStatistics(myCurrentTest.getParent()); } else{ - myChildInfo.onSelectionChanged(myCurrentTest); + myChildInfo.updateStatistics(myCurrentTest); } final int idx = myChildInfo.getIndexOf(myCurrentTest); TableUtil.selectRows(myTable, new int[]{idx}); @@ -99,13 +97,7 @@ class StatisticsPanel extends JPanel implements DataProvider{ private class MyJUnitListener extends JUnitAdapter { public void onTestChanged(final TestEvent event) { if (!StatisticsPanel.this.isShowing()) return; - if (event instanceof StatisticsChanged) { - if (myCurrentTest == event.getSource()) - updateStatistics(); - } else if (event instanceof NewChildEvent) { - if (event.getSource() == myCurrentTest && !myTable.isVisible()) - updateStatistics(); - } + if (myCurrentTest == event.getSource()) updateStatistics(); } public void onTestSelected(final TestProxy test) { diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsTable.java b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsTable.java index 2bd2cb6076f1..2a079c63aac2 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsTable.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/StatisticsTable.java @@ -47,8 +47,7 @@ public class StatisticsTable extends ListTableModel { private void setTest(final TestProxy test) { if (myTest == test) return; - myTest = test; - changeTableData(); + updateStatistics(test); } private void changeTableData() { @@ -102,4 +101,9 @@ public class StatisticsTable extends ListTableModel { } return -1; } + + public void updateStatistics(TestProxy currentTest) { + myTest = currentTest; + changeTableData(); + } } diff --git a/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitListenersNotifier.java b/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitListenersNotifier.java index f0973f6b6299..74c15e09ffda 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitListenersNotifier.java +++ b/plugins/junit/src/com/intellij/execution/junit2/ui/model/JUnitListenersNotifier.java @@ -23,12 +23,12 @@ import com.intellij.execution.junit2.segments.DispatchListener; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.Alarm; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class JUnitListenersNotifier implements JUnitListener, TestEventsConsumer, DispatchListener, Runnable { private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.ui.model.JUnitListenersNotifier"); @@ -142,7 +142,7 @@ public class JUnitListenersNotifier implements JUnitListener, TestEventsConsumer private void dispatchAllEvents() { //long start = System.currentTimeMillis(); - final List filteredEvents = removeDuplicatesFromEnd(myEventsQueue); + final List filteredEvents = removeDuplicates(myEventsQueue); myEventsQueue.clear(); // MEASURER.start(DISPATCH_SINGLES); for (final TestEvent event : filteredEvents) { @@ -153,11 +153,14 @@ public class JUnitListenersNotifier implements JUnitListener, TestEventsConsumer //System.out.println("duration = " + (System.currentTimeMillis() - start)); } - public static List removeDuplicatesFromEnd(final List list) { - ArrayList result = new ArrayList(list); - Collections.reverse(result); - ContainerUtil.removeDuplicates(result); - Collections.reverse(result); + private static List removeDuplicates(final List list) { + final ArrayList result = new ArrayList(list.size()); + final Set collected = new HashSet(); + for (T t : list) { + if (collected.contains(t)) continue; + collected.add(t); + result.add(t); + } return result; } } From ae74fb7e2bd17c8018055b9c7e8b050402235449 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 26 Oct 2009 11:36:04 +0300 Subject: [PATCH 03/21] Win32fs re-enabled --- .../vfs/impl/local/LocalFileSystemImpl.java | 5 +- .../openapi/vfs/impl/win32/Win32Kernel.java | 73 ++++++++++++++----- .../vfs/impl/win32/Win32LocalFileSystem.java | 33 ++++++--- .../vfs/newvfs/persistent/RefreshWorker.java | 3 +- .../src/misc/registry.properties | 2 +- 5 files changed, 81 insertions(+), 35 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index 6a068d3eec5c..c958f3fae362 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -21,7 +21,6 @@ import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.win32.Win32Kernel; @@ -125,9 +124,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap } public void disposeComponent() { - if (SystemInfo.isWindows && Registry.is("filesystem.useNative")) { - Win32Kernel.release(); - } + Win32Kernel.release(); } @TestOnly diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java index 689420919582..5948ba9ca0e8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java @@ -34,22 +34,34 @@ import java.util.Map; */ public class Win32Kernel { - private static Kernel32 myKernel = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class, new HashMap() { - { - put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); - put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); - }}); + private static Kernel32 ourKernel; private static final int MAX_PATH = 0x00000104; public static final int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; public static final int FILE_ATTRIBUTE_READONLY = 0x0001; + private synchronized static Kernel32 getKernel() { + if (ourKernel == null) { + ourKernel = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class, new HashMap() { + { + put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); + put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); + }}); + } + return ourKernel; + } + private static class FileInfo { private FileInfo(WIN32_FIND_DATA data) { this.dwFileAttributes = data.dwFileAttributes; this.ftLastWriteTime = data.ftLastWriteTime.toLong(); } + private FileInfo(BY_HANDLE_FILE_INFORMATION information) { + this.dwFileAttributes = information.dwFileAttributes; + this.ftLastWriteTime = information.ftLastWriteTime.toLong(); + } + int dwFileAttributes; long ftLastWriteTime; } @@ -68,22 +80,27 @@ public class Win32Kernel { myCache.clear(); ArrayList list = new ArrayList(); - W32API.HANDLE hFind = myKernel.FindFirstFile(absolutePath.replace('/', '\\') + "\\*", DATA); + W32API.HANDLE hFind = getKernel().FindFirstFile(absolutePath.replace('/', '\\') + "\\*", DATA); if (hFind.equals(INVALID_HANDLE_VALUE)) return new String[0]; do { String name = toString(DATA.cFileName); - if (name.equals(".") || name.equals("..")) { + if (name.equals(".")) { + myCache.put(absolutePath, new FileInfo(DATA)); + continue; + } + else if (name.equals("..")) { continue; } myCache.put(absolutePath + "/" + name, new FileInfo(DATA)); list.add(name); } - while (myKernel.FindNextFile(hFind, DATA)); - myKernel.FindClose(hFind); + while (getKernel().FindNextFile(hFind, DATA)); + getKernel().FindClose(hFind); return list.toArray(new String[list.size()]); } public boolean exists(String path) { + myCache.clear(); try { getData(path); return true; @@ -110,10 +127,10 @@ public class Win32Kernel { FileInfo data = myCache.get(path); if (data == null) { myCache.clear(); - W32API.HANDLE hFind = myKernel.FindFirstFile(path.replace('/', '\\'), DATA); - if (hFind.equals(INVALID_HANDLE_VALUE)) throw new FileNotFoundException(path); - data = new FileInfo(DATA); - myKernel.FindClose(hFind); + if (!getKernel().GetFileAttributesEx(path.replace('/', '\\'), 0, BY_HANDLE_FILE_INFORMATION.INSTANCE)) { + throw new FileNotFoundException(path); + } + data = new FileInfo(BY_HANDLE_FILE_INFORMATION.INSTANCE); myCache.put(path, data); } return data; @@ -130,22 +147,25 @@ public class Win32Kernel { W32API.HANDLE FindFirstFile(String lpFileName, WIN32_FIND_DATA lpFindFileData); + boolean GetFileAttributesEx(String lpFileName, int level, BY_HANDLE_FILE_INFORMATION lpFileInformation); + boolean FindNextFile(W32API.HANDLE hFindFile, WIN32_FIND_DATA lpFindFileData); boolean FindClose(W32API.HANDLE hFindFile); } public static class FILETIME extends Structure implements Structure.ByValue { - + public int dwLowDateTime; public int dwHighDateTime; private static long l(int i) { - if (i >= 0) { - return i; - } else { - return ((long) i & 0x7FFFFFFFl) + 0x80000000l; - } + if (i >= 0) { + return i; + } + else { + return ((long)i & 0x7FFFFFFFl) + 0x80000000l; + } } public long toLong() { @@ -169,11 +189,24 @@ public class Win32Kernel { public int nFileSizeLow; public int dwReserved0; - + public int dwReserved1; public char[] cFileName = new char[MAX_PATH]; public char[] cAlternateFileName = new char[14]; } + + @SuppressWarnings({"UnusedDeclaration"}) + public static class BY_HANDLE_FILE_INFORMATION extends Structure { + + public static BY_HANDLE_FILE_INFORMATION INSTANCE = new BY_HANDLE_FILE_INFORMATION(); + + public int dwFileAttributes; + public FILETIME ftCreationTime; + public FILETIME ftLastAccessTime; + public FILETIME ftLastWriteTime; + public int nFileSizeHigh; + public int nFileSizeLow; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java index 18ee4893b600..6213638e1344 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java @@ -33,19 +33,33 @@ public class Win32LocalFileSystem extends LocalFileSystemBase { @Override public String[] list(VirtualFile file) { try { - return myKernel.list(file.getPath()); + String[] strings = myKernel.list(file.getPath()); + //assert Arrays.asList(strings).equals(Arrays.asList(super.list(file))); + return strings; } catch (Exception e) { +// assert false; return super.list(file); } } + @Override + public boolean exists(VirtualFile fileOrDirectory) { + if (fileOrDirectory.getParent() == null) return true; + boolean b = myKernel.exists(fileOrDirectory.getPath()); + //assert b == super.exists(fileOrDirectory); + return b; + } + @Override public boolean isDirectory(VirtualFile file) { try { - return myKernel.isDirectory(file.getPath()); + boolean b = myKernel.isDirectory(file.getPath()); + //assert b == super.isDirectory(file); + return b; } catch (FileNotFoundException e) { +// assert false; return super.isDirectory(file); } } @@ -53,9 +67,12 @@ public class Win32LocalFileSystem extends LocalFileSystemBase { @Override public boolean isWritable(VirtualFile file) { try { - return myKernel.isWritable(file.getPath()); + boolean b = myKernel.isWritable(file.getPath()); + //assert b == super.isWritable(file); + return b; } catch (FileNotFoundException e) { +// assert false: file; return super.isWritable(file); } } @@ -63,18 +80,16 @@ public class Win32LocalFileSystem extends LocalFileSystemBase { @Override public long getTimeStamp(VirtualFile file) { try { - return myKernel.getTimeStamp(file.getPath()); + long timeStamp = myKernel.getTimeStamp(file.getPath()); + //assert timeStamp == super.getTimeStamp(file); + return timeStamp; } catch (FileNotFoundException e) { +// assert false; return super.getTimeStamp(file); } } - @Override - public boolean exists(VirtualFile fileOrDirectory) { - return myKernel.exists(fileOrDirectory.getPath()); - } - @Override public WatchRequest addRootToWatch(@NotNull String rootPath, boolean toWatchRecursively) { throw new UnsupportedOperationException(); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java index e4fbdacfc36d..2c0a6c716d77 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java @@ -19,6 +19,7 @@ */ package com.intellij.openapi.vfs.newvfs.persistent; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.LocalFileSystem; @@ -58,7 +59,7 @@ public class RefreshWorker { } else { if (delegate.getProtocol().equals(LocalFileSystem.PROTOCOL) && SystemInfo.isWindows && root.isDirectory() && - (Registry.is("filesystem.useNative"))) { + (ApplicationManager.getApplication().isUnitTestMode() || Registry.is("filesystem.useNative"))) { delegate = new Win32LocalFileSystem(); } diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 9afb7eaa830a..7d51aa49a4e3 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -39,4 +39,4 @@ ide.tabbedPane.bufferedPaint=true debugger.valueTooltipAutoShow=true debugger.valueTooltipAutoShow.description=Auto show tooltip on mouse over -filesystem.useNative=false \ No newline at end of file +filesystem.useNative=true \ No newline at end of file From 0fe3a19093c88bc6edeb091236bb4376cd8f60f8 Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 26 Oct 2009 12:40:27 +0300 Subject: [PATCH 04/21] IDEADEV-40991: Artifact editor: misleading label in Create manifest chooser --- .../impl/ui/properties/ElementWithManifestPropertiesPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.java index e5d3b18da96a..534c960c33b0 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/properties/ElementWithManifestPropertiesPanel.java @@ -130,7 +130,7 @@ public abstract class ElementWithManifestPropertiesPanel Date: Mon, 26 Oct 2009 13:02:34 +0300 Subject: [PATCH 05/21] Win32fs disabled in tests --- .../intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java index 2c0a6c716d77..07dfa15c6dad 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/RefreshWorker.java @@ -59,7 +59,7 @@ public class RefreshWorker { } else { if (delegate.getProtocol().equals(LocalFileSystem.PROTOCOL) && SystemInfo.isWindows && root.isDirectory() && - (ApplicationManager.getApplication().isUnitTestMode() || Registry.is("filesystem.useNative"))) { + (!ApplicationManager.getApplication().isUnitTestMode() && Registry.is("filesystem.useNative"))) { delegate = new Win32LocalFileSystem(); } From 965352d2f2fdf3043e7d4fac817768e6c695abd5 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Mon, 26 Oct 2009 13:04:24 +0300 Subject: [PATCH 06/21] actionSystem.suspendFocusTransferIfApplicationInactive=false by default --- platform/platform-resources-en/src/misc/registry.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 9afb7eaa830a..44b9ecd2e80a 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -19,7 +19,7 @@ actionSystem.playback.description=Delay between events generated by the playback actionSystem.focusIdleTimeout=20 actionSystem.mac.screenMenuNotUpdatedFix=false actionSystem.keyGestures.enabled=false -actionSystem.suspendFocusTransferIfApplicationInactive=true +actionSystem.suspendFocusTransferIfApplicationInactive=false ide.debugMode=true ide.debugMode.description=Record additonal information to make bug reports more informative From 1bb6ebc283f8953b07d567b8ee61770406dfb64c Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 26 Oct 2009 13:21:30 +0300 Subject: [PATCH 07/21] fixed problem with non-disposed root models? --- .../ProjectStructureDaemonAnalyzer.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/ProjectStructureDaemonAnalyzer.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/ProjectStructureDaemonAnalyzer.java index f7beb9aed5ba..aa5b46984392 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/ProjectStructureDaemonAnalyzer.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/ProjectStructureDaemonAnalyzer.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; /** * @author nik @@ -25,7 +26,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { private Set myElementWithNotCalculatedUsages = new HashSet(); private MergingUpdateQueue myAnalyzerQueue; private List myListeners = new ArrayList(); - private boolean myStopped; + private final AtomicBoolean myStopped = new AtomicBoolean(false); public ProjectStructureDaemonAnalyzer(StructureConfigurableContext context) { Disposer.register(context, this); @@ -33,7 +34,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { } private void doUpdate(final ProjectStructureElement element, final boolean check, final boolean collectUsages) { - if (myStopped) return; + if (myStopped.get()) return; if (check) { doCheck(element); @@ -47,7 +48,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { final ProjectStructureProblemsHolder problemsHolder = new ProjectStructureProblemsHolder(); new ReadAction() { protected void run(final Result result) { - if (myStopped) return; + if (myStopped.get()) return; if (LOG.isDebugEnabled()) { LOG.debug("checking " + element); @@ -57,7 +58,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { }.execute(); invokeLater(new Runnable() { public void run() { - if (myStopped) return; + if (myStopped.get()) return; if (LOG.isDebugEnabled()) { LOG.debug("updating problems for " + element); @@ -78,7 +79,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { private void doCollectUsages(final ProjectStructureElement element) { final List usages = new ReadAction>() { protected void run(final Result> result) { - if (myStopped) return; + if (myStopped.get()) return; if (LOG.isDebugEnabled()) { LOG.debug("collecting usages in " + element); @@ -89,7 +90,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { invokeLater(new Runnable() { public void run() { - if (myStopped) return; + if (myStopped.get()) return; if (LOG.isDebugEnabled()) { LOG.debug("updating usages for " + element); @@ -166,7 +167,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { public void stop() { LOG.debug("analyzer stopped"); - myStopped = true; + myStopped.set(true); myAnalyzerQueue.cancelAllUpdates(); clearCaches(); myAnalyzerQueue.deactivate(); @@ -183,7 +184,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { } public void dispose() { - myStopped = true; + myStopped.set(true); myAnalyzerQueue.cancelAllUpdates(); } @@ -211,7 +212,7 @@ public class ProjectStructureDaemonAnalyzer implements Disposable { myAnalyzerQueue.activate(); myAnalyzerQueue.queue(new Update("reset") { public void run() { - myStopped = false; + myStopped.set(false); } }); } From 9c8f56dc62034cae2715e5c34af17f4be65a20b0 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 26 Oct 2009 13:28:13 +0300 Subject: [PATCH 08/21] GitRootTracker moved to background --- .../src/git4idea/vfs/GitRootTracker.java | 204 ++++++++++-------- 1 file changed, 111 insertions(+), 93 deletions(-) diff --git a/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java b/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java index c0295a11e6f3..c1a5417c7aad 100644 --- a/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java +++ b/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java @@ -26,6 +26,10 @@ import com.intellij.openapi.command.CommandAdapter; import com.intellij.openapi.command.CommandEvent; import com.intellij.openapi.command.CommandListener; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootEvent; import com.intellij.openapi.roots.ModuleRootListener; @@ -57,6 +61,9 @@ import java.util.concurrent.atomic.AtomicBoolean; * shows balloon that notifies user about the problem and offers to correct root mapping. */ public class GitRootTracker implements VcsListener { + + private static final Logger LOG = Logger.getInstance("#git4idea.vfs.GitRootTracker"); + /** * The context project */ @@ -169,7 +176,7 @@ public class GitRootTracker implements VcsListener { } }; fileManager.addVirtualFileManagerListener(myVirtualFileManagerListener); - StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new Runnable() { + StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() { public void run() { myIsEnabled.set(true); checkRoots(true); @@ -208,94 +215,106 @@ public class GitRootTracker implements VcsListener { if (!myIsEnabled.get() || (!rootsChanged && !myHasGitRoots.get())) { return; } - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run() { - boolean hasInvalidRoots = false; - HashSet rootSet = new HashSet(); - for (VcsDirectoryMapping m : myVcsManager.getDirectoryMappings()) { - if (!m.getVcs().equals(myVcs.getName())) { - continue; + ProgressManager.getInstance().run(new Task.Backgroundable(myProject, "Checking unmapped Git roots...") { + @Override + public void run(@NotNull ProgressIndicator indicator) { + ApplicationManager.getApplication().runReadAction(new Runnable() { + public void run() { + LOG.info("Checking unmapped Git roots..."); + long start = System.currentTimeMillis(); + doCheck(); + LOG.info("Unmapped Git roots checked in " + (System.currentTimeMillis() - start) + "ms"); } - String path = m.getDirectory(); - if (path.length() == 0) { - VirtualFile baseDir = myProject.getBaseDir(); - assert baseDir != null; - path = baseDir.getPath(); - } - VirtualFile root = lookupFile(path); - if (root == null) { - hasInvalidRoots = true; - break; - } - else { - rootSet.add(root.getPath()); - } - } - if (!hasInvalidRoots && rootSet.isEmpty()) { - myHasGitRoots.set(false); - return; - } - else { - myHasGitRoots.set(true); - } - if (!hasInvalidRoots) { - // check if roots have a problem - loop: - for (String path : rootSet) { - VirtualFile root = lookupFile(path); - VirtualFile gitRoot = GitUtil.gitRootOrNull(root); - if (gitRoot == null || hasUnmappedSubroots(root, rootSet)) { - hasInvalidRoots = true; - break; - } - for (String otherPath : rootSet) { - if (otherPath.equals(path)) { - continue; - } - if (otherPath.startsWith(path)) { - VirtualFile otherFile = lookupFile(otherPath); - if (otherFile == null) { - hasInvalidRoots = true; - break loop; - } - VirtualFile otherRoot = GitUtil.gitRootOrNull(otherFile); - if (otherRoot == null || otherRoot == root || otherFile != otherRoot) { - hasInvalidRoots = true; - break loop; - } - } - } - } - } - if (!hasInvalidRoots) { - // all roots are correct - if (myNotificationPosted.compareAndSet(true, false)) { - if (myNotification != null) { - if (!myNotification.isExpired()) { - myNotification.expire(); - } - - myNotification = null; - } - } - return; - } - if (myNotificationPosted.compareAndSet(false, true)) { - myNotification = new Notification(GIT_INVALID_ROOTS_ID, GitBundle.getString("root.tracker.message.title"), - GitBundle.getString("root.tracker.message"), - NotificationType.ERROR, new NotificationListener() { - public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - if (fixRoots()) { - notification.expire(); - } - } - }); - - Notifications.Bus.notify(myNotification, myProject); - } + }); + myMulticaster.gitRootsChanged(); } }); - myMulticaster.gitRootsChanged(); + } + + private void doCheck() { + boolean hasInvalidRoots = false; + HashSet rootSet = new HashSet(); + for (VcsDirectoryMapping m : myVcsManager.getDirectoryMappings()) { + if (!m.getVcs().equals(myVcs.getName())) { + continue; + } + String path = m.getDirectory(); + if (path.length() == 0) { + VirtualFile baseDir = myProject.getBaseDir(); + assert baseDir != null; + path = baseDir.getPath(); + } + VirtualFile root = lookupFile(path); + if (root == null) { + hasInvalidRoots = true; + break; + } + else { + rootSet.add(root.getPath()); + } + } + if (!hasInvalidRoots && rootSet.isEmpty()) { + myHasGitRoots.set(false); + return; + } + else { + myHasGitRoots.set(true); + } + if (!hasInvalidRoots) { + // check if roots have a problem + loop: + for (String path : rootSet) { + VirtualFile root = lookupFile(path); + VirtualFile gitRoot = GitUtil.gitRootOrNull(root); + if (gitRoot == null || hasUnmappedSubroots(root, true, rootSet)) { + hasInvalidRoots = true; + break; + } + for (String otherPath : rootSet) { + if (otherPath.equals(path)) { + continue; + } + if (otherPath.startsWith(path)) { + VirtualFile otherFile = lookupFile(otherPath); + if (otherFile == null) { + hasInvalidRoots = true; + break loop; + } + VirtualFile otherRoot = GitUtil.gitRootOrNull(otherFile); + if (otherRoot == null || otherRoot == root || otherFile != otherRoot) { + hasInvalidRoots = true; + break loop; + } + } + } + } + } + if (!hasInvalidRoots) { + // all roots are correct + if (myNotificationPosted.compareAndSet(true, false)) { + if (myNotification != null) { + if (!myNotification.isExpired()) { + myNotification.expire(); + } + + myNotification = null; + } + } + return; + } + if (myNotificationPosted.compareAndSet(false, true)) { + myNotification = new Notification(GIT_INVALID_ROOTS_ID, GitBundle.getString("root.tracker.message.title"), + GitBundle.getString("root.tracker.message"), + NotificationType.ERROR, new NotificationListener() { + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + if (fixRoots()) { + notification.expire(); + } + } + }); + + Notifications.Bus.notify(myNotification, myProject); + } } /** @@ -305,15 +324,14 @@ public class GitRootTracker implements VcsListener { * @param rootSet the mapped root set * @return true if there are unmapped subroots */ - private static boolean hasUnmappedSubroots(VirtualFile directory, HashSet rootSet) { + private static boolean hasUnmappedSubroots(VirtualFile directory, boolean isRoot, HashSet rootSet) { for (VirtualFile child : directory.getChildren()) { - if (child.getName().equals(".git") || !child.isDirectory()) { - continue; + if (child.getName().equals(".git")) { + if (isRoot || !child.isDirectory()) + continue; + return !rootSet.contains(directory.getPath()); } - if (child.findChild(".git") != null && !rootSet.contains(child.getPath())) { - return true; - } - if (hasUnmappedSubroots(child, rootSet)) { + if (child.isDirectory() && hasUnmappedSubroots(child, false, rootSet)) { return true; } } From b8e3f9e1de561cc5cc4dc92af1339b1dce720357 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 26 Oct 2009 13:44:50 +0300 Subject: [PATCH 09/21] JVM crash fix? --- .../src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java index 5948ba9ca0e8..d18278499ee2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java @@ -71,6 +71,7 @@ public class Win32Kernel { public static void release() { DATA = null; + BY_HANDLE_FILE_INFORMATION.INSTANCE = null; } private Map myCache = new HashMap(); From ec45a449c09d439c8e992b7c01b2fe712e4dcb9d Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 26 Oct 2009 13:52:41 +0300 Subject: [PATCH 10/21] correctly put web and ejb artifacts in ear artifact && unused classes removed --- .../ModuleWithDependenciesElementType.java | 72 ---------- ...oduleWithDependenciesPackagingElement.java | 127 ------------------ .../elements/PackagingElementFactoryImpl.java | 1 - .../packaging/artifacts/ArtifactType.java | 5 - .../sourceItems/ArtifactSourceItem.java | 4 + 5 files changed, 4 insertions(+), 205 deletions(-) delete mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesElementType.java delete mode 100644 java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesPackagingElement.java diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesElementType.java deleted file mode 100644 index 6e2bc355df99..000000000000 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesElementType.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2000-2009 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.packaging.impl.elements; - -import com.intellij.openapi.module.Module; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.IconLoader; -import com.intellij.packaging.artifacts.Artifact; -import com.intellij.packaging.elements.ComplexPackagingElementType; -import com.intellij.packaging.elements.CompositePackagingElement; -import com.intellij.packaging.ui.ArtifactEditorContext; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.List; - -/** - * @author nik - */ -public class ModuleWithDependenciesElementType extends ComplexPackagingElementType { - public static final ModuleWithDependenciesElementType MODULE_WITH_DEPENDENCIES_TYPE = new ModuleWithDependenciesElementType(); - - public ModuleWithDependenciesElementType() { - super("module-with-dependencies", "Module With Dependencies"); - } - - @Override - public String getShowContentActionText() { - return "Module with dependencies"; - } - - @Override - public Icon getCreateElementIcon() { - return IconLoader.getIcon("/nodes/ModuleOpen.png"); - } - - @Override - public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) { - return context.getModulesProvider().getModules().length > 0; - } - - @NotNull - public List chooseAndCreate(@NotNull ArtifactEditorContext context, - @NotNull Artifact artifact, - @NotNull CompositePackagingElement parent) { - final List modules = ModuleOutputElementType.chooseModules(context); - final List elements = new ArrayList(); - for (Module module : modules) { - elements.add(new ModuleWithDependenciesPackagingElement(module.getName())); - } - return elements; - } - - @NotNull - public ModuleWithDependenciesPackagingElement createEmpty(@NotNull Project project) { - return new ModuleWithDependenciesPackagingElement(); - } -} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesPackagingElement.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesPackagingElement.java deleted file mode 100644 index 54951bdf4465..000000000000 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesPackagingElement.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2000-2009 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.packaging.impl.elements; - -import com.intellij.openapi.compiler.CompilerBundle; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.roots.*; -import com.intellij.openapi.roots.libraries.Library; -import com.intellij.packaging.elements.ComplexPackagingElement; -import com.intellij.packaging.elements.PackagingElement; -import com.intellij.packaging.elements.PackagingElementFactory; -import com.intellij.packaging.elements.PackagingElementResolvingContext; -import com.intellij.packaging.impl.ui.DelegatedPackagingElementPresentation; -import com.intellij.packaging.impl.ui.ModuleElementPresentation; -import com.intellij.packaging.ui.PackagingElementPresentation; -import com.intellij.packaging.ui.PackagingElementWeights; -import com.intellij.packaging.ui.ArtifactEditorContext; -import com.intellij.packaging.artifacts.ArtifactType; -import com.intellij.util.xmlb.annotations.Attribute; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author nik - */ -public class ModuleWithDependenciesPackagingElement extends ComplexPackagingElement { - private String myModuleName; - - public ModuleWithDependenciesPackagingElement() { - super(ModuleWithDependenciesElementType.MODULE_WITH_DEPENDENCIES_TYPE); - } - - public ModuleWithDependenciesPackagingElement(String moduleName) { - super(ModuleWithDependenciesElementType.MODULE_WITH_DEPENDENCIES_TYPE); - myModuleName = moduleName; - } - - public List> getSubstitution(@NotNull PackagingElementResolvingContext context, @NotNull ArtifactType artifactType) { - final Module module = findModule(context); - - List> elements = new ArrayList>(); - final PackagingElementFactory factory = PackagingElementFactory.getInstance(); - if (module != null) { - final ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module); - for (OrderEntry entry : rootModel.getOrderEntries()) { - if (entry instanceof ModuleSourceOrderEntry) { - elements.add(factory.createModuleOutput(myModuleName, context.getProject())); - } - else if (entry instanceof LibraryOrderEntry) { - final Library library = ((LibraryOrderEntry)entry).getLibrary(); - if (library != null) { - elements.addAll(factory.createLibraryElements(library)); - } - } - else if (entry instanceof ModuleOrderEntry) { - elements.add(new ModuleWithDependenciesPackagingElement(((ModuleOrderEntry)entry).getModuleName())); - } - } - } - - final List> substitution = new ArrayList>(); - for (PackagingElement element : elements) { - final String path = artifactType.getDefaultPathFor(element, context); - if (path != null) { - substitution.add(factory.createParentDirectories(path, element)); - } - } - return substitution; - } - - public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) { - return new DelegatedPackagingElementPresentation(new ModuleElementPresentation(myModuleName, findModule(context), context) { - @Override - protected String getNodeText() { - return CompilerBundle.message("node.text.0.with.dependencies", getPresentableName()); - } - - @Override - public int getWeight() { - return PackagingElementWeights.ARTIFACT - 10; - } - }); - } - - public boolean isEqualTo(@NotNull PackagingElement element) { - return element instanceof ModuleWithDependenciesPackagingElement && myModuleName != null - && myModuleName.equals(((ModuleWithDependenciesPackagingElement)element).getModuleName()); - } - - public ModuleWithDependenciesPackagingElement getState() { - return this; - } - - public void loadState(ModuleWithDependenciesPackagingElement state) { - myModuleName = state.getModuleName(); - } - - @Nullable - public Module findModule(PackagingElementResolvingContext context) { - return context.getModulesProvider().getModule(myModuleName); - } - - @Attribute("module-name") - public String getModuleName() { - return myModuleName; - } - - public void setModuleName(String moduleName) { - myModuleName = moduleName; - } -} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java index ef3f0ca0bf19..e4569f661bc9 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java @@ -64,7 +64,6 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { private static final PackagingElementType[] STANDARD_TYPES = { DIRECTORY_ELEMENT_TYPE, ARCHIVE_ELEMENT_TYPE, LibraryElementType.LIBRARY_ELEMENT_TYPE, ModuleOutputElementType.MODULE_OUTPUT_ELEMENT_TYPE, - //ModuleWithDependenciesElementType.MODULE_WITH_DEPENDENCIES_TYPE, ArtifactElementType.ARTIFACT_ELEMENT_TYPE, FILE_COPY_ELEMENT_TYPE, DIRECTORY_COPY_ELEMENT_TYPE }; diff --git a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactType.java b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactType.java index c3ec0bcb3113..533c2adc5657 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactType.java +++ b/java/compiler/openapi/src/com/intellij/packaging/artifacts/ArtifactType.java @@ -60,11 +60,6 @@ public abstract class ArtifactType { return getDefaultPathFor(sourceItem.getKindOfProducedElements()); } - @Nullable - public String getDefaultPathFor(@NotNull PackagingElement element, @NotNull PackagingElementResolvingContext context) { - return getDefaultPathFor(element.getFilesKind(context)); - } - @Nullable public abstract String getDefaultPathFor(@NotNull PackagingElementOutputKind kind); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactSourceItem.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactSourceItem.java index afb8b855c89b..b393f4785910 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactSourceItem.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ArtifactSourceItem.java @@ -64,6 +64,10 @@ public class ArtifactSourceItem extends PackagingSourceItem { return myArtifact.getArtifactType() instanceof JarArtifactType ? PackagingElementOutputKind.JAR_FILES : PackagingElementOutputKind.OTHER; } + public Artifact getArtifact() { + return myArtifact; + } + public int hashCode() { return myArtifact.hashCode(); } From e3b8d043a181984765b5469ae8ec78a7f50614f4 Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 26 Oct 2009 13:55:35 +0300 Subject: [PATCH 11/21] sort artifacts targets in generated ant xml --- .../com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java b/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java index 13b851299b06..4997d9c42085 100644 --- a/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java +++ b/java/compiler/impl/src/com/intellij/compiler/ant/artifacts/ArtifactsGenerator.java @@ -63,7 +63,7 @@ public class ArtifactsGenerator { generators.add(initTarget); initTarget.add(new Property(ArtifactAntGenerationContextImpl.ARTIFACTS_TEMP_DIR_PROPERTY, BuildProperties.propertyRelativePath(BuildProperties.getProjectBaseDirProperty(), "artifactsTemp"))); - final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getArtifacts(); + final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getSortedArtifacts(); for (Artifact artifact : artifacts) { if (!myContext.shouldBuildIntoTempDirectory(artifact)) { generators.add(new CleanArtifactTarget(artifact, myContext)); From 9d1d1d559716477cdc7ed514f30188893f1babee Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 26 Oct 2009 14:32:42 +0300 Subject: [PATCH 12/21] JVM crash fix? --- .../openapi/vfs/impl/win32/Win32Kernel.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java index d18278499ee2..12a087131f3a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java @@ -47,6 +47,8 @@ public class Win32Kernel { put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); }}); + WIN32_FIND_DATA.INSTANCE = new WIN32_FIND_DATA(); + BY_HANDLE_FILE_INFORMATION.INSTANCE = new BY_HANDLE_FILE_INFORMATION(); } return ourKernel; } @@ -67,11 +69,12 @@ public class Win32Kernel { } private static W32API.HANDLE INVALID_HANDLE_VALUE = new W32API.HANDLE(Pointer.createConstant(0xFFFFFFFFl)); - private static WIN32_FIND_DATA DATA = new WIN32_FIND_DATA(); public static void release() { - DATA = null; - BY_HANDLE_FILE_INFORMATION.INSTANCE = null; + if (ourKernel != null) { + WIN32_FIND_DATA.INSTANCE = null; + BY_HANDLE_FILE_INFORMATION.INSTANCE = null; + } } private Map myCache = new HashMap(); @@ -81,21 +84,21 @@ public class Win32Kernel { myCache.clear(); ArrayList list = new ArrayList(); - W32API.HANDLE hFind = getKernel().FindFirstFile(absolutePath.replace('/', '\\') + "\\*", DATA); + W32API.HANDLE hFind = getKernel().FindFirstFile(absolutePath.replace('/', '\\') + "\\*", WIN32_FIND_DATA.INSTANCE); if (hFind.equals(INVALID_HANDLE_VALUE)) return new String[0]; do { - String name = toString(DATA.cFileName); + String name = Native.toString(WIN32_FIND_DATA.INSTANCE.cFileName); if (name.equals(".")) { - myCache.put(absolutePath, new FileInfo(DATA)); + myCache.put(absolutePath, new FileInfo(WIN32_FIND_DATA.INSTANCE)); continue; } else if (name.equals("..")) { continue; } - myCache.put(absolutePath + "/" + name, new FileInfo(DATA)); + myCache.put(absolutePath + "/" + name, new FileInfo(WIN32_FIND_DATA.INSTANCE)); list.add(name); } - while (getKernel().FindNextFile(hFind, DATA)); + while (getKernel().FindNextFile(hFind, WIN32_FIND_DATA.INSTANCE)); getKernel().FindClose(hFind); return list.toArray(new String[list.size()]); } @@ -137,13 +140,6 @@ public class Win32Kernel { return data; } - private static String toString(char[] array) { - for (int i = 0; i < array.length; i++) { - if (array[i] == 0) return new String(array, 0, i); - } - return new String(array); - } - public interface Kernel32 extends StdCallLibrary { W32API.HANDLE FindFirstFile(String lpFileName, WIN32_FIND_DATA lpFindFileData); @@ -177,6 +173,8 @@ public class Win32Kernel { @SuppressWarnings({"UnusedDeclaration"}) public static class WIN32_FIND_DATA extends Structure { + public static WIN32_FIND_DATA INSTANCE; + public int dwFileAttributes; public FILETIME ftCreationTime; @@ -201,7 +199,7 @@ public class Win32Kernel { @SuppressWarnings({"UnusedDeclaration"}) public static class BY_HANDLE_FILE_INFORMATION extends Structure { - public static BY_HANDLE_FILE_INFORMATION INSTANCE = new BY_HANDLE_FILE_INFORMATION(); + public static BY_HANDLE_FILE_INFORMATION INSTANCE; public int dwFileAttributes; public FILETIME ftCreationTime; From 47cc84088fc21d2d07fb4ddd80745a4fa3bd0bcf Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Mon, 26 Oct 2009 14:39:47 +0300 Subject: [PATCH 13/21] 16432 IOE: VirtualDirectoryImpl.getOutputStream: file based storage should have an extension --- .../components/impl/stores/StateStorageManagerImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java index bcbf5630e755..36c993fe3527 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java @@ -23,6 +23,7 @@ import com.intellij.openapi.options.StreamProvider; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.MultiMap; @@ -267,6 +268,11 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di return null; } + final String extension = FileUtil.getExtension(new File(expandedFile).getName()); + if (extension.length() == 0) { + throw new IllegalArgumentException("Extension is missing for storage file: " + expandedFile); + } + return createFileStateStorage(fileSpec, expandedFile, myRootTagName, myPicoContainer); } From e07ea32dfdaa03cbfee6ee6b9ac55c0d38ab6f0d Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Mon, 26 Oct 2009 14:52:08 +0300 Subject: [PATCH 14/21] TreeUi: expand node when enqueued for update --- .../com/intellij/ide/util/treeView/AbstractTreeUi.java | 7 ++++++- .../intellij/ide/util/treeView/AbstractTreeUpdater.java | 9 +++++++++ .../com/intellij/ide/util/treeView/TreeUpdatePass.java | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index 297d34242879..1197cbcdc0cc 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -2956,7 +2956,9 @@ public class AbstractTreeUi { if (myTree.isExpanded(getPathFor(toExpand)) && !myUnbuiltNodes.contains(toExpand)) { - processNodeActionsIfReady(toExpand); + if (!areChildrenToBeUpdated(toExpand)) { + processNodeActionsIfReady(toExpand); + } } else { if (!myUnbuiltNodes.contains(toExpand)) { @@ -2968,6 +2970,9 @@ public class AbstractTreeUi { } } + private boolean areChildrenToBeUpdated(DefaultMutableTreeNode node) { + return getUpdater().isEnqueuedToUpdate(node) || isUpdatingParent(node); + } private String asString(DefaultMutableTreeNode node) { if (node == null) return null; diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java index c07e0f09b868..f3d8e100fee6 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUpdater.java @@ -316,4 +316,13 @@ public class AbstractTreeUpdater implements Disposable, Activatable { public void flush() { myUpdateQueue.sendFlush(); } + + public boolean isEnqueuedToUpdate(DefaultMutableTreeNode node) { + Iterator nodes = myNodeQueue.iterator(); + while (nodes.hasNext()) { + TreeUpdatePass each = nodes.next(); + if (each.willUpdate(node)) return true; + } + return false; + } } diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeUpdatePass.java b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeUpdatePass.java index 143565f69b71..8ce8fcd374b0 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeUpdatePass.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeUpdatePass.java @@ -79,4 +79,9 @@ public class TreeUpdatePass { public String toString() { return "TreUpdatePass node=" + myNode + " stamp=" + myUpdateStamp + " expired=" + myExpired + " currentNode=" + myCurrentNode + " allocation=" + myAllocation; } + + public boolean willUpdate(@NotNull DefaultMutableTreeNode node) { + @NotNull DefaultMutableTreeNode currentNode = myCurrentNode != null ? myCurrentNode : myNode; + return node.isNodeAncestor(currentNode); + } } \ No newline at end of file From e1f2e7ed1d53f971e782d2922614d42de6cb7d0d Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Mon, 26 Oct 2009 15:04:32 +0300 Subject: [PATCH 15/21] ProjectView: position on new created element fixed --- .../ide/actions/CreateTemplateInPackageAction.java | 3 +-- .../intellij/ide/projectView/impl/ProjectViewImpl.java | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/ide/actions/CreateTemplateInPackageAction.java b/java/java-impl/src/com/intellij/ide/actions/CreateTemplateInPackageAction.java index 423118294fc3..463509a7bcbe 100644 --- a/java/java-impl/src/com/intellij/ide/actions/CreateTemplateInPackageAction.java +++ b/java/java-impl/src/com/intellij/ide/actions/CreateTemplateInPackageAction.java @@ -66,8 +66,7 @@ public abstract class CreateTemplateInPackageAction extend } }); if (createdElement != null) { - final PsiElement navigationElement = getNavigationElement(createdElement); - view.selectElement(navigationElement == null ? createdElement : navigationElement); + view.selectElement(createdElement); } } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index feec037c4e16..ab5586a11604 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -1194,16 +1194,22 @@ public final class ProjectViewImpl extends ProjectView implements PersistentStat private final class MyIdeView implements IdeView { public void selectElement(PsiElement element) { - selectPsiElement(element, true); + selectPsiElement(element, false); + boolean requestFocus = true; if (element != null) { final boolean isDirectory = element instanceof PsiDirectory; if (!isDirectory) { Editor editor = EditorHelper.openInEditor(element); if (editor != null) { ToolWindowManager.getInstance(myProject).activateEditorComponent(); + requestFocus = false; } } } + + if (requestFocus) { + selectPsiElement(element, true); + } } public PsiDirectory[] getDirectories() { From 387fc80395c2d94615293eb0c4d95db8f60d534a Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Mon, 26 Oct 2009 15:25:51 +0300 Subject: [PATCH 16/21] Moved UI components to community/platform/util --- .../src/com/intellij/ui/CheckBoxList.java | 91 ++++++++++++++++ .../com/intellij/ui/CheckBoxListListener.java | 8 ++ .../intellij/ui/OptionalChooserComponent.form | 28 +++++ .../intellij/ui/OptionalChooserComponent.java | 69 ++++++++++++ .../intellij/ui/PathsChooserComponent.form | 49 +++++++++ .../intellij/ui/PathsChooserComponent.java | 101 ++++++++++++++++++ platform/util/util.iml | 1 + 7 files changed, 347 insertions(+) create mode 100644 platform/util/src/com/intellij/ui/CheckBoxList.java create mode 100644 platform/util/src/com/intellij/ui/CheckBoxListListener.java create mode 100644 platform/util/src/com/intellij/ui/OptionalChooserComponent.form create mode 100644 platform/util/src/com/intellij/ui/OptionalChooserComponent.java create mode 100644 platform/util/src/com/intellij/ui/PathsChooserComponent.form create mode 100644 platform/util/src/com/intellij/ui/PathsChooserComponent.java diff --git a/platform/util/src/com/intellij/ui/CheckBoxList.java b/platform/util/src/com/intellij/ui/CheckBoxList.java new file mode 100644 index 000000000000..9570eb4abc13 --- /dev/null +++ b/platform/util/src/com/intellij/ui/CheckBoxList.java @@ -0,0 +1,91 @@ +package com.intellij.ui; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.plaf.basic.BasicRadioButtonUI; +import java.awt.*; +import java.awt.event.*; + +/** + * @author oleg + */ +public class CheckBoxList extends JList { + private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); + private static final int DEFAULT_CHECK_BOX_WIDTH = 20; + + public CheckBoxList(final ListModel dataModel, final CheckBoxListListener checkBoxListListener) { + super(dataModel); + setCellRenderer(new CellRenderer()); + setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + setBorder(BorderFactory.createEtchedBorder()); + addKeyListener(new KeyAdapter() { + @Override + public void keyTyped(KeyEvent e) { + if (e.getKeyChar() == ' ') { + int index = CheckBoxList.this.getSelectedIndex(); + + if (index >= 0) { + JCheckBox checkbox = (JCheckBox)getModel().getElementAt(index); + setSelected(checkbox, index, checkBoxListListener); + } + } + } + }); + addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (isEnabled()) { + int index = locationToIndex(e.getPoint()); + + if (index != -1) { + JCheckBox checkbox = (JCheckBox)getModel().getElementAt(index); + int iconArea; + try { + iconArea = ((BasicRadioButtonUI)checkbox.getUI()).getDefaultIcon().getIconWidth(); + } + catch (ClassCastException c) { + iconArea = DEFAULT_CHECK_BOX_WIDTH; + } + if (e.getX() < iconArea) { + setSelected(checkbox, index, checkBoxListListener); + } + } + } + } + }); + } + + private void setSelected(JCheckBox checkbox, int index, CheckBoxListListener checkBoxListListener) { + boolean value = !checkbox.isSelected(); + checkbox.setSelected(value); + repaint(); + checkBoxListListener.checkBoxSelectionChanged(index, value); + } + + private class CellRenderer implements ListCellRenderer { + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + JCheckBox checkbox = (JCheckBox)value; + checkbox.setBackground(getBackgound(isSelected, checkbox)); + checkbox.setForeground(getForeGround(isSelected, checkbox)); + checkbox.setEnabled(isEnabled()); + checkbox.setFont(getFont(checkbox)); + checkbox.setFocusPainted(false); + checkbox.setBorderPainted(true); + checkbox.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder); + return checkbox; + } + } + + protected Font getFont(final JCheckBox checkbox) { + return getFont(); + } + + protected Color getBackgound(final boolean isSelected, final JCheckBox checkbox) { + return isSelected ? getSelectionBackground() : getBackground(); + } + + protected Color getForeGround(final boolean isSelected, final JCheckBox checkbox) { + return isSelected ? getSelectionForeground() : getForeground(); + } + +} diff --git a/platform/util/src/com/intellij/ui/CheckBoxListListener.java b/platform/util/src/com/intellij/ui/CheckBoxListListener.java new file mode 100644 index 000000000000..80e12a2566c3 --- /dev/null +++ b/platform/util/src/com/intellij/ui/CheckBoxListListener.java @@ -0,0 +1,8 @@ +package com.intellij.ui; + +/** + * @author oleg + */ +public interface CheckBoxListListener { + void checkBoxSelectionChanged(int index, boolean value); +} diff --git a/platform/util/src/com/intellij/ui/OptionalChooserComponent.form b/platform/util/src/com/intellij/ui/OptionalChooserComponent.form new file mode 100644 index 000000000000..8bebb6b2da4d --- /dev/null +++ b/platform/util/src/com/intellij/ui/OptionalChooserComponent.form @@ -0,0 +1,28 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/platform/util/src/com/intellij/ui/OptionalChooserComponent.java b/platform/util/src/com/intellij/ui/OptionalChooserComponent.java new file mode 100644 index 000000000000..67e294ed1503 --- /dev/null +++ b/platform/util/src/com/intellij/ui/OptionalChooserComponent.java @@ -0,0 +1,69 @@ +package com.intellij.ui; + +import com.intellij.openapi.util.Pair; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author oleg + * This component represents a list of checkboxes. + */ +public abstract class OptionalChooserComponent implements CheckBoxListListener { + private JPanel myContentPane; + private CheckBoxList myList; + private DefaultListModel myListModel; + private List> myInitialList; + private ArrayList> myWorkingList; + + public OptionalChooserComponent(@NotNull final List> list) { + myInitialList = list; + myWorkingList = new ArrayList>(myInitialList); + + // fill list + reset(); + } + + public JPanel getContentPane() { + return myContentPane; + } + + public void checkBoxSelectionChanged(int index, boolean value) { + final Pair pair = myWorkingList.remove(index); + myWorkingList.add(index, Pair.create(pair.first, value)); + } + + private void createUIComponents() { + myListModel = new DefaultListModel(); + myList = new CheckBoxList(myListModel, this); + } + + public void reset() { + myWorkingList = new ArrayList>(myInitialList); + update(); + } + + public abstract JCheckBox createCheckBox(final String path, final boolean checked); + + public boolean isModified() { + return !myWorkingList.equals(myInitialList); + } + + public ArrayList> getValue() { + return myWorkingList; + } + + public void apply() { + myInitialList.clear(); + myInitialList.addAll(myWorkingList); + } + + public void update() { + myListModel.clear(); + for (Pair pair : myWorkingList) { + myListModel.addElement(createCheckBox(pair.first, pair.second)); + } + } +} diff --git a/platform/util/src/com/intellij/ui/PathsChooserComponent.form b/platform/util/src/com/intellij/ui/PathsChooserComponent.form new file mode 100644 index 000000000000..24a5f47f4b65 --- /dev/null +++ b/platform/util/src/com/intellij/ui/PathsChooserComponent.form @@ -0,0 +1,49 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/platform/util/src/com/intellij/ui/PathsChooserComponent.java b/platform/util/src/com/intellij/ui/PathsChooserComponent.java new file mode 100644 index 000000000000..d74b34e3c035 --- /dev/null +++ b/platform/util/src/com/intellij/ui/PathsChooserComponent.java @@ -0,0 +1,101 @@ +package com.intellij.ui; + +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; +import com.intellij.openapi.fileChooser.FileChooserDialog; +import com.intellij.openapi.fileChooser.FileChooserFactory; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; + +/** + * @author oleg + * This component is used to configure list of folders with add/remove buttons. + */ +public class PathsChooserComponent { + private JPanel myContentPane; + private JList myList; + private JButton myAddButton; + private JButton myRemoveButton; + private DefaultListModel myListModel; + + private List myWorkingCollection; + private List myInitialCollection; + + public PathsChooserComponent(@NotNull final List collection, @NotNull final PathProcessor processor) { + myInitialCollection = collection; + myWorkingCollection = new ArrayList(myInitialCollection); + myListModel = new DefaultListModel(); + myList.setModel(myListModel); + + // fill list + reset(); + + // listeners + myAddButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + final FileChooserDescriptor dirChooser = FileChooserDescriptorFactory.createSingleFolderDescriptor(); + dirChooser.setShowFileSystemRoots(true); + dirChooser.setHideIgnored(true); + dirChooser.setTitle(UIBundle.message("file.chooser.default.title")); + FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(dirChooser, myContentPane); + VirtualFile[] files = chooser.choose(null, null); + for (VirtualFile file : files) { + // adding to the end + final String path = file.getPath(); + if (processor.addPath(myWorkingCollection, path)){ + myListModel.addElement(path); + } + } + } + }); + + myRemoveButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int selected = myList.getSelectedIndex(); + if (selected != -1) { + // removing index + final String path = (String) myListModel.get(selected); + if (processor.removePath(myWorkingCollection, path)){ + myListModel.remove(selected); + } + } + } + }); + } + + public JPanel getContentPane() { + return myContentPane; + } + + public List getValues(){ + return myWorkingCollection; + } + + public void reset() { + myListModel.clear(); + myWorkingCollection = new ArrayList(myInitialCollection); + for (String path : myWorkingCollection) { + myListModel.addElement(path); + } + } + + public boolean isModified() { + return !myWorkingCollection.equals(myInitialCollection); + } + + public void apply() { + myInitialCollection.clear(); + myInitialCollection.addAll(myWorkingCollection); + } + + public interface PathProcessor { + boolean addPath(List paths, String path); + boolean removePath(List paths, String path); + } +} diff --git a/platform/util/util.iml b/platform/util/util.iml index 315d1bbcb801..619f920cf77c 100644 --- a/platform/util/util.iml +++ b/platform/util/util.iml @@ -16,6 +16,7 @@ + From 2fa02d1344238b1744ecde5bb364ebcf499aa858 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Mon, 26 Oct 2009 15:59:33 +0300 Subject: [PATCH 17/21] Accessing PSI requires read action. --- .../codeInsight/completion/CompletionContributor.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java index 49b203ce2c2c..5a78fb069e72 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java @@ -19,8 +19,10 @@ import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementPresentation; import com.intellij.lang.Language; import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.keymap.KeymapUtil; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.KeyedExtensionCollector; import com.intellij.openapi.util.Pair; import com.intellij.patterns.ElementPattern; @@ -213,8 +215,12 @@ public abstract class CompletionContributor extends AbstractCompletionContributo return KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(actionId)); } - public static List forParameters(CompletionParameters parameters) { - return forLanguage(PsiUtilBase.getLanguageAtOffset(parameters.getPosition().getContainingFile(), parameters.getOffset())); + public static List forParameters(final CompletionParameters parameters) { + return ApplicationManager.getApplication().runReadAction(new Computable>() { + public List compute() { + return forLanguage(PsiUtilBase.getLanguageAtOffset(parameters.getPosition().getContainingFile(), parameters.getOffset())); + } + }); } public static List forLanguage(Language language) { From e902d04d9981d263c1ee4d73b4a9105711d384f9 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Mon, 26 Oct 2009 16:03:49 +0300 Subject: [PATCH 18/21] TreeUi: insert new element for node which is to always show plus --- .../src/com/intellij/ide/util/treeView/AbstractTreeUi.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index 1197cbcdc0cc..880ba9902567 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -829,7 +829,12 @@ public class AbstractTreeUi { boolean notRequiredToUpdateChildren = !forcedNow && !wasExpanded; if (notRequiredToUpdateChildren && forceUpdate && !wasExpanded) { - notRequiredToUpdateChildren = getBuilder().isAlwaysShowPlus(descriptor); + boolean alwaysPlus = getBuilder().isAlwaysShowPlus(descriptor); + if (alwaysPlus && wasLeaf) { + notRequiredToUpdateChildren = false; + } else { + notRequiredToUpdateChildren = alwaysPlus; + } } final Ref preloaded = new Ref(loadedChildren); From 210a570e952fc1a89b3f7b0752c30f7062816935 Mon Sep 17 00:00:00 2001 From: Ekaterina Shliakhovetskaja Date: Mon, 26 Oct 2009 03:34:50 +0300 Subject: [PATCH 19/21] Spellchecker: fix suggestions for words in camel case, improve spellchecker configuration, introduce dictionary managment --- plugins/spellchecker/src/META-INF/plugin.xml | 6 +- .../spellchecker/BaseSuggestionProvider.java | 80 +++++ .../com/intellij/spellchecker/FileLoader.java | 57 +-- .../spellchecker/SpellCheckerManager.java | 62 +++- .../intellij/spellchecker/StreamLoader.java | 59 ++++ .../spellchecker/dictionary/Loader.java | 3 +- .../spellchecker/engine/BaseSpellChecker.java | 11 +- .../engine/SpellCheckerFactory.java | 12 +- .../SuggestionProvider.java} | 11 +- .../inspections/SpellCheckingInspection.java | 46 ++- .../options/SpellCheckerConfigurable.java | 102 ------ .../options/SpellCheckerOptions.form | 46 --- .../options/SpellCheckerOptions.java | 169 --------- .../DictionarySuggestionProvider.java | 49 +-- .../quickfixes/ShowSuggestions.java | 2 - .../settings/SpellCheckerSettings.java | 167 +++++++++ .../settings/SpellCheckerSettingsManager.java | 86 +++++ .../settings/SpellCheckerSettingsPane.form | 102 ++++++ .../settings/SpellCheckerSettingsPane.java | 325 ++++++++++++++++++ .../spellchecker/state/StateLoader.java | 6 +- .../spellchecker/util/SPFileUtil.java | 44 +++ .../util/SpellCheckerBundle.properties | 2 + .../inspector/SuggestionTest.java | 24 +- 23 files changed, 1031 insertions(+), 440 deletions(-) create mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/BaseSuggestionProvider.java create mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/StreamLoader.java rename plugins/spellchecker/src/com/intellij/spellchecker/{dictionary/Processor.java => engine/SuggestionProvider.java} (74%) delete mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerConfigurable.java delete mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerOptions.form delete mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerOptions.java create mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java create mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsManager.java create mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.form create mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java create mode 100644 plugins/spellchecker/src/com/intellij/spellchecker/util/SPFileUtil.java diff --git a/plugins/spellchecker/src/META-INF/plugin.xml b/plugins/spellchecker/src/META-INF/plugin.xml index e6068267a7a9..abbd2798d3fb 100644 --- a/plugins/spellchecker/src/META-INF/plugin.xml +++ b/plugins/spellchecker/src/META-INF/plugin.xml @@ -48,11 +48,11 @@ - + - + getSuggestions(@NotNull String text) { + + String[] words = NameUtil.nameToWords(text); + + int index = 0; + List[] res = new List[words.length]; + int i = 0; + for (String word : words) { + int start = text.indexOf(word, index); + int end = start + word.length(); + if (!manager.hasProblem(word)) { + List variants = new ArrayList(); + variants.add(word); + res[i++] = variants; + } + else { + List variants = manager.getRawSuggestions(word); + res[i++] = variants; + } + index = end; + } + + String[] all = null; + int[] counter = new int[i]; + int size = 1; + for (int j = 0; j < i; j++) { + size *= res[j].size(); + } + all = new String[size]; + + for (int k = 0; k < size; k++) { + for (int j = 0; j < i; j++) { + if (all[k] == null) { + all[k] = ""; + } + all[k] += res[j].get(counter[j]); + counter[j]++; + if (counter[j] >= res[j].size()) { + counter[j] = 0; + } + } + } + + return Arrays.asList(all); + } +} diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/FileLoader.java b/plugins/spellchecker/src/com/intellij/spellchecker/FileLoader.java index 77c69ebd836e..2659bb5843d5 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/FileLoader.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/FileLoader.java @@ -15,42 +15,45 @@ */ package com.intellij.spellchecker; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.spellchecker.dictionary.Loader; -import com.intellij.spellchecker.dictionary.Processor; +import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; public class FileLoader implements Loader { - private String url; + private static final Logger LOG = Logger.getInstance("#com.intellij.spellchecker.FileLoader"); - public FileLoader(String url) { - this.url = url; + private String url; + + public FileLoader(String url) { + this.url = url; + } + + public void load(@NotNull Consumer consumer) { + File file = new File(url); + FileInputStream stream = null; + try { + stream = new FileInputStream(file); + StreamLoader loader = new StreamLoader(stream); + loader.load(consumer); } - - public void load(@NotNull Processor processor) { - - InputStream io = SpellCheckerManager.class.getResourceAsStream(url); - DataInputStream in = new DataInputStream(io); - BufferedReader br = new BufferedReader(new InputStreamReader(in)); - try{ - String strLine; - while ((strLine = br.readLine()) != null) { - processor.process(strLine); - } - in.close(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - br.close(); - } - catch (IOException ignored) { - - } - } + catch (Exception e) { + LOG.error(e); } + finally { + try { + stream.close(); + } + catch (IOException ignored) { + } + } + } + } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java b/plugins/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java index 56826fc02006..35d9c54368eb 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java @@ -25,8 +25,12 @@ import com.intellij.spellchecker.dictionary.Dictionary; import com.intellij.spellchecker.dictionary.Loader; import com.intellij.spellchecker.engine.SpellCheckerEngine; import com.intellij.spellchecker.engine.SpellCheckerFactory; +import com.intellij.spellchecker.engine.SuggestionProvider; +import com.intellij.spellchecker.settings.SpellCheckerSettings; import com.intellij.spellchecker.state.StateLoader; +import com.intellij.spellchecker.util.SPFileUtil; import com.intellij.spellchecker.util.Strings; +import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,13 +47,26 @@ public class SpellCheckerManager { private Dictionary userDictionary; + private final String[] bundledDictionaries = new String[]{"english.dic", "jetbrains.dic"}; + + @NotNull + private final SuggestionProvider suggestionProvider = new BaseSuggestionProvider(this); + + private final SpellCheckerSettings settings; + public static SpellCheckerManager getInstance(Project project) { return ServiceManager.getService(project, SpellCheckerManager.class); } - public SpellCheckerManager(Project project) { + public SpellCheckerManager(Project project, SpellCheckerSettings settings) { this.project = project; + this.settings = settings; reloadConfiguration(); + + } + + public Project getProject() { + return project; } public Dictionary getUserDictionary() { @@ -64,7 +81,26 @@ public class SpellCheckerManager { private void fillEngineDictionary() { spellChecker.reset(); final StateLoader stateLoader = new StateLoader(project); - Loader[] loaders = new Loader[]{new FileLoader("english.dic"), new FileLoader("jetbrains.dic"), stateLoader}; + final List loaders = new ArrayList(); + for (String dictionary : bundledDictionaries) { + if (this.settings == null || !this.settings.getBundledDisabledDictionariesPaths().contains(dictionary)) { + loaders.add(new StreamLoader(SpellCheckerManager.class.getResourceAsStream(dictionary))); + } + } + if (this.settings != null && this.settings.getDictionaryFoldersPaths() != null) { + final Set disabledDictionaries = settings.getDisabledDictionariesPaths(); + for (String folder : this.settings.getDictionaryFoldersPaths()) { + SPFileUtil.processFilesRecursively(folder, new Consumer() { + public void consume(final String s) { + if (!disabledDictionaries.contains(s)) { + loaders.add(new FileLoader(s)); + } + } + }); + + } + } + loaders.add(stateLoader); for (Loader loader : loaders) { spellChecker.loadDictionary(loader); } @@ -84,22 +120,31 @@ public class SpellCheckerManager { } } - public void updateUserWords(@Nullable Collection words) { - Set transformed = spellChecker.getTransformation().transform(words); - userDictionary.replaceAll(transformed); - fillEngineDictionary(); + public void update(@Nullable Collection words, SpellCheckerSettings allDictionaries) { + reloadConfiguration(); restartInspections(); } + @NotNull + public List getBundledDictionaries() { + return (bundledDictionaries != null ? Arrays.asList(bundledDictionaries) : Collections.emptyList()); + } + @NotNull public static HighlightDisplayLevel getHighlightDisplayLevel() { return HighlightDisplayLevel.find(SpellCheckerSeveritiesProvider.TYPO); } - @NotNull - public List getSuggestions(@NotNull String word) { + public List getSuggestions(@NotNull String text) { + return suggestionProvider.getSuggestions(text); + } + + + + @NotNull + protected List getRawSuggestions(@NotNull String word) { if (!spellChecker.isCorrect(word)) { List suggestions = spellChecker.getSuggestions(word, MAX_SUGGESTIONS_THRESHOLD, MAX_METRICS); if (suggestions.size() != 0) { @@ -144,5 +189,4 @@ public class SpellCheckerManager { } - } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/StreamLoader.java b/plugins/spellchecker/src/com/intellij/spellchecker/StreamLoader.java new file mode 100644 index 000000000000..570967259cbb --- /dev/null +++ b/plugins/spellchecker/src/com/intellij/spellchecker/StreamLoader.java @@ -0,0 +1,59 @@ +/* + * Copyright 2000-2009 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.spellchecker; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.spellchecker.dictionary.Loader; +import com.intellij.util.Consumer; +import org.jetbrains.annotations.NotNull; + +import java.io.*; + +public class StreamLoader implements Loader { + + private static final Logger LOG = Logger.getInstance("#com.intellij.spellchecker.StreamLoader"); + + private InputStream stream; + + public StreamLoader(InputStream stream) { + this.stream = stream; + } + + + public void load(@NotNull Consumer consumer) { + DataInputStream in = new DataInputStream(stream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + try { + String strLine; + while ((strLine = br.readLine()) != null) { + consumer.consume(strLine); + } + } + catch (Exception e) { + LOG.error(e); + } + finally { + try { + br.close(); + } + catch (IOException ignored) { + + } + } + } + +} + diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/dictionary/Loader.java b/plugins/spellchecker/src/com/intellij/spellchecker/dictionary/Loader.java index 7911179f55a5..e66a13933749 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/dictionary/Loader.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/dictionary/Loader.java @@ -15,10 +15,11 @@ */ package com.intellij.spellchecker.dictionary; +import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; public interface Loader { - void load(@NotNull Processor processor); + void load(@NotNull Consumer consumer); } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/engine/BaseSpellChecker.java b/plugins/spellchecker/src/com/intellij/spellchecker/engine/BaseSpellChecker.java index 205d15705dfc..5af0d0b6cc25 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/engine/BaseSpellChecker.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/engine/BaseSpellChecker.java @@ -15,8 +15,11 @@ */ package com.intellij.spellchecker.engine; -import com.intellij.spellchecker.dictionary.*; +import com.intellij.spellchecker.dictionary.Dictionary; +import com.intellij.spellchecker.dictionary.Loader; +import com.intellij.spellchecker.dictionary.UserDictionary; import com.intellij.spellchecker.trie.Action; +import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,8 +37,8 @@ public class BaseSpellChecker implements SpellCheckerEngine { private Metrics metrics = new LevenshteinDistance(); - private Processor processor = new Processor() { - public void process(@Nullable String word) { + private Consumer consumer = new Consumer() { + public void consume(@Nullable String word) { final String transformed = transform.transform(word); if (transformed != null) { engineDictionary.addToDictionary(transformed); @@ -48,7 +51,7 @@ public class BaseSpellChecker implements SpellCheckerEngine { } public void loadDictionary(@NotNull Loader loader) { - loader.load(processor); + loader.load(consumer); } public Transformation getTransformation() { diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/engine/SpellCheckerFactory.java b/plugins/spellchecker/src/com/intellij/spellchecker/engine/SpellCheckerFactory.java index c9418bba0362..aa3f9bc460b5 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/engine/SpellCheckerFactory.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/engine/SpellCheckerFactory.java @@ -16,10 +16,12 @@ package com.intellij.spellchecker.engine; public final class SpellCheckerFactory { - private SpellCheckerFactory() { - } + private SpellCheckerFactory() { + } - public static SpellCheckerEngine create() { - return new BaseSpellChecker(); - } + public static SpellCheckerEngine create() { + return new BaseSpellChecker(); + } + + } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/dictionary/Processor.java b/plugins/spellchecker/src/com/intellij/spellchecker/engine/SuggestionProvider.java similarity index 74% rename from plugins/spellchecker/src/com/intellij/spellchecker/dictionary/Processor.java rename to plugins/spellchecker/src/com/intellij/spellchecker/engine/SuggestionProvider.java index 2960da80200f..f26ba1ebd9b2 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/dictionary/Processor.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/engine/SuggestionProvider.java @@ -13,11 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.spellchecker.dictionary; +package com.intellij.spellchecker.engine; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; -public interface Processor { +import java.util.List; - void process(@Nullable String word); +public interface SuggestionProvider { + + @NotNull + List getSuggestions(@NotNull String text); } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java index 07459ca9cc14..ee08f5596d10 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/inspections/SpellCheckingInspection.java @@ -49,6 +49,9 @@ import java.util.Map; public class SpellCheckingInspection extends LocalInspectionTool { + + public static final String SPELL_CHECKING_INSPECTION_TOOL_NAME = "SpellCheckingInspection"; + @Nls @NotNull public String getGroupDisplayName() { @@ -64,7 +67,7 @@ public class SpellCheckingInspection extends LocalInspectionTool { @NonNls @NotNull public String getShortName() { - return "SpellCheckingInspection"; + return SPELL_CHECKING_INSPECTION_TOOL_NAME; } public boolean isEnabledByDefault() { @@ -79,19 +82,19 @@ public class SpellCheckingInspection extends LocalInspectionTool { private static final Map factories = new HashMap(); private static void ensureFactoriesAreLoaded() { - synchronized (factories) { - if (!factories.isEmpty()) return; - final SpellcheckingStrategy[] spellcheckingStrategies = Extensions.getExtensions(SpellcheckingStrategy.EP_NAME); - if (spellcheckingStrategies != null) { - for (SpellcheckingStrategy spellcheckingStrategy : spellcheckingStrategies) { - final Language language = spellcheckingStrategy.getLanguage(); - if (language != Language.ANY) { - factories.put(language, spellcheckingStrategy); - } + synchronized (factories) { + if (!factories.isEmpty()) return; + final SpellcheckingStrategy[] spellcheckingStrategies = Extensions.getExtensions(SpellcheckingStrategy.EP_NAME); + if (spellcheckingStrategies != null) { + for (SpellcheckingStrategy spellcheckingStrategy : spellcheckingStrategies) { + final Language language = spellcheckingStrategy.getLanguage(); + if (language != Language.ANY) { + factories.put(language, spellcheckingStrategy); } } } } + } private static SpellcheckingStrategy getFactoryByLanguage(@NotNull Language lang) { @@ -106,7 +109,7 @@ public class SpellCheckingInspection extends LocalInspectionTool { public void visitElement(final PsiElement element) { final ASTNode node = element.getNode(); - if (node == null){ + if (node == null) { return; } // Extract parser definition from element @@ -115,17 +118,18 @@ public class SpellCheckingInspection extends LocalInspectionTool { final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language); // Handle selected options - if (parserDefinition != null){ + if (parserDefinition != null) { if (parserDefinition.getStringLiteralElements().contains(elementType)) { - if (!processLiterals){ + if (!processLiterals) { return; } } else if (parserDefinition.getCommentTokens().contains(elementType)) { - if (!processComments){ + if (!processComments) { return; } - } else if (!processCode){ + } + else if (!processCode) { return; } } @@ -246,6 +250,18 @@ public class SpellCheckingInspection extends LocalInspectionTool { verticalBox.add(new SingleCheckboxOptionsPanel(SpellCheckerBundle.message("process.code"), this, "processCode")); verticalBox.add(new SingleCheckboxOptionsPanel(SpellCheckerBundle.message("process.literals"), this, "processLiterals")); verticalBox.add(new SingleCheckboxOptionsPanel(SpellCheckerBundle.message("process.comments"), this, "processComments")); + /*HyperlinkLabel linkToSettings = new HyperlinkLabel(SpellCheckerBundle.message("link.to.settings")); + linkToSettings.addHyperlinkListener(new HyperlinkListener() { + public void hyperlinkUpdate(final HyperlinkEvent e) { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(DataManager.getInstance().getDataContext()); + // ??project? + + } + } + }); + + verticalBox.add(linkToSettings);*/ final JPanel panel = new JPanel(new BorderLayout()); panel.add(verticalBox, BorderLayout.NORTH); return panel; diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerConfigurable.java b/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerConfigurable.java deleted file mode 100644 index 27f5f8624d53..000000000000 --- a/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerConfigurable.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2000-2009 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.spellchecker.options; - -import com.intellij.openapi.options.Configurable; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.project.Project; -import com.intellij.spellchecker.SpellCheckerManager; -import com.intellij.spellchecker.util.SpellCheckerBundle; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.List; -import java.util.Set; - - -public final class SpellCheckerConfigurable implements Configurable { - private SpellCheckerOptions options; - private SpellCheckerManager manager; - private final Project myProject; - - - public SpellCheckerConfigurable(Project project) { - myProject = project; - } - - @Nls - public String getDisplayName() { - return SpellCheckerBundle.message("spelling"); - } - - @Nullable - public Icon getIcon() { - return null; - } - - @Nullable - @NonNls - public String getHelpTopic() { - return "reference.settings.ide.settings.spelling"; - } - - public JComponent createComponent() { - manager = SpellCheckerManager.getInstance(myProject); - if (options == null) { - options = new SpellCheckerOptions(manager); - } - return options.getRoot(); - } - - public boolean isModified() { - if (options != null) { - return wordsListIsModified(); - } - return false; - } - - - private boolean wordsListIsModified() { - assert options != null; - List newWords = options.getWords(); - Set words = manager.getUserDictionary().getEditableWords(); - if (words == null && newWords == null) { - return false; - } - if (words == null || newWords == null || newWords.size() != words.size()) { - return true; - } - return !(words.containsAll(newWords) && newWords.containsAll(words)); - } - - - public void apply() throws ConfigurationException { - manager.updateUserWords(options.getWords()); - } - - - public void reset() { - } - - public void disposeUIResources() { - if (options != null) { - options.dispose(); - options = null; - } - } -} diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerOptions.form b/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerOptions.form deleted file mode 100644 index c08916ddf759..000000000000 --- a/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerOptions.form +++ /dev/null @@ -1,46 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerOptions.java b/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerOptions.java deleted file mode 100644 index 9654d9374c08..000000000000 --- a/plugins/spellchecker/src/com/intellij/spellchecker/options/SpellCheckerOptions.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2000-2009 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.spellchecker.options; - - -import com.intellij.openapi.Disposable; -import com.intellij.openapi.ui.Messages; -import com.intellij.spellchecker.SpellCheckerManager; -import com.intellij.spellchecker.dictionary.Dictionary; -import com.intellij.spellchecker.util.SpellCheckerBundle; -import com.intellij.spellchecker.util.Strings; -import com.intellij.ui.AddDeleteListPanel; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - - -public class SpellCheckerOptions implements Disposable { - - private final SpellCheckerManager manager; - private JPanel root; - private JPanel wordPanelHolder; - private WordsPanel wordsPanel; - - - - public SpellCheckerOptions(SpellCheckerManager manager) { - this.manager = manager; - } - - public void createUIComponents() { - wordsPanel = new WordsPanel(manager); - - } - - public JPanel getRoot() { - return root; - } - - @Nullable - public List getWords(){ - Object[] pairs = wordsPanel.getListItems(); - if (pairs==null){ - return null; - } - List words = new ArrayList(); - for (Object pair : pairs) { - words.add(pair.toString()); - } - return words; - } - - public void dispose() { - - wordsPanel.dispose(); - } - - - public static final class WordDescriber { - private Dictionary dictionary; - - public WordDescriber(Dictionary dictionary) { - this.dictionary = dictionary; - } - - @NotNull - public List process() { - if (this.dictionary == null) { - return new ArrayList(); - } - Set words = this.dictionary.getEditableWords(); - if (words == null) { - return new ArrayList(); - } - List result = new ArrayList(); - for (String word : words) { - result.add(new Pair(word, "")); - } - Collections.sort(result); - return result; - } - } - - public static final class Pair implements Comparable { - private String word; - private String description; - - public Pair(@NotNull String word, String description) { - this.word = word; - this.description = description; - } - - public String getWord() { - return word; - } - - public String getDescription() { - return description; - } - - public int compareTo(Object o) { - if (!(o instanceof Pair)) { - throw new IllegalArgumentException(); - } - return word.compareTo(((Pair)o).getWord()); - } - - @Override - public String toString() { - return word + (description!=null && description.trim().length()>0?"("+description+")":""); - } - } - - private static final class WordsPanel extends AddDeleteListPanel implements Disposable { - private SpellCheckerManager manager; - - private WordsPanel(SpellCheckerManager manager) { - super(null, new WordDescriber(manager.getUserDictionary()).process()); - this.manager = manager; - } - - - protected Object findItemToAdd() { - String word = Messages.showInputDialog(com.intellij.spellchecker.util.SpellCheckerBundle.message("enter.simple.word"), - SpellCheckerBundle.message("add.new.word"), null); - if (word == null) { - return null; - } - else { - word = word.trim(); - } - - if (Strings.isMixedCase(word)) { - Messages.showWarningDialog(SpellCheckerBundle.message("entered.word.0.is.mixed.cased.you.must.enter.simple.word", word), - SpellCheckerBundle.message("add.new.word")); - return null; - } - if (!manager.hasProblem(word)) { - Messages.showWarningDialog(SpellCheckerBundle.message("entered.word.0.is.correct.you.no.need.to.add.this.in.list", word), - SpellCheckerBundle.message("add.new.word")); - return null; - } - return word; - } - - - public void dispose() { - myListModel.removeAllElements(); - } - } -} diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/DictionarySuggestionProvider.java b/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/DictionarySuggestionProvider.java index 2e9ea068cae2..eff9744b151e 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/DictionarySuggestionProvider.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/DictionarySuggestionProvider.java @@ -18,12 +18,14 @@ package com.intellij.spellchecker.quickfixes; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNamedElement; -import com.intellij.psi.codeStyle.NameUtil; import com.intellij.psi.codeStyle.SuggestedNameInfo; import com.intellij.refactoring.rename.NameSuggestionProvider; import com.intellij.spellchecker.SpellCheckerManager; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; public class DictionarySuggestionProvider implements NameSuggestionProvider { @@ -49,49 +51,8 @@ public class DictionarySuggestionProvider implements NameSuggestionProvider { SpellCheckerManager manager = SpellCheckerManager.getInstance(element.getProject()); - String[] words = NameUtil.nameToWords(text); - - int index = 0; - List[] res = new List[words.length]; - int i = 0; - for (String word : words) { - int start = text.indexOf(word, index); - int end = start + word.length(); - if (!manager.hasProblem(word)) { - List variants = new ArrayList(); - variants.add(word); - res[i++] = variants; - } - else { - List variants = manager.getSuggestions(word); - res[i++] = variants; - } - index = end; - } - - String[] all = null; - int counter[] = new int[i]; - int size = 1; - for (int j = 0; j < i; j++) { - size *= res[j].size(); - } - all = new String[size]; - - for (int k = 0; k < size; k++) { - for (int j = 0; j < i; j++) { - if (all[k] == null) { - all[k] = ""; - } - all[k] += res[j].get(counter[j]); - counter[j]++; - if (counter[j] >= res[j].size()) { - counter[j] = 0; - } - } - } - Set set = new TreeSet(); - set.addAll(Arrays.asList(all)); + set.addAll(manager.getSuggestions(text)); result.addAll(set); return null; } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/ShowSuggestions.java b/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/ShowSuggestions.java index 8c9fe5f5ceb8..95ec166bf7cf 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/ShowSuggestions.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/quickfixes/ShowSuggestions.java @@ -35,8 +35,6 @@ public abstract class ShowSuggestions implements LocalQuickFix, Iconable { private boolean processed; - - public ShowSuggestions(@NotNull TextRange textRange, @NotNull String word, @NotNull Project project) { this.textRange = textRange; this.word = word; diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java new file mode 100644 index 000000000000..9217bbae7d75 --- /dev/null +++ b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettings.java @@ -0,0 +1,167 @@ +/* + * Copyright 2000-2009 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.spellchecker.settings; + +import com.intellij.openapi.components.*; +import com.intellij.openapi.project.Project; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +@State( + name = "SpellCheckerSettings", + storages = {@Storage( + id = "other", + file = "$PROJECT_FILE$"), + @Storage( + id = "dir", + file = "$PROJECT_CONFIG_DIR$/spellchecker-settings.xml", + scheme = StorageScheme.DIRECTORY_BASED)}) +public class SpellCheckerSettings implements PersistentStateComponent { + // For xml serialization + private static final String SPELLCHECKER_MANAGER_SETTINGS_TAG = "SpellCheckerSettings"; + + private static final String FOLDERS_ATTR_NAME = "Folders"; + private static final String FOLDER_ATTR_NAME = "Folder"; + private static final String DICTIONARIES_ATTR_NAME = "Dictionaries"; + private static final String DICTIONARY_ATTR_NAME = "Dictionary"; + + private static final String BUNDLED_DICTIONARIES_ATTR_NAME = "BundledDictionaries"; + private static final String BUNDLED_DICTIONARY_ATTR_NAME = "BundledDictionary"; + + // Paths + private List myDictionaryFoldersPaths = new ArrayList(); + private Set myDisabledDictionariesPaths = new HashSet(); + + private Set myBundledDisabledDictionariesPaths = new HashSet(); + + public static SpellCheckerSettings getInstance(Project project){ + return ServiceManager.getService(project,SpellCheckerSettings.class); + } + + + public List getDictionaryFoldersPaths() { + return myDictionaryFoldersPaths; + } + + public void setDictionaryFoldersPaths(List dictionaryFoldersPaths) { + myDictionaryFoldersPaths = dictionaryFoldersPaths; + } + + public Set getDisabledDictionariesPaths() { + return myDisabledDictionariesPaths; + } + + + public Set getEnabledDictionariesPaths() { + final HashSet enabledDictionaries = new HashSet(); + for (String folder : myDictionaryFoldersPaths) { + /*RFileUtil.processFilesRecursively(folder, new Consumer() { + public void consume(final String s) { + if (!myDisabledDictionariesPaths.contains(s)){ + enabledDictionaries.add(s); + } + } + });*/ + } + return enabledDictionaries; + } + + public Set getBundledEnabledDictionariesPaths() { + final HashSet bundledEnabledDictionaries = new HashSet(); + final List builtInFolders = getBundledDictionariesFoldersPaths(); + for (String folder : builtInFolders) { + /*RFileUtil.processFilesRecursively(folder, new Consumer() { + public void consume(final String s) { + if (!myBundledDisabledDictionariesPaths.contains(s)){ + bundledEnabledDictionaries.add(s); + } + } + });*/ + } + return bundledEnabledDictionaries; + } + + public void setDisabledDictionariesPaths(Set disabledDictionariesPaths) { + myDisabledDictionariesPaths = disabledDictionariesPaths; + } + + public List getBundledDictionariesFoldersPaths() { + /*return Collections.unmodifiableList(RubySupportLoader.getBuiltinScriptFolders());*/ + return Collections.emptyList(); + } + + public Set getBundledDisabledDictionariesPaths() { + return myBundledDisabledDictionariesPaths; + } + + public void setBundledDisabledDictionariesPaths(Set bundledDisabledDictionariesPaths) { + myBundledDisabledDictionariesPaths = bundledDisabledDictionariesPaths; + } + + public Element getState() { + final Element element = new Element(SPELLCHECKER_MANAGER_SETTINGS_TAG); + // bundled + element.setAttribute(BUNDLED_DICTIONARIES_ATTR_NAME, String.valueOf(myBundledDisabledDictionariesPaths.size())); + Iterator iterator = myBundledDisabledDictionariesPaths.iterator(); + int i=0; + while (iterator.hasNext()){ + element.setAttribute(BUNDLED_DICTIONARY_ATTR_NAME + i, iterator.next()); + i++; + } + // user + element.setAttribute(FOLDERS_ATTR_NAME, String.valueOf(myDictionaryFoldersPaths.size())); + for (int j=0;j< myDictionaryFoldersPaths.size();j++){ + element.setAttribute(FOLDER_ATTR_NAME + j, myDictionaryFoldersPaths.get(j)); + } + element.setAttribute(DICTIONARIES_ATTR_NAME, String.valueOf(myDisabledDictionariesPaths.size())); + iterator = myDisabledDictionariesPaths.iterator(); + i=0; + while (iterator.hasNext()){ + element.setAttribute(DICTIONARY_ATTR_NAME + i, iterator.next()); + i++; + } + + return element; + } + + + public void loadState(@NotNull final Element element) { + myBundledDisabledDictionariesPaths.clear(); + myDictionaryFoldersPaths.clear(); + myDisabledDictionariesPaths.clear(); + try { + // bundled + final int bundledDictionariesSize = Integer.valueOf(element.getAttributeValue(BUNDLED_DICTIONARIES_ATTR_NAME)); + for (int i=0;i +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java new file mode 100644 index 000000000000..b5d242500e2d --- /dev/null +++ b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java @@ -0,0 +1,325 @@ +/* + * Copyright 2000-2009 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.spellchecker.settings; + +import com.intellij.ide.DataManager; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.options.ConfigurationException; +import com.intellij.openapi.options.newEditor.OptionsEditor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.profile.codeInspection.ui.ProjectInspectionToolsConfigurable; +import com.intellij.spellchecker.SpellCheckerManager; +import com.intellij.spellchecker.dictionary.Dictionary; +import com.intellij.spellchecker.util.SPFileUtil; +import com.intellij.spellchecker.util.SpellCheckerBundle; +import com.intellij.spellchecker.util.Strings; +import com.intellij.ui.AddDeleteListPanel; +import com.intellij.ui.HyperlinkLabel; +import com.intellij.util.Consumer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.ruby.RBundle; +import org.jetbrains.plugins.ruby.support.OptionalChooserComponent; +import org.jetbrains.plugins.ruby.support.PathsChooserComponent; + +import javax.swing.*; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import java.awt.*; +import java.util.*; +import java.util.List; + +public class SpellCheckerSettingsPane implements Disposable { + private JPanel root; + private JPanel general; + private JPanel linkContainer; + private JPanel panelForDictionaryChooser; + private JPanel panelForAcceptedWords; + private JPanel panelForFolderChooser; + private OptionalChooserComponent optionalChooserComponent; + private PathsChooserComponent pathsChooserComponent; + private final List> allDictionaries = new ArrayList>(); + private final List dictionariesFolders = new ArrayList(); + private final WordsPanel wordsPanel; + private final SpellCheckerManager manager; + private final SpellCheckerSettings settings; + + public SpellCheckerSettingsPane(SpellCheckerSettings settings, final Project project) { + this.settings = settings; + manager = SpellCheckerManager.getInstance(project); + HyperlinkLabel link = new HyperlinkLabel(SpellCheckerBundle.message("link.to.inspection.settings")); + link.addHyperlinkListener(new HyperlinkListener() { + public void hyperlinkUpdate(final HyperlinkEvent e) { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(DataManager.getInstance().getDataContext()); + final ProjectInspectionToolsConfigurable toolsConfigurable = ProjectInspectionToolsConfigurable.getInstance(project); + if (optionsEditor != null && toolsConfigurable != null) { + optionsEditor.select(toolsConfigurable).doWhenDone(new Runnable() { + public void run() { + toolsConfigurable.selectInspectionTool("SpellCheckingInspection"); + } + }); + + } + + } + } + }); + linkContainer.setLayout(new BorderLayout()); + linkContainer.add(link); + + // Fill in all the dictionaries folders (not implemented yet) and enabled dictionaries + fillAllDictionaries(); + + + pathsChooserComponent = new PathsChooserComponent(dictionariesFolders, new PathsChooserComponent.PathProcessor() { + public boolean addPath(List paths, String path) { + if (paths.contains(path)) { + final String title = RBundle.message("module.settings.add.directory.title"); + final String msg = RBundle.message("module.settings.directory.is.already.included"); + Messages.showErrorDialog(root, msg, title); + return false; + } + paths.add(path); + + final ArrayList> currentDictionaries = optionalChooserComponent.getValue(); + SPFileUtil.processFilesRecursively(path, new Consumer() { + public void consume(final String s) { + currentDictionaries.add(Pair.create(s, true)); + } + }); + optionalChooserComponent.update(); + return true; + } + + public boolean removePath(List paths, String path) { + if (paths.remove(path)) { + final ArrayList> result = new ArrayList>(); + final ArrayList> currentDictionaries = optionalChooserComponent.getValue(); + for (Pair pair : currentDictionaries) { + if (!pair.first.startsWith(path)) { + result.add(pair); + } + } + currentDictionaries.clear(); + currentDictionaries.addAll(result); + optionalChooserComponent.update(); + return true; + } + return false; + } + }); + panelForFolderChooser.setLayout(new BorderLayout()); + panelForFolderChooser.add(pathsChooserComponent.getContentPane(), BorderLayout.CENTER); + + + optionalChooserComponent = new OptionalChooserComponent(allDictionaries) { + @Override + public JCheckBox createCheckBox(String path, boolean checked) { + if (isUserDictionary(path)) { + path = FileUtil.toSystemIndependentName(path); + final int i = path.lastIndexOf('/'); + if (i != -1) { + final String name = path.substring(i + 1); + return new JCheckBox("[user] " + name, checked); + } + } + return new JCheckBox("[bundled] " + FileUtil.toSystemDependentName(path), checked); + } + }; + + panelForDictionaryChooser.setLayout(new BorderLayout()); + panelForDictionaryChooser.add(optionalChooserComponent.getContentPane(), BorderLayout.CENTER); + + + wordsPanel = new WordsPanel(manager); + panelForAcceptedWords.setLayout(new BorderLayout()); + panelForAcceptedWords.add(wordsPanel, BorderLayout.CENTER); + + } + + public JComponent getPane() { + return root; + } + + public boolean isModified() { + return wordsPanel.isModified() || optionalChooserComponent.isModified(); + } + + public void apply() throws ConfigurationException { + optionalChooserComponent.apply(); + pathsChooserComponent.apply(); + settings.setDictionaryFoldersPaths(pathsChooserComponent.getValues()); + + final HashSet disabledDictionaries = new HashSet(); + final HashSet bundledDisabledDictionaries = new HashSet(); + for (Pair pair : allDictionaries) { + if (!pair.second) { + final String scriptPath = pair.first; + if (isUserDictionary(scriptPath)) { + disabledDictionaries.add(scriptPath); + } + else { + bundledDisabledDictionaries.add(scriptPath); + } + } + + } + settings.setDisabledDictionariesPaths(disabledDictionaries); + settings.setBundledDisabledDictionariesPaths(bundledDisabledDictionaries); + + manager.update(wordsPanel.getWords(), settings); + } + + private boolean isUserDictionary(final String dictionary) { + boolean isUserDictionary = false; + for (String dictionaryFolder : pathsChooserComponent.getValues()) { + if (dictionary.startsWith(dictionaryFolder)) { + isUserDictionary = true; + break; + } + } + return isUserDictionary; + + } + + public void reset() { + pathsChooserComponent.reset(); + fillAllDictionaries(); + optionalChooserComponent.reset(); + } + + + private void fillAllDictionaries() { + dictionariesFolders.clear(); + dictionariesFolders.addAll(settings.getDictionaryFoldersPaths()); + allDictionaries.clear(); + for (String dictionary : manager.getBundledDictionaries()) { + allDictionaries.add(new Pair(dictionary, !settings.getBundledDisabledDictionariesPaths().contains(dictionary))); + } + + // user + //todo [shkate]: refactoring - SpellCheckerManager contains the same code withing reloadConfiguration() + final Set disabledDictionaries = settings.getDisabledDictionariesPaths(); + for (String folder : dictionariesFolders) { + SPFileUtil.processFilesRecursively(folder, new Consumer() { + public void consume(final String s) { + allDictionaries.add(Pair.create(s, !disabledDictionaries.contains(s))); + } + }); + } + } + + + public void dispose() { + if (wordsPanel != null) { + wordsPanel.dispose(); + } + } + + public static final class WordDescriber { + private Dictionary dictionary; + + public WordDescriber(Dictionary dictionary) { + this.dictionary = dictionary; + } + + @NotNull + public List process() { + if (this.dictionary == null) { + return new ArrayList(); + } + Set words = this.dictionary.getEditableWords(); + if (words == null) { + return new ArrayList(); + } + List result = new ArrayList(); + for (String word : words) { + result.add(word); + } + Collections.sort(result); + return result; + } + } + + private static final class WordsPanel extends AddDeleteListPanel implements Disposable { + private SpellCheckerManager manager; + + private WordsPanel(SpellCheckerManager manager) { + super(null, new WordDescriber(manager.getUserDictionary()).process()); + this.manager = manager; + } + + + protected Object findItemToAdd() { + String word = Messages.showInputDialog(com.intellij.spellchecker.util.SpellCheckerBundle.message("enter.simple.word"), + SpellCheckerBundle.message("add.new.word"), null); + if (word == null) { + return null; + } + else { + word = word.trim(); + } + + if (Strings.isMixedCase(word)) { + Messages.showWarningDialog(SpellCheckerBundle.message("entered.word.0.is.mixed.cased.you.must.enter.simple.word", word), + SpellCheckerBundle.message("add.new.word")); + return null; + } + if (!manager.hasProblem(word)) { + Messages.showWarningDialog(SpellCheckerBundle.message("entered.word.0.is.correct.you.no.need.to.add.this.in.list", word), + SpellCheckerBundle.message("add.new.word")); + return null; + } + return word; + } + + + public void dispose() { + myListModel.removeAllElements(); + } + + @Nullable + public List getWords() { + Object[] pairs = getListItems(); + if (pairs == null) { + return null; + } + List words = new ArrayList(); + for (Object pair : pairs) { + words.add(pair.toString()); + } + return words; + } + + public boolean isModified() { + List newWords = getWords(); + Set words = manager.getUserDictionary().getEditableWords(); + if (words == null && newWords == null) { + return false; + } + if (words == null || newWords == null || newWords.size() != words.size()) { + return true; + } + return !(words.containsAll(newWords) && newWords.containsAll(words)); + } + } + + +} diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/state/StateLoader.java b/plugins/spellchecker/src/com/intellij/spellchecker/state/StateLoader.java index c48e1d56b94d..86d163adc407 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/state/StateLoader.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/state/StateLoader.java @@ -19,7 +19,7 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.spellchecker.dictionary.Dictionary; import com.intellij.spellchecker.dictionary.Loader; -import com.intellij.spellchecker.dictionary.Processor; +import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -35,7 +35,7 @@ public class StateLoader implements Loader { } - public void load(@NotNull Processor processor) { + public void load(@NotNull Consumer consumer) { AggregatedDictionaryState state = ServiceManager.getService(project, AggregatedDictionaryState.class); state.setProject(project); state.loadState(); @@ -43,7 +43,7 @@ public class StateLoader implements Loader { final Set storedWords = dictionary.getWords(); if (storedWords!=null){ for (String word : storedWords) { - processor.process(word); + consumer.consume(word); } } } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/util/SPFileUtil.java b/plugins/spellchecker/src/com/intellij/spellchecker/util/SPFileUtil.java new file mode 100644 index 000000000000..1de914758a76 --- /dev/null +++ b/plugins/spellchecker/src/com/intellij/spellchecker/util/SPFileUtil.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2009 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.spellchecker.util; + +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.Consumer; +import com.intellij.util.Processor; + +import java.io.File; + + +@SuppressWarnings({"UtilityClassWithoutPrivateConstructor"}) +public class SPFileUtil { + + public static void processFilesRecursively(final String rootPath, final Consumer consumer){ + final File rootFile = new File(rootPath); + if (rootFile.exists() && rootFile.isDirectory()){ + FileUtil.processFilesRecursively(rootFile, new Processor() { + public boolean process(final File file) { + if (!file.isDirectory()){ + final String path = file.getPath(); + if (path.endsWith(".dic")){ + consumer.consume(path); + } + } + return true; + } + }); + } + } +} diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/util/SpellCheckerBundle.properties b/plugins/spellchecker/src/com/intellij/spellchecker/util/SpellCheckerBundle.properties index b97ba87c082b..f36b582f4611 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/util/SpellCheckerBundle.properties +++ b/plugins/spellchecker/src/com/intellij/spellchecker/util/SpellCheckerBundle.properties @@ -25,3 +25,5 @@ no.suggestions= process.code=Process code process.literals=Process literals process.comments=Process comments +link.to.settings=Manage Dictionaries +link.to.inspection.settings=Manage spelling inspection settings diff --git a/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspector/SuggestionTest.java b/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspector/SuggestionTest.java index 43382ae171e5..f873498647c5 100644 --- a/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspector/SuggestionTest.java +++ b/plugins/spellchecker/testSrc/com/intellij/spellchecker/inspector/SuggestionTest.java @@ -23,19 +23,31 @@ import java.util.List; public class SuggestionTest extends JavaCodeInsightFixtureTestCase { + private SpellCheckerManager spManager; + private SpellCheckerManager getManager(){ + if (spManager==null){ + spManager = SpellCheckerManager.getInstance(getProject()); + } + assert spManager!=null; + return spManager; + } + public void testSuggestions(){ - SpellCheckerManager manager = SpellCheckerManager.getInstance(getProject()); - assert manager!=null; - List result = manager.getSuggestions("upgade"); - assertEquals(result.get(0),"upgrade"); + List result = getManager().getSuggestions("upgade"); + assertEquals("upgrade",result.get(0)); } public void testFirstLetterUppercaseSuggestions(){ + List result = getManager().getSuggestions("Upgade"); + assertEquals("Upgrade",result.get(0)); + } + + public void testCamelCaseSuggestions(){ SpellCheckerManager manager = SpellCheckerManager.getInstance(getProject()); assert manager!=null; - List result = manager.getSuggestions("Upgade"); - assertEquals(result.get(0),"Upgrade"); + List result = manager.getSuggestions("TestUpgade"); + assertEquals("TestUpgrade",result.get(0)); } } From 741b18cde432cf47b6c1b21b4bcf4ce0939473f1 Mon Sep 17 00:00:00 2001 From: Ekaterina Shliakhovetskaja Date: Mon, 26 Oct 2009 15:46:35 +0300 Subject: [PATCH 20/21] Spellchecker: update spellchecker configuration --- .../src/com/intellij/spellchecker/jetbrains.dic | 3 ++- .../settings/SpellCheckerSettingsPane.form | 4 ++-- .../settings/SpellCheckerSettingsPane.java | 10 ++++------ .../spellchecker/util/SpellCheckerBundle.properties | 3 +++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic index deaa1a8d415a..48ae7396e2d8 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic +++ b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic @@ -91,6 +91,7 @@ dirs fileset filesets javadoc - +spellchecker +spellchecking diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.form b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.form index 8a75dac5763e..6bad93a2b19e 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.form +++ b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.form @@ -8,7 +8,7 @@ - + @@ -79,7 +79,7 @@ - + diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java index b5d242500e2d..379e6eb17b16 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java +++ b/plugins/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java @@ -31,12 +31,11 @@ import com.intellij.spellchecker.util.SpellCheckerBundle; import com.intellij.spellchecker.util.Strings; import com.intellij.ui.AddDeleteListPanel; import com.intellij.ui.HyperlinkLabel; +import com.intellij.ui.OptionalChooserComponent; +import com.intellij.ui.PathsChooserComponent; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.ruby.RBundle; -import org.jetbrains.plugins.ruby.support.OptionalChooserComponent; -import org.jetbrains.plugins.ruby.support.PathsChooserComponent; import javax.swing.*; import javax.swing.event.HyperlinkEvent; @@ -47,7 +46,6 @@ import java.util.List; public class SpellCheckerSettingsPane implements Disposable { private JPanel root; - private JPanel general; private JPanel linkContainer; private JPanel panelForDictionaryChooser; private JPanel panelForAcceptedWords; @@ -91,8 +89,8 @@ public class SpellCheckerSettingsPane implements Disposable { pathsChooserComponent = new PathsChooserComponent(dictionariesFolders, new PathsChooserComponent.PathProcessor() { public boolean addPath(List paths, String path) { if (paths.contains(path)) { - final String title = RBundle.message("module.settings.add.directory.title"); - final String msg = RBundle.message("module.settings.directory.is.already.included"); + final String title = SpellCheckerBundle.message("add.directory.title"); + final String msg = SpellCheckerBundle.message("directory.is.already.included"); Messages.showErrorDialog(root, msg, title); return false; } diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/util/SpellCheckerBundle.properties b/plugins/spellchecker/src/com/intellij/spellchecker/util/SpellCheckerBundle.properties index f36b582f4611..78e0129a5e28 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/util/SpellCheckerBundle.properties +++ b/plugins/spellchecker/src/com/intellij/spellchecker/util/SpellCheckerBundle.properties @@ -27,3 +27,6 @@ process.literals=Process literals process.comments=Process comments link.to.settings=Manage Dictionaries link.to.inspection.settings=Manage spelling inspection settings +exact.rename.to=Typo: Rename to ''{0}'' +add.directory.title=User Dictionary Path +directory.is.already.included=Directory is already included From f7f6c9d7d6d6a31b7fceb830eb83b75f6690f68d Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Mon, 26 Oct 2009 16:51:17 +0300 Subject: [PATCH 21/21] remove storage verbouse logging [STORAGE], etc --- .../components/impl/stores/ModuleStoreImpl.java | 1 - .../impl/stores/ComponentStoreImpl.java | 1 - .../components/impl/stores/FileBasedStorage.java | 1 - .../components/impl/stores/ProjectStoreImpl.java | 4 ---- .../openapi/project/impl/ProjectManagerImpl.java | 16 ---------------- 5 files changed, 23 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java index f7f2c3c6df04..690277d4c018 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java @@ -266,7 +266,6 @@ public class ModuleStoreImpl extends BaseFileConfigurableStoreImpl implements IM @Override public void reinitComponents(Set componentNames, boolean reloadData) { - LOG.info("[STORAGE] Module: " + myModule.getName()); super.reinitComponents(componentNames, reloadData); } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java index d09a5fd60e26..4b00cfe4bf0a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java @@ -497,7 +497,6 @@ abstract class ComponentStoreImpl implements IComponentStore { for (String componentName : componentNames) { final PersistentStateComponent component = (PersistentStateComponent)myComponents.get(componentName); if (component != null) { - LOG.info("[STORAGE] Reinit component '" + componentName + "'"); initPersistentComponent(component, reloadData); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java index 50074b6a729f..22af3f4bae6d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java @@ -93,7 +93,6 @@ public class FileBasedStorage extends XmlElementStorage { final Listener listener = messageBus.syncPublisher(STORAGE_TOPIC); virtualFileTracker.addTracker(fileUrl, new VirtualFileAdapter() { public void contentsChanged(final VirtualFileEvent event) { - LOG.info("[STORAGE] Changed: " + myFilePath); listener.storageFileChanged(event, FileBasedStorage.this); } }, false, this); diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java index a11c72e04fb1..f4cb4e31f6dc 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java @@ -624,14 +624,11 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject final Set componentNames; try { componentNames = saveSession.analyzeExternalChanges(changedFiles); - LOG.info("[STORAGE] Changes affects: " + (componentNames == null ? "[NONE]" : - StringUtil.join(componentNames.toArray(new String[componentNames.size()]), ", "))); if (componentNames == null) return false; // TODO[mike]: This is a hack to prevent NPE (assert != null) in StateStorageManagerImpl.reload, storage is null for... for (Pair pair : changedFiles) { if (pair.second == null) { - LOG.info("[STORAGE] Soft reload is not possible: no state for:" + pair.first.getName()); return false; } } @@ -641,7 +638,6 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject } if (!isReloadPossible(componentNames)) { - LOG.info("[STORAGE] Soft reload is not possible for some components :("); return false; } } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index d8028832e215..b458a7e6231a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -116,9 +116,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt connection.subscribe(StateStorage.STORAGE_TOPIC, new StateStorage.Listener() { public void storageFileChanged(final VirtualFileEvent event, @NotNull final StateStorage storage) { VirtualFile file = event.getFile(); - LOG.info("[STORAGE] Check if application reload is required for: " + file.getPath()); if (!file.isDirectory() && !(event.getRequestor() instanceof StateStorage.SaveSession)) { - LOG.info("[STORAGE] Scheduling application reload triggered by change in: " + file.getPath()); saveChangedProjectFile(file, null, storage); } } @@ -133,9 +131,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt connection.subscribe(StateStorage.STORAGE_TOPIC, new StateStorage.Listener() { public void storageFileChanged(final VirtualFileEvent event, @NotNull final StateStorage storage) { VirtualFile file = event.getFile(); - LOG.info("[STORAGE] Check if project reload is required for: " + file.getPath()); if (!file.isDirectory() && !(event.getRequestor() instanceof StateStorage.SaveSession)) { - LOG.info("[STORAGE] Scheduling project reload triggered by change in: " + file.getPath()); saveChangedProjectFile(file, project, storage); } } @@ -575,7 +571,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt } private void askToReloadProjectIfConfigFilesChangedExternally() { - LOG.info("[STORAGE] trying to reload project while myReloadBlockCount = " + myReloadBlockCount); if (myReloadBlockCount.get() == 0) { Set projects; @@ -584,8 +579,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt projects = new HashSet(myChangedProjectFiles.keySet()); } - LOG.info("[STORAGE] iterate over opened project & reload"); - List projectsToReload = new ArrayList(); for (Project project : projects) { @@ -661,8 +654,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt if (project.isDisposed()) return false; final HashSet> causes = new HashSet>(); - LOG.info("[STORAGE] Should reload project now"); - synchronized (myChangedProjectFiles) { final List> changes = myChangedProjectFiles.remove(project); if (changes != null) { @@ -677,7 +668,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { try { - LOG.info("[STORAGE] Checking if we could reinit components w/o project reload..."); reloadOk[0] = ((ProjectEx)project).getStateStore().reload(causes); } catch (StateStorage.StateStorageException e) { @@ -692,8 +682,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt }); if (reloadOk[0]) return false; - LOG.info("[STORAGE] Unable to reinit components, scheduling full project reload..."); - String message; if (causes.size() == 1) { message = ProjectBundle.message("project.reload.external.change.single", causes.iterator().next().first.getPresentableUrl()); @@ -730,13 +718,9 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt } private void scheduleReloadApplicationAndProject() { - LOG.info("[STORAGE] Scheduling reload with myReloadBlockCount = " + myReloadBlockCount); - ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - LOG.info("[STORAGE] trying reloading application and should reload project"); if (!tryToReloadApplication()) return; - LOG.info("[STORAGE] reloading project"); askToReloadProjectIfConfigFilesChangedExternally(); }