Merge remote-tracking branch 'origin/master'

This commit is contained in:
Kirill Likhodedov
2012-01-27 19:54:15 +04:00
10 changed files with 144 additions and 32 deletions
@@ -87,6 +87,13 @@ public class CompileContext extends UserDataHolderBase implements MessageHandler
}
}
public void markDirty(final ModuleChunk chunk) throws Exception {
final Set<Module> 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<Module> modules = chunk.getModules();
final Set<Module> dirtyModules = new HashSet<Module>(modules);
@@ -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<AnActionButtonUpdater> 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<AnActionButtonUpdater>();
}
myUpdaters.add(updater);
}
public void updateButton(AnActionEvent e) {
}
@@ -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);
}
@@ -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
@@ -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);
}
@@ -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
@@ -1045,6 +1045,7 @@ inner.class.may.be.static.problem.descriptor=Inner class <code>#ref</code> may b
string.buffer.must.have.initial.capacity.problem.descriptor=<code>#ref</code> without initial capacity #loc
string.buffer.replaceable.by.string.builder.problem.descriptor=<code>StringBuffer #ref</code> may be declared as ''StringBuilder'' #loc
string.buffer.replaceable.by.string.problem.descriptor=<code>{0} #ref</code> can be replaced with ''String'' #loc
new.string.buffer.replaceable.by.string.problem.descriptor=<code>#ref</code> can be replaced with 'String' #loc
string.replaceable.by.string.buffer.problem.descriptor=Non-constant <code>String #ref</code> should probably be declared as ''StringBuilder'' #loc
collections.must.have.initial.capacity.problem.descriptor=<code>#ref</code> without initial capacity #loc
string.concatenation.in.loops.problem.descriptor=String concatenation <code>#ref</code> in loop #loc
@@ -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;
}
}
@@ -27,4 +27,11 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'StringBuffer' can be replaced with 'String'</problem_class>
<description>&lt;code&gt;StringBuffer buffer&lt;/code&gt; can be replaced with 'String' #loc</description>
</problem>
<problem>
<file>StringBufferReplaceableByString.java</file>
<line>25</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">'StringBuffer' can be replaced with 'String'</problem_class>
<description>&lt;code&gt;StringBuilder&lt;/code&gt; can be replaced with 'String' #loc</description>
</problem>
</problems>
@@ -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<String, XsltSymbolI
return Collections.emptyMap();
}
final HashMap<String, Kind> map = new HashMap<String, Kind>();
NanoXmlUtil.parse(new ByteArrayInputStream(inputData.getContent()), new NanoXmlUtil.IXMLBuilderAdapter() {
NanoXmlUtil.parse(new UnsyncByteArrayInputStream(inputData.getContent()), new NanoXmlUtil.IXMLBuilderAdapter() {
NanoXmlUtil.IXMLBuilderAdapter attributeHandler;
int depth;