From 8eb784f0267ef0f8f045ca418f31dc066fc28955 Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 8 Oct 2010 13:22:17 +0400 Subject: [PATCH 1/4] fixed adding source/javadoc roots to library created in the new project wizard --- .../libraries/LibraryCompositionSettings.java | 3 +- .../libraryEditor/NewLibraryEditor.java | 15 +++++ .../projectRoot/LibrariesContainer.java | 3 + .../LibrariesContainerFactory.java | 60 +++++++++++-------- 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java index f8c16e806d0e..1c950688d919 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java @@ -108,9 +108,8 @@ public class LibraryCompositionSettings implements Disposable { @Nullable private Library createLibrary(final ModifiableRootModel rootModel, @Nullable LibrariesContainer additionalContainer) { if (myNewLibraryEditor != null) { - VirtualFile[] roots = myNewLibraryEditor.getFiles(OrderRootType.CLASSES); return LibrariesContainerFactory.createLibrary(additionalContainer, LibrariesContainerFactory.createContainer(rootModel), - myNewLibraryEditor.getName(), getLibraryLevel(), roots, VirtualFile.EMPTY_ARRAY); + myNewLibraryEditor, getLibraryLevel()); } return null; } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java index 6f448fc6506d..d4a48d5b0ff0 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/NewLibraryEditor.java @@ -126,6 +126,10 @@ public class NewLibraryEditor implements LibraryEditor { public void apply(@NotNull Library.ModifiableModel model) { model.setName(myLibraryName); + applyRoots(model); + } + + public void applyRoots(Library.ModifiableModel model) { for (OrderRootType type : myRoots.keySet()) { for (LightFilePointer pointer : myRoots.get(type)) { model.addRoot(pointer.getUrl(), type); @@ -135,4 +139,15 @@ public class NewLibraryEditor implements LibraryEditor { model.addJarDirectory(entry.getKey(), entry.getValue()); } } + + public void copyRoots(ExistingLibraryEditor editor) { + for (OrderRootType type : myRoots.keySet()) { + for (LightFilePointer pointer : myRoots.get(type)) { + editor.addRoot(pointer.getUrl(), type); + } + } + for (Map.Entry entry : myJarDirectories.entrySet()) { + editor.addJarDirectory(entry.getKey(), entry.getValue()); + } + } } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainer.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainer.java index 39a98803bef9..3b0b23719f61 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainer.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainer.java @@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor; +import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NonNls; @@ -54,6 +55,8 @@ public interface LibrariesContainer { Library createLibrary(@NotNull @NonNls String name, @NotNull LibraryLevel level, @NotNull VirtualFile[] classRoots, @NotNull VirtualFile[] sourceRoots); + Library createLibrary(@NotNull NewLibraryEditor libraryEditor, @NotNull LibraryLevel level); + @NotNull String suggestUniqueLibraryName(@NotNull String baseName); diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainerFactory.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainerFactory.java index a14670142748..f8444ad44229 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainerFactory.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/LibrariesContainerFactory.java @@ -25,6 +25,7 @@ import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider; import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; +import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; @@ -72,27 +73,21 @@ public class LibrariesContainerFactory { } public static Library createLibrary(@Nullable LibrariesContainer container1, @NotNull LibrariesContainer container2, - @NotNull @NonNls final String name, @NotNull final LibrariesContainer.LibraryLevel level, - @NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) { + @NotNull @NonNls final NewLibraryEditor editor, @NotNull final LibrariesContainer.LibraryLevel level) { if (container1 != null && container1.canCreateLibrary(level)) { - return container1.createLibrary(name, level, classRoots, sourceRoots); + return container1.createLibrary(editor, level); } else { - return container2.createLibrary(name, level, classRoots, sourceRoots); + return container2.createLibrary(editor, level); } } @NotNull - public static Library createLibraryInTable(final @NonNls String name, final VirtualFile[] roots, final VirtualFile[] sources, final LibraryTable table) { + private static Library createLibraryInTable(final @NotNull NewLibraryEditor editor, final LibraryTable table) { LibraryTable.ModifiableModel modifiableModel = table.getModifiableModel(); - Library library = modifiableModel.createLibrary(getUniqueLibraryName(name, modifiableModel)); + Library library = modifiableModel.createLibrary(getUniqueLibraryName(editor.getName(), modifiableModel)); final Library.ModifiableModel model = library.getModifiableModel(); - for (VirtualFile root : roots) { - model.addRoot(root, OrderRootType.CLASSES); - } - for (VirtualFile root : sources) { - model.addRoot(root, OrderRootType.SOURCES); - } + editor.applyRoots(model); model.commit(); modifiableModel.commit(); return library; @@ -111,6 +106,22 @@ public class LibrariesContainerFactory { private abstract static class LibrariesContainerBase implements LibrariesContainer { private UniqueNameGenerator myNameGenerator; + @Override + public Library createLibrary(@NotNull @NonNls String name, + @NotNull LibraryLevel level, + @NotNull VirtualFile[] classRoots, + @NotNull VirtualFile[] sourceRoots) { + NewLibraryEditor editor = new NewLibraryEditor(); + editor.setName(name); + for (VirtualFile classRoot : classRoots) { + editor.addRoot(classRoot, OrderRootType.CLASSES); + } + for (VirtualFile sourceRoot : sourceRoots) { + editor.addRoot(sourceRoot, OrderRootType.SOURCES); + } + return createLibrary(editor, level); + } + @NotNull public Library[] getAllLibraries() { Library[] libraries = getLibraries(LibraryLevel.GLOBAL); @@ -204,10 +215,11 @@ public class LibrariesContainerFactory { return level == LibraryLevel.GLOBAL || myProject != null; } - public Library createLibrary(@NotNull @NonNls final String name, @NotNull final LibraryLevel level, - @NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) { + @Override + public Library createLibrary(@NotNull NewLibraryEditor libraryEditor, + @NotNull LibraryLevel level) { if (level == LibraryLevel.MODULE && myRootModel != null) { - return createLibraryInTable(name, classRoots, sourceRoots, myRootModel.getModuleLibraryTable()); + return createLibraryInTable(libraryEditor, myRootModel.getModuleLibraryTable()); } LibraryTablesRegistrar registrar = LibraryTablesRegistrar.getInstance(); @@ -221,7 +233,7 @@ public class LibrariesContainerFactory { else { return null; } - return createLibraryInTable(name, classRoots, sourceRoots, table); + return createLibraryInTable(libraryEditor, table); } @Override @@ -239,22 +251,18 @@ public class LibrariesContainerFactory { myContext = context; } - public Library createLibrary(@NotNull @NonNls final String name, @NotNull final LibraryLevel level, - @NotNull final VirtualFile[] classRoots, @NotNull final VirtualFile[] sourceRoots) { + @Override + public Library createLibrary(@NotNull NewLibraryEditor libraryEditor, + @NotNull LibraryLevel level) { LibraryTableModifiableModelProvider provider = getProvider(level); if (provider == null) { LOG.error("cannot create module library in this context"); } LibraryTable.ModifiableModel model = provider.getModifiableModel(); - Library library = model.createLibrary(getUniqueLibraryName(name, model)); - LibraryEditor libraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library); - for (VirtualFile root : classRoots) { - libraryEditor.addRoot(root, OrderRootType.CLASSES); - } - for (VirtualFile source : sourceRoots) { - libraryEditor.addRoot(source, OrderRootType.SOURCES); - } + Library library = model.createLibrary(getUniqueLibraryName(libraryEditor.getName(), model)); + ExistingLibraryEditor createdLibraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library); + libraryEditor.copyRoots(createdLibraryEditor); return library; } From a3487f46cd8f9c3f8c2c87cf63871d2bda9389ae Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 8 Oct 2010 13:21:46 +0400 Subject: [PATCH 2/4] indexing multithreaded by default --- .../src/com/intellij/openapi/project/CacheUpdateRunner.java | 3 +++ platform/platform-resources-en/src/misc/registry.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java index f88c47a08817..b2dd0d85eb9a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/CacheUpdateRunner.java @@ -134,6 +134,9 @@ class CacheUpdateRunner { final boolean[] isFinished = new boolean[1]; try { int threadsCount = Registry.intValue("caches.indexerThreadsCount"); + if (threadsCount == -1) { + threadsCount = Math.min(Runtime.getRuntime().availableProcessors(), 2); + } if (threadsCount == 1) { Runnable process = new MyRunnable(innerIndicator, queue, isFinished, progressUpdater, processInReadAction, application); ProgressManager.getInstance().runProcess(process, innerIndicator); diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 48dfb12ded9d..839a7c19dc00 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -99,4 +99,4 @@ jar.build=false keymap.show.alias.actions=false frameworks.download.libraries.server.url=http://pluginsrepo-test:8080 -caches.indexerThreadsCount=1 \ No newline at end of file +caches.indexerThreadsCount=-1 \ No newline at end of file From 27844e41ea9e80b5ff59f82eedb8832aefe22bd8 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 8 Oct 2010 12:01:12 +0200 Subject: [PATCH 3/4] create less new variables --- .../forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java index d756d88033f8..cb3bace8866f 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java @@ -198,7 +198,7 @@ public class ReplaceForEachLoopWithIndexedForLoopIntention extends Intention { return createVariable(variableName, expression, context); } final PsiElement target = referenceElement.resolve(); - if (target instanceof PsiLocalVariable) { + if (target instanceof PsiVariable) { // maybe should not do this for local variables outside of // anonymous classes return variableName; From 4336c764668fbc71f41a71843fd5d57c8bf65bfe Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 8 Oct 2010 12:30:19 +0200 Subject: [PATCH 4/4] IDEA-59582 (intention Convert to Plain for double literal does not work) --- ...ConvertToEngineeringNotationIntention.java | 42 +++++++++++------ .../ipp/integer/ConvertToPlainIntention.java | 47 +++++++++++++------ .../ipp/integer/ConvertToPlainPredicate.java | 2 +- 3 files changed, 62 insertions(+), 29 deletions(-) diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToEngineeringNotationIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToEngineeringNotationIntention.java index 22d725470c76..508f57e6b629 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToEngineeringNotationIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToEngineeringNotationIntention.java @@ -28,21 +28,35 @@ import java.text.DecimalFormat; * @author Konstantin Bulenkov */ public class ConvertToEngineeringNotationIntention extends Intention { - private static final DecimalFormat FORMAT = new DecimalFormat("0.00000000000000E00"); - private static final ConvertToEngineeringNotationPredicate PREDICATE = new ConvertToEngineeringNotationPredicate(); - @Override - protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException { - String text = FORMAT.format(Double.parseDouble(element.getText())).replace(',', '.'); - while (text.contains("0E") && !text.contains(".0E")) { - text = text.replace("0E", "E"); + private static final DecimalFormat FORMAT = + new DecimalFormat("0.00000000000000E00"); + private static final ConvertToEngineeringNotationPredicate PREDICATE = + new ConvertToEngineeringNotationPredicate(); + + @Override + protected void processIntention(@NotNull PsiElement element) + throws IncorrectOperationException { + final String elementText = element.getText(); + if (elementText.length() == 0) { + return; + } + final int lastIndex = elementText.length() - 1; + final char lastChar = elementText.charAt(lastIndex); + String text = FORMAT.format(Double.parseDouble(elementText)).replace(',', '.'); + while (text.contains("0E") && !text.contains(".0E")) { + text = text.replace("0E", "E"); + } + if (lastChar == 'f' || lastChar == 'F') { + replaceExpression(text + lastChar, (PsiExpression)element); + } else { + replaceExpression(text, (PsiExpression)element); + } } - replaceExpression(text, (PsiExpression)element); - } - @NotNull - @Override - protected PsiElementPredicate getElementPredicate() { - return PREDICATE; - } + @NotNull + @Override + protected PsiElementPredicate getElementPredicate() { + return PREDICATE; + } } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainIntention.java index 9d31b0b6f3e2..ea0d42785008 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainIntention.java @@ -22,24 +22,43 @@ import com.siyeh.ipp.base.Intention; import com.siyeh.ipp.base.PsiElementPredicate; import org.jetbrains.annotations.NotNull; +import java.math.BigDecimal; + /** * @author Konstantin Bulenkov */ public class ConvertToPlainIntention extends Intention { - private static final ConvertToPlainPredicate PREDICATE = new ConvertToPlainPredicate(); - @Override - protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException { - try { - replaceExpression(Double.toString(Double.parseDouble(element.getText())), (PsiExpression)element); - } - catch (Exception e) {// - } - } + private static final ConvertToPlainPredicate PREDICATE = + new ConvertToPlainPredicate(); - @NotNull - @Override - protected PsiElementPredicate getElementPredicate() { - return PREDICATE; - } + @Override + protected void processIntention(@NotNull PsiElement element) + throws IncorrectOperationException { + try { + final String elementText = element.getText(); + if (elementText.length() == 0) { + return; + } + final int lastIndex = elementText.length() - 1; + final char lastChar = elementText.charAt(lastIndex); + if (lastChar == 'f' || lastChar == 'F') { + final BigDecimal bigDecimal = + new BigDecimal(elementText.substring(0, lastIndex)); + replaceExpression(bigDecimal.toPlainString() + lastChar, + (PsiExpression) element); + } else { + final BigDecimal bigDecimal = new BigDecimal(elementText); + replaceExpression(bigDecimal.toPlainString(), + (PsiExpression) element); + } + } catch (Exception e) {// + } + } + + @NotNull + @Override + protected PsiElementPredicate getElementPredicate() { + return PREDICATE; + } } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainPredicate.java index a12df598692e..25060ba0c2e9 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainPredicate.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/integer/ConvertToPlainPredicate.java @@ -24,7 +24,7 @@ import com.siyeh.ipp.base.PsiElementPredicate; * @author Konstantin Bulenkov */ public class ConvertToPlainPredicate implements PsiElementPredicate { - @Override + public boolean satisfiedBy(PsiElement element) { if (element instanceof PsiLiteralExpression) { final PsiLiteralExpression expression = (PsiLiteralExpression)element;