From 6ac774dafbdc2e025f7835ec6912f64dcfe25cd4 Mon Sep 17 00:00:00 2001 From: sweinreuter Date: Mon, 16 Apr 2012 17:40:23 +0200 Subject: [PATCH 01/24] IDEA-84409: Support EXSLT functions --- .../functions/DefaultFunctionContext.java | 4 ++ .../xslt/context/XsltFunctionContext.java | 59 +++++++++++++++++++ .../xpath/xslt/impl/XsltResourceProvider.java | 7 +++ 3 files changed, 70 insertions(+) diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/functions/DefaultFunctionContext.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/functions/DefaultFunctionContext.java index def1f2f7e4c1..308701e47cae 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/functions/DefaultFunctionContext.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/context/functions/DefaultFunctionContext.java @@ -356,6 +356,10 @@ public class DefaultFunctionContext extends AbstractFunctionContext { decls.put(Pair.create(new QName(null, value.getName()), value.getParameters().length), value); } + public static void addFunction(Map, Function> decls, String namespace, Function value) { + decls.put(Pair.create(new QName(namespace, value.getName()), value.getParameters().length), value); + } + public boolean allowsExtensions() { return false; } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltFunctionContext.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltFunctionContext.java index e3b027dc1f5e..81831d4598a0 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltFunctionContext.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltFunctionContext.java @@ -38,6 +38,12 @@ public class XsltFunctionContext extends DefaultFunctionContext { } }; + public static final String EXSLT_DATE_TIME = "http://exslt.org/dates-and-times"; + public static final String EXSLT_COMMON = "http://exslt.org/common"; + public static final String EXSLT_MATH = "http://exslt.org/math"; + public static final String EXSLT_SETS = "http://exslt.org/sets"; + public static final String EXSLT_DYNAMIC = "http://exslt.org/dynamic"; + static { final Map, Function> decls = new HashMap, Function>(); @@ -75,6 +81,59 @@ public class XsltFunctionContext extends DefaultFunctionContext { // node-set current() addFunction(decls, new FunctionImpl("current", XPathType.NODESET)); + final Parameter optional_string = new Parameter(XPathType.STRING, Parameter.Kind.OPTIONAL); + final Parameter required_nodeset = new Parameter(XPathType.NODESET, Parameter.Kind.REQUIRED); + + // EXSLT (http://www.exslt.org) extensions supported by Xalan & Saxon + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("date", XPathType.STRING, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("date-time", XPathType.STRING)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("day-abbreviation", XPathType.STRING, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("day-in-month", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("day-in-week", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("day-in-year", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("day-name", XPathType.STRING, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("day-of-week-in-month", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("hour-in-day", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("leap-year", XPathType.BOOLEAN, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("minute-in-hour", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("month-abbreviation", XPathType.STRING, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("month-in-year", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("month-name", XPathType.STRING, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("second-in-minute", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("time", XPathType.STRING, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("week-in-year", XPathType.NUMBER, optional_string)); + addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("year", XPathType.NUMBER, optional_string)); + + addFunction(decls, EXSLT_COMMON, new FunctionImpl("node-set", XPathType.NODESET, new Parameter(XPathType.ANY, Parameter.Kind.REQUIRED))); + addFunction(decls, EXSLT_COMMON, new FunctionImpl("object-type", XPathType.STRING, new Parameter(XPathType.ANY, Parameter.Kind.REQUIRED))); + + addFunction(decls, EXSLT_MATH, new FunctionImpl("highest", XPathType.NODESET, required_nodeset)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("lowest", XPathType.NODESET, required_nodeset)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("max", XPathType.NUMBER, required_nodeset)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("min", XPathType.NUMBER, required_nodeset)); + + addFunction(decls, EXSLT_SETS, new FunctionImpl("difference", XPathType.NODESET, + required_nodeset, + required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("intersection", XPathType.NODESET, + required_nodeset, + required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("leading", XPathType.NODESET, + required_nodeset, + required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("trailing", XPathType.NODESET, + required_nodeset, + required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("has-same-node", XPathType.BOOLEAN, + required_nodeset, + required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("distinct", XPathType.NODESET, + required_nodeset)); + + // Xalan only + addFunction(decls, EXSLT_DYNAMIC, new FunctionImpl("evaluate", XPathType.ANY, new Parameter(XPathType.STRING, Parameter.Kind.REQUIRED))); + + XSLT_FUNCTIONS = Collections.unmodifiableMap(decls); } diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltResourceProvider.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltResourceProvider.java index 5e37b0292f71..15354c72b136 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltResourceProvider.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltResourceProvider.java @@ -19,6 +19,7 @@ package org.intellij.lang.xpath.xslt.impl; import com.intellij.javaee.ResourceRegistrar; import com.intellij.javaee.StandardResourceProvider; import org.intellij.lang.xpath.xslt.XsltSupport; +import org.intellij.lang.xpath.xslt.context.XsltFunctionContext; /** * @author Dmitry Avdeev @@ -28,5 +29,11 @@ public class XsltResourceProvider implements StandardResourceProvider { public void registerResources(ResourceRegistrar registrar) { registrar.addStdResource(XsltSupport.XSLT_NS, "/org/intellij/lang/xpath/xslt/resources/xslt-schema.xsd", getClass()); registrar.addIgnoredResource(XsltSupport.PLUGIN_EXTENSIONS_NS); + + registrar.addIgnoredResource(XsltFunctionContext.EXSLT_COMMON); + registrar.addIgnoredResource(XsltFunctionContext.EXSLT_DATE_TIME); + registrar.addIgnoredResource(XsltFunctionContext.EXSLT_DYNAMIC); + registrar.addIgnoredResource(XsltFunctionContext.EXSLT_MATH); + registrar.addIgnoredResource(XsltFunctionContext.EXSLT_SETS); } } From 6f9943c7ee7df871487acf8efa203c8f9fe84482 Mon Sep 17 00:00:00 2001 From: sweinreuter Date: Tue, 17 Apr 2012 10:50:21 +0200 Subject: [PATCH 02/24] IDEA-84409: Support EXSLT functions (2) --- .../xslt/context/XsltFunctionContext.java | 54 ++++++++++++------- .../xpath/xslt/impl/XsltResourceProvider.java | 1 + 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltFunctionContext.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltFunctionContext.java index 81831d4598a0..973cb07d7b79 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltFunctionContext.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/context/XsltFunctionContext.java @@ -43,6 +43,7 @@ public class XsltFunctionContext extends DefaultFunctionContext { public static final String EXSLT_MATH = "http://exslt.org/math"; public static final String EXSLT_SETS = "http://exslt.org/sets"; public static final String EXSLT_DYNAMIC = "http://exslt.org/dynamic"; + public static final String EXSLT_STRINGS = "http://exslt.org/strings"; static { final Map, Function> decls = new HashMap, Function>(); @@ -82,7 +83,9 @@ public class XsltFunctionContext extends DefaultFunctionContext { addFunction(decls, new FunctionImpl("current", XPathType.NODESET)); final Parameter optional_string = new Parameter(XPathType.STRING, Parameter.Kind.OPTIONAL); + final Parameter required_string = new Parameter(XPathType.STRING, Parameter.Kind.REQUIRED); final Parameter required_nodeset = new Parameter(XPathType.NODESET, Parameter.Kind.REQUIRED); + final Parameter required_number = new Parameter(XPathType.NUMBER, Parameter.Kind.REQUIRED); // EXSLT (http://www.exslt.org) extensions supported by Xalan & Saxon addFunction(decls, EXSLT_DATE_TIME, new FunctionImpl("date", XPathType.STRING, optional_string)); @@ -112,26 +115,41 @@ public class XsltFunctionContext extends DefaultFunctionContext { addFunction(decls, EXSLT_MATH, new FunctionImpl("max", XPathType.NUMBER, required_nodeset)); addFunction(decls, EXSLT_MATH, new FunctionImpl("min", XPathType.NUMBER, required_nodeset)); - addFunction(decls, EXSLT_SETS, new FunctionImpl("difference", XPathType.NODESET, - required_nodeset, - required_nodeset)); - addFunction(decls, EXSLT_SETS, new FunctionImpl("intersection", XPathType.NODESET, - required_nodeset, - required_nodeset)); - addFunction(decls, EXSLT_SETS, new FunctionImpl("leading", XPathType.NODESET, - required_nodeset, - required_nodeset)); - addFunction(decls, EXSLT_SETS, new FunctionImpl("trailing", XPathType.NODESET, - required_nodeset, - required_nodeset)); - addFunction(decls, EXSLT_SETS, new FunctionImpl("has-same-node", XPathType.BOOLEAN, - required_nodeset, - required_nodeset)); - addFunction(decls, EXSLT_SETS, new FunctionImpl("distinct", XPathType.NODESET, - required_nodeset)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("abs", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("sqrt", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("log", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("sin", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("cos", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("tan", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("asin", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("acos", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("atan", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("exp", XPathType.NUMBER, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("atan2", XPathType.NUMBER, required_number, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("power", XPathType.NUMBER, required_number, required_number)); + addFunction(decls, EXSLT_MATH, new FunctionImpl("random", XPathType.NUMBER)); + + addFunction(decls, EXSLT_MATH, new FunctionImpl("constant", XPathType.NUMBER, required_string, required_number)); + + addFunction(decls, EXSLT_SETS, new FunctionImpl("difference", XPathType.NODESET, required_nodeset, required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("intersection", XPathType.NODESET, required_nodeset, required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("leading", XPathType.NODESET, required_nodeset, required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("trailing", XPathType.NODESET, required_nodeset, required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("has-same-node", XPathType.BOOLEAN, required_nodeset, required_nodeset)); + addFunction(decls, EXSLT_SETS, new FunctionImpl("distinct", XPathType.NODESET, required_nodeset)); // Xalan only - addFunction(decls, EXSLT_DYNAMIC, new FunctionImpl("evaluate", XPathType.ANY, new Parameter(XPathType.STRING, Parameter.Kind.REQUIRED))); + addFunction(decls, EXSLT_DYNAMIC, new FunctionImpl("evaluate", XPathType.ANY, required_string)); + addFunction(decls, EXSLT_DYNAMIC, new FunctionImpl("min", XPathType.NUMBER, required_nodeset, required_string)); + addFunction(decls, EXSLT_DYNAMIC, new FunctionImpl("max", XPathType.NUMBER, required_nodeset, required_string)); + addFunction(decls, EXSLT_DYNAMIC, new FunctionImpl("sum", XPathType.NUMBER, required_nodeset, required_string)); + addFunction(decls, EXSLT_DYNAMIC, new FunctionImpl("map", XPathType.NODESET, required_nodeset, required_string)); + addFunction(decls, EXSLT_DYNAMIC, new FunctionImpl("closure", XPathType.NODESET, required_nodeset, required_string)); + + addFunction(decls, EXSLT_STRINGS, new FunctionImpl("align", XPathType.STRING, required_string, required_string, optional_string)); + addFunction(decls, EXSLT_STRINGS, new FunctionImpl("padding", XPathType.STRING, required_number, optional_string)); + addFunction(decls, EXSLT_STRINGS, new FunctionImpl("tokenize", XPathType.NODESET, required_string, optional_string)); + addFunction(decls, EXSLT_STRINGS, new FunctionImpl("split", XPathType.NODESET, required_string, optional_string)); XSLT_FUNCTIONS = Collections.unmodifiableMap(decls); diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltResourceProvider.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltResourceProvider.java index 15354c72b136..d4e14eee092d 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltResourceProvider.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/xslt/impl/XsltResourceProvider.java @@ -35,5 +35,6 @@ public class XsltResourceProvider implements StandardResourceProvider { registrar.addIgnoredResource(XsltFunctionContext.EXSLT_DYNAMIC); registrar.addIgnoredResource(XsltFunctionContext.EXSLT_MATH); registrar.addIgnoredResource(XsltFunctionContext.EXSLT_SETS); + registrar.addIgnoredResource(XsltFunctionContext.EXSLT_STRINGS); } } From f4939d27712961f2a11cdb630635512f8c42dcd8 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 18 Apr 2012 09:08:44 +0200 Subject: [PATCH 03/24] export inspection results: catch exception to proceed with other inspections --- .../codeInspection/ex/GlobalInspectionContextImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index 18d9ef0bc84e..36e27ed70db5 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -337,7 +337,12 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G for (Element element : globalTools.keySet()) { final Tools tools = globalTools.get(element); for (ScopeToolState state : tools.getTools()) { - ((InspectionTool)state.getTool()).exportResults(element, refEntity); + try { + ((InspectionTool)state.getTool()).exportResults(element, refEntity); + } + catch (Exception e) { + LOG.error(e); + } } } } From c16ac8d1864db445851d392a80e0985610905986 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 18 Apr 2012 09:13:36 +0200 Subject: [PATCH 04/24] inspections: avoid getElement() calls --- .../codeInspection/deadCode/UnusedDeclarationInspection.java | 2 +- .../codeInspection/ex/DescriptorProviderInspection.java | 2 +- .../src/com/intellij/codeInspection/ex/InspectionTool.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java index 6968e8ff5f9f..d4d740f832b7 100644 --- a/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/deadCode/UnusedDeclarationInspection.java @@ -644,7 +644,7 @@ public class UnusedDeclarationInspection extends FilteringInspectionTool { final RefElement refElement = (RefElement)refEntity; final HighlightSeverity severity = getCurrentSeverity(refElement); final String attributeKey = - getTextAttributeKey(refElement.getElement().getProject(), severity, ProblemHighlightType.LIKE_UNUSED_SYMBOL); + getTextAttributeKey(refElement.getRefManager().getProject(), severity, ProblemHighlightType.LIKE_UNUSED_SYMBOL); problemClassElement.setAttribute("severity", severity.myName); problemClassElement.setAttribute("attribute_key", attributeKey); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorProviderInspection.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorProviderInspection.java index 36c4d93b92a7..12812e249899 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorProviderInspection.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/DescriptorProviderInspection.java @@ -290,7 +290,7 @@ public abstract class DescriptorProviderInspection extends InspectionTool implem ProblemHighlightType problemHighlightType = description instanceof ProblemDescriptor ? ((ProblemDescriptor)description).getHighlightType() : ProblemHighlightType.GENERIC_ERROR_OR_WARNING; - final String attributeKey = getTextAttributeKey(refElement.getElement().getProject(), severity, problemHighlightType); + final String attributeKey = getTextAttributeKey(refElement.getRefManager().getProject(), severity, problemHighlightType); problemClassElement.setAttribute("severity", severity.myName); problemClassElement.setAttribute("attribute_key", attributeKey); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java index e9d0aa00349d..9ecf87d5e620 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java @@ -168,7 +168,7 @@ public abstract class InspectionTool extends InspectionProfileEntry { } protected HighlightSeverity getCurrentSeverity(RefElement element) { - final PsiElement psiElement = element.getElement(); + final PsiElement psiElement = element.getPointer().getContainingFile(); if (psiElement != null) { if (myContext != null) { final Tools tools = myContext.getTools().get(getShortName()); From 4328612df80dabdf4ec02c062cdc9745cfb6d143 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 18 Apr 2012 10:16:29 +0200 Subject: [PATCH 05/24] export inspection results: logging --- .../intellij/codeInspection/ex/GlobalInspectionContextImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index 36e27ed70db5..34c5757bc028 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -341,7 +341,7 @@ public class GlobalInspectionContextImpl extends UserDataHolderBase implements G ((InspectionTool)state.getTool()).exportResults(element, refEntity); } catch (Exception e) { - LOG.error(e); + LOG.error("Problem when exporting: " + refEntity.getExternalName(), e); } } } From 44f831119aceaaf9a2bb365bf2f056012e150b20 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Wed, 18 Apr 2012 13:20:28 +0400 Subject: [PATCH 06/24] OC-3672 Comment line doesn't move cursor on the next line if it is located next to a argument placeholder --- .../generation/CommentByLineCommentHandler.java | 8 +++++++- .../com/intellij/openapi/editor/impl/CaretModelImpl.java | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java index 95058b4fba54..5fb421a74221 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java @@ -97,6 +97,12 @@ public class CommentByLineCommentHandler implements CodeInsightActionHandler { myStartOffset = selectionModel.getSelectionStart(); myEndOffset = selectionModel.getSelectionEnd(); + FoldRegion fold = myEditor.getFoldingModel().getCollapsedRegionAtOffset(myStartOffset); + if (fold != null && fold.shouldNeverExpand() && fold.getStartOffset() == myStartOffset && fold.getEndOffset() == myEndOffset) { + // Foldings that never expand are automatically selected, so the fact it is selected must not interfer with commenter's logic + hasSelection = false; + } + if (myDocument.getTextLength() == 0) return; while (true) { @@ -648,4 +654,4 @@ public class CommentByLineCommentHandler implements CodeInsightActionHandler { } } } -} \ No newline at end of file +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index 7550c73112b6..7344d2b74d15 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -196,6 +196,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, for (CaretListener listener : myCaretListeners) { listener.caretPositionChanged(event); } + EditorActionUtil.selectNonexpandableFold(myEditor); } } @@ -237,6 +238,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, for (CaretListener listener : myCaretListeners) { listener.caretPositionChanged(event); } + EditorActionUtil.selectNonexpandableFold(myEditor); } } @@ -593,6 +595,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, listener.caretPositionChanged(event); } } + EditorActionUtil.selectNonexpandableFold(myEditor); } return null; } From 44fbfceeffb8b3bff1844ec666f1be55a28356ce Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 17 Apr 2012 13:07:16 +0200 Subject: [PATCH 07/24] [^ann] IDEA-84691 Groovy run configuration factory name was changed without legacy recognition --- plugins/groovy/src/META-INF/plugin.xml | 1 + .../groovy/config/GroovyProjectConverter.java | 2 +- ...oovyRunConfigurationConverterProvider.java | 66 +++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyRunConfigurationConverterProvider.java diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index a271e68e9f9c..9fb7cc16c54c 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -354,6 +354,7 @@ + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyProjectConverter.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyProjectConverter.java index f8d76b8b0f80..97ab86f1eeea 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyProjectConverter.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyProjectConverter.java @@ -61,7 +61,7 @@ public class GroovyProjectConverter extends ProjectConverter { } else { element.setAttribute("type", wasGrails ? GRAILS_RUN_CONFIGURATION_TYPE : "GroovyScriptRunConfiguration"); - element.setAttribute("factoryName", wasGrails ? "Grails" : "Groovy Script"); + element.setAttribute("factoryName", wasGrails ? "Grails" : "Groovy"); } } else if (GRAILS_RUN_CONFIGURATION_TYPE.equals(confType) && diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyRunConfigurationConverterProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyRunConfigurationConverterProvider.java new file mode 100644 index 000000000000..16b3f3cc71cc --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyRunConfigurationConverterProvider.java @@ -0,0 +1,66 @@ +/* + * 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 org.jetbrains.plugins.groovy.config; + +import com.intellij.conversion.*; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; + +/** + * @author peter + */ +public class GroovyRunConfigurationConverterProvider extends ConverterProvider { + public GroovyRunConfigurationConverterProvider() { + super("groovy-script-run-configurations"); + } + + @NotNull + @Override + public String getConversionDescription() { + return "Groovy Script run configurations will be converted into a new format"; + } + + @NotNull + @Override + public ProjectConverter createConverter(@NotNull ConversionContext context) { + return new ProjectConverter() { + @Override + public ConversionProcessor createRunConfigurationsConverter() { + return new ConversionProcessor() { + @Override + public boolean isConversionNeeded(RunManagerSettings settings) { + for (Element element : settings.getRunConfigurations()) { + if ("Groovy Script".equals(element.getAttributeValue("factoryName"))) { + return true; + } + } + return false; + } + + @Override + public void process(RunManagerSettings settings) throws CannotConvertException { + for (Element element : settings.getRunConfigurations()) { + if ("Groovy Script".equals(element.getAttributeValue("factoryName"))) { + element.setAttribute("factoryName", "Groovy"); + } + } + } + }; + } + }; + } +} From 304d46bb965356c6aa2a880b41355b00b3de0ec2 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 17 Apr 2012 17:06:25 +0200 Subject: [PATCH 08/24] don't multiply dfa states up to infinity when comparing ints (NameUtil.MinusculeMatcher.matchAfterFragment too complex to analyze) --- .../dataFlow/DfaMemoryStateImpl.java | 60 +++++++++++-------- .../fixture/TernaryInWhileNotComplex.java | 25 ++++++++ .../DataFlowInspectionFixtureTest.java | 1 + 3 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/TernaryInWhileNotComplex.java diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index 2b4005a40ef8..82a0cc5358c3 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -297,9 +297,13 @@ public class DfaMemoryStateImpl implements DfaMemoryState { } } - private int getOrCreateEqClassIndex(DfaValue dfaValue) { + @Nullable("for boxed values which can't be compared by ==") + private Integer getOrCreateEqClassIndex(DfaValue dfaValue) { int i = getEqClassIndex(dfaValue); if (i != -1) return i; + if (!canBeReused(dfaValue) && !(((DfaBoxedValue)dfaValue).getWrappedValue() instanceof DfaConstValue)) { + return null; + } SortedIntSet aClass = new SortedIntSet(); aClass.add(dfaValue.getID()); myEqClasses.add(aClass); @@ -338,26 +342,28 @@ public class DfaMemoryStateImpl implements DfaMemoryState { for (int i = 0; i < myEqClasses.size(); i++) { SortedIntSet aClass = myEqClasses.get(i); if (aClass != null && aClass.contains(dfaValue.getID())) { - if (dfaValue instanceof DfaBoxedValue && !canBeReused(((DfaBoxedValue)dfaValue).getWrappedValue(), this) && aClass.size() > 1) return -1; + if (!canBeReused(dfaValue) && aClass.size() > 1) return -1; return i; } } return -1; } - private static boolean canBeReused(final DfaValue valueToWrap, final DfaMemoryState memoryState) { - if (valueToWrap instanceof DfaConstValue) { - return cacheable((DfaConstValue)valueToWrap); - } - else if (valueToWrap instanceof DfaVariableValue) { - if (PsiType.BOOLEAN.equals(((DfaVariableValue)valueToWrap).getPsiVariable().getType())) return true; - List values = ((DfaMemoryStateImpl)memoryState).getEqClassesFor(valueToWrap); - for (DfaValue value : values) { - if (value instanceof DfaConstValue && cacheable((DfaConstValue)value)) return true; + + private boolean canBeReused(final DfaValue dfaValue) { + if (dfaValue instanceof DfaBoxedValue) { + DfaValue valueToWrap = ((DfaBoxedValue)dfaValue).getWrappedValue(); + if (valueToWrap instanceof DfaConstValue) { + return cacheable((DfaConstValue)valueToWrap); + } + if (valueToWrap instanceof DfaVariableValue) { + if (PsiType.BOOLEAN.equals(((DfaVariableValue)valueToWrap).getPsiVariable().getType())) return true; + for (DfaValue value : getEqClassesFor(valueToWrap)) { + if (value instanceof DfaConstValue && cacheable((DfaConstValue)value)) return true; + } } return false; } - return false; - //throw new IllegalArgumentException(""+valueToWrap); + return true; } private static boolean cacheable(DfaConstValue dfaConstValue) { @@ -474,10 +480,10 @@ public class DfaMemoryStateImpl implements DfaMemoryState { if (dfaValue instanceof DfaVariableValue || dfaValue instanceof DfaConstValue) { DfaConstValue dfaNull = myFactory.getConstFactory().getNull(); - int c1Index = getOrCreateEqClassIndex(dfaValue); - int c2Index = getOrCreateEqClassIndex(dfaNull); + Integer c1Index = getOrCreateEqClassIndex(dfaValue); + Integer c2Index = getOrCreateEqClassIndex(dfaNull); - return c1Index == c2Index; + return c1Index != null && c1Index.equals(c2Index); } return false; @@ -485,13 +491,16 @@ public class DfaMemoryStateImpl implements DfaMemoryState { public boolean isNotNull(DfaVariableValue dfaVar) { DfaConstValue dfaNull = myFactory.getConstFactory().getNull(); - int c1Index = getOrCreateEqClassIndex(dfaVar); - int c2Index = getOrCreateEqClassIndex(dfaNull); + Integer c1Index = getOrCreateEqClassIndex(dfaVar); + Integer c2Index = getOrCreateEqClassIndex(dfaNull); + if (c1Index == null || c2Index == null) { + return false; + } long[] pairs = myDistinctClasses.toArray(); for (long pair : pairs) { - if (low(pair) == c1Index && high(pair) == c2Index || - high(pair) == c1Index && low(pair) == c2Index) { + if (c1Index.equals(low(pair)) && c2Index.equals(high(pair)) || + c1Index.equals(high(pair)) && c2Index.equals(low(pair))) { return true; } } @@ -637,15 +646,18 @@ public class DfaMemoryStateImpl implements DfaMemoryState { private boolean applyRelation(@NotNull final DfaValue dfaLeft, @NotNull final DfaValue dfaRight, boolean isNegated) { // DfaConstValue || DfaVariableValue - int c1Index = getOrCreateEqClassIndex(dfaLeft); - int c2Index = getOrCreateEqClassIndex(dfaRight); + Integer c1Index = getOrCreateEqClassIndex(dfaLeft); + Integer c2Index = getOrCreateEqClassIndex(dfaRight); + if (c1Index == null || c2Index == null) { + return true; + } if (!isNegated) { //Equals - if (c1Index == c2Index) return true; + if (c1Index.equals(c2Index)) return true; if (!uniteClasses(c1Index, c2Index)) return false; } else { // Not Equals - if (c1Index == c2Index) return false; + if (c1Index.equals(c2Index)) return false; makeClassesDistinct(c1Index, c2Index); } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/TernaryInWhileNotComplex.java b/java/java-tests/testData/inspection/dataFlow/fixture/TernaryInWhileNotComplex.java new file mode 100644 index 000000000000..a1b2affe100e --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/TernaryInWhileNotComplex.java @@ -0,0 +1,25 @@ +import java.util.List; + +public class Foo { + public void matchAfterFragment(int patternIndex, int matchLen) { + int star = patternIndex < matchLen ? matchLen : -1; + while (matchLen > 0) { + int i = matchLen == star ? matchLen : star; + } + } + + public void matchAfterFragmentBoxed(Integer patternIndex, Integer matchLen) { + Integer star = patternIndex < matchLen ? matchLen : -1; + while (matchLen > 0) { + Integer i = matchLen == star ? matchLen : star; + } + } + + public void matchAfterFragmentSemiBoxed(Integer patternIndex, Integer matchLen) { + int star = patternIndex < matchLen ? matchLen : -1; + while (matchLen > 0) { + Integer i = matchLen == star ? matchLen : star; + } + } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java index a4b7ec1fe242..22407c7359ce 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java @@ -53,4 +53,5 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas /*public void testAnnReport() throws Throwable { doTest(); }*/ public void testBigMethodNotComplex() throws Throwable { doTest(); } + public void testTernaryInWhileNotComplex() throws Throwable { doTest(); } } From a58fdb19914eb66903335b1f54a6d95d70a7209c Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 17 Apr 2012 17:34:42 +0200 Subject: [PATCH 09/24] empty dfa stack when going to catch or finally in control flow --- .../codeInspection/dataFlow/ControlFlowAnalyzer.java | 2 ++ .../dataFlow/fixture/TryCatchInForNotComplex.java | 12 ++++++++++++ .../DataFlowInspectionFixtureTest.java | 1 + 3 files changed, 15 insertions(+) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/TryCatchInForNotComplex.java diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index e99d06cbf2ad..f51ac1972979 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -642,6 +642,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { pushUnknown(); final ConditionalGotoInstruction branch = new ConditionalGotoInstruction(-1, false, null); addInstruction(branch); + addInstruction(new EmptyStackInstruction()); addInstruction(new GosubInstruction(cd.getJumpOffset())); addInstruction(new ReturnInstruction()); branch.setOffset(myCurrentFlow.getInstructionCount()); @@ -651,6 +652,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor { pushUnknown(); final ConditionalGotoInstruction branch = new ConditionalGotoInstruction(-1, false, null); addInstruction(branch); + addInstruction(new EmptyStackInstruction()); addInstruction(new PushInstruction(myFactory.getNotNullFactory().create(myRuntimeException), null)); addGotoCatch(cd); branch.setOffset(myCurrentFlow.getInstructionCount()); diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/TryCatchInForNotComplex.java b/java/java-tests/testData/inspection/dataFlow/fixture/TryCatchInForNotComplex.java new file mode 100644 index 000000000000..909749168391 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/TryCatchInForNotComplex.java @@ -0,0 +1,12 @@ +public class Bar { + public static void main(String[] args) { + for (String s : args) { + try { + System.out.println(s); + } + catch (Exception e) { + System.out.println(e); + } + } + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java index 22407c7359ce..f01b63465068 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java @@ -54,4 +54,5 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas public void testBigMethodNotComplex() throws Throwable { doTest(); } public void testTernaryInWhileNotComplex() throws Throwable { doTest(); } + public void testTryCatchInForNotComplex() throws Throwable { doTest(); } } From 8a6f6f7a9d8e56f281492a652ebc3af389c27ad6 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 17 Apr 2012 18:13:25 +0200 Subject: [PATCH 10/24] synchronized block start should really flush fields --- .../dataFlow/DfaMemoryStateImpl.java | 8 ++++---- .../dataFlow/InstructionVisitor.java | 3 +++ .../instructions/PushInstruction.java | 6 ++++++ ...FieldChangedBetweenSynchronizedBlocks.java | 20 +++++++++++++++++++ .../DataFlowInspectionFixtureTest.java | 2 ++ .../DataFlowInspectionTest.java | 12 +++++++++++ 6 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/FieldChangedBetweenSynchronizedBlocks.java diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index 82a0cc5358c3..9364e3ecd374 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -718,8 +718,8 @@ public class DfaMemoryStateImpl implements DfaMemoryState { boolean resetNullability = isNotNull(field); flushVariable(field); if (resetNullability) { - getVariableState(field).setNullable(false); } + getVariableState(field).setNullable(false); } } @@ -728,15 +728,15 @@ public class DfaMemoryStateImpl implements DfaMemoryState { return; } - doFlash(variable); + doFlush(variable); } @Override public void flushVariableOutOfScope(DfaVariableValue variable) { - doFlash(variable); + doFlush(variable); } - private void doFlash(DfaVariableValue varPlain) { + private void doFlush(DfaVariableValue varPlain) { DfaVariableValue varNegated = (DfaVariableValue)varPlain.createNegated(); final int idPlain = varPlain.getID(); diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/InstructionVisitor.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/InstructionVisitor.java index 518b4621bab1..e9b2754724d0 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/InstructionVisitor.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/InstructionVisitor.java @@ -150,6 +150,9 @@ public abstract class InstructionVisitor { } public DfaInstructionState[] visitPush(PushInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) { + if (instruction.isFieldReference()) { + memState.fieldReferenced(); + } memState.push(instruction.getValue()); return nextInstruction(instruction, runner, memState); } diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/PushInstruction.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/PushInstruction.java index f6c1257c8ad5..9bf11de1cb54 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/PushInstruction.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/instructions/PushInstruction.java @@ -31,6 +31,8 @@ import com.intellij.codeInspection.dataFlow.InstructionVisitor; import com.intellij.codeInspection.dataFlow.value.DfaUnknownValue; import com.intellij.codeInspection.dataFlow.value.DfaValue; import com.intellij.psi.PsiExpression; +import com.intellij.psi.PsiField; +import com.intellij.psi.PsiReferenceExpression; import org.jetbrains.annotations.NotNull; public class PushInstruction extends Instruction { @@ -59,4 +61,8 @@ public class PushInstruction extends Instruction { public String toString() { return "PUSH " + myValue; } + + public boolean isFieldReference() { + return myPlace instanceof PsiReferenceExpression && ((PsiReferenceExpression)myPlace).resolve() instanceof PsiField; + } } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/FieldChangedBetweenSynchronizedBlocks.java b/java/java-tests/testData/inspection/dataFlow/fixture/FieldChangedBetweenSynchronizedBlocks.java new file mode 100644 index 000000000000..411e3a086efc --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/FieldChangedBetweenSynchronizedBlocks.java @@ -0,0 +1,20 @@ +public class Bar { + private Object field; + private final Object lock = new Object(); + + public void main() { + synchronized (lock) { + if (field != null) { + return; + } + } + synchronized (lock) { + if (field != null) { + return; + } + if (field == null) { + System.out.println(); + } + } + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java index f01b63465068..251b4e6ed81c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java @@ -55,4 +55,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas public void testBigMethodNotComplex() throws Throwable { doTest(); } public void testTernaryInWhileNotComplex() throws Throwable { doTest(); } public void testTryCatchInForNotComplex() throws Throwable { doTest(); } + public void testFieldChangedBetweenSynchronizedBlocks() throws Throwable { doTest(); } + } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index dc0428ae3fa8..6e6ed040da94 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -9,9 +9,12 @@ package com.intellij.codeInspection; import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.slice.SliceTreeTest; import com.intellij.codeInspection.dataFlow.DataFlowInspection; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.testFramework.InspectionTestCase; +import junit.framework.Test; +import junit.framework.TestSuite; import org.jetbrains.annotations.NonNls; public class DataFlowInspectionTest extends InspectionTestCase { @@ -148,4 +151,13 @@ public class DataFlowInspectionTest extends InspectionTestCase { //public void testIDEADEV11033() throws Exception { doTest15(); } public void testSwitchEnumCases() throws Exception { doTest15(); } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTestSuite(DataFlowInspectionFixtureTest.class); + suite.addTestSuite(DataFlowInspectionTest.class); + suite.addTestSuite(SliceTreeTest.class); + return suite; + } + } From afb17f31a13f355ef6c51bf1db954863ba127aab Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 17 Apr 2012 21:03:41 +0200 Subject: [PATCH 11/24] Revert: [rollback] NotNullValues mustn't end up in equivalence classes table. (Check SliceTreeTest next time) (dec4450) --- .../codeInspection/dataFlow/DfaMemoryStateImpl.java | 7 +++---- .../codeInspection/DataFlowInspectionFixtureTest.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index 9364e3ecd374..d169fe49775f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -577,21 +577,20 @@ public class DfaMemoryStateImpl implements DfaMemoryState { return true; } - /* if (dfaRight instanceof DfaNotNullValue) { if (dfaLeft instanceof DfaVariableValue) { DfaVariableState varState = getVariableState((DfaVariableValue)dfaLeft); DfaVariableValue dfaVar = (DfaVariableValue)dfaLeft; DfaTypeValue type = myFactory.getTypeFactory().create(((DfaNotNullValue)dfaRight).getType()); if (isNegated) { - return varState.addNotInstanceofValue(type) || applyCondition(compareToNull(dfaVar, false)); + return varState.addNotInstanceofValue(type) || + applyCondition(myFactory.getRelationFactory().create(dfaVar, DfaUnknownValue.getInstance(), JavaTokenType.EQEQ, false)); } - return applyCondition(compareToNull(dfaVar, true)) && varState.setInstanceofValue(type); + return applyCondition(compareToNull(dfaVar, false)) && varState.setInstanceofValue(type); } return true; } - */ if (dfaRight == myFactory.getConstFactory().getNull() && dfaLeft instanceof DfaVariableValue) { final DfaVariableState varState = getVariableState((DfaVariableValue)dfaLeft); diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java index 251b4e6ed81c..f596460b3247 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java @@ -50,7 +50,7 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas public void testFieldInAnonymous() throws Throwable { doTest(); } public void testNullableField() throws Throwable { doTest(); } public void testCanBeNullDoesntImplyIsNull() throws Throwable { doTest(); } - /*public void testAnnReport() throws Throwable { doTest(); }*/ + public void testAnnReport() throws Throwable { doTest(); } public void testBigMethodNotComplex() throws Throwable { doTest(); } public void testTernaryInWhileNotComplex() throws Throwable { doTest(); } From c805dc4cdbe956ca8748a7013b31ee29b08660b2 Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 18 Apr 2012 12:06:44 +0200 Subject: [PATCH 12/24] check module conflicts if move directory (IDEA-62765) --- .../JavaMoveDirectoryWithClassesHelper.java | 11 ++++++++ .../MoveClassesOrPackagesImpl.java | 27 +++++++++++++------ .../util/RefactoringConflictsUtil.java | 2 +- .../MoveDirectoryWithClassesHelper.java | 8 ++++++ .../MoveDirectoryWithClassesProcessor.java | 3 +++ 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/JavaMoveDirectoryWithClassesHelper.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/JavaMoveDirectoryWithClassesHelper.java index ca4a899167a0..7e3838ac891d 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/JavaMoveDirectoryWithClassesHelper.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/JavaMoveDirectoryWithClassesHelper.java @@ -6,8 +6,10 @@ import com.intellij.psi.*; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.listeners.RefactoringElementListener; +import com.intellij.refactoring.util.RefactoringConflictsUtil; import com.intellij.usageView.UsageInfo; import com.intellij.util.Function; +import com.intellij.util.containers.MultiMap; import java.util.*; @@ -99,6 +101,15 @@ public class JavaMoveDirectoryWithClassesHelper extends MoveDirectoryWithClasses } } + @Override + public void preprocessUsages(Project project, + Set files, + UsageInfo[] infos, + PsiDirectory directory, + MultiMap conflicts) { + RefactoringConflictsUtil.analyzeModuleConflicts(project, files, infos, directory, conflicts); + } + @Override public void beforeMove(PsiFile psiFile) { ChangeContextUtil.encodeContextInfo(psiFile, true); diff --git a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesImpl.java b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesImpl.java index 47c4b9a8fb48..f732c2284200 100644 --- a/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesImpl.java +++ b/java/java-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveClassesOrPackagesImpl.java @@ -33,18 +33,15 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; -import com.intellij.refactoring.HelpID; -import com.intellij.refactoring.JavaRefactoringSettings; -import com.intellij.refactoring.PackageWrapper; -import com.intellij.refactoring.RefactoringBundle; +import com.intellij.refactoring.*; import com.intellij.refactoring.move.MoveCallback; import com.intellij.refactoring.rename.DirectoryAsPackageRenameHandlerBase; import com.intellij.refactoring.rename.RenameUtil; -import com.intellij.refactoring.util.CommonRefactoringUtil; -import com.intellij.refactoring.util.RefactoringUIUtil; -import com.intellij.refactoring.util.RefactoringUtil; -import com.intellij.refactoring.util.TextOccurrencesUtil; +import com.intellij.refactoring.ui.ConflictsDialog; +import com.intellij.refactoring.util.*; +import com.intellij.usageView.UsageInfo; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -326,6 +323,20 @@ public class MoveClassesOrPackagesImpl { if (!chooser.isOK()) return; final PsiDirectory selectedTarget = chooser.getSelectedDirectory(); if (selectedTarget == null) return; + final MultiMap conflicts = new MultiMap(); + RefactoringConflictsUtil.analyzeModuleConflicts(project, Arrays.asList(directories), UsageInfo.EMPTY_ARRAY, selectedTarget, conflicts); + if (!conflicts.isEmpty()) { + if (ApplicationManager.getApplication().isUnitTestMode()) { + throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values()); + } + else { + final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts); + conflictsDialog.show(); + if (!conflictsDialog.isOK()) { + return; + } + } + } final Ref ex = Ref.create(null); final String commandDescription = RefactoringBundle.message("moving.directories.command"); Runnable runnable = new Runnable() { diff --git a/java/java-impl/src/com/intellij/refactoring/util/RefactoringConflictsUtil.java b/java/java-impl/src/com/intellij/refactoring/util/RefactoringConflictsUtil.java index d5f6b4414ff3..9c2fb9458b3d 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/RefactoringConflictsUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/RefactoringConflictsUtil.java @@ -227,7 +227,7 @@ public class RefactoringConflictsUtil { final MultiMap conflicts) { if (scopes == null) return; for (final PsiElement scope : scopes) { - if (scope instanceof PsiPackage || scope instanceof PsiDirectory) return; + if (scope instanceof PsiPackage) return; } final Module targetModule = ModuleUtil.findModuleForFile(vFile, project); diff --git a/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesHelper.java b/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesHelper.java index 77401394a326..e68ffd487575 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesHelper.java +++ b/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesHelper.java @@ -11,12 +11,14 @@ import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFileHandler; import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesUtil; import com.intellij.usageView.UsageInfo; import com.intellij.util.Function; +import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; /** * @author ksafonov @@ -40,6 +42,12 @@ public abstract class MoveDirectoryWithClassesHelper { public abstract void afterMove(PsiElement newElement); + public void preprocessUsages(Project project, + Set files, + UsageInfo[] infos, + PsiDirectory directory, + MultiMap conflicts) {} + public static MoveDirectoryWithClassesHelper[] findAll() { return Extensions.getExtensions(EP_NAME); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesProcessor.java index 697be80c58dd..017c41d38b40 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/MoveDirectoryWithClassesProcessor.java @@ -123,6 +123,9 @@ public class MoveDirectoryWithClassesProcessor extends BaseRefactoringProcessor conflicts.putValue(psiFile, e.getMessage()); } } + for (MoveDirectoryWithClassesHelper helper : MoveDirectoryWithClassesHelper.findAll()) { + helper.preprocessUsages(myProject, myFilesToMove.keySet(), refUsages.get(), myTargetDirectory, conflicts); + } return showConflicts(conflicts, refUsages.get()); } From 0808cc0b316453858443437220908a4cc0039d9f Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 18 Apr 2012 14:55:17 +0400 Subject: [PATCH 13/24] windows virtual directory test --- .../vfs/local/LocalFileSystemTest.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java index e724acfe7420..e933b286b664 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java @@ -20,11 +20,9 @@ import com.intellij.ide.GeneralSettings; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.SafeWriteRequestor; -import com.intellij.openapi.vfs.VfsUtilCore; -import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.newvfs.ManagingFS; +import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem; import com.intellij.openapi.vfs.newvfs.RefreshQueue; import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; @@ -323,4 +321,17 @@ public class LocalFileSystemTest extends PlatformLangTestCase { FileUtil.delete(dir); } } + + public void testWindowsVirtualDirectory() throws Exception { + if (!SystemInfo.isWindows) return; + File file = new File("c:\\Documents and Settings\\desktop.ini"); + VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); + assertNotNull("File not found: " + file, virtualFile); + + System.out.println("desktop.ini found"); + NewVirtualFileSystem system = (NewVirtualFileSystem)virtualFile.getFileSystem(); + system = PersistentFS.replaceWithNativeFS(system); + + assertTrue(system.exists(virtualFile)); + } } From 5da15f18fe288c53ae7f8d935cfbbbd84183c8a5 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 18 Apr 2012 13:04:40 +0200 Subject: [PATCH 14/24] [^kb] 300px max lookup size -> 500px --- .../src/com/intellij/codeInsight/lookup/impl/LookupImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index a7c31b5a67dc..63170422bf1d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -1535,7 +1535,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable if (!myResizePending) { Dimension preferredSize = preferredLayoutSize(null); if (preferredSize.width != size.width) { - UISettings.getInstance().MAX_LOOKUP_WIDTH = Math.max(300, size.width); + UISettings.getInstance().MAX_LOOKUP_WIDTH = Math.max(500, size.width); } int listHeight = myList.getLastVisibleIndex() - myList.getFirstVisibleIndex() + 1; From b18e58e8ca99fabc71000ad8e6bfb7bc4ebbbed5 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 18 Apr 2012 13:20:23 +0200 Subject: [PATCH 15/24] overwrite 300px limit for existing users --- .../src/com/intellij/codeInsight/lookup/impl/LookupImpl.java | 4 ++-- platform/platform-api/src/com/intellij/ide/ui/UISettings.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 63170422bf1d..5b9d61aa4584 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -1520,7 +1520,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable public Dimension preferredLayoutSize(@Nullable Container parent) { int maxCellWidth = myLookupTextWidth + myCellRenderer.getIconIndent(); int scrollBarWidth = myScrollPane.getPreferredSize().width - myScrollPane.getViewport().getPreferredSize().width; - int listWidth = Math.min(scrollBarWidth + maxCellWidth, UISettings.getInstance().MAX_LOOKUP_WIDTH); + int listWidth = Math.min(scrollBarWidth + maxCellWidth, UISettings.getInstance().MAX_LOOKUP_WIDTH2); int adWidth = myAdComponent.getAdComponent().getPreferredSize().width; return new Dimension(Math.max(listWidth, adWidth), Math.min(mainPanel.getPreferredSize().height, myMaximumHeight)); @@ -1535,7 +1535,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable if (!myResizePending) { Dimension preferredSize = preferredLayoutSize(null); if (preferredSize.width != size.width) { - UISettings.getInstance().MAX_LOOKUP_WIDTH = Math.max(500, size.width); + UISettings.getInstance().MAX_LOOKUP_WIDTH2 = Math.max(500, size.width); } int listHeight = myList.getLastVisibleIndex() - myList.getFirstVisibleIndex() + 1; diff --git a/platform/platform-api/src/com/intellij/ide/ui/UISettings.java b/platform/platform-api/src/com/intellij/ide/ui/UISettings.java index a0cb9483c2c0..0d4a55e5b87a 100644 --- a/platform/platform-api/src/com/intellij/ide/ui/UISettings.java +++ b/platform/platform-api/src/com/intellij/ide/ui/UISettings.java @@ -93,7 +93,7 @@ public class UISettings implements PersistentStateComponent, Exporta public boolean DISABLE_MNEMONICS = SystemInfo.isMac; // IDEADEV-33409, should be disabled by default on MacOS public boolean DISABLE_MNEMONICS_IN_CONTROLS = false; public boolean SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false; - public int MAX_LOOKUP_WIDTH = 500; + public int MAX_LOOKUP_WIDTH2 = 500; public int MAX_LOOKUP_LIST_HEIGHT = 11; public boolean HIDE_NAVIGATION_ON_FOCUS_LOSS = true; From 7c56c449ceb9d1491eb3b030bf8e15afedb7d593 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 18 Apr 2012 15:29:35 +0400 Subject: [PATCH 16/24] IDEA-82122 JSP ambiguous import conflict / priority (multiple choices) --- .../impl/source/resolve/ClassResolverProcessor.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java index 878ecce5a3ba..d1bcc1f39828 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/ClassResolverProcessor.java @@ -32,6 +32,7 @@ import java.util.Iterator; import java.util.List; public class ClassResolverProcessor extends BaseScopeProcessor implements NameHint, ElementClassHint { + private static final String[] DEFAULT_PACKAGES = new String[]{CommonClassNames.DEFAULT_PACKAGE}; private final String myClassName; private final PsiElement myPlace; private PsiClass myAccessClass = null; @@ -108,12 +109,16 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi String fqn = psiClass.getQualifiedName(); if (fqn == null) return false; + + PsiFile file = myPlace == null ? null : FileContextUtil.getContextFile(myPlace); + + String[] defaultPackages = file instanceof PsiJavaFile ? ((PsiJavaFile)file).getImplicitlyImportedPackages() : DEFAULT_PACKAGES; String packageName = StringUtil.getPackageName(fqn); - if (CommonClassNames.DEFAULT_PACKAGE.equals(packageName)) return true; + for (String defaultPackage : defaultPackages) { + if (defaultPackage.equals(packageName)) return true; + } // class from my package imported implicitly - PsiFile file = myPlace == null ? null : FileContextUtil.getContextFile(myPlace); - return file instanceof PsiJavaFile && ((PsiJavaFile)file).getPackageName().equals(packageName); } From 990dde0d1c58d2ebe4ba61724ade502accbda452 Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Wed, 18 Apr 2012 15:49:29 +0400 Subject: [PATCH 17/24] EA-359528: ApplicationImpl.assertReadAccessAllowed() in MavenExternalParameters.createJavaParameters() --- .../idea/maven/execution/MavenExecutor.java | 11 ++--- .../execution/MavenExternalExecutor.java | 34 +++++++++---- .../idea/maven/execution/MavenRunner.java | 48 ++++++++++++------- .../tasks/MavenBeforeRunTasksProvider.java | 18 ++++--- 4 files changed, 70 insertions(+), 41 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExecutor.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExecutor.java index 1ee28ac6c98e..451fe53d6074 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExecutor.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExecutor.java @@ -20,6 +20,7 @@ package org.jetbrains.idea.maven.execution; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; +import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.project.MavenConsole; import org.jetbrains.idea.maven.project.MavenGeneralSettings; import org.jetbrains.idea.maven.server.MavenServerConsole; @@ -28,8 +29,6 @@ import java.text.MessageFormat; public abstract class MavenExecutor { final MavenRunnerParameters myParameters; - final MavenGeneralSettings myCoreSettings; - final MavenRunnerSettings myRunnerSettings; private final String myCaption; protected MavenConsole myConsole; private String myAction; @@ -39,13 +38,9 @@ public abstract class MavenExecutor { private int exitCode = 0; public MavenExecutor(MavenRunnerParameters parameters, - MavenGeneralSettings coreSettings, - MavenRunnerSettings runnerSettings, String caption, MavenConsole console) { myParameters = parameters; - myCoreSettings = coreSettings; - myRunnerSettings = runnerSettings; myCaption = caption; myConsole = console; } @@ -58,7 +53,7 @@ public abstract class MavenExecutor { return myConsole; } - public void setAction(final String action) { + public void setAction(@Nullable final String action) { myAction = action; } @@ -113,5 +108,5 @@ public abstract class MavenExecutor { } } - public abstract boolean execute(ProgressIndicator indicator); + public abstract boolean execute(@Nullable ProgressIndicator indicator); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalExecutor.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalExecutor.java index 988ff62cf6b1..dee6065e8e34 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalExecutor.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenExternalExecutor.java @@ -19,6 +19,7 @@ package org.jetbrains.idea.maven.execution; import com.intellij.execution.ExecutionException; +import com.intellij.execution.configurations.JavaParameters; import com.intellij.execution.process.DefaultJavaProcessHandler; import com.intellij.execution.process.OSProcessHandler; import com.intellij.openapi.application.ApplicationManager; @@ -26,6 +27,8 @@ import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.project.MavenConsole; import org.jetbrains.idea.maven.project.MavenGeneralSettings; import org.jetbrains.idea.maven.server.MavenServerConsole; @@ -36,24 +39,35 @@ public class MavenExternalExecutor extends MavenExecutor { @NonNls private static final String PHASE_INFO_REGEXP = "\\[INFO\\] \\[.*:.*\\]"; @NonNls private static final int INFO_PREFIX_SIZE = "[INFO] ".length(); - private final Project myProject; + + private JavaParameters myJavaParameters; + private ExecutionException myParameterCreationError; public MavenExternalExecutor(Project project, - MavenRunnerParameters parameters, - MavenGeneralSettings coreSettings, - MavenRunnerSettings runnerSettings, - MavenConsole console) { - super(parameters, coreSettings, runnerSettings, RunnerBundle.message("external.executor.caption"), console); - myProject = project; + @NotNull MavenRunnerParameters parameters, + @Nullable MavenGeneralSettings coreSettings, + @Nullable MavenRunnerSettings runnerSettings, + @NotNull MavenConsole console) { + super(parameters, RunnerBundle.message("external.executor.caption"), console); + + try { + myJavaParameters = MavenExternalParameters.createJavaParameters(project, myParameters, coreSettings, runnerSettings); + } + catch (ExecutionException e) { + myParameterCreationError = e; + } } public boolean execute(final ProgressIndicator indicator) { displayProgress(); try { + if (myParameterCreationError != null) { + throw myParameterCreationError; + } + myProcessHandler = - new DefaultJavaProcessHandler( - MavenExternalParameters.createJavaParameters(myProject, myParameters, myCoreSettings, myRunnerSettings)) { + new DefaultJavaProcessHandler(myJavaParameters) { public void notifyTextAvailable(String text, Key outputType) { // todo move this logic to ConsoleAdapter class if (!myConsole.isSuppressed(text)) { @@ -91,7 +105,7 @@ public class MavenExternalExecutor extends MavenExecutor { myProcessHandler.waitFor(); } - private void updateProgress(final ProgressIndicator indicator, final String text) { + private void updateProgress(@Nullable final ProgressIndicator indicator, final String text) { if (indicator != null) { if (indicator.isCanceled()) { if (!isCancelled()) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunner.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunner.java index d8372bf7f7c8..aa647520f110 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunner.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunner.java @@ -15,7 +15,9 @@ */ package org.jetbrains.idea.maven.execution; +import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; @@ -26,7 +28,6 @@ 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.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.maven.project.MavenConsole; @@ -65,10 +66,9 @@ public class MavenRunner implements PersistentStateComponent commands, @Nullable MavenGeneralSettings coreSettings, @Nullable MavenRunnerSettings runnerSettings, @Nullable final String action, - ProgressIndicator indicator) { + @Nullable ProgressIndicator indicator) { + assert !ApplicationManager.getApplication().isReadAccessAllowed(); + if (commands.isEmpty()) return true; - final MavenGeneralSettings effectiveCoreSettings = coreSettings != null ? coreSettings : getGeneralSettings(); - final MavenRunnerSettings effectiveRunnerSettings = runnerSettings != null ? runnerSettings : getState(); + MavenConsole console; + + AccessToken accessToken = ReadAction.start(); + try { + if (myProject.isDisposed()) return false; + console = createConsole(); + } + finally { + accessToken.finish(); + } - MavenConsole console = createConsole(effectiveCoreSettings, null); try { int count = 0; for (MavenRunnerParameters command : commands) { @@ -136,7 +141,17 @@ public class MavenRunner implements PersistentStateComponent parametersAndSettings) { + private MavenConsole createConsole() { if (ApplicationManager.getApplication().isUnitTestMode()) { return new SoutMavenConsole(); } @@ -167,8 +181,8 @@ public class MavenRunner implements PersistentStateComponent { @@ -76,6 +78,7 @@ public class MavenBeforeRunTasksProvider extends BeforeRunTaskProvider getProjectAndGoalChecked(MavenBeforeRunTask task) { String path = task.getProjectPath(); String goal = task.getGoal(); @@ -129,6 +132,9 @@ public class MavenBeforeRunTasksProvider extends BeforeRunTaskProvider explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles(); + final MavenRunner mavenRunner = MavenRunner.getInstance(project); + targetDone.down(); new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) { public void run(@NotNull ProgressIndicator indicator) { @@ -137,13 +143,13 @@ public class MavenBeforeRunTasksProvider extends BeforeRunTaskProvider Date: Wed, 18 Apr 2012 15:54:28 +0400 Subject: [PATCH 18/24] EA-35641: IndexOutOfBoundsException in MavenResumeAction --- .../org/jetbrains/idea/maven/execution/MavenResumeAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenResumeAction.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenResumeAction.java index ef58e4603d20..c4ac16e22f89 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenResumeAction.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenResumeAction.java @@ -143,7 +143,7 @@ public class MavenResumeAction extends AnAction { case STATE_WAIT_FOR_BUILD: if (textWithoutInfo.startsWith("Building ")) { String projectName = textWithoutInfo.substring("Building ".length()); - if (myBuildingProjectIndex > myMavenProjectNames.size() || + if (myBuildingProjectIndex >= myMavenProjectNames.size() || !projectName.startsWith(myMavenProjectNames.get(myBuildingProjectIndex))) { myState = STATE_WTF; log(String.format("Invalid project building order. Defined order: %s, error index: %d, invalid line: %s", From fe9e90548a2d676c6d58f5d07e5eb00c539af710 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Wed, 18 Apr 2012 16:15:14 +0400 Subject: [PATCH 19/24] IDEA-84489 --- .../dataFlow/StandardInstructionVisitor.java | 5 +++-- .../inspection/dataFlow/fixture/IDEA84489.java | 11 +++++++++++ .../codeInspection/DataFlowInspectionFixtureTest.java | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/IDEA84489.java diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java index ee177909adad..fca310c9f390 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java @@ -289,8 +289,6 @@ public class StandardInstructionVisitor extends InstructionVisitor { } else if (JavaTokenType.PLUS == opSign) { memState.push(instruction.getNonNullStringValue(factory)); - instruction.setTrueReachable(); // Not a branching instruction actually. - instruction.setFalseReachable(); } else { if (instruction instanceof InstanceofInstruction) { @@ -319,6 +317,9 @@ public class StandardInstructionVisitor extends InstructionVisitor { memState.push(DfaUnknownValue.getInstance()); } + instruction.setTrueReachable(); // Not a branching instruction actually. + instruction.setFalseReachable(); + return nextInstruction(instruction, runner, memState); } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/IDEA84489.java b/java/java-tests/testData/inspection/dataFlow/fixture/IDEA84489.java new file mode 100644 index 000000000000..20230a7e1e56 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/IDEA84489.java @@ -0,0 +1,11 @@ +class Main { + static class User { + public int RegistrationState; + } + + public static void fun(User user) { + if ((user.RegistrationState == 5 || user.RegistrationState == 10) == true) { + + } + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java index f596460b3247..52bf9c73e8de 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java @@ -57,4 +57,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas public void testTryCatchInForNotComplex() throws Throwable { doTest(); } public void testFieldChangedBetweenSynchronizedBlocks() throws Throwable { doTest(); } + public void testIDEA84489() throws Throwable { doTest(); } + } From 18a26b46d9bc33f0c77224ecdad515ce9a86aaaa Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Wed, 18 Apr 2012 16:28:18 +0400 Subject: [PATCH 20/24] change assert x to Logger.assertTrue(x) --- .../org/jetbrains/idea/maven/execution/MavenRunner.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunner.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunner.java index aa647520f110..b3eb40f1418e 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunner.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/execution/MavenRunner.java @@ -22,6 +22,7 @@ import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; @@ -40,6 +41,9 @@ import java.util.List; @State(name = "MavenRunner", storages = {@Storage( file = "$WORKSPACE_FILE$")}) public class MavenRunner implements PersistentStateComponent { + + private static final Logger LOG = Logger.getInstance("#org.jetbrains.idea.maven.execution.MavenRunner"); + private MavenRunnerSettings mySettings = new MavenRunnerSettings(); private final Project myProject; @@ -119,7 +123,7 @@ public class MavenRunner implements PersistentStateComponent Date: Wed, 18 Apr 2012 14:50:07 +0200 Subject: [PATCH 21/24] IDEA-84781 (no more double free) --- .../src/com/intellij/ui/mac/MacFileChooserDialogImpl.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java b/platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java index b29031c6ed37..ea9d175ac0da 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java @@ -223,8 +223,6 @@ public class MacFileChooserDialogImpl implements PathChooserDialog { directory, file, types, focusedWindow, self, Foundation.createSelector("openPanelDidEnd:returnCode:contextInfo:"), null); } } - - Foundation.cfRelease(directory, file, types); } }; From 3235961d126a3d25787cb6ded1ccc561bd1a4728 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 18 Apr 2012 14:51:29 +0200 Subject: [PATCH 22/24] Fix reorder task --- build/scripts/layouts.gant | 1 + 1 file changed, 1 insertion(+) diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index 6381e2e9eab8..640780b32468 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -498,6 +498,7 @@ def reorder(String home, String targetDirectory) { arg(value: "$home/lib") classpath { pathelement(location: util.output) + pathelement(location: getProperty('util-rt').output) pathelement(location: "$home/lib/jna.jar") pathelement(location: "$home/lib/trove4j.jar") } From 290c10755a55b11818955f789832896a9aa3adfa Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 18 Apr 2012 17:15:05 +0400 Subject: [PATCH 23/24] IDEA-84350 Synchronize action causes UI Freeze: Win32Kernel does not work under junction points, so we need a fallback to Java implementation --- .../openapi/vfs/impl/win32/Win32Kernel.java | 18 +++++++++-------- .../vfs/impl/win32/Win32LocalFileSystem.java | 20 ++++++++++++++----- .../vfs/local/LocalFileSystemTest.java | 3 ++- 3 files changed, 27 insertions(+), 14 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 f99169a8d569..78b60daab2b9 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 @@ -64,8 +64,8 @@ public class Win32Kernel { return ArrayUtil.toStringArray(names); } - public boolean exists(String path) { - return doGetInfo(path) != null; + public void exists(String path) throws FileNotFoundException { + getInfo(path); } public boolean isDirectory(String path) throws FileNotFoundException { @@ -88,6 +88,7 @@ public class Win32Kernel { return getInfo(path).length; } + @NotNull private FileInfo getInfo(String path) throws FileNotFoundException { FileInfo info = doGetInfo(path); if (info == null) { @@ -110,20 +111,21 @@ public class Win32Kernel { } @FileUtil.FileBooleanAttributes - public int getBooleanAttributes(@NotNull String path, @FileUtil.FileBooleanAttributes int flags) { - FileInfo info = doGetInfo(path); + public int getBooleanAttributes(@NotNull String path, @FileUtil.FileBooleanAttributes int flags) throws FileNotFoundException { + FileInfo info = getInfo(path); int result = 0; if ((flags & FileUtil.BA_EXISTS) != 0) { - result |= info == null ? 0 : FileUtil.BA_EXISTS; + result |= FileUtil.BA_EXISTS; } if ((flags & FileUtil.BA_DIRECTORY) != 0) { - result |= info == null || (info.attributes & FILE_ATTRIBUTE_DIRECTORY) == 0 ? 0 : FileUtil.BA_DIRECTORY; + result |= (info.attributes & FILE_ATTRIBUTE_DIRECTORY) == 0 ? 0 : FileUtil.BA_DIRECTORY; } if ((flags & FileUtil.BA_REGULAR) != 0) { - result |= info == null || (info.attributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_REPARSE_POINT)) != 0 ? 0 : FileUtil.BA_REGULAR; + result |= (info.attributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_REPARSE_POINT)) != 0 + ? 0 : FileUtil.BA_REGULAR; } if ((flags & FileUtil.BA_HIDDEN) != 0) { - result |= info == null || (info.attributes & FILE_ATTRIBUTE_HIDDEN) == 0 ? 0 : FileUtil.BA_HIDDEN; + result |= (info.attributes & FILE_ATTRIBUTE_HIDDEN) == 0 ? 0 : FileUtil.BA_HIDDEN; } return result; } 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 0bba1c9e3913..3f1829355b65 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 @@ -118,11 +118,16 @@ public class Win32LocalFileSystem extends LocalFileSystemBase { @Override public boolean exists(@NotNull VirtualFile fileOrDirectory) { if (fileOrDirectory.getParent() == null) return true; - boolean b = myKernel.exists(fileOrDirectory.getPath()); - if (checkMe && b != super.exists(fileOrDirectory)) { - LOG.error(fileOrDirectory.getPath()); + try { + myKernel.exists(fileOrDirectory.getPath()); + if (checkMe && !super.exists(fileOrDirectory)) { + LOG.error(fileOrDirectory.getPath()); + } + return true; + } + catch (FileNotFoundException e) { + return super.exists(fileOrDirectory); } - return b; } @Override @@ -199,7 +204,12 @@ public class Win32LocalFileSystem extends LocalFileSystemBase { @Override public int getBooleanAttributes(@NotNull VirtualFile file, int flags) { - return myKernel.getBooleanAttributes(file.getPath(), flags); + try { + return myKernel.getBooleanAttributes(file.getPath(), flags); + } + catch (FileNotFoundException e) { + return super.getBooleanAttributes(file, flags); + } } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java index e933b286b664..76f2f10ef1f1 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java @@ -328,10 +328,11 @@ public class LocalFileSystemTest extends PlatformLangTestCase { VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); assertNotNull("File not found: " + file, virtualFile); - System.out.println("desktop.ini found"); NewVirtualFileSystem system = (NewVirtualFileSystem)virtualFile.getFileSystem(); system = PersistentFS.replaceWithNativeFS(system); assertTrue(system.exists(virtualFile)); + int childAttributes = system.getBooleanAttributes(virtualFile, -1); + assertTrue((childAttributes & FileUtil.BA_EXISTS) != 0); } } From 71c0022eca5b13954ebaa21986a4ae27cc102359 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Wed, 18 Apr 2012 17:22:31 +0400 Subject: [PATCH 24/24] Nested caret moves fixed --- .../src/com/intellij/openapi/editor/impl/CaretModelImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index 7344d2b74d15..80a7541243cd 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -595,7 +595,6 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, listener.caretPositionChanged(event); } } - EditorActionUtil.selectNonexpandableFold(myEditor); } return null; }