From de826033069206f9cbcd3dbb93af3449032c452a Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 17 Jan 2018 13:03:03 +0100 Subject: [PATCH 01/25] disable convert to functional in var context (IDEA-185038) --- .../codeInspection/AnonymousCanBeLambdaInspection.java | 8 ++++---- .../UnnecessaryModuleDependencyInspection.java | 2 ++ java/java-psi-api/src/com/intellij/psi/LambdaUtil.java | 7 ++++++- .../daemonCodeAnalyzer/advLVTI/DisabledInspections.java | 9 +++++++++ .../daemonCodeAnalyzer/advLVTI/SimpleAvailability.java | 2 +- .../codeInsight/daemon/LightAdvLVTIHighlightingTest.java | 5 +++++ 6 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/DisabledInspections.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java index cf940d8a3bfd..69da289fe55d 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java @@ -78,10 +78,7 @@ public class AnonymousCanBeLambdaInspection extends AbstractBaseJavaLocalInspect public void visitAnonymousClass(final PsiAnonymousClass aClass) { super.visitAnonymousClass(aClass); final PsiElement parent = aClass.getParent(); - final PsiElement lambdaContext = parent != null ? parent.getParent() : null; - if (lambdaContext != null && - (LambdaUtil.isValidLambdaContext(lambdaContext) || !(lambdaContext instanceof PsiExpressionStatement)) && - canBeConvertedToLambda(aClass, false, isOnTheFly || reportNotAnnotatedInterfaces, Collections.emptySet())) { + if (canBeConvertedToLambda(aClass, false, isOnTheFly || reportNotAnnotatedInterfaces, Collections.emptySet())) { final PsiElement lBrace = aClass.getLBrace(); LOG.assertTrue(lBrace != null); final TextRange rangeInElement = new TextRange(0, aClass.getStartOffsetInParent() + lBrace.getStartOffsetInParent()); @@ -199,6 +196,9 @@ public class AnonymousCanBeLambdaInspection extends AbstractBaseJavaLocalInspect boolean acceptParameterizedFunctionTypes, boolean reportNotAnnotatedInterfaces, @NotNull Set ignoredRuntimeAnnotations) { + PsiElement parent = aClass.getParent(); + final PsiElement lambdaContext = parent != null ? parent.getParent() : null; + if (lambdaContext == null || !LambdaUtil.isValidLambdaContext(lambdaContext) && !(lambdaContext instanceof PsiReferenceExpression)) return false; if (PsiUtil.getLanguageLevel(aClass).isAtLeast(LanguageLevel.JDK_1_8)) { final PsiClassType baseClassType = aClass.getBaseClassType(); final PsiClassType.ClassResolveResult resolveResult = baseClassType.resolveGenerics(); diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java index debc0d1ebe63..04336281d88a 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyInspection.java @@ -52,6 +52,7 @@ public class UnnecessaryModuleDependencyInspection extends GlobalInspectionTool } final RefManager refManager = globalContext.getRefManager(); + currentDependencies: for (final OrderEntry entry : declaredDependencies) { if (entry instanceof ModuleOrderEntry && ((ModuleOrderEntry)entry).getScope() != DependencyScope.RUNTIME) { final Module dependency = ((ModuleOrderEntry)entry).getModule(); @@ -62,6 +63,7 @@ public class UnnecessaryModuleDependencyInspection extends GlobalInspectionTool final Iterator iterator = graph.getOut(module); while (iterator.hasNext()) { final Module dep = iterator.next(); + if (!scope.containsModule(dep)) continue currentDependencies; final RefModule depRefModule = refManager.getRefModule(dep); if (depRefModule != null) { final Set neededModules = depRefModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES); diff --git a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java index ab859840489e..b3db391d64c9 100644 --- a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java @@ -143,10 +143,15 @@ public class LambdaUtil { return context instanceof PsiLambdaExpression || context instanceof PsiReturnStatement || context instanceof PsiAssignmentExpression || - context instanceof PsiVariable || + context instanceof PsiVariable && !withInferredType((PsiVariable)context) || context instanceof PsiArrayInitializerExpression; } + private static boolean withInferredType(PsiVariable variable) { + PsiTypeElement typeElement = variable.getTypeElement(); + return typeElement != null && typeElement.isInferredType(); + } + @Contract("null -> null") @Nullable public static MethodSignature getFunction(final PsiClass psiClass) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/DisabledInspections.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/DisabledInspections.java new file mode 100644 index 000000000000..65bd7ee6316e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/DisabledInspections.java @@ -0,0 +1,9 @@ +class Test { + { + var r = new Runnable() { + public void run() { + System.out.println(); + } + }; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/SimpleAvailability.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/SimpleAvailability.java index a8a8ea897420..bc0ebdf7e68f 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/SimpleAvailability.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advLVTI/SimpleAvailability.java @@ -29,7 +29,7 @@ class Main { var f = () -> "hello"; var m = Main::localVariableDeclaration; var g = null; - var runnable = true ? () -> {} : () -> {}; + var runnable = true ? () -> {} : () -> {}; } private void forEachType(String[] strs, Iterable it, Iterable raw) { diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvLVTIHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvLVTIHighlightingTest.java index 34eaed628228..f375024fea60 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvLVTIHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/LightAdvLVTIHighlightingTest.java @@ -16,6 +16,7 @@ package com.intellij.java.codeInsight.daemon; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; +import com.intellij.codeInspection.AnonymousCanBeLambdaInspection; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.pom.java.LanguageLevel; @@ -36,6 +37,10 @@ public class LightAdvLVTIHighlightingTest extends LightDaemonAnalyzerTestCase { } public void testSimpleAvailability() { doTest(); } + public void testDisabledInspections() { + enableInspectionTool(new AnonymousCanBeLambdaInspection()); + doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false); + } public void testVarClassNameConflicts() { doTest(); } public void testStandaloneInVarContext() { doTest(); } public void testUpwardProjection() { doTest(); } From 1412a849d5573305ea38017d4fea7f3d0476ff08 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 17 Jan 2018 13:24:13 +0100 Subject: [PATCH 02/25] junit 5: ensure tags are not empty --- .../execution/junit/JUnitConfiguration.java | 8 ++++---- .../junit2/configuration/JUnitConfigurable.java | 13 +++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnitConfiguration.java b/plugins/junit/src/com/intellij/execution/junit/JUnitConfiguration.java index 5d0c849d4d28..950aabcef4f0 100644 --- a/plugins/junit/src/com/intellij/execution/junit/JUnitConfiguration.java +++ b/plugins/junit/src/com/intellij/execution/junit/JUnitConfiguration.java @@ -536,8 +536,8 @@ public class JUnitConfiguration extends JavaTestConfigurationBase { public String PACKAGE_NAME; public String MAIN_CLASS_NAME; public String METHOD_NAME; - private String[] UNIQUE_ID; - private String[] TAGS; + private String[] UNIQUE_ID = ArrayUtil.EMPTY_STRING_ARRAY; + private String[] TAGS = ArrayUtil.EMPTY_STRING_ARRAY; public String TEST_OBJECT = TEST_CLASS; public String VM_PARAMETERS; public String PARAMETERS; @@ -700,10 +700,10 @@ public class JUnitConfiguration extends JavaTestConfigurationBase { return "@Category(" + (StringUtil.isEmpty(CATEGORY_NAME) ? "Invalid" : CATEGORY_NAME) + ")"; } if (TEST_UNIQUE_ID.equals(TEST_OBJECT)) { - return UNIQUE_ID != null ? StringUtil.join(UNIQUE_ID, " ") : "Temp suite"; + return UNIQUE_ID != null && UNIQUE_ID.length > 0 ? StringUtil.join(UNIQUE_ID, " ") : "Temp suite"; } if (TEST_TAGS.equals(TEST_OBJECT)) { - return TAGS != null ? "Tags (" + StringUtil.join(TAGS, " ") + ")" : "Temp suite"; + return TAGS != null && TAGS.length > 0 ? "Tags (" + StringUtil.join(TAGS, " ") + ")" : "Temp suite"; } final String className = JavaExecutionUtil.getPresentableClassName(getMainClassName()); if (TEST_METHOD.equals(TEST_OBJECT)) { diff --git a/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurable.java b/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurable.java index f7acd7c57fe4..bb004a6aee4a 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurable.java +++ b/plugins/junit/src/com/intellij/execution/junit2/configuration/JUnitConfigurable.java @@ -55,6 +55,7 @@ import com.intellij.rt.execution.junit.RepeatCount; import com.intellij.ui.*; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.fields.ExpandableTextField; +import com.intellij.util.ArrayUtil; import com.intellij.util.IconUtil; import com.intellij.util.ui.UIUtil; import gnu.trove.TIntArrayList; @@ -311,8 +312,8 @@ public class JUnitConfigurable extends SettingsEdi catch (NumberFormatException e) { configuration.setRepeatCount(1); } - configuration.getPersistentData().setUniqueIds(myUniqueIdField.getComponent().getText().split(" ")); - configuration.getPersistentData().setTags(myTagsField.getComponent().getText().split(" ")); + configuration.getPersistentData().setUniqueIds(setArrayFromText(myUniqueIdField)); + configuration.getPersistentData().setTags(setArrayFromText(myTagsField)); configuration.getPersistentData().setChangeList((String)myChangeListLabeledComponent.getComponent().getSelectedItem()); myModel.apply(getModuleSelector().getModule(), configuration); applyHelpersTo(configuration); @@ -334,6 +335,14 @@ public class JUnitConfigurable extends SettingsEdi configuration.setShortenCommandLine((ShortenCommandLine)myShortenClasspathModeCombo.getComponent().getSelectedItem()); } + protected String[] setArrayFromText(LabeledComponent field) { + String text = field.getComponent().getText(); + if (text.isEmpty()) { + return ArrayUtil.EMPTY_STRING_ARRAY; + } + return text.split(" "); + } + public void resetEditorFrom(@NotNull final JUnitConfiguration configuration) { final int count = configuration.getRepeatCount(); myRepeatCountField.setText(String.valueOf(count)); From 52158da46561f0e45a5d651e379617291b56b101 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 17 Jan 2018 13:29:57 +0100 Subject: [PATCH 03/25] escape mnemonics (IDEA-185032) --- .../runner/history/actions/ImportTestsFromHistoryAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/ImportTestsFromHistoryAction.java b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/ImportTestsFromHistoryAction.java index 2cf1c863254c..6647e0b7e790 100644 --- a/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/ImportTestsFromHistoryAction.java +++ b/platform/smRunner/src/com/intellij/execution/testframework/sm/runner/history/actions/ImportTestsFromHistoryAction.java @@ -21,6 +21,7 @@ import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties import com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.text.DateFormatUtil; @@ -36,7 +37,7 @@ public class ImportTestsFromHistoryAction extends AbstractImportTestsAction { private String myFileName; public ImportTestsFromHistoryAction(@Nullable SMTRunnerConsoleProperties properties, Project project, String name) { - super(properties, getPresentableText(project, name), getPresentableText(project, name), getIcon(project, name)); + super(properties, StringUtil.escapeMnemonics(getPresentableText(project, name)), getPresentableText(project, name), getIcon(project, name)); myFileName = name; } From d0a2fce763ecc07d2fc6e06f5f4e921af452d0c6 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 17 Jan 2018 13:38:53 +0100 Subject: [PATCH 04/25] restore comments: simplify typed lambda --- .../lambda/RedundantLambdaParameterTypeInspection.java | 9 +++++++-- .../InferredFromOtherArgs.java | 2 +- .../InferredFromOtherArgs_after.java | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/lambda/RedundantLambdaParameterTypeInspection.java b/java/java-impl/src/com/intellij/codeInspection/lambda/RedundantLambdaParameterTypeInspection.java index 856535a858b8..a443b065431f 100644 --- a/java/java-impl/src/com/intellij/codeInspection/lambda/RedundantLambdaParameterTypeInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/lambda/RedundantLambdaParameterTypeInspection.java @@ -1,11 +1,15 @@ // Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInspection.lambda; -import com.intellij.codeInspection.*; +import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool; +import com.intellij.codeInspection.LocalQuickFix; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.ProblemsHolder; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; +import com.siyeh.ig.psiutils.CommentTracker; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -73,7 +77,8 @@ public class RedundantLambdaParameterTypeInspection extends AbstractBaseJavaLoca } final PsiLambdaExpression expression = (PsiLambdaExpression)JavaPsiFacade.getElementFactory(lambdaExpression.getProject()) .createExpressionFromText(text + "->{}", lambdaExpression); - lambdaExpression.getParameterList().replace(expression.getParameterList()); + CommentTracker tracker = new CommentTracker(); + tracker.replaceAndRestoreComments(lambdaExpression.getParameterList(), expression.getParameterList()); } } diff --git a/java/java-tests/testData/codeInspection/redundantLambdaParameterType/InferredFromOtherArgs.java b/java/java-tests/testData/codeInspection/redundantLambdaParameterType/InferredFromOtherArgs.java index abf7228a0904..71da837b4add 100644 --- a/java/java-tests/testData/codeInspection/redundantLambdaParameterType/InferredFromOtherArgs.java +++ b/java/java-tests/testData/codeInspection/redundantLambdaParameterType/InferredFromOtherArgs.java @@ -10,6 +10,6 @@ class ReturnTypeCompatibility { } public static void main(String[] args) { - call("", (String i) -> ""); + call("", (String/*comment*/ i) -> ""); } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInspection/redundantLambdaParameterType/InferredFromOtherArgs_after.java b/java/java-tests/testData/codeInspection/redundantLambdaParameterType/InferredFromOtherArgs_after.java index 4849f5818119..5f24cd9ac936 100644 --- a/java/java-tests/testData/codeInspection/redundantLambdaParameterType/InferredFromOtherArgs_after.java +++ b/java/java-tests/testData/codeInspection/redundantLambdaParameterType/InferredFromOtherArgs_after.java @@ -10,6 +10,6 @@ class ReturnTypeCompatibility { } public static void main(String[] args) { - call("", i -> ""); + call("", i -> /*comment*/ ""); } } \ No newline at end of file From 1e34231fc26e35cfe81fb35ebf7bccb37d88da1e Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 17 Jan 2018 14:12:46 +0100 Subject: [PATCH 05/25] [java] extracts and fixes find-JDK-by-version function --- .../JavaProjectDataService.java | 43 ++----------------- .../projectRoots/JavaSdkVersionUtil.java | 30 +++++++------ .../wizard/GradleProjectImportBuilder.java | 24 ++--------- 3 files changed, 25 insertions(+), 72 deletions(-) diff --git a/java/java-impl/src/com/intellij/externalSystem/JavaProjectDataService.java b/java/java-impl/src/com/intellij/externalSystem/JavaProjectDataService.java index 84006c24c4d1..e2e41e81d4fa 100644 --- a/java/java-impl/src/com/intellij/externalSystem/JavaProjectDataService.java +++ b/java/java-impl/src/com/intellij/externalSystem/JavaProjectDataService.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2013 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.externalSystem; @@ -24,10 +12,7 @@ import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjec import com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.project.Project; -import com.intellij.openapi.projectRoots.JavaSdk; -import com.intellij.openapi.projectRoots.JavaSdkVersion; -import com.intellij.openapi.projectRoots.ProjectJdkTable; -import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.*; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.pom.java.LanguageLevel; @@ -35,14 +20,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; -import java.util.List; /** * @author Denis Zhdanov * @since 4/15/13 12:09 PM */ public class JavaProjectDataService extends AbstractProjectDataService { - @NotNull @Override public Key getTargetDataKey() { @@ -91,7 +74,7 @@ public class JavaProjectDataService extends AbstractProjectDataService javaSdks = ProjectJdkTable.getInstance().getSdksOfType(javaSdk); - Sdk candidate = null; - for (Sdk sdk : javaSdks) { - JavaSdkVersion v = javaSdk.getVersion(sdk); - if (v == version) { - return sdk; - } - if (candidate == null && v != null && version.getMaxLanguageLevel().isAtLeast(version.getMaxLanguageLevel())) { - candidate = sdk; - } - } - return candidate; - } - @SuppressWarnings("MethodMayBeStatic") public void setLanguageLevel(@NotNull final LanguageLevel languageLevel, @NotNull Project project) { final LanguageLevelProjectExtension languageLevelExtension = LanguageLevelProjectExtension.getInstance(project); @@ -137,5 +103,4 @@ public class JavaProjectDataService extends AbstractProjectDataService javaSdks = ProjectJdkTable.getInstance().getSdksOfType(javaSdk); - Sdk candidate = null; - for (Sdk sdk : javaSdks) { - JavaSdkVersion v = javaSdk.getVersion(sdk); - if (v == version) { - return sdk; - } - else if (candidate == null && v != null && version.getMaxLanguageLevel().isAtLeast(version.getMaxLanguageLevel())) { - candidate = sdk; - } - } - return candidate; - } - @NotNull @Override protected File getExternalProjectConfigToUse(@NotNull File file) { From d6837a5f0a81a3b1161bc1e4884a09e994b66eae Mon Sep 17 00:00:00 2001 From: "Irina.Chernushina" Date: Wed, 17 Jan 2018 12:47:47 +0100 Subject: [PATCH 06/25] json schema: no need to through file types changed on settings change - json schema does not have a separate file type any more - caching by psi modification count in JsonLiteralMixin prevents $ref references from being updated after json schema settings changed (json file becomes json schema file, and no psi is changed). Seems caching of references is not used in any other places. Will open a review for that. Alternatively, psi count can be moved forward on schema changes. IDEA-185034 Unexpected "Restoring from roots change start / finish mismatch" --- .../json/psi/impl/JsonLiteralMixin.java | 20 ++++--------------- .../impl/JsonSchemaServiceImpl.java | 12 +++++------ .../schemaFile/JsonSchemaFileResolveTest.java | 20 +++++++------------ 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/json/src/com/intellij/json/psi/impl/JsonLiteralMixin.java b/json/src/com/intellij/json/psi/impl/JsonLiteralMixin.java index 9ab98d52ca6c..3ada20024a04 100644 --- a/json/src/com/intellij/json/psi/impl/JsonLiteralMixin.java +++ b/json/src/com/intellij/json/psi/impl/JsonLiteralMixin.java @@ -1,3 +1,6 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.json.psi.impl; import com.intellij.json.psi.JsonLiteral; @@ -7,28 +10,13 @@ import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry import org.jetbrains.annotations.NotNull; abstract class JsonLiteralMixin extends JsonElementImpl implements JsonLiteral { - private final Object myRefLock = new Object(); - private volatile PsiReference[] myRefs; - private volatile long myModCount = -1; - protected JsonLiteralMixin(ASTNode node) { super(node); } - // TODO AppCode legacy code, may worth to get rid of it in future @NotNull @Override public PsiReference[] getReferences() { - final long count = getManager().getModificationTracker().getModificationCount(); - if (count != myModCount) { - synchronized (myRefLock) { - if (count != myModCount) { - myRefs = ReferenceProvidersRegistry.getReferencesFromProviders(this); - myModCount = count; - } - } - } - - return myRefs; + return ReferenceProvidersRegistry.getReferencesFromProviders(this); } } diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java index 0e7a351d0054..b18a41878926 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaServiceImpl.java @@ -1,17 +1,16 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.jetbrains.jsonSchema.impl; +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.json.JsonLanguage; import com.intellij.json.psi.JsonFile; import com.intellij.json.psi.JsonObject; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.LanguageFileType; -import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.AtomicClearableLazyValue; import com.intellij.openapi.util.Factory; @@ -90,8 +89,7 @@ public class JsonSchemaServiceImpl implements JsonSchemaService { public void reset() { myAnyChangeCount.incrementAndGet(); myState.reset(); - ApplicationManager.getApplication().invokeLater(() -> WriteAction.run(() -> FileTypeManagerEx.getInstanceEx().fireFileTypesChanged()), - ModalityState.NON_MODAL, myProject.getDisposed()); + DaemonCodeAnalyzer.getInstance(myProject).restart(); } @Override diff --git a/json/tests/test/com/jetbrains/jsonSchema/schemaFile/JsonSchemaFileResolveTest.java b/json/tests/test/com/jetbrains/jsonSchema/schemaFile/JsonSchemaFileResolveTest.java index 22cb2444f5a0..9f56af588b9f 100644 --- a/json/tests/test/com/jetbrains/jsonSchema/schemaFile/JsonSchemaFileResolveTest.java +++ b/json/tests/test/com/jetbrains/jsonSchema/schemaFile/JsonSchemaFileResolveTest.java @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.jetbrains.jsonSchema.schemaFile; @@ -34,6 +22,12 @@ public class JsonSchemaFileResolveTest extends JsonSchemaHeavyAbstractTest { return "/tests/testData/jsonSchema/schemaFile/resolve"; } + @Override + public void setUp() throws Exception { + super.setUp(); + myDoCompletion = false; + } + public void testResolveLocalRef() throws Exception { skeleton(new Callback() { @Override From 1f1b4cb34d2df8e7b18b5e53e2e40b4805f285cc Mon Sep 17 00:00:00 2001 From: Ivan Bessonov Date: Wed, 17 Jan 2018 16:29:04 +0300 Subject: [PATCH 07/25] IDEA-183879 maven - Project from Existing Sources can be imported from pom file with non-default name --- .../java/org/jetbrains/idea/maven/utils/MavenUtil.java | 4 ++++ .../idea/maven/wizards/MavenProjectImportProvider.java | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java index a576f6172ab9..39fb6d05ddd0 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenUtil.java @@ -964,6 +964,10 @@ public class MavenUtil { if (isPomFileName(file.getName())) return true; if (!isPotentialPomFile(file.getPath())) return false; + return isPomFileIgnoringName(project, file); + } + + public static boolean isPomFileIgnoringName(@Nullable Project project, @NotNull VirtualFile file) { if (project == null || !project.isInitialized()) { if (!FileUtil.extensionEquals(file.getName(), "xml")) return false; try { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectImportProvider.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectImportProvider.java index c03072aac15e..ee4e78791aa8 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectImportProvider.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectImportProvider.java @@ -26,11 +26,8 @@ import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.projectImport.ProjectImportProvider; import com.intellij.projectImport.SelectImportedProjectsStep; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.idea.maven.dom.MavenDomUtil; import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.project.MavenProjectsManager; import org.jetbrains.idea.maven.utils.MavenUtil; @@ -95,11 +92,8 @@ public class MavenProjectImportProvider extends ProjectImportProvider { public boolean canImport(@NotNull VirtualFile fileOrDirectory, @Nullable Project project) { if (super.canImport(fileOrDirectory, project)) return true; - if (!fileOrDirectory.isDirectory() && project != null) { - PsiFile psiFile = PsiManager.getInstance(project).findFile(fileOrDirectory); - if (psiFile != null) { - return MavenDomUtil.isProjectFile(psiFile); - } + if (!fileOrDirectory.isDirectory()) { + return MavenUtil.isPomFileIgnoringName(project, fileOrDirectory); } return false; From d43d75fa01f4b1dae99ff801a595dcd4aff398c6 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 15 Jan 2018 15:48:52 +0300 Subject: [PATCH 08/25] diff: do not break preferred tool order by switching to LocalChangeListDiffTool Display custom tool, but use original ID for DiffSettings --- .../diff/impl/DiffRequestProcessor.java | 21 ++++++++++++++++--- .../diff/impl/DiffToolSubstitutor.java | 21 +++++++++++++++++++ .../src/com/intellij/diff/util/DiffUtil.java | 19 +++++++++++++++++ .../src/META-INF/PlatformExtensionPoints.xml | 1 + .../src/META-INF/VcsExtensions.xml | 2 +- .../actions/diff/LocalChangeListDiffTool.java | 15 ++++++------- 6 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 platform/diff-impl/src/com/intellij/diff/impl/DiffToolSubstitutor.java diff --git a/platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java b/platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java index b906d8e3adc2..df34664951f1 100644 --- a/platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java +++ b/platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java @@ -200,8 +200,16 @@ public abstract class DiffRequestProcessor implements Disposable { List result = new ArrayList<>(); for (DiffTool tool : tools) { try { - if (tool instanceof FrameDiffTool && tool.canShow(myContext, myActiveRequest)) { - result.add((FrameDiffTool)tool); + if (tool instanceof FrameDiffTool) { + if (tool.canShow(myContext, myActiveRequest)) { + result.add((FrameDiffTool)tool); + } + else { + DiffTool substitutor = DiffUtil.findToolSubstitutor(tool, myContext, myActiveRequest); + if (substitutor instanceof FrameDiffTool) { + result.add((FrameDiffTool)tool); + } + } } } catch (Throwable e) { @@ -212,6 +220,13 @@ public abstract class DiffRequestProcessor implements Disposable { return DiffUtil.filterSuppressedTools(result); } + @NotNull + private FrameDiffTool findToolSubstitutor(@NotNull FrameDiffTool tool) { + DiffTool substitutor = DiffUtil.findToolSubstitutor(tool, myContext, myActiveRequest); + if (substitutor instanceof FrameDiffTool) return (FrameDiffTool)substitutor; + return tool; + } + private void moveToolOnTop(@NotNull DiffTool tool) { myToolOrder.remove(tool); @@ -228,7 +243,7 @@ public abstract class DiffRequestProcessor implements Disposable { @NotNull private ViewerState createState() { - FrameDiffTool frameTool = getFittedTool(); + FrameDiffTool frameTool = findToolSubstitutor(getFittedTool()); DiffViewer viewer = frameTool.createComponent(myContext, myActiveRequest); diff --git a/platform/diff-impl/src/com/intellij/diff/impl/DiffToolSubstitutor.java b/platform/diff-impl/src/com/intellij/diff/impl/DiffToolSubstitutor.java new file mode 100644 index 000000000000..f178dfdcbd26 --- /dev/null +++ b/platform/diff-impl/src/com/intellij/diff/impl/DiffToolSubstitutor.java @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package com.intellij.diff.impl; + +import com.intellij.diff.DiffContext; +import com.intellij.diff.DiffTool; +import com.intellij.diff.requests.DiffRequest; +import com.intellij.openapi.extensions.ExtensionPointName; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@ApiStatus.Experimental +public interface DiffToolSubstitutor { + ExtensionPointName EP_NAME = + ExtensionPointName.create("com.intellij.diff.impl.DiffToolSubstitutor"); + + @Nullable + DiffTool getReplacement(@NotNull DiffTool tool, @NotNull DiffContext context, @NotNull DiffRequest request); +} diff --git a/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java b/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java index ce7806fe0263..2c0f0dd86620 100644 --- a/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java +++ b/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java @@ -30,7 +30,9 @@ import com.intellij.diff.fragments.LineFragment; import com.intellij.diff.fragments.MergeLineFragment; import com.intellij.diff.fragments.MergeWordFragment; import com.intellij.diff.impl.DiffSettingsHolder.DiffSettings; +import com.intellij.diff.impl.DiffToolSubstitutor; import com.intellij.diff.requests.ContentDiffRequest; +import com.intellij.diff.requests.DiffRequest; import com.intellij.diff.tools.util.DiffNotifications; import com.intellij.diff.tools.util.FoldingModelSupport; import com.intellij.diff.tools.util.base.TextDiffSettingsHolder.TextDiffSettings; @@ -1558,6 +1560,23 @@ public class DiffUtil { return filteredTools.isEmpty() ? tools : filteredTools; } + @Nullable + public static DiffTool findToolSubstitutor(@NotNull DiffTool tool, @NotNull DiffContext context, @NotNull DiffRequest request) { + for (DiffToolSubstitutor substitutor : DiffToolSubstitutor.EP_NAME.getExtensions()) { + DiffTool replacement = substitutor.getReplacement(tool, context, request); + if (replacement == null) continue; + + boolean canShow = replacement.canShow(context, request); + if (!canShow) { + LOG.error("DiffTool substitutor returns invalid tool"); + continue; + } + + return replacement; + } + return null; + } + // // Helpers // diff --git a/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml b/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml index ea89383fd0ab..62443373b86b 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml @@ -259,6 +259,7 @@ + diff --git a/platform/platform-resources/src/META-INF/VcsExtensions.xml b/platform/platform-resources/src/META-INF/VcsExtensions.xml index c2d50bd7442b..fa7bcef6aaaf 100644 --- a/platform/platform-resources/src/META-INF/VcsExtensions.xml +++ b/platform/platform-resources/src/META-INF/VcsExtensions.xml @@ -41,7 +41,7 @@ - + diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/LocalChangeListDiffTool.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/LocalChangeListDiffTool.java index 31377978475f..46e815429bce 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/LocalChangeListDiffTool.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/LocalChangeListDiffTool.java @@ -18,16 +18,14 @@ package com.intellij.openapi.vcs.changes.actions.diff; import com.intellij.diff.DiffContext; import com.intellij.diff.DiffTool; import com.intellij.diff.FrameDiffTool; -import com.intellij.diff.SuppressiveDiffTool; +import com.intellij.diff.impl.DiffToolSubstitutor; import com.intellij.diff.requests.DiffRequest; import com.intellij.diff.tools.simple.SimpleDiffTool; import com.intellij.openapi.vcs.ex.PartialLocalLineStatusTracker; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.List; - -public class LocalChangeListDiffTool implements FrameDiffTool, SuppressiveDiffTool { +public class LocalChangeListDiffTool implements FrameDiffTool, DiffToolSubstitutor { @NotNull @Override public DiffViewer createComponent(@NotNull DiffContext context, @NotNull DiffRequest request) { @@ -48,8 +46,11 @@ public class LocalChangeListDiffTool implements FrameDiffTool, SuppressiveDiffTo return SimpleDiffTool.INSTANCE.getName(); } + @Nullable @Override - public List> getSuppressedTools() { - return ContainerUtil.list(SimpleDiffTool.class); + public DiffTool getReplacement(@NotNull DiffTool tool, @NotNull DiffContext context, @NotNull DiffRequest request) { + if (tool != SimpleDiffTool.INSTANCE) return null; + if (!canShow(context, request)) return null; + return this; } } From a551fbfdeae32412e26b87653811551cbc7aa3ab Mon Sep 17 00:00:00 2001 From: "Maxim.Kolmakov" Date: Wed, 17 Jan 2018 14:47:01 +0100 Subject: [PATCH 09/25] GUI-71 New Maven project: Please make possible to select a specified maven archetype from the list --- .../cellReader/ExtendedCellReaders.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/cellReader/ExtendedCellReaders.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/cellReader/ExtendedCellReaders.kt index e38cf3f191c2..0e9050ec9acc 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/cellReader/ExtendedCellReaders.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/cellReader/ExtendedCellReaders.kt @@ -36,6 +36,7 @@ import java.util.* import javax.annotation.Nonnull import javax.annotation.Nullable import javax.swing.* +import javax.swing.tree.DefaultMutableTreeNode /** @@ -46,10 +47,15 @@ class ExtendedJTreeCellReader : BasicJTreeCellReader(), JTreeCellReader { override fun valueAt(tree: JTree, modelValue: Any?): String? { if (modelValue == null) return null - val cellRendererComponent = tree.cellRenderer.getTreeCellRendererComponent(tree, modelValue, false, false, true, 0, false) + val isLeaf = modelValue is DefaultMutableTreeNode && modelValue.leafCount == 1 + val cellRendererComponent = if (isLeaf) { + tree.cellRenderer.getTreeCellRendererComponent(tree, modelValue, false, false, true, 0, false) + } + else { + tree.cellRenderer.getTreeCellRendererComponent(tree, modelValue, false, false, false, 0, false) + } return getValueWithCellRenderer(cellRendererComponent) } - } class ExtendedJListCellReader : BasicJListCellReader(), JListCellReader { @@ -63,7 +69,7 @@ class ExtendedJListCellReader : BasicJListCellReader(), JListCellReader { } } -class ExtendedJTableCellReader: BasicJTableCellReader(), JTableCellReader { +class ExtendedJTableCellReader : BasicJTableCellReader(), JTableCellReader { override fun valueAt(table: JTable, row: Int, column: Int): String? { val cellRendererComponent = table.prepareRenderer(table.getCellRenderer(row, column), row, column) From 5555feb4fcd140a3e6294dfd5852314d96138701 Mon Sep 17 00:00:00 2001 From: Kirill Kirichenko Date: Wed, 17 Jan 2018 17:16:52 +0300 Subject: [PATCH 10/25] Post review component panel and progress panel fixes. CheckBox/RadioButton iconTextGap scaled with JBUI.scale --- .../ui/panel/ProgressPanelBuilder.java | 10 ++++++ .../ui/laf/darcula/ui/DarculaCheckBoxUI.java | 5 +++ .../laf/darcula/ui/DarculaRadioButtonUI.java | 31 +++++++++++-------- .../internal/ui/ComponentPanelTestAction.java | 9 +++--- .../ui/panel/ComponentPanelBuilderImpl.java | 6 ++-- .../ui/panel/ProgressPanelBuilderImpl.java | 15 ++++++--- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/panel/ProgressPanelBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/panel/ProgressPanelBuilder.java index 7c56a763924d..71de579da404 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/panel/ProgressPanelBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/panel/ProgressPanelBuilder.java @@ -49,6 +49,16 @@ public interface ProgressPanelBuilder extends PanelBuilder { */ ProgressPanelBuilder andCancelAsButton(); + /** + * If cancel button looks like a button (see {@link #andCancelAsButton()}) sets the text to be displayed on cancel button. + * Otherwise sets the text to be displayed under the progressbar on mouse hover over the cancel icon. + * + * "Cancel" is the default text. + * + * @return this + */ + ProgressPanelBuilder andCancelText(String cancelText); + /** * Enables play button (icon styled) and sets action for it. Can't coexist with cancel action. * diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaCheckBoxUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaCheckBoxUI.java index 37a5eae40cc2..7c2c964e8c4f 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaCheckBoxUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaCheckBoxUI.java @@ -41,6 +41,11 @@ public class DarculaCheckBoxUI extends MetalCheckBoxUI { return new DarculaCheckBoxUI(); } + @Override public void installDefaults(AbstractButton b) { + super.installDefaults(b); + b.setIconTextGap(JBUI.scale(b.getIconTextGap())); + } + @Override public synchronized void paint(Graphics g2d, JComponent c) { Graphics2D g = (Graphics2D)g2d; diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaRadioButtonUI.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaRadioButtonUI.java index 75e64a33a22d..33a80be0feb3 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaRadioButtonUI.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/ui/DarculaRadioButtonUI.java @@ -44,6 +44,11 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI { return new DarculaRadioButtonUI(); } + @Override public void installDefaults(AbstractButton b) { + super.installDefaults(b); + b.setIconTextGap(JBUI.scale(b.getIconTextGap())); + } + @Override public synchronized void paint(Graphics g2d, JComponent c) { Graphics2D g = (Graphics2D)g2d; @@ -116,46 +121,46 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI { if (!UIUtil.isUnderDarcula() && selected) { GraphicsConfig fillOvalConf = new GraphicsConfig(g); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - g.fill(new Ellipse2D.Float(0, JBUI.scale(1), w, h)); + g.fill(new Ellipse2D.Float(0, 0, w, h)); fillOvalConf.restore(); } else { if (focus) { - g.fill(new Ellipse2D.Float(0, JBUI.scale(1), w, h)); + g.fill(new Ellipse2D.Float(0, 0, w, h)); } else if (c.isEnabled()){ - g.fill(new Ellipse2D.Float(0, JBUI.scale(1), w - JBUI.scale(1), h - JBUI.scale(1))); + g.fill(new Ellipse2D.Float(0, 0, w - JBUI.scale(1), h - JBUI.scale(1))); } } if (focus) { - DarculaUIUtil.paintFocusOval(g, 0, JBUI.scale(1), w, h); + DarculaUIUtil.paintFocusOval(g, 0, 0, w, h); } else { if (UIUtil.isUnderDarcula()) { if (c.isEnabled()) { g.setPaint(UIUtil.getGradientPaint(w / 2, 1, Gray._160.withAlpha(90), w / 2, h, Gray._100.withAlpha(90))); Path2D shape = new Path2D.Float(Path2D.WIND_EVEN_ODD); - shape.append(new Ellipse2D.Float(0, JBUI.scale(1) + 1, w - 1, h - 1), false); - shape.append(new Ellipse2D.Float(lw, JBUI.scale(1) + 1 + lw, w - 1 - lw*2, h - 1 - lw*2), false); + shape.append(new Ellipse2D.Float(0, 1, w - 1, h - 1), false); + shape.append(new Ellipse2D.Float(lw, 1 + lw, w - 1 - lw*2, h - 1 - lw*2), false); g.fill(shape); g.setPaint(Gray._40.withAlpha(200)); shape = new Path2D.Float(Path2D.WIND_EVEN_ODD); - shape.append(new Ellipse2D.Float(0, JBUI.scale(1), w - 1, h - 1), false); - shape.append(new Ellipse2D.Float(lw, JBUI.scale(1) + lw, w - 1 - lw*2, h - 1 - lw*2), false); + shape.append(new Ellipse2D.Float(0, 0, w - 1, h - 1), false); + shape.append(new Ellipse2D.Float(lw, lw, w - 1 - lw*2, h - 1 - lw*2), false); g.fill(shape); } else { g.setColor(Gray.x58); Path2D shape = new Path2D.Float(Path2D.WIND_EVEN_ODD); - shape.append(new Ellipse2D.Float(0, JBUI.scale(1), w - 1, h - 1), false); - shape.append(new Ellipse2D.Float(lw, JBUI.scale(1) + lw, w - 1 - lw*2, h - 1 - lw*2), false); + shape.append(new Ellipse2D.Float(0, 0, w - 1, h - 1), false); + shape.append(new Ellipse2D.Float(lw, lw, w - 1 - lw*2, h - 1 - lw*2), false); g.fill(shape); } } else { g.setPaint(selected ? ijGradient : c.isEnabled() ? Gray._30 : Gray._130); if (!selected) { Path2D shape = new Path2D.Float(Path2D.WIND_EVEN_ODD); - shape.append(new Ellipse2D.Float(0, JBUI.scale(1) + 1, w - 1, h - 1), false); - shape.append(new Ellipse2D.Float(lw, JBUI.scale(1) + 1 + lw, w - 1 - lw*2, h - 1 - lw*2), false); + shape.append(new Ellipse2D.Float(0, 1, w - 1, h - 1), false); + shape.append(new Ellipse2D.Float(lw, 1 + lw, w - 1 - lw*2, h - 1 - lw*2), false); g.fill(shape); } } @@ -163,7 +168,7 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI { if (selected) { boolean enabled = c.isEnabled(); - int yOff = 1 + JBUI.scale(1); + int yOff = 1; if (!UIUtil.isUnderDarcula() || enabled) { g.setColor(UIManager.getColor(enabled ? "RadioButton.darcula.selectionEnabledShadowColor" : "RadioButton.darcula.selectionDisabledShadowColor")); diff --git a/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java b/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java index ca65a953df65..13fcf1f94cfe 100644 --- a/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java +++ b/platform/platform-impl/src/com/intellij/internal/ui/ComponentPanelTestAction.java @@ -244,11 +244,11 @@ public class ComponentPanelTestAction extends DumbAwareAction { panel.add(JBPanelFactory.grid(). add(JBPanelFactory.panel(pb1). - withLabel("Label ygp 1.1"). - withCancel(()-> myAlarm.cancelRequest(timerRequest))). + withLabel("Label 1.1"). + withCancel(()-> myAlarm.cancelRequest(timerRequest)). + andCancelText("Stop")). add(JBPanelFactory.panel(pb2). - withTopSeparator(). - withLabel("Label ygp 1.2"). + withLabel("Label 1.2"). withPause(()-> System.out.println("Pause action #2")). withResume(()-> System.out.println("Resume action #2"))). expandVertically(). @@ -261,7 +261,6 @@ public class ComponentPanelTestAction extends DumbAwareAction { JProgressBar pb4 = new JProgressBar(0, 100); panel.add(JBPanelFactory.grid(). add(JBPanelFactory.panel(pb3). - withTopSeparator(). withLabel("Label 2.1").moveLabelLeft(). withCancel(()-> System.out.println("Cancel action #3"))). add(JBPanelFactory.panel(pb4). diff --git a/platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilderImpl.java b/platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilderImpl.java index 9b987c665d8c..1f6a76f0998f 100644 --- a/platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilderImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/panel/ComponentPanelBuilderImpl.java @@ -186,18 +186,18 @@ public class ComponentPanelBuilderImpl implements ComponentPanelBuilder, GridBag if (myComponent instanceof JRadioButton || myComponent instanceof JCheckBox) { top = 0; - left = isMacDefault ? 27 : 22; + left = isMacDefault ? 27 : 24; bottom = isWin10 ? 10 : isMacDefault ? 8 : 9; } else if (myComponent instanceof JTextField || myComponent instanceof EditorTextField || myComponent instanceof JComboBox || myComponent instanceof ComponentWithBrowseButton) { top = isWin10 ? 3 : 4; - left = isWin10 ? 1 : isMacDefault ? 5 : 2; + left = isWin10 ? 1 : isMacDefault ? 5 : 4; bottom = isWin10 ? 10 : isMacDefault ? 8 : 9; } else if (myComponent instanceof JButton) { top = isWin10 ? 2 : 4; - left = isWin10 ? 1 : isMacDefault ? 5 : 4; + left = isWin10 ? 1 : isMacDefault ? 5 : 6; bottom = 0; } diff --git a/platform/platform-impl/src/com/intellij/ui/panel/ProgressPanelBuilderImpl.java b/platform/platform-impl/src/com/intellij/ui/panel/ProgressPanelBuilderImpl.java index 06fa0dee4757..c61b0c012617 100644 --- a/platform/platform-impl/src/com/intellij/ui/panel/ProgressPanelBuilderImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/panel/ProgressPanelBuilderImpl.java @@ -28,6 +28,7 @@ public class ProgressPanelBuilderImpl implements ProgressPanelBuilder, GridBagPa private Runnable resumeAction; private Runnable pauseAction; + private String cancelText = "Cancel"; private boolean cancelAsButton; private boolean smallVariant; @@ -59,6 +60,12 @@ public class ProgressPanelBuilderImpl implements ProgressPanelBuilder, GridBagPa return this; } + @Override + public ProgressPanelBuilder andCancelText(String cancelText) { + this.cancelText = cancelText; + return this; + } + @Override public ProgressPanelBuilder andCancelAsButton() { this.cancelAsButton = true; @@ -231,7 +238,7 @@ public class ProgressPanelBuilderImpl implements ProgressPanelBuilder, GridBagPa gc.fill = GridBagConstraints.HORIZONTAL; if (topSeparatorEnabled) { - gc.insets = JBUI.insets(8, 0); + gc.insets = JBUI.insets(14, 0, 10, 0); gc.gridwidth = gridWidth(); gc.weightx = 1.0; panel.add(mySeparatorComponent, gc); @@ -259,11 +266,11 @@ public class ProgressPanelBuilderImpl implements ProgressPanelBuilder, GridBagPa myProgressBar.putClientProperty(LABELED_PANEL_PROPERTY, this); gc.weightx = 0.0; - gc.insets = JBUI.insets(labelAbove || topSeparatorEnabled || smallVariant ? 0 : 14, 10, 0, 13); + gc.insets = JBUI.insets(labelAbove || topSeparatorEnabled || smallVariant ? 1 : 14, 10, 0, 13); if (cancelAction != null) { if (cancelAsButton) { - JButton cancelButton = new JButton("Cancel"); + JButton cancelButton = new JButton(cancelText); cancelButton.addActionListener((e) -> cancelAction.run()); panel.add(cancelButton, gc); } @@ -321,7 +328,7 @@ public class ProgressPanelBuilderImpl implements ProgressPanelBuilder, GridBagPa @Override public void mouseEntered(MouseEvent e) { if (cancelAction != null) { - setCommentText("Cancel", true); + setCommentText(cancelText, true); } else if (resumeAction != null && pauseAction != null) { setCommentText(state == State.PLAYING ? "Pause" : "Resume", true); From bb3bf5dad5db86d1f0ca540c3609631b86bd9099 Mon Sep 17 00:00:00 2001 From: Kirill Kirichenko Date: Wed, 17 Jan 2018 17:26:12 +0300 Subject: [PATCH 11/25] API break fix: revert removed DarculaUIUtil.paintFocusRing method. --- .../intellij/ide/ui/laf/darcula/DarculaUIUtil.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaUIUtil.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaUIUtil.java index 43e452031a0a..e806c5953774 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaUIUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaUIUtil.java @@ -94,6 +94,20 @@ public class DarculaUIUtil { abstract public void setGraphicsColor(Graphics2D g, boolean focused); } + /** + * Deprecated in favor of {@link #paintFocusBorder(Graphics2D, int, int, float, boolean)} + */ + @Deprecated + public static void paintFocusRing(Graphics g, Rectangle r) { + Graphics2D g2 = (Graphics2D)g.create(); + try { + g2.translate(r.x, r.y); + paintFocusBorder(g2, r.width, r.height, arc(), true); + } finally { + g2.dispose(); + } + } + public static void paintFocusOval(Graphics2D g, float x, float y, float width, float height) { g.setPaint(IntelliJLaf.isGraphite() ? GRAPHITE_COLOR : REGULAR_COLOR); From 8e32df538546f60275e8bba084aa4c69533c16fd Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Mon, 15 Jan 2018 22:41:51 +0300 Subject: [PATCH 12/25] [groovy] use elvis --- .../typedef/code/BodyCodeMembersProvider.kt | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/BodyCodeMembersProvider.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/BodyCodeMembersProvider.kt index 9b17a9ccc2ce..6649fae27d70 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/BodyCodeMembersProvider.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/BodyCodeMembersProvider.kt @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.code @@ -22,17 +10,14 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe object BodyCodeMembersProvider : GrCodeMembersProvider { override fun getCodeMethods(definition: GrTypeDefinition): Array { - val body = definition.body - return if (body == null) GrMethod.EMPTY_ARRAY else body.methods + return definition.body?.methods ?: GrMethod.EMPTY_ARRAY } override fun getCodeFields(definition: GrTypeDefinition): Array { - val body = definition.body - return if (body == null) GrField.EMPTY_ARRAY else body.fields + return definition.body?.fields ?: GrField.EMPTY_ARRAY } override fun getCodeInnerClasses(definition: GrTypeDefinition): Array { - val body = definition.body - return if (body == null) GrTypeDefinition.EMPTY_ARRAY else body.innerClasses + return definition.body?.innerClasses ?: GrTypeDefinition.EMPTY_ARRAY } } From b0998fef06312d5ceabe041a9427c19f340976c8 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Wed, 17 Jan 2018 17:34:38 +0300 Subject: [PATCH 13/25] use correct ProjectViewPane to select an object in tests --- .../ide/impl/ProjectViewSelectInTarget.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java b/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java index 18f188916058..040f52ab3bb7 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/ProjectViewSelectInTarget.java @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide.impl; @@ -75,7 +63,7 @@ public abstract class ProjectViewSelectInTarget extends SelectInTargetPsiWrapper if (projectView == null) return ActionCallback.REJECTED; if (ApplicationManager.getApplication().isUnitTestMode()) { - AbstractProjectViewPane pane = projectView.getProjectViewPaneById(ProjectViewPane.ID); + AbstractProjectViewPane pane = projectView.getProjectViewPaneById(ObjectUtils.chooseNotNull(viewId, ProjectViewPane.ID)); pane.select(toSelect, virtualFile, requestFocus); return ActionCallback.DONE; } From 3d73f2c56f946152b23c1f2a34ee28a57858fc94 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 17 Jan 2018 17:37:46 +0300 Subject: [PATCH 14/25] [groovy] remove default methods from GrCodeMembersProvider --- .../typedef/code/FileCodeMembersProvider.kt | 19 ++++++------------ .../typedef/code/GrCodeMembersProvider.kt | 20 ++++--------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/FileCodeMembersProvider.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/FileCodeMembersProvider.kt index b0e029c66c56..5c8160f67acc 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/FileCodeMembersProvider.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/FileCodeMembersProvider.kt @@ -1,20 +1,10 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.code +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass @@ -22,4 +12,7 @@ object FileCodeMembersProvider : GrCodeMembersProvider { override fun getCodeMethods(definition: GroovyScriptClass): Array = definition.containingFile.methods + override fun getCodeFields(definition: GroovyScriptClass): Array = GrField.EMPTY_ARRAY + + override fun getCodeInnerClasses(definition: GroovyScriptClass): Array = GrTypeDefinition.EMPTY_ARRAY } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/GrCodeMembersProvider.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/GrCodeMembersProvider.kt index 0943535c2866..32e8dbc6edbe 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/GrCodeMembersProvider.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/code/GrCodeMembersProvider.kt @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.code @@ -21,9 +9,9 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe interface GrCodeMembersProvider { - open fun getCodeMethods(definition: T): Array = GrMethod.EMPTY_ARRAY + fun getCodeMethods(definition: T): Array - open fun getCodeFields(definition: T): Array = GrField.EMPTY_ARRAY + fun getCodeFields(definition: T): Array - open fun getCodeInnerClasses(definition: T): Array = GrTypeDefinition.EMPTY_ARRAY + fun getCodeInnerClasses(definition: T): Array } From 3eff710599899e11202cb4d901cf4773ad5e98e1 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Mon, 18 Dec 2017 18:13:46 +0300 Subject: [PATCH 15/25] [groovy] @NotNull --- .../psi/impl/synthetic/GroovyScriptClass.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GroovyScriptClass.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GroovyScriptClass.java index 3883d9b6a201..e67a494c7b42 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GroovyScriptClass.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/GroovyScriptClass.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic; @@ -65,6 +53,7 @@ public class GroovyScriptClass extends GrLightTypeDefinitionBase implements Synt return new GroovyScriptClass(myFile); } + @NotNull @Override public GroovyFile getContainingFile() { return myFile; From 684d64a73e805c790831fd645945fb8a327daa61 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Thu, 14 Dec 2017 19:15:36 +0300 Subject: [PATCH 16/25] [groovy] remove resolveClosures parameter (it's always true) --- .../impl/statements/expressions/TypesUtil.java | 6 ++++-- .../path/GrIndexPropertyReference.kt | 18 +++--------------- .../groovy/lang/resolve/ResolveUtil.java | 15 ++++----------- .../resolve/references/GrOperatorResolver.kt | 4 ++-- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java index 838eb2ee7a47..3d8e119c9326 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/TypesUtil.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions; import com.intellij.openapi.project.Project; @@ -79,7 +81,7 @@ public class TypesUtil implements TypeConstants { @NotNull GroovyPsiElement place, PsiType[] argumentTypes, boolean incompleteCode) { - return ResolveUtil.getMethodCandidates(thisType, ourOperationsToOperatorNames.get(tokenType), place, true, incompleteCode, argumentTypes); + return ResolveUtil.getMethodCandidates(thisType, ourOperationsToOperatorNames.get(tokenType), place, incompleteCode, argumentTypes); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyReference.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyReference.kt index 7e15a11b7b0a..887cc2327143 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyReference.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyReference.kt @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.path @@ -67,9 +55,9 @@ private fun GrIndexProperty.doMultiResolve(rhs: Boolean, incomplete: Boolean): A val name = if (rhs) "getAt" else "putAt" val argTypes = if (rType == null) arrayOf(argumentListType) else arrayOf(argumentListType, rType) - val candidates = ResolveUtil.getMethodCandidates(thisType, name, this, true, incomplete, *argTypes) + val candidates = ResolveUtil.getMethodCandidates(thisType, name, this, incomplete, *argTypes) if (argumentListType !is GrTupleType || candidates.any { it.isValidResult }) return candidates val unwrappedArgTypes = if (rType == null) argumentListType.componentTypes else argumentListType.componentTypes + rType - return ResolveUtil.getMethodCandidates(thisType, name, this, true, incomplete, *unwrappedArgTypes) + return ResolveUtil.getMethodCandidates(thisType, name, this, incomplete, *unwrappedArgTypes) } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java index f4cd467c64fb..3cd6533a5682 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java @@ -709,14 +709,13 @@ public class ResolveUtil { @Nullable String methodName, @NotNull PsiElement place, @Nullable PsiType... argumentTypes) { - return getMethodCandidates(thisType, methodName, place, true, false, argumentTypes); + return getMethodCandidates(thisType, methodName, place, false, argumentTypes); } @NotNull public static GroovyResolveResult[] getMethodCandidates(@NotNull PsiType thisType, @Nullable String methodName, @NotNull PsiElement place, - boolean resolveClosures, boolean allVariants, @Nullable PsiType... argumentTypes) { if (methodName == null) return GroovyResolveResult.EMPTY_ARRAY; @@ -729,15 +728,9 @@ public class ResolveUtil { final GroovyResolveResult[] methodCandidates = processor.getCandidates(); if (hasApplicableMethods && methodCandidates.length == 1) return methodCandidates; - final GroovyResolveResult[] allPropertyCandidates; - if (resolveClosures) { - PropertyResolverProcessor propertyResolver = new PropertyResolverProcessor(methodName, place); - processAllDeclarations(thisType, propertyResolver, state, place); - allPropertyCandidates = propertyResolver.getCandidates(); - } - else { - allPropertyCandidates = GroovyResolveResult.EMPTY_ARRAY; - } + PropertyResolverProcessor propertyResolver = new PropertyResolverProcessor(methodName, place); + processAllDeclarations(thisType, propertyResolver, state, place); + final GroovyResolveResult[] allPropertyCandidates = propertyResolver.getCandidates(); List propertyCandidates = new ArrayList<>(allPropertyCandidates.length); for (GroovyResolveResult candidate : allPropertyCandidates) { diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/references/GrOperatorResolver.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/references/GrOperatorResolver.kt index 3ff797c0af2b..df95b5176ea7 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/references/GrOperatorResolver.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/references/GrOperatorResolver.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.resolve.references @@ -72,6 +72,6 @@ object GrOperatorResolver : DependentResolver() { val operatorName = operatorNames[ref.operator] ?: return EMPTY_ARRAY val leftType = ref.leftType ?: return EMPTY_ARRAY val rightType = ref.rightType - return getMethodCandidates(leftType, operatorName, ref, true, incomplete, rightType) + return getMethodCandidates(leftType, operatorName, ref, incomplete, rightType) } } From 4b8f149e90fc22527e4678b9b0d44fdc458195fb Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 16 Jan 2018 17:27:49 +0300 Subject: [PATCH 17/25] [groovy] @NotNull and clean CollectClassMembersUtil --- .../lang/resolve/CollectClassMembersUtil.java | 73 +++++++------------ 1 file changed, 25 insertions(+), 48 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/CollectClassMembersUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/CollectClassMembersUtil.java index a9f31f5455f2..5354f650ddf0 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/CollectClassMembersUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/CollectClassMembersUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.resolve; @@ -23,48 +23,21 @@ import java.util.*; * @author ven */ public class CollectClassMembersUtil { + private static class ClassMembers { - private final Map myFields; - private final Map> myMethods; - private final Map myInnerClasses; - - private ClassMembers(@NotNull Map fields, - @NotNull Map> methods, - @NotNull Map innerClasses) { - myFields = fields; - myMethods = methods; - myInnerClasses = innerClasses; - } - - public static ClassMembers create(@NotNull LinkedHashMap first, - @NotNull LinkedHashMap> second, - @NotNull LinkedHashMap third) { - return new ClassMembers(first, second, third); - } - - private Map getFields() { - return myFields; - } - - private Map> getMethods() { - return myMethods; - } - - private Map getInnerClasses() { - return myInnerClasses; - } + private final Map fields = ContainerUtil.newLinkedHashMap(); + private final Map> methods = ContainerUtil.newLinkedHashMap(); + private final Map innerClasses = ContainerUtil.newLinkedHashMap(); } private static final Key> CACHED_MEMBERS = Key.create("CACHED_CLASS_MEMBERS"); - private static final Key> CACHED_MEMBERS_INCLUDING_SYNTHETIC = Key.create("CACHED_MEMBERS_INCLUDING_SYNTHETIC"); - private CollectClassMembersUtil() { - } + private CollectClassMembersUtil() {} - - public static Map> getAllMethods(final PsiClass aClass, boolean includeSynthetic) { - return getCachedMembers(aClass, includeSynthetic).getMethods(); + @NotNull + public static Map> getAllMethods(@NotNull PsiClass aClass, boolean includeSynthetic) { + return getCachedMembers(aClass, includeSynthetic).methods; } @NotNull @@ -77,12 +50,12 @@ public class CollectClassMembersUtil { return buildCache(aClass, includeSynthetic && checkClass(aClass)); } - private static boolean checkClass(PsiClass aClass) { + private static boolean checkClass(@NotNull PsiClass aClass) { Set visited = ContainerUtil.newHashSet(); Queue queue = ContainerUtil.newLinkedList(aClass); while (!queue.isEmpty()) { - PsiClass current = queue.poll(); + PsiClass current = queue.remove(); if (current instanceof ClsClassImpl) continue; if (visited.add(current)) { if (TransformationUtilKt.isUnderTransformation(current)) return false; @@ -98,31 +71,31 @@ public class CollectClassMembersUtil { return true; } + @NotNull public static Map getAllInnerClasses(@NotNull final PsiClass aClass, boolean includeSynthetic) { - return getCachedMembers(aClass, includeSynthetic).getInnerClasses(); + return getCachedMembers(aClass, includeSynthetic).innerClasses; } + @NotNull public static Map getAllFields(@NotNull final PsiClass aClass, boolean includeSynthetic) { - return getCachedMembers(aClass, includeSynthetic).getFields(); + return getCachedMembers(aClass, includeSynthetic).fields; } + @NotNull public static Map getAllFields(@NotNull final PsiClass aClass) { return getAllFields(aClass, true); } + @NotNull private static ClassMembers buildCache(@NotNull final PsiClass aClass, final boolean includeSynthetic) { return CachedValuesManager.getManager(aClass.getProject()).getCachedValue(aClass, getMemberCacheKey(includeSynthetic), () -> { - LinkedHashMap allFields = ContainerUtil.newLinkedHashMap(); - LinkedHashMap> allMethods = ContainerUtil.newLinkedHashMap(); - LinkedHashMap allInnerClasses = ContainerUtil.newLinkedHashMap(); - - processClass(aClass, allFields, allMethods, allInnerClasses, new HashSet<>(), PsiSubstitutor.EMPTY, includeSynthetic); - return CachedValueProvider.Result.create( - ClassMembers.create(allFields, allMethods, allInnerClasses), PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT - ); + ClassMembers result = new ClassMembers(); + processClass(aClass, result.fields, result.methods, result.innerClasses, new HashSet<>(), PsiSubstitutor.EMPTY, includeSynthetic); + return CachedValueProvider.Result.create(result, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); }, false); } + @NotNull private static Key> getMemberCacheKey(boolean includeSynthetic) { return includeSynthetic ? CACHED_MEMBERS_INCLUDING_SYNTHETIC : CACHED_MEMBERS; } @@ -179,20 +152,24 @@ public class CollectClassMembersUtil { } } + @NotNull public static PsiField[] getFields(@NotNull PsiClass aClass, boolean includeSynthetic) { return includeSynthetic || !(aClass instanceof GrTypeDefinition) ? aClass.getFields() : ((GrTypeDefinition)aClass).getCodeFields(); } + @NotNull public static PsiMethod[] getMethods(@NotNull PsiClass aClass, boolean includeSynthetic) { return includeSynthetic || !(aClass instanceof GrTypeDefinition) ? aClass.getMethods() : ((GrTypeDefinition)aClass).getCodeMethods(); } + @NotNull public static PsiClass[] getInnerClasses(@NotNull PsiClass aClass, boolean includeSynthetic) { return includeSynthetic || !(aClass instanceof GrTypeDefinition) ? aClass.getInnerClasses() : ((GrTypeDefinition)aClass).getCodeInnerClasses(); } + @NotNull public static PsiClass[] getSupers(@NotNull PsiClass aClass, boolean includeSynthetic) { return aClass instanceof GrTypeDefinition ? ((GrTypeDefinition)aClass).getSupers(includeSynthetic) From 7554f1612b1ea142539e1b4b5bb2cac23d693f6a Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 17 Jan 2018 15:10:01 +0300 Subject: [PATCH 18/25] [groovy] add isThisExpression and update isSuperExpression --- .../plugins/groovy/lang/psi/util/psiUtil.kt | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/psiUtil.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/psiUtil.kt index 4d8e853f2f30..6497ded8487e 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/psiUtil.kt +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/psiUtil.kt @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.psi.util @@ -51,6 +39,9 @@ fun modifierListMayBeEmpty(owner: PsiElement?): Boolean = when (owner) { } fun GrExpression?.isSuperExpression(): Boolean { - val referenceExpression = this as? GrReferenceExpression - return referenceExpression?.referenceNameElement?.node?.elementType == GroovyTokenTypes.kSUPER + return this is GrReferenceExpression && referenceNameElement?.node?.elementType === GroovyTokenTypes.kSUPER +} + +fun GrExpression?.isThisExpression(): Boolean { + return this is GrReferenceExpression && referenceNameElement?.node?.elementType === GroovyTokenTypes.kTHIS } From 86d1ad70d8b02f738755fff2eb25b6722043a938 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 17 Jan 2018 15:41:49 +0300 Subject: [PATCH 19/25] [groovy] extract ThrowingTransformation --- .../GrNoTransformationsTest.groovy | 18 +++++----------- .../groovy/util/ThrowingTransformation.kt | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 plugins/groovy/test/org/jetbrains/plugins/groovy/util/ThrowingTransformation.kt diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/transformations/GrNoTransformationsTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/transformations/GrNoTransformationsTest.groovy index 674b785f4f65..3f950187d570 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/transformations/GrNoTransformationsTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/transformations/GrNoTransformationsTest.groovy @@ -1,15 +1,16 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package org.jetbrains.plugins.groovy.transformations import com.intellij.testFramework.LightProjectDescriptor import groovy.transform.CompileStatic -import org.jetbrains.annotations.NotNull import org.jetbrains.plugins.groovy.GroovyLightProjectDescriptor import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter import org.jetbrains.plugins.groovy.lang.resolve.GroovyResolveTestCase -import static com.intellij.testFramework.PlatformTestUtil.registerExtension +import static org.jetbrains.plugins.groovy.util.ThrowingTransformation.disableTransformations @CompileStatic class GrNoTransformationsTest extends GroovyResolveTestCase { @@ -19,7 +20,7 @@ class GrNoTransformationsTest extends GroovyResolveTestCase { @Override void setUp() { super.setUp() - disableTransformations() + disableTransformations testRootDisposable addSomeClasses() } @@ -123,13 +124,4 @@ class Hello {} class World {} ''' } - - private void disableTransformations() { - registerExtension AstTransformationSupport.EP_NAME, new AstTransformationSupport() { - @Override - void applyTransformation(@NotNull TransformationContext context) { - assert false: "Transformation of $context.codeClass.name was requested. Transformations are not allowed" - } - }, testRootDisposable - } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/util/ThrowingTransformation.kt b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/ThrowingTransformation.kt new file mode 100644 index 000000000000..5b9482488581 --- /dev/null +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/util/ThrowingTransformation.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ +package org.jetbrains.plugins.groovy.util + +import com.intellij.openapi.Disposable +import com.intellij.testFramework.PlatformTestUtil.registerExtension +import org.jetbrains.plugins.groovy.transformations.AstTransformationSupport +import org.jetbrains.plugins.groovy.transformations.TransformationContext + +object ThrowingTransformation : AstTransformationSupport { + + @JvmStatic + fun disableTransformations(parentDisposable: Disposable) { + registerExtension(AstTransformationSupport.EP_NAME, this, parentDisposable) + } + + override fun applyTransformation(context: TransformationContext): Nothing { + throw UnsupportedOperationException("Transformation requested for ${context.codeClass.name}") + } +} From e4556e78d1afef263c26538bd02f7cebdc090f75 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 17 Jan 2018 15:51:50 +0300 Subject: [PATCH 20/25] [groovy] disable transformations in local variable tests --- .../lang/resolve/ResolvePropertyTest.groovy | 63 ++++++++++++------- .../resolve/ResolveWithDelegatesToTest.groovy | 38 ++++------- 2 files changed, 54 insertions(+), 47 deletions(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy index 06dc4218b07c..d18edbe2c56e 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolvePropertyTest.groovy @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package org.jetbrains.plugins.groovy.lang.resolve import com.intellij.psi.* @@ -20,6 +22,8 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil import org.jetbrains.plugins.groovy.util.TestUtils +import static org.jetbrains.plugins.groovy.util.ThrowingTransformation.disableTransformations + /** * @author ven */ @@ -27,11 +31,13 @@ class ResolvePropertyTest extends GroovyResolveTestCase { final String basePath = TestUtils.testDataPath + "resolve/property/" void testParameter1() throws Exception { - doTest("parameter1/A.groovy") + disableTransformations testRootDisposable + resolve "A.groovy", GrParameter } void testClosureParameter1() throws Exception { - doTest("closureParameter1/A.groovy") + disableTransformations testRootDisposable + resolve "A.groovy", GrParameter } void testClosureOwner() throws Exception { @@ -41,6 +47,7 @@ class ResolvePropertyTest extends GroovyResolveTestCase { } void testLocal1() throws Exception { + disableTransformations testRootDisposable doTest("local1/A.groovy") } @@ -53,7 +60,8 @@ class ResolvePropertyTest extends GroovyResolveTestCase { } void testForVariable1() throws Exception { - doTest("forVariable1/ForVariable.groovy") + disableTransformations testRootDisposable + resolve "ForVariable.groovy", GrParameter } void testArrayLength() throws Exception { @@ -85,14 +93,17 @@ class ResolvePropertyTest extends GroovyResolveTestCase { } void testCatchParameter() throws Exception { - doTest("catchParameter/CatchParameter.groovy") + disableTransformations testRootDisposable + resolve "CatchParameter.groovy", GrParameter } void testCaseClause() throws Exception { + disableTransformations testRootDisposable doTest("caseClause/CaseClause.groovy") } void testGrvy104() throws Exception { + disableTransformations testRootDisposable doTest("grvy104/Test.groovy") } @@ -102,8 +113,8 @@ class ResolvePropertyTest extends GroovyResolveTestCase { } void testGrvy1483() throws Exception { - PsiReference ref = configureByFile("grvy1483/Test.groovy") - assertNotNull(ref.resolve()) + disableTransformations testRootDisposable + resolve "Test.groovy", GrVariable } void testField3() throws Exception { @@ -158,7 +169,8 @@ c = aa } void testDefinedVar1() throws Exception { - doTest("definedVar1/A.groovy") + disableTransformations testRootDisposable + resolve "A.groovy", GrVariable } void testOperatorOverload() throws Exception { @@ -190,6 +202,7 @@ c = aa } void testGrvy575() throws Exception { + disableTransformations testRootDisposable doTest("grvy575/A.groovy") } @@ -199,6 +212,7 @@ c = aa } void testClosureCall() throws Exception { + disableTransformations testRootDisposable PsiReference ref = configureByFile("closureCall/ClosureCall.groovy") assertTrue(ref.resolve() instanceof GrVariable) } @@ -624,6 +638,7 @@ setFoo(2) } void testAnonymousClassFieldAndLocalVar() { + disableTransformations testRootDisposable final PsiElement resolved = resolve("A.groovy") assertInstanceOf resolved, PsiVariable assertTrue PsiUtil.isLocalVariable(resolved) @@ -759,8 +774,8 @@ class SomeMapClass extends HashMap { assertEquals(resolved.containingClass.name, 'B') } - void testLocalVarVsFieldInWithClosure() { +// TODO disableTransformations testRootDisposable def ref = configureByText('''\ class Test { def var @@ -1071,7 +1086,8 @@ print Field1 } void testLocalVarVsClassFieldInAnonymous() { - final ref = configureByText('a.groovy', '''\ + disableTransformations testRootDisposable + def resolved = resolveByText '''\ class A { public foo } @@ -1083,10 +1099,8 @@ print Field1 print foo } } -''') - - assertFalse(ref.resolve() instanceof PsiField) - assertTrue(ref.resolve() instanceof GrVariable) +''', GrVariable + assert !(resolved instanceof PsiField) } void testInterfaceDoesNotResolveWithExpressionQualifier() { @@ -1269,22 +1283,24 @@ aaa = 1 void testVarVsPackage2() { myFixture.addClass('''package p; public class A {}''') + disableTransformations testRootDisposable - resolveByText('''\ + resolveByText '''\ def p = [A:5] print p -''', PsiVariable) +''', GrVariable } void testVarVsPackage3() { myFixture.addClass('''package p; public class A {}''') + disableTransformations testRootDisposable - resolveByText('''\ + resolveByText '''\ def p = [A:{2}] print p.A() -''', PsiVariable) +''', GrVariable } void testVarVsPackage4() { @@ -1299,26 +1315,28 @@ aaa = 1 void testVarVsClass1() { myFixture.addClass('package p; public class A {public static int foo() {return 1;}}') + disableTransformations testRootDisposable - resolveByText('''\ + resolveByText '''\ import p.A def A = [a:{-1}] print A -''', PsiVariable) +''', GrVariable } void testVarVsClass2() { myFixture.addClass('package p; public class A {public static int foo() {return 1;}}') + disableTransformations testRootDisposable - resolveByText('''\ + resolveByText '''\ import p.A def A = [a:{-1}] print A.a() -''', PsiVariable) +''', GrVariable } void testPropertyVsAccessor() { @@ -1556,6 +1574,7 @@ class Foo { } void 'test prefer local over map key'() { + disableTransformations testRootDisposable resolveByText 'def abc = 42; [:].with { abc }', GrVariable } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveWithDelegatesToTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveWithDelegatesToTest.groovy index 87ede2267456..6fdd4579e8b5 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveWithDelegatesToTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveWithDelegatesToTest.groovy @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.lang.resolve @@ -24,6 +12,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter +import static org.jetbrains.plugins.groovy.util.ThrowingTransformation.disableTransformations + /** * @author Max Medvedev */ @@ -703,14 +693,14 @@ class Methods { static m1(@DelegatesTo(value = String, strategy = Closure.DELEGATE_ONLY) Closure c) {} } ''' + disableTransformations testRootDisposable + // resolve to outer closure parameter - resolveByText('''\ + resolveByText '''\ def c = { String s1 -> Methods.m1 { s1 + toUpperCase() } } -''').with { - assert it instanceof GrParameter - } +''', GrParameter // resolve to outer closure local variable resolveByText('''\ @@ -718,18 +708,16 @@ def c = { String s1 -> def s2 = "123" Methods.m1 { s2 + toUpperCase() } } -''').with { - assert it instanceof GrVariable && !(it instanceof GrField) && !(it instanceof GrParameter) +''', GrVariable).with { + assert !(it instanceof GrField) && !(it instanceof GrParameter) } // resolve to outer method parameter - resolveByText('''\ + resolveByText '''\ def m(String s1) { Methods.m1 {s1 + toUpperCase() } } -''').with { - assert it instanceof GrParameter - } +''', GrParameter // resolve to outer method local variable resolveByText('''\ @@ -737,8 +725,8 @@ def m(String s1) { def s2 = "123" Methods.m1 { s1 + s2 + toUpperCase() } } -''').with { - assert it instanceof GrVariable && !(it instanceof GrField) && !(it instanceof GrParameter) +''', GrVariable).with { + assert !(it instanceof GrField) && !(it instanceof GrParameter) } } From ad7ebf74a85a013f0bcead251f431d32450af173 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Mon, 18 Dec 2017 20:22:32 +0300 Subject: [PATCH 21/25] [groovy] clean up GrClosureType --- .../groovy/lang/psi/impl/GrClosureType.java | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrClosureType.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrClosureType.java index ed382e1cf80f..a8a21eec61cc 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrClosureType.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrClosureType.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package org.jetbrains.plugins.groovy.lang.psi.impl; import com.intellij.openapi.util.Comparing; @@ -146,23 +148,6 @@ public class GrClosureType extends GrLiteralClassType { return create(signature, resolveScope, facade,LanguageLevel.JDK_1_5, shouldInferTypeParameters); } - @Deprecated - public static GrClosureType create(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor) { - final GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, substitutor); - final GlobalSearchScope scope = GlobalSearchScope.allScope(method.getProject()); - final JavaPsiFacade facade = JavaPsiFacade.getInstance(method.getProject()); - return create(signature, scope, facade, LanguageLevel.JDK_1_5, true); - } - - @Deprecated - public static GrClosureType create(@NotNull PsiParameter[] parameters, - @Nullable PsiType returnType, - JavaPsiFacade facade, - GlobalSearchScope scope, - LanguageLevel languageLevel) { - return create(GrClosureSignatureUtil.createSignature(parameters, returnType), scope, facade, languageLevel, true); - } - public static GrClosureType create(@NotNull GrSignature signature, GlobalSearchScope scope, JavaPsiFacade facade, From ed7f0acb3c482a95a91a8587acf2477c40c7b16d Mon Sep 17 00:00:00 2001 From: Olga Strizhenko Date: Wed, 17 Jan 2018 15:54:59 +0300 Subject: [PATCH 22/25] Spellchecker: fix test dict path --- .../dictionary/CustomDictionaryTest.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java b/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java index 8dadfa64dc12..1d8f3b9b2a26 100644 --- a/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java +++ b/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.spellchecker.dictionary; @@ -134,7 +122,7 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { private void doLoadTest() throws IOException { final VirtualFile file = findFileByIoFile(Paths.get(getTestDictDirectory(), TEST_DIC_AFTER).toFile(), true); - final String new_test_dic = toSystemIndependentName(file.getParent().getPath()) + File.separator + NEW_TEST_DIC; + final String new_test_dic = toSystemIndependentName(file.getParent().getPath() + File.separator + NEW_TEST_DIC); settings.getCustomDictionariesPaths().add(new_test_dic); spellCheckerManager.fullConfigurationReload(); try { From fb1f1fa2f4af6431b1c5474b5ec92f00e68d3178 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 17 Jan 2018 16:20:51 +0100 Subject: [PATCH 23/25] Cleanup (minor optimization; warnings) --- .../ui/impl/watch/CompilingEvaluator.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluator.java b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluator.java index 83a45c9ba9b7..2e55c8ff86ee 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluator.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/impl/watch/CompilingEvaluator.java @@ -1,6 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. -// Use of this source code is governed by the Apache 2.0 license that can be -// found in the LICENSE file. +/* + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.debugger.ui.impl.watch; import com.intellij.debugger.DebuggerInvocationUtil; @@ -22,7 +22,6 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.psi.PsiElement; import com.intellij.refactoring.extractMethodObject.ExtractLightMethodObjectHandler; import com.sun.jdi.ClassLoaderReference; -import com.sun.jdi.ClassType; import com.sun.jdi.Value; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -65,10 +64,9 @@ public abstract class CompilingEvaluator implements ExpressionEvaluator { ClassLoaderReference classLoader = ClassLoadingUtils.getClassLoader(autoLoadContext, process); autoLoadContext.setClassLoader(classLoader); - String version = ((VirtualMachineProxyImpl)process.getVirtualMachineProxy()).version(); - Collection classes = compile(JavaSdkVersion.fromVersionString(version)); - - defineClasses(classes, autoLoadContext, process, classLoader); + JavaSdkVersion version = JavaSdkVersion.fromVersionString(((VirtualMachineProxyImpl)process.getVirtualMachineProxy()).version()); + Collection classes = compile(version); + defineClasses(version, classes, autoLoadContext, process, classLoader); try { // invoke base evaluator on call code @@ -90,12 +88,12 @@ public abstract class CompilingEvaluator implements ExpressionEvaluator { } } - private ClassType defineClasses(Collection classes, - EvaluationContext context, - DebugProcess process, - ClassLoaderReference classLoader) throws EvaluateException { - JavaSdkVersion targetVersion = JavaSdkVersion.fromVersionString(((VirtualMachineProxyImpl)process.getVirtualMachineProxy()).version()); - boolean useMagicAccessorImpl = targetVersion != null && !targetVersion.isAtLeast(JavaSdkVersion.JDK_1_9); + private void defineClasses(JavaSdkVersion version, + Collection classes, + EvaluationContext context, + DebugProcess process, + ClassLoaderReference classLoader) throws EvaluateException { + boolean useMagicAccessorImpl = version != null && !version.isAtLeast(JavaSdkVersion.JDK_1_9); for (ClassObject cls : classes) { if (cls.getPath().contains(GEN_CLASS_NAME)) { @@ -108,7 +106,7 @@ public abstract class CompilingEvaluator implements ExpressionEvaluator { } } } - return (ClassType)process.findClass(context, getGenClassQName(), classLoader); + process.findClass(context, getGenClassQName(), classLoader); } private static byte[] changeSuperToMagicAccessor(byte[] bytes) { From b68d6a07315c043cfeea6443a2a3be7531ea420a Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 17 Jan 2018 16:30:23 +0100 Subject: [PATCH 24/25] Cleanup (simpler runtime version check) --- .../compiler/GroovyCompilerTestCase.groovy | 24 ++++++------------- .../javaFX/sceneBuilder/SceneBuilderImpl.java | 5 ++-- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy index a5933a1f06f5..8b4c16c5e670 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.groovy @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package org.jetbrains.plugins.groovy.compiler @@ -46,6 +34,7 @@ import com.intellij.testFramework.builders.JavaModuleFixtureBuilder import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase import com.intellij.util.SystemProperties import com.intellij.util.io.PathKt +import com.intellij.util.lang.JavaVersion import groovy.transform.CompileStatic import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable @@ -53,6 +42,7 @@ import org.jetbrains.plugins.groovy.config.GroovyFacetUtil import org.jetbrains.plugins.groovy.runner.GroovyScriptRunConfiguration import org.jetbrains.plugins.groovy.runner.GroovyScriptRunConfigurationType import org.jetbrains.plugins.groovy.util.Slow + /** * @author aalmiray * @author peter @@ -81,7 +71,7 @@ abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase imp @Override protected void tuneFixture(JavaModuleFixtureBuilder moduleBuilder) throws Exception { - moduleBuilder.setLanguageLevel(JavaSdkVersion.fromVersionString(SystemProperties.javaVersion).maxLanguageLevel) + moduleBuilder.setLanguageLevel(JavaSdkVersion.fromJavaVersion(JavaVersion.current()).maxLanguageLevel) def javaHome = FileUtil.toSystemIndependentName(SystemProperties.javaHome) moduleBuilder.addJdk(StringUtil.trimEnd(StringUtil.trimEnd(javaHome, '/'), '/jre')) super.tuneFixture(moduleBuilder) @@ -223,9 +213,9 @@ abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase imp }, ProgramRunner.PROGRAM_RUNNER_EP.findExtension(DefaultJavaProgramRunner.class)) process.waitFor() def output = StringUtil.convertLineSeparators(sb.toString().trim()).readLines() - output = output.findAll { line -> - !StringUtil.containsIgnoreCase(line, "illegal") && - !line.contains("consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass") + output = output.findAll { line -> + !StringUtil.containsIgnoreCase(line, "illegal") && + !line.contains("consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass") } assertEquals(expected.trim(), output.join("\n")) } diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/sceneBuilder/SceneBuilderImpl.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/sceneBuilder/SceneBuilderImpl.java index f1fcd76f53c0..4b872535311a 100644 --- a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/sceneBuilder/SceneBuilderImpl.java +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/sceneBuilder/SceneBuilderImpl.java @@ -29,6 +29,7 @@ import com.intellij.psi.util.PsiModificationTracker; import com.intellij.psi.util.PsiUtilCore; import com.intellij.util.Query; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.lang.JavaVersion; import com.intellij.util.xml.NanoXmlUtil; import com.oracle.javafx.scenebuilder.kit.editor.EditorController; import com.oracle.javafx.scenebuilder.kit.editor.panel.content.ContentPanelController; @@ -185,8 +186,8 @@ public class SceneBuilderImpl implements SceneBuilder { // Take custom components from libraries, but not from the project modules, because SceneBuilder instantiates the components' classes. // Modules might be not compiled or may change since last compile, it's too expensive to keep track of that. final GlobalSearchScope scope = ProjectScope.getLibrariesScope(nodeClass.getProject()); - final String ideJdkVersion = Object.class.getPackage().getSpecificationVersion(); - final LanguageLevel ideLanguageLevel = LanguageLevel.parse(ideJdkVersion); + final JavaSdkVersion ideJdkVersion = JavaSdkVersion.fromJavaVersion(JavaVersion.current()); + final LanguageLevel ideLanguageLevel = ideJdkVersion != null ? ideJdkVersion.getMaxLanguageLevel() : null; final Query query = ClassInheritorsSearch.search(nodeClass, scope, true, true, false); final Set result = new THashSet<>(); query.forEach(psiClass -> { From d6846d4ba6052ef08facff29e1d78a2f3472af29 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 17 Jan 2018 16:31:23 +0100 Subject: [PATCH 25/25] Cleanup (code reuse) --- .../codeInspection/JavaSuppressionUtil.java | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/JavaSuppressionUtil.java b/java/java-analysis-impl/src/com/intellij/codeInspection/JavaSuppressionUtil.java index d9a1dd34428f..62fab5d176b9 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/JavaSuppressionUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/JavaSuppressionUtil.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2017 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. + * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.codeInspection; @@ -24,6 +12,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.JavaSdkVersion; +import com.intellij.openapi.projectRoots.JavaSdkVersionUtil; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.util.text.StringUtil; @@ -317,19 +306,12 @@ public class JavaSuppressionUtil { if (module == null) return false; final Sdk jdk = ModuleRootManager.getInstance(module).getSdk(); if (jdk == null) return false; - JavaSdkVersion version = getVersion(jdk); + final JavaSdkVersion version = JavaSdkVersionUtil.getJavaSdkVersion(jdk); if (version == null) return false; final boolean is_1_5 = version.isAtLeast(JavaSdkVersion.JDK_1_5); return DaemonCodeAnalyzerSettings.getInstance().isSuppressWarnings() && is_1_5 && PsiUtil.isLanguageLevel5OrHigher(file); } - @Nullable - private static JavaSdkVersion getVersion(@NotNull Sdk sdk) { - String version = sdk.getVersionString(); - if (version == null) return null; - return JavaSdkVersion.fromVersionString(version); - } - @Nullable public static PsiElement getElementToAnnotate(PsiElement element, PsiElement container) { if (container instanceof PsiDeclarationStatement) {