diff --git a/.idea/libraries/Eclipse.xml b/.idea/libraries/Eclipse.xml index 270d58e2ae95..f680844b8415 100644 --- a/.idea/libraries/Eclipse.xml +++ b/.idea/libraries/Eclipse.xml @@ -1,7 +1,7 @@ - + diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java index 48dbf15eda4b..d45440dbe99a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java @@ -298,9 +298,7 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp return null; } PsiType type = typeElement.getType(); - if (type instanceof PsiPrimitiveType) return null; - type = type.getDeepComponentType(); - if (type instanceof PsiClassType && (((PsiClassType)type).resolve() instanceof PsiTypeParameter)) return null; + if (type instanceof PsiPrimitiveType || PsiUtil.resolveClassInType(type) instanceof PsiTypeParameter) return null; return expression; } } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/InlineStreamMapAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/InlineStreamMapAction.java index 7dbb7f3a3fce..cf3dcba1c3a5 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/InlineStreamMapAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/InlineStreamMapAction.java @@ -31,8 +31,8 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.util.LambdaRefactoringUtil; import com.intellij.util.IncorrectOperationException; import com.siyeh.ig.psiutils.ParenthesesUtils; -import com.siyeh.ig.style.MethodRefCanBeReplacedWithLambdaInspection; import one.util.streamex.StreamEx; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -87,8 +87,7 @@ public class InlineStreamMapAction extends PsiElementBaseIntentionAction { return lambdaExpression.getParameterList().getParametersCount() == 1 && (!requireExpressionLambda || LambdaUtil.extractSingleExpressionFromBody(lambdaExpression.getBody()) != null); } else if(expression instanceof PsiMethodReferenceExpression) { - PsiMethodReferenceExpression methodReference = (PsiMethodReferenceExpression)expression; - return !MethodRefCanBeReplacedWithLambdaInspection.isWithSideEffects(methodReference); + return LambdaRefactoringUtil.canConvertToLambda((PsiMethodReferenceExpression)expression); } return false; } @@ -161,12 +160,29 @@ public class InlineStreamMapAction extends PsiElementBaseIntentionAction { } } if(nextName.equals("flatMap") && prevClassName.equals(CommonClassNames.JAVA_UTIL_STREAM_STREAM)) { - String mapMethod = translateMap(prevName); - return "flatM"+mapMethod.substring(1); + return mapToFlatMap(prevName); } return null; } + @Contract(pure = true) + @Nullable + private static String mapToFlatMap(String mapMethod) { + switch (mapMethod) { + case "map": + return "flatMap"; + case "mapToInt": + return "flatMapToInt"; + case "mapToLong": + return "flatMapToLong"; + case "mapToDouble": + return "flatMapToDouble"; + } + // Something unsupported passed: ignore + return null; + } + + @Contract(pure = true) @NotNull private static String translateMap(String nextMethod) { switch (nextMethod) { diff --git a/java/java-impl/src/com/intellij/refactoring/util/LambdaRefactoringUtil.java b/java/java-impl/src/com/intellij/refactoring/util/LambdaRefactoringUtil.java index 6763e30c1864..e5d467213976 100644 --- a/java/java-impl/src/com/intellij/refactoring/util/LambdaRefactoringUtil.java +++ b/java/java-impl/src/com/intellij/refactoring/util/LambdaRefactoringUtil.java @@ -77,7 +77,6 @@ public class LambdaRefactoringUtil { final PsiParameter[] psiParameters = resolve instanceof PsiMethod ? ((PsiMethod)resolve).getParameterList().getParameters() : null; final StringBuilder buf = new StringBuilder("("); - LOG.assertTrue(functionalInterfaceType != null); buf.append(GenericsUtil.getVariableTypeByExpressionType(functionalInterfaceType).getCanonicalText()).append(")("); final PsiParameterList parameterList = interfaceMethod.getParameterList(); final PsiParameter[] parameters = parameterList.getParameters(); @@ -103,6 +102,7 @@ public class LambdaRefactoringUtil { else { initialName = parameter.getName(); } + LOG.assertTrue(initialName != null); baseName = codeStyleManager.variableNameToPropertyName(initialName, VariableKind.PARAMETER); } @@ -265,4 +265,16 @@ public class LambdaRefactoringUtil { } } } + + /** + * Checks whether method reference can be converted to lambda without significant semantics change + * (i.e. method reference qualifier has no side effects) + * + * @param methodReferenceExpression method reference to check + * @return true if method reference can be converted to lambda + */ + public static boolean canConvertToLambda(PsiMethodReferenceExpression methodReferenceExpression) { + final PsiExpression qualifierExpression = methodReferenceExpression.getQualifierExpression(); + return qualifierExpression != null && !SideEffectChecker.mayHaveSideEffects(qualifierExpression); + } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/OrderEntryTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/OrderEntryTest.java index d6cf7e6a9ad0..5768afa9a718 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/OrderEntryTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/quickFix/OrderEntryTest.java @@ -100,7 +100,7 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase { private IntentionAction findActionAndCheck(final ActionHint actionHint, Collection infosBefore) { List actions = LightQuickFixTestCase.getAvailableActions(getEditor(), getFile()); - return actionHint.findAndCheck(actions, () -> "Infos: " + infosBefore); + return actionHint.findAndCheck(actions, "Infos: " + infosBefore); } public void testAddDependency() throws Exception { diff --git a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java index a6aaa7011c06..b6161f23c3ae 100644 --- a/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java +++ b/java/structuralsearch-java/src/com/intellij/structuralsearch/JavaStructuralSearchProfile.java @@ -517,7 +517,7 @@ public class JavaStructuralSearchProfile extends StructuralSearchProfile { } @Override - Configuration[] getPredefinedTemplates() { + public Configuration[] getPredefinedTemplates() { return JavaPredefinedConfigurations.createPredefinedTemplates(); } diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java index 425a6558ba4e..b0bc698ad4c6 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java @@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -72,19 +71,19 @@ public class ActionHint { * if this ActionHint asserts that no action should be present. * * @param actions actions collection to search inside - * @param infoSupplier a supplier which provides additional info which will be appended to exception message if check fails + * @param errorMessage an additional error message which will be appended to exception message if check fails * @return the action or null * @throws AssertionError if no action is found, but it should present, or if action is found, but it should not present. */ @Nullable - public IntentionAction findAndCheck(Collection actions, Supplier infoSupplier) { + public IntentionAction findAndCheck(@NotNull Collection actions, @NotNull String errorMessage) { IntentionAction result = actions.stream().filter(t -> t.getText().equals(myExpectedText)).findFirst().orElse(null); if(result == null && myShouldPresent) { fail("Action with text '" + myExpectedText + "' not found\nAvailable actions: " + actions.stream().map(IntentionAction::getText).collect(Collectors.joining(", ", "[", "]\n")) + - infoSupplier.get()); + errorMessage); } else if(result != null && !myShouldPresent) { - fail("Action with text '" + myExpectedText + "' is present, but should not\n" + infoSupplier.get()); + fail("Action with text '" + myExpectedText + "' is present, but should not\n" + errorMessage); } return result; } diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java index 19ec879a4f35..7abf74ec5e7b 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixTestCase.java @@ -103,7 +103,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase String testName, QuickFixTestCase quickFix) throws Exception { IntentionAction action = actionHint.findAndCheck(quickFix.getAvailableActions(), - () -> "Test: "+testFullPath+"\nInfos: "+quickFix.doHighlighting()); + "Test: "+testFullPath+"\nInfos: "+quickFix.doHighlighting()); if (action != null) { String text = action.getText(); quickFix.invoke(action); @@ -157,7 +157,7 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase } protected IntentionAction findActionAndCheck(@NotNull ActionHint hint, String testFullPath) { - return hint.findAndCheck(getAvailableActions(), () -> "Test: "+testFullPath); + return hint.findAndCheck(getAvailableActions(), "Test: "+testFullPath); } protected IntentionAction findActionWithText(@NotNull String text) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/builders/impl/java/EclipseCompilerTool.java b/jps/jps-builders/src/org/jetbrains/jps/builders/impl/java/EclipseCompilerTool.java index a76b5d8fcf02..22630d16bfd6 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/builders/impl/java/EclipseCompilerTool.java +++ b/jps/jps-builders/src/org/jetbrains/jps/builders/impl/java/EclipseCompilerTool.java @@ -26,7 +26,7 @@ import org.jetbrains.jps.incremental.CompileContext; import org.jetbrains.jps.incremental.Utils; import org.jetbrains.jps.model.java.compiler.JavaCompilers; -import javax.tools.*; +import javax.tools.JavaCompiler; import java.io.File; import java.io.FilenameFilter; import java.util.Collections; @@ -34,6 +34,9 @@ import java.util.List; import java.util.ServiceLoader; /** + * The latest version of ecj batch compiler can be found here: + * http://download.eclipse.org/eclipse/downloads/ + * * @author nik */ public class EclipseCompilerTool extends JavaCompilingTool { diff --git a/lib/ecj-4.5.2.jar b/lib/ecj-4.5.2.jar deleted file mode 100644 index 7457eda29057..000000000000 Binary files a/lib/ecj-4.5.2.jar and /dev/null differ diff --git a/lib/ecj-4.6.1.jar b/lib/ecj-4.6.1.jar new file mode 100644 index 000000000000..1c7e9cad3046 Binary files /dev/null and b/lib/ecj-4.6.1.jar differ diff --git a/lib/required_for_dist.txt b/lib/required_for_dist.txt index 9ca949275b3c..38879ce13c8b 100644 --- a/lib/required_for_dist.txt +++ b/lib/required_for_dist.txt @@ -13,7 +13,7 @@ httpcore-4.4.5.jar httpclient-4.5.2.jar fluent-hc-4.5.2.jar httpmime-4.5.2.jar -ecj-4.5.2.jar +ecj-4.6.1.jar groovy-all-2.4.6.jar gson-2.5.jar guava-19.0.jar diff --git a/platform/duplicates-analysis/src/com/intellij/dupLocator/AbstractMatchingVisitor.java b/platform/duplicates-analysis/src/com/intellij/dupLocator/AbstractMatchingVisitor.java index 0b6bd6519edd..71202aa31898 100644 --- a/platform/duplicates-analysis/src/com/intellij/dupLocator/AbstractMatchingVisitor.java +++ b/platform/duplicates-analysis/src/com/intellij/dupLocator/AbstractMatchingVisitor.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2016 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.dupLocator; import com.intellij.dupLocator.util.NodeFilter; @@ -85,11 +100,11 @@ public abstract class AbstractMatchingVisitor { ); } - protected boolean isLeftLooseMatching() { + public boolean isLeftLooseMatching() { return true; } - protected boolean isRightLooseMatching() { + public boolean isRightLooseMatching() { return true; } diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index a29b9b4d6c33..a2dac56738a7 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -532,11 +532,19 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo public void setSelected(AnActionEvent event, boolean flag) { final AbstractProjectViewPane viewPane = getCurrentProjectViewPane(); final SelectionInfo selectionInfo = SelectionInfo.create(viewPane); - + if (isGlobalOptions()) { + setFlattenPackages(flag, viewPane.getId()); + } super.setSelected(event, flag); selectionInfo.apply(viewPane); } + + @Override + public boolean isSelected(AnActionEvent event) { + if (isGlobalOptions()) return getGlobalOptions().getFlattenPackages(); + return super.isSelected(event); + } }).setAsSecondary(true); } @@ -549,6 +557,14 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo super(optionsMap, text, description, icon, optionDefaultValue); } + @Override + public void setSelected(AnActionEvent event, boolean flag) { + if (isGlobalOptions()) { + getGlobalOptions().setFlattenPackages(flag); + } + super.setSelected(event, flag); + } + @Override public void update(AnActionEvent e) { super.update(e); @@ -1376,8 +1392,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo public void setFlattenPackages(boolean flattenPackages, String paneId) { if (isGlobalOptions()) { getGlobalOptions().setFlattenPackages(flattenPackages); + for (String pane : myFlattenPackages.keySet()) { + setPaneOption(myFlattenPackages, flattenPackages, pane, true); + } + } else { + setPaneOption(myFlattenPackages, flattenPackages, paneId, true); } - setPaneOption(myFlattenPackages, flattenPackages, paneId, true); } public boolean isFoldersAlwaysOnTop() { @@ -1477,8 +1497,12 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo public void setHideEmptyPackages(boolean hideEmptyPackages, @NotNull String paneId) { if (isGlobalOptions()) { getGlobalOptions().setHideEmptyPackages(hideEmptyPackages); + for (String pane : myHideEmptyPackages.keySet()) { + setPaneOption(myHideEmptyPackages, hideEmptyPackages, pane, true); + } + } else { + setPaneOption(myHideEmptyPackages, hideEmptyPackages, paneId, true); } - setPaneOption(myHideEmptyPackages, hideEmptyPackages, paneId, true); } @Override @@ -1516,16 +1540,25 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo final AbstractProjectViewPane viewPane = getCurrentProjectViewPane(); final SelectionInfo selectionInfo = SelectionInfo.create(viewPane); + if (isGlobalOptions()) { + getGlobalOptions().setHideEmptyPackages(flag); + } super.setSelected(event, flag); selectionInfo.apply(viewPane); } + @Override + public boolean isSelected(AnActionEvent event) { + if (isGlobalOptions()) return getGlobalOptions().getHideEmptyPackages(); + return super.isSelected(event); + } + @Override public void update(AnActionEvent e) { super.update(e); final Presentation presentation = e.getPresentation(); - if (isFlattenPackages(myCurrentViewId)) { + if (isHideEmptyMiddlePackages(myCurrentViewId)) { presentation.setText(IdeBundle.message("action.hide.empty.middle.packages")); presentation.setDescription(IdeBundle.message("action.show.hide.empty.middle.packages")); } diff --git a/platform/platform-api/src/com/intellij/execution/configurations/GeneralCommandLine.java b/platform/platform-api/src/com/intellij/execution/configurations/GeneralCommandLine.java index cffa472ff73b..cfb1832cf095 100644 --- a/platform/platform-api/src/com/intellij/execution/configurations/GeneralCommandLine.java +++ b/platform/platform-api/src/com/intellij/execution/configurations/GeneralCommandLine.java @@ -180,12 +180,7 @@ public class GeneralCommandLine implements UserDataHolder { return myParentEnvironmentType != ParentEnvironmentType.NONE; } - /** @deprecated use {@link #withParentEnvironmentType(ParentEnvironmentType)} (to be removed in IDEA 2017.*) */ - public GeneralCommandLine withPassParentEnvironment(boolean passParentEnvironment) { - return withParentEnvironmentType(passParentEnvironment ? ParentEnvironmentType.CONSOLE : ParentEnvironmentType.NONE); - } - - /** @deprecated use {@link #withParentEnvironmentType(ParentEnvironmentType)} (to be removed in IDEA 2017.*) */ + /** @deprecated use {@link #withParentEnvironmentType(ParentEnvironmentType)} (to be removed in IDEA 2018.*) */ public void setPassParentEnvironment(boolean passParentEnvironment) { withParentEnvironmentType(passParentEnvironment ? ParentEnvironmentType.CONSOLE : ParentEnvironmentType.NONE); } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java index 796099c7057f..aae8f0043f5f 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -31,6 +31,7 @@ import com.intellij.ui.tabs.UiDecorator; import com.intellij.ui.tabs.impl.table.TableLayout; import com.intellij.util.PairConsumer; import com.intellij.util.ui.Centerizer; +import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.accessibility.ScreenReader; import org.jetbrains.annotations.Nullable; @@ -204,9 +205,9 @@ public class TabLabel extends JPanel implements Accessible { }; label.setOpaque(false); label.setBorder(null); - label.setIconTextGap(tabs.isEditorTabs() ? (!UISettings.getInstance().HIDE_TABS_IF_NEED ? 4 : 2) : new JLabel().getIconTextGap()); + label.setIconTextGap(tabs.isEditorTabs() ? (!UISettings.getShadowInstance().HIDE_TABS_IF_NEED ? 4 : 2) : new JLabel().getIconTextGap()); label.setIconOpaque(false); - label.setIpad(new Insets(0, 0, 0, 0)); + label.setIpad(JBUI.emptyInsets()); return label; } @@ -214,7 +215,7 @@ public class TabLabel extends JPanel implements Accessible { @Override public Insets getInsets() { Insets insets = super.getInsets(); - if (myTabs.isEditorTabs() && UISettings.getInstance().SHOW_CLOSE_BUTTON) { + if (myTabs.isEditorTabs() && UISettings.getShadowInstance().SHOW_CLOSE_BUTTON) { insets.right = 3; } return insets; @@ -462,6 +463,10 @@ public class TabLabel extends JPanel implements Accessible { } public void apply(UiDecorator.UiDecoration decoration) { + if (decoration == null) { + return; + } + if (decoration.getLabelFont() != null) { setFont(decoration.getLabelFont()); getLabelComponent().setFont(decoration.getLabelFont()); @@ -671,23 +676,19 @@ public class TabLabel extends JPanel implements Accessible { @Override public String getAccessibleName() { String name = super.getAccessibleName(); - if (name == null) { - if (myLabel instanceof Accessible){ + if (name == null && myLabel != null) { name = myLabel.getAccessibleContext().getAccessibleName(); - } } return name; } @Override public String getAccessibleDescription() { - String name = super.getAccessibleDescription(); - if (name == null) { - if (myLabel instanceof Accessible){ - name = myLabel.getAccessibleContext().getAccessibleDescription(); - } + String description = super.getAccessibleDescription(); + if (description == null && myLabel != null) { + description = myLabel.getAccessibleContext().getAccessibleDescription(); } - return name; + return description; } @Override diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/StructuralSearchProfile.java b/platform/structuralsearch/source/com/intellij/structuralsearch/StructuralSearchProfile.java index bbce04ce87fd..85ed8586f28c 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/StructuralSearchProfile.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/StructuralSearchProfile.java @@ -222,7 +222,7 @@ public abstract class StructuralSearchProfile { return fileType; } - Configuration[] getPredefinedTemplates() { + public Configuration[] getPredefinedTemplates() { return Configuration.EMPTY_ARRAY; } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/XmlStructuralSearchProfile.java b/platform/structuralsearch/source/com/intellij/structuralsearch/XmlStructuralSearchProfile.java index 5882e2f69f4f..45bba9d90039 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/XmlStructuralSearchProfile.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/XmlStructuralSearchProfile.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2016 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.structuralsearch; import com.intellij.codeInsight.template.TemplateContextType; @@ -197,7 +212,7 @@ public class XmlStructuralSearchProfile extends StructuralSearchProfile { } @Override - Configuration[] getPredefinedTemplates() { + public Configuration[] getPredefinedTemplates() { return XmlPredefinedConfigurations.createPredefinedTemplates(); } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/GlobalMatchingVisitor.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/GlobalMatchingVisitor.java index 35c644311db0..3622115f4420 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/GlobalMatchingVisitor.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/GlobalMatchingVisitor.java @@ -312,12 +312,12 @@ public class GlobalMatchingVisitor extends AbstractMatchingVisitor { } @Override - protected boolean isLeftLooseMatching() { + public boolean isLeftLooseMatching() { return matchContext.getOptions().isLooseMatching(); } @Override - protected boolean isRightLooseMatching() { + public boolean isRightLooseMatching() { return false; } diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/CompileContext.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/CompileContext.java index f28e83b7ad1c..cb0a32f87543 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/CompileContext.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/compiler/CompileContext.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2016 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.structuralsearch.impl.matcher.compiler; import com.intellij.openapi.application.ApplicationManager; @@ -6,11 +21,9 @@ import com.intellij.structuralsearch.MatchOptions; import com.intellij.structuralsearch.impl.matcher.CompiledPattern; /** - * Created by IntelliJ IDEA. - * User: maxim + * @author maxim * Date: 17.11.2004 * Time: 19:26:37 - * To change this template use File | Settings | File Templates. */ public class CompileContext { private OptimizingSearchHelper searchHelper; @@ -49,7 +62,7 @@ public class CompileContext { this.pattern = pattern; } - MatchOptions getOptions() { + public MatchOptions getOptions() { return options; } @@ -57,7 +70,7 @@ public class CompileContext { this.options = options; } - Project getProject() { + public Project getProject() { return project; } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/style/MethodRefCanBeReplacedWithLambdaInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/style/MethodRefCanBeReplacedWithLambdaInspection.java index 4d755dcf77d1..9cfe67755b83 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/style/MethodRefCanBeReplacedWithLambdaInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/style/MethodRefCanBeReplacedWithLambdaInspection.java @@ -34,14 +34,10 @@ import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.InspectionGadgetsFix; -import com.siyeh.ig.psiutils.SideEffectChecker; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; - public class MethodRefCanBeReplacedWithLambdaInspection extends BaseInspection { @Nls @@ -74,16 +70,6 @@ public class MethodRefCanBeReplacedWithLambdaInspection extends BaseInspection { return null; } - public static boolean isWithSideEffects(PsiMethodReferenceExpression methodReferenceExpression) { - final PsiExpression qualifierExpression = methodReferenceExpression.getQualifierExpression(); - if (qualifierExpression != null) { - final List sideEffects = new ArrayList<>(); - SideEffectChecker.checkSideEffects(qualifierExpression, sideEffects); - return !sideEffects.isEmpty(); - } - return false; - } - private static class MethodRefToLambdaVisitor extends BaseInspectionVisitor { @Override public void visitMethodReferenceExpression(PsiMethodReferenceExpression methodReferenceExpression) { @@ -92,12 +78,13 @@ public class MethodRefCanBeReplacedWithLambdaInspection extends BaseInspection { if (interfaceType != null && LambdaUtil.getFunctionalInterfaceMethod(interfaceType) != null && methodReferenceExpression.resolve() != null) { - registerError(methodReferenceExpression, getFixFactory(isWithSideEffects(methodReferenceExpression), isOnTheFly())); + registerError(methodReferenceExpression, + getFixFactory(LambdaRefactoringUtil.canConvertToLambda(methodReferenceExpression), isOnTheFly())); } } - private static FixFactory getFixFactory(boolean withSideEffects, boolean onTheFly) { - if (!withSideEffects) return MethodRefToLambdaFix::new; + private static FixFactory getFixFactory(boolean canConvert, boolean onTheFly) { + if (canConvert) return MethodRefToLambdaFix::new; if (onTheFly || ApplicationManager.getApplication().isUnitTestMode()) return SideEffectsMethodRefToLambdaFix::new; return null; } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java index 365fbb2a9daf..bf0742c74dba 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenServerManager.java @@ -25,6 +25,7 @@ import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.rmi.RemoteProcessSupport; import com.intellij.execution.runners.ProgramRunner; import com.intellij.notification.Notification; +import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.AnAction; @@ -33,7 +34,9 @@ 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.options.ShowSettingsUtil; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.projectRoots.*; import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl; import com.intellij.openapi.roots.ProjectRootManager; @@ -51,6 +54,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import org.jetbrains.idea.maven.execution.MavenExecutionOptions; import org.jetbrains.idea.maven.execution.MavenRunnerSettings; +import org.jetbrains.idea.maven.execution.RunnerBundle; import org.jetbrains.idea.maven.model.MavenExplicitProfiles; import org.jetbrains.idea.maven.model.MavenId; import org.jetbrains.idea.maven.model.MavenModel; @@ -59,10 +63,12 @@ import org.jetbrains.idea.maven.project.MavenGeneralSettings; import org.jetbrains.idea.maven.project.MavenProjectsManager; import org.jetbrains.idea.maven.utils.MavenLog; import org.jetbrains.idea.maven.utils.MavenProgressIndicator; +import org.jetbrains.idea.maven.utils.MavenSettings; import org.jetbrains.idea.maven.utils.MavenUtil; import org.slf4j.Logger; import org.slf4j.impl.Log4jLoggerFactory; +import javax.swing.event.HyperlinkEvent; import java.io.File; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; @@ -283,14 +289,43 @@ public class MavenServerManager extends RemoteObjectWrapper impleme } } - final String currentMavenVersion = forceMaven2 ? "2.2.1" : getCurrentMavenVersion(); - params.getVMParametersList().addProperty(MavenServerEmbedder.MAVEN_EMBEDDER_VERSION, currentMavenVersion); + final File mavenHome; + final String mavenVersion; + final File currentMavenHomeFile = forceMaven2 ? BundledMavenPathHolder.myBundledMaven2Home : getCurrentMavenHomeFile(); + if (currentMavenHomeFile == null) { + mavenHome = BundledMavenPathHolder.myBundledMaven3Home; + mavenVersion = getMavenVersion(mavenHome); + + Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); + final Project project = openProjects.length == 1 ? openProjects[0] : null; + if (project != null) { + new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "", RunnerBundle.message( + "external.maven.home.invalid.substitution.warning.with.fix", myState.mavenHome, mavenVersion), NotificationType.WARNING, + new NotificationListener() { + @Override + public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { + ShowSettingsUtil.getInstance().showSettingsDialog(project, MavenSettings.DISPLAY_NAME); + } + }).notify(null); + } + else { + new Notification(MavenUtil.MAVEN_NOTIFICATION_GROUP, "", RunnerBundle.message( + "external.maven.home.invalid.substitution.warning", myState.mavenHome, mavenVersion), NotificationType.WARNING).notify(null); + } + } + else { + mavenHome = currentMavenHomeFile; + mavenVersion = getMavenVersion(mavenHome); + } + assert mavenVersion != null; + + params.getVMParametersList().addProperty(MavenServerEmbedder.MAVEN_EMBEDDER_VERSION, mavenVersion); String sdkConfigLocation = "Settings | Build, Execution, Deployment | Build Tools | Maven | Importing | JDK for Importer"; - verifyMavenSdkRequirements(jdk, currentMavenVersion, sdkConfigLocation); + verifyMavenSdkRequirements(jdk, mavenVersion, sdkConfigLocation); final List classPath = new ArrayList<>(); classPath.add(PathUtil.getJarPathForClass(org.apache.log4j.Logger.class)); - if (currentMavenVersion == null || StringUtil.compareVersionNumbers(currentMavenVersion, "3.1") < 0) { + if (StringUtil.compareVersionNumbers(mavenVersion, "3.1") < 0) { classPath.add(PathUtil.getJarPathForClass(Logger.class)); classPath.add(PathUtil.getJarPathForClass(Log4jLoggerFactory.class)); } @@ -299,7 +334,7 @@ public class MavenServerManager extends RemoteObjectWrapper impleme ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Query.class)); params.getClassPath().add(PathManager.getResourceRoot(getClass(), "/messages/CommonBundle.properties")); params.getClassPath().addAll(classPath); - params.getClassPath().addAllFiles(collectClassPathAndLibsFolder(forceMaven2)); + params.getClassPath().addAllFiles(collectClassPathAndLibsFolder(mavenVersion, mavenHome)); String embedderXmx = System.getProperty("idea.maven.embedder.xmx"); if (embedderXmx != null) { @@ -381,14 +416,12 @@ public class MavenServerManager extends RemoteObjectWrapper impleme return MavenUtil.getMavenVersion(mavenHome); } + @Nullable public String getCurrentMavenVersion() { return getMavenVersion(myState.mavenHome); } - public List collectClassPathAndLibsFolder(boolean forceMaven2) { - final String currentMavenVersion = forceMaven2 ? "2.2.1" : getCurrentMavenVersion(); - File mavenHome = forceMaven2 ? BundledMavenPathHolder.myBundledMaven2Home : currentMavenVersion == null ? BundledMavenPathHolder.myBundledMaven3Home : getCurrentMavenHomeFile(); - + private static List collectClassPathAndLibsFolder(@NotNull String mavenVersion, @NotNull File mavenHome) { final File pluginFileOrDir = new File(PathUtil.getJarPathForClass(MavenServerManager.class)); final List classpath = new ArrayList<>(); final String root = pluginFileOrDir.getParent(); @@ -396,11 +429,11 @@ public class MavenServerManager extends RemoteObjectWrapper impleme if (pluginFileOrDir.isDirectory()) { classpath.add(new File(root, "maven-server-api")); File parentFile = getMavenPluginParentFile(); - if (forceMaven2 || (currentMavenVersion != null && StringUtil.compareVersionNumbers(currentMavenVersion, "3") < 0)) { + if (StringUtil.compareVersionNumbers(mavenVersion, "3") < 0) { classpath.add(new File(root, "maven2-server-impl")); addDir(classpath, new File(parentFile, "maven2-server-impl/lib")); // use bundled maven 2.2.1 for all 2.0.x version (since we use org.apache.maven.project.interpolation.StringSearchModelInterpolator introduced in 2.1.0) - if (StringUtil.compareVersionNumbers(currentMavenVersion, "2.1.0") < 0) { + if (StringUtil.compareVersionNumbers(mavenVersion, "2.1.0") < 0) { mavenHome = BundledMavenPathHolder.myBundledMaven2Home; } } @@ -408,7 +441,7 @@ public class MavenServerManager extends RemoteObjectWrapper impleme classpath.add(new File(root, "maven3-server-common")); addDir(classpath, new File(parentFile, "maven3-server-common/lib")); - if (currentMavenVersion == null || StringUtil.compareVersionNumbers(currentMavenVersion, "3.1") < 0) { + if (StringUtil.compareVersionNumbers(mavenVersion, "3.1") < 0) { classpath.add(new File(root, "maven30-server-impl")); } else { @@ -419,7 +452,7 @@ public class MavenServerManager extends RemoteObjectWrapper impleme else { classpath.add(new File(root, "maven-server-api.jar")); - if (forceMaven2 || (currentMavenVersion != null && StringUtil.compareVersionNumbers(currentMavenVersion, "3") < 0)) { + if (StringUtil.compareVersionNumbers(mavenVersion, "3") < 0) { classpath.add(new File(root, "maven2-server-impl.jar")); addDir(classpath, new File(root, "maven2-server-lib")); } @@ -427,7 +460,7 @@ public class MavenServerManager extends RemoteObjectWrapper impleme classpath.add(new File(root, "maven3-server-common.jar")); addDir(classpath, new File(root, "maven3-server-lib")); - if (currentMavenVersion == null || StringUtil.compareVersionNumbers(currentMavenVersion, "3.1") < 0) { + if (StringUtil.compareVersionNumbers(mavenVersion, "3.1") < 0) { classpath.add(new File(root, "maven30-server-impl.jar")); } else { @@ -602,7 +635,7 @@ public class MavenServerManager extends RemoteObjectWrapper impleme public boolean isUseMaven2() { final String version = getCurrentMavenVersion(); - return StringUtil.compareVersionNumbers(version, "3") < 0 && StringUtil.compareVersionNumbers(version, "2") >= 0; + return version != null && StringUtil.compareVersionNumbers(version, "3") < 0 && StringUtil.compareVersionNumbers(version, "2") >= 0; } @TestOnly diff --git a/plugins/maven/src/main/resources/RunnerBundle.properties b/plugins/maven/src/main/resources/RunnerBundle.properties index 4ebc0700a113..8e9ec5416fa8 100644 --- a/plugins/maven/src/main/resources/RunnerBundle.properties +++ b/plugins/maven/src/main/resources/RunnerBundle.properties @@ -16,6 +16,9 @@ external.maven.home.does.not.exist.with.fix=Specified Maven home directory ({0}) external.maven.home.invalid={0} is not a valid Maven home directory external.maven.home.invalid.with.fix={0} is not a valid Maven home directory. Configure Maven home +external.maven.home.invalid.substitution.warning=Invalid Maven home directory configured
{0}
Bundled maven {1} will be used +external.maven.home.invalid.substitution.warning.with.fix=Invalid Maven home directory configured
{0}
Bundled maven {1} will be used. Configure Maven home. + embedded.executor.caption=Executing Maven - using embedded Maven embedded.cannot.create=Cannot create Maven Embedder embedded.build.failed=BUILD FAILED diff --git a/resources-en/src/inspectionDescriptions/OptionalIsPresent.html b/resources-en/src/inspectionDescriptions/OptionalIsPresent.html index 25274767fccf..e62f4d326bb0 100644 --- a/resources-en/src/inspectionDescriptions/OptionalIsPresent.html +++ b/resources-en/src/inspectionDescriptions/OptionalIsPresent.html @@ -2,6 +2,7 @@ Reports conditions like if(Optional.isPresent()) which could be rewritten in functional style. +

New in 2016.3 \ No newline at end of file diff --git a/updater/src/com/intellij/updater/CreateAction.java b/updater/src/com/intellij/updater/CreateAction.java index 5a002d1cbee1..8b3b5e527eaa 100644 --- a/updater/src/com/intellij/updater/CreateAction.java +++ b/updater/src/com/intellij/updater/CreateAction.java @@ -73,32 +73,28 @@ public class CreateAction extends PatchAction { @Override protected void doApply(ZipFile patchFile, File backupDir, File toFile) throws IOException { - if (toFile.getParentFile().exists()) { - prepareToWriteFile(toFile); + prepareToWriteFile(toFile); - ZipEntry entry = Utils.getZipEntry(patchFile, myPath); - if (entry.isDirectory()) { - if (!toFile.mkdir()) { - throw new IOException("Unable to create directory " + myPath); - } - } else { - InputStream in = Utils.findEntryInputStreamForEntry(patchFile, entry); - try { - int filePermissions = in.read(); - if (filePermissions > 1) { - Utils.createLink(readLinkInfo(in, filePermissions), toFile); - } - else { - Utils.copyStreamToFile(in, toFile); - Utils.setExecutable(toFile, filePermissions == 1); - } - } - finally { - in.close(); - } + ZipEntry entry = Utils.getZipEntry(patchFile, myPath); + if (entry.isDirectory()) { + if (!toFile.mkdir()) { + throw new IOException("Unable to create directory " + myPath); } } else { - Runner.logger().info("Create action skipped. The parent is absent: " + toFile.getParentFile()); + InputStream in = Utils.findEntryInputStreamForEntry(patchFile, entry); + try { + int filePermissions = in.read(); + if (filePermissions > 1 ) { + Utils.createLink(readLinkInfo(in, filePermissions), toFile); + } + else { + Utils.copyStreamToFile(in, toFile); + Utils.setExecutable(toFile, filePermissions == 1 ); + } + } + finally { + in.close(); + } } } diff --git a/updater/src/com/intellij/updater/Patch.java b/updater/src/com/intellij/updater/Patch.java index 9217a5788ae9..420f7fc7ae89 100644 --- a/updater/src/com/intellij/updater/Patch.java +++ b/updater/src/com/intellij/updater/Patch.java @@ -319,8 +319,13 @@ public class Patch { boolean cancelled = false; try { forEach(actionsToProcess, "Applying patch...", ui, true, action -> { - appliedActions.add(action); - action.apply(patchFile, backupDir, toDir); + if ((action instanceof CreateAction) && + !new File(toDir, action.getPath()).getParentFile().exists()) { + Runner.logger().info("Create action: " + action.getPath() + " skipped. The parent folder is absent."); + } else { + appliedActions.add(action); + action.apply(patchFile, backupDir, toDir); + } }); } catch (OperationCancelledException e) {