From 44d8f40d40f7d3bf85fec23464d5d5d1f5e8f616 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 27 Jan 2012 15:56:35 +0100 Subject: [PATCH 1/5] wording (IDEA-80443) --- .../src/messages/ActionsBundle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index fba31187d44c..e8ba69be03c1 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -676,8 +676,8 @@ action.GenerateJavadoc.description=Run the JavaDoc tool group.Macros.text=_Macros group.Macros.description=View, Change, Record, Play Macros group.StanardMacroActions.text=Standard Macro Actions -action.PlaybackLastMacro.text=Pla_yback Last Macro -action.PlaybackLastMacro.description=Playback last used macro +action.PlaybackLastMacro.text=Pla_y Back Last Macro +action.PlaybackLastMacro.description=Play Back last used macro action.StartStopMacroRecording.text=Start/Stop Macro _Recording action.StartStopMacroRecording.description=Start/Stop recording of a new macro action.EditMacros.text=_Edit Macros From eb9f282b3b75dec5e44b2927e35e61616ef52842 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 27 Jan 2012 15:59:55 +0100 Subject: [PATCH 2/5] action button updater --- .../src/com/intellij/ui/AnActionButton.java | 27 ++++++++++++++++--- .../intellij/ui/AnActionButtonUpdater.java | 25 +++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 platform/platform-api/src/com/intellij/ui/AnActionButtonUpdater.java diff --git a/platform/platform-api/src/com/intellij/ui/AnActionButton.java b/platform/platform-api/src/com/intellij/ui/AnActionButton.java index 7ecf3b2af477..99c74f1ea744 100644 --- a/platform/platform-api/src/com/intellij/ui/AnActionButton.java +++ b/platform/platform-api/src/com/intellij/ui/AnActionButton.java @@ -18,10 +18,13 @@ package com.intellij.ui; import com.intellij.openapi.actionSystem.*; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.HashSet; +import java.util.Set; /** * @author Konstantin Bulenkov @@ -32,6 +35,7 @@ public abstract class AnActionButton extends AnAction implements ShortcutProvide private ShortcutSet myShortcut; private AnAction myAction = null; private JComponent myContextComponent; + private Set myUpdaters; public AnActionButton(String text) { super(text); @@ -92,12 +96,20 @@ public abstract class AnActionButton extends AnAction implements ShortcutProvide public final void update(AnActionEvent e) { boolean myActionVisible = true; boolean myActionEnabled = true; - if (myAction != null) { + if (myAction != null) { myAction.update(e); - myActionEnabled = myAction.getTemplatePresentation().isEnabled(); - myActionVisible = myAction.getTemplatePresentation().isVisible(); + myActionEnabled = e.getPresentation().isEnabled(); + myActionVisible = e.getPresentation().isVisible(); + } + boolean enabled = isEnabled() && isContextComponentOk() && myActionEnabled; + if (enabled) { + for (AnActionButtonUpdater updater : myUpdaters) { + if (!updater.isEnabled(e)) { + enabled = false; + break; + } + } } - final boolean enabled = isEnabled() && isContextComponentOk() && myActionEnabled; e.getPresentation().setEnabled(enabled); e.getPresentation().setVisible(isVisible() && myActionVisible); @@ -105,6 +117,13 @@ public abstract class AnActionButton extends AnAction implements ShortcutProvide updateButton(e); } } + + public final void addCustomUpdater(@NotNull AnActionButtonUpdater updater) { + if (myUpdaters == null) { + myUpdaters = new HashSet(); + } + myUpdaters.add(updater); + } public void updateButton(AnActionEvent e) { } diff --git a/platform/platform-api/src/com/intellij/ui/AnActionButtonUpdater.java b/platform/platform-api/src/com/intellij/ui/AnActionButtonUpdater.java new file mode 100644 index 000000000000..bc9cc43f65cf --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/AnActionButtonUpdater.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2012 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.ui; + +import com.intellij.openapi.actionSystem.AnActionEvent; + +/** + * @author Konstantin Bulenkov + */ +public interface AnActionButtonUpdater { + boolean isEnabled(AnActionEvent e); +} From 25e8b4bbe19d8001a9bea441eed4ded7250bb598 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Fri, 27 Jan 2012 17:58:48 +0400 Subject: [PATCH 3/5] less garbage and synchronization during building indexed --- .../com/intellij/util/io/storage/RefCountingStorage.java | 4 ++-- .../util/src/com/intellij/util/lang/JarMemoryLoader.java | 3 ++- .../intellij/lang/xpath/xslt/impl/XsltSymbolIndex.java | 8 ++------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/platform/util/src/com/intellij/util/io/storage/RefCountingStorage.java b/platform/util/src/com/intellij/util/io/storage/RefCountingStorage.java index 3ab8d0060740..eb8ba08a3140 100644 --- a/platform/util/src/com/intellij/util/io/storage/RefCountingStorage.java +++ b/platform/util/src/com/intellij/util/io/storage/RefCountingStorage.java @@ -25,8 +25,8 @@ import com.intellij.openapi.util.io.StreamUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.containers.ConcurrentHashMap; import com.intellij.util.io.PagePool; +import com.intellij.util.io.UnsyncByteArrayInputStream; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.util.Map; @@ -58,7 +58,7 @@ public class RefCountingStorage extends AbstractStorage { synchronized (myLock) { byte[] result = super.readBytes(record); - InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(result)); + InflaterInputStream in = new InflaterInputStream(new UnsyncByteArrayInputStream(result)); try { return StreamUtil.loadFromStream(in); } diff --git a/platform/util/src/com/intellij/util/lang/JarMemoryLoader.java b/platform/util/src/com/intellij/util/lang/JarMemoryLoader.java index 63f9a81171a4..44628c743e82 100644 --- a/platform/util/src/com/intellij/util/lang/JarMemoryLoader.java +++ b/platform/util/src/com/intellij/util/lang/JarMemoryLoader.java @@ -1,6 +1,7 @@ package com.intellij.util.lang; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.io.UnsyncByteArrayInputStream; import com.intellij.util.io.zip.ZipShort; import gnu.trove.THashMap; import org.jetbrains.annotations.Nullable; @@ -95,7 +96,7 @@ public class JarMemoryLoader { @Override public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(myContent); + return new UnsyncByteArrayInputStream(myContent); } @Override diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltSymbolIndex.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltSymbolIndex.java index 05810b698f1d..cfb60158ed04 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltSymbolIndex.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltSymbolIndex.java @@ -29,10 +29,7 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.ArrayUtil; import com.intellij.util.indexing.*; -import com.intellij.util.io.DataExternalizer; -import com.intellij.util.io.EnumDataDescriptor; -import com.intellij.util.io.EnumeratorStringDescriptor; -import com.intellij.util.io.KeyDescriptor; +import com.intellij.util.io.*; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.xml.NanoXmlUtil; import org.intellij.lang.xpath.xslt.XsltSupport; @@ -41,7 +38,6 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.ByteArrayInputStream; import java.util.*; /* @@ -94,7 +90,7 @@ public class XsltSymbolIndex extends FileBasedIndexExtension map = new HashMap(); - NanoXmlUtil.parse(new ByteArrayInputStream(inputData.getContent()), new NanoXmlUtil.IXMLBuilderAdapter() { + NanoXmlUtil.parse(new UnsyncByteArrayInputStream(inputData.getContent()), new NanoXmlUtil.IXMLBuilderAdapter() { NanoXmlUtil.IXMLBuilderAdapter attributeHandler; int depth; From 708849dd042ef7534d16c18cf6f4da5b562f820c Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 27 Jan 2012 16:32:22 +0100 Subject: [PATCH 4/5] let "'StringBuffer' can be replaced with 'String'" inspection report more cases --- .../siyeh/InspectionGadgetsBundle.properties | 1 + ...ngBufferReplaceableByStringInspection.java | 90 +++++++++++++++---- .../expected.xml | 7 ++ 3 files changed, 81 insertions(+), 17 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 92894cd75ab9..4639e93c509b 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1045,6 +1045,7 @@ inner.class.may.be.static.problem.descriptor=Inner class #ref may b string.buffer.must.have.initial.capacity.problem.descriptor=#ref without initial capacity #loc string.buffer.replaceable.by.string.builder.problem.descriptor=StringBuffer #ref may be declared as ''StringBuilder'' #loc string.buffer.replaceable.by.string.problem.descriptor={0} #ref can be replaced with ''String'' #loc +new.string.buffer.replaceable.by.string.problem.descriptor=#ref can be replaced with 'String' #loc string.replaceable.by.string.buffer.problem.descriptor=Non-constant String #ref should probably be declared as ''StringBuilder'' #loc collections.must.have.initial.capacity.problem.descriptor=#ref without initial capacity #loc string.concatenation.in.loops.problem.descriptor=String concatenation #ref in loop #loc diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java index 9d56ab1b5c69..38eed03f36cd 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/StringBufferReplaceableByStringInspection.java @@ -39,13 +39,17 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection { @Override @NotNull public String buildErrorString(Object... infos) { - final String typeText = ((PsiType)infos[0]).getPresentableText(); + final PsiElement element = (PsiElement)infos[0]; + if (element instanceof PsiNewExpression) { + return InspectionGadgetsBundle.message("new.string.buffer.replaceable.by.string.problem.descriptor"); + } + final String typeText = ((PsiType)infos[1]).getPresentableText(); return InspectionGadgetsBundle.message("string.buffer.replaceable.by.string.problem.descriptor", typeText); } @Override protected InspectionGadgetsFix buildFix(Object... infos) { - final String typeText = ((PsiType)infos[0]).getCanonicalText(); + final String typeText = ((PsiType)infos[1]).getCanonicalText(); return new StringBufferReplaceableByStringFix(CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(typeText)); } @@ -72,6 +76,13 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection { final PsiElement element = descriptor.getPsiElement(); final PsiElement parent = element.getParent(); if (!(parent instanceof PsiVariable)) { + if (parent instanceof PsiNewExpression) { + final PsiNewExpression newExpression = (PsiNewExpression)parent; + final PsiExpression stringBuilderExpression = getCompleteExpression(newExpression); + final StringBuilder stringExpression = buildStringExpression(stringBuilderExpression, new StringBuilder()); + replaceExpression(stringBuilderExpression, stringExpression.toString()); + return; + } return; } final PsiVariable variable = (PsiVariable)parent; @@ -83,18 +94,18 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection { if (initializer == null) { return; } + final StringBuilder stringExpression = buildStringExpression(initializer, new StringBuilder()); + if (stringExpression == null) { + return; + } final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); final PsiClassType javaLangString = factory.createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING, variable.getResolveScope()); final PsiTypeElement typeElement = factory.createTypeElement(javaLangString); - final StringBuilder newInitializer = buildReplacementInitializer(initializer, new StringBuilder()); - if (newInitializer == null) { - return; - } + replaceExpression(initializer, stringExpression.toString()); originalTypeElement.replace(typeElement); - replaceExpression(initializer, newInitializer.toString()); } - private static StringBuilder buildReplacementInitializer(PsiExpression initializer, StringBuilder result) { + private static StringBuilder buildStringExpression(PsiExpression initializer, StringBuilder result) { if (initializer instanceof PsiNewExpression) { final PsiNewExpression newExpression = (PsiNewExpression)initializer; final PsiExpressionList argumentList = newExpression.getArgumentList(); @@ -116,18 +127,20 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection { final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)initializer; final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final PsiExpression qualifier = methodExpression.getQualifierExpression(); - result = buildReplacementInitializer(qualifier, result); + result = buildStringExpression(qualifier, result); if (result == null) { return null; } - final PsiExpressionList argumentList = methodCallExpression.getArgumentList(); - final PsiExpression[] arguments = argumentList.getExpressions(); - if (arguments.length != 1) { - return null; + if (!"toString".equals(methodExpression.getReferenceName())) { + final PsiExpressionList argumentList = methodCallExpression.getArgumentList(); + final PsiExpression[] arguments = argumentList.getExpressions(); + if (arguments.length != 1) { + return null; + } + final PsiExpression argument = arguments[0]; + result.append('+'); + result.append(argument.getText()); } - final PsiExpression argument = arguments[0]; - result.append('+'); - result.append(argument.getText()); } else { return null; } @@ -176,7 +189,22 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection { if (variableIsModified(variable, codeBlock)) { return; } - registerVariableError(variable, type); + registerVariableError(variable, variable, type); + } + + @Override + public void visitNewExpression(PsiNewExpression expression) { + super.visitNewExpression(expression); + final PsiType type = expression.getType(); + if (!TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_STRING_BUFFER, type) && + !TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_STRING_BUILDER, type)) { + return; + } + final PsiExpression completeExpression = getCompleteExpression(expression); + if (completeExpression == null) { + return; + } + registerNewExpressionError(expression, expression, type); } public static boolean variableIsModified(PsiVariable variable, PsiElement context) { @@ -210,4 +238,32 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection { return "append".equals(methodName); } } + + private static PsiExpression getCompleteExpression(PsiNewExpression expression) { + PsiElement completeExpression = expression; + boolean found = false; + while (true) { + final PsiElement parent = completeExpression.getParent(); + if (!(parent instanceof PsiReferenceExpression)) { + break; + } + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)parent; + final String name = referenceExpression.getReferenceName(); + if (!"append".equals(name)) { + if (!"toString".equals(name)) { + return null; + } + found = true; + } + final PsiElement grandParent = parent.getParent(); + if (!(grandParent instanceof PsiMethodCallExpression)) { + break; + } + completeExpression = grandParent; + if (found) { + return (PsiExpression) completeExpression; + } + } + return null; + } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/string_buffer_replaceable_by_string/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/string_buffer_replaceable_by_string/expected.xml index fbc4c4e90c9d..601059cf5a26 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/string_buffer_replaceable_by_string/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/performance/string_buffer_replaceable_by_string/expected.xml @@ -27,4 +27,11 @@ 'StringBuffer' can be replaced with 'String' <code>StringBuffer buffer</code> can be replaced with 'String' #loc + + + StringBufferReplaceableByString.java + 25 + 'StringBuffer' can be replaced with 'String' + <code>StringBuilder</code> can be replaced with 'String' #loc + \ No newline at end of file From d81b5778821ae10afebdfa8982b26e7f2e450563 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 27 Jan 2012 16:43:58 +0100 Subject: [PATCH 5/5] compile-server: mark dirty for module chunk --- .../src/org/jetbrains/jps/incremental/CompileContext.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java index 23200ff2ffb2..7a89f170c5a2 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/CompileContext.java @@ -87,6 +87,13 @@ public class CompileContext extends UserDataHolderBase implements MessageHandler } } + public void markDirty(final ModuleChunk chunk) throws Exception { + final Set modules = chunk.getModules(); + for (Module module : modules) { + markDirtyFiles(module, myTsStorage, true, isCompilingTests()? DirtyMarkScope.TESTS : DirtyMarkScope.PRODUCTION, null); + } + } + public void markDirtyRecursively(ModuleChunk chunk) throws Exception { final Set modules = chunk.getModules(); final Set dirtyModules = new HashSet(modules);