Merge remote-tracking branch 'origin/master'

This commit is contained in:
Sergey.Anchipolevsky
2018-01-17 18:40:15 +03:00
55 changed files with 415 additions and 487 deletions
@@ -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<ClassObject> classes = compile(JavaSdkVersion.fromVersionString(version));
defineClasses(classes, autoLoadContext, process, classLoader);
JavaSdkVersion version = JavaSdkVersion.fromVersionString(((VirtualMachineProxyImpl)process.getVirtualMachineProxy()).version());
Collection<ClassObject> 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<ClassObject> 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<ClassObject> 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) {
@@ -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<String> 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();
@@ -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) {
@@ -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<Module> 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<Module> neededModules = depRefModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES);
@@ -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());
}
}
@@ -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<JavaProjectData, Project> {
@NotNull
@Override
public Key<JavaProjectData> getTargetDataKey() {
@@ -91,7 +74,7 @@ public class JavaProjectDataService extends AbstractProjectDataService<JavaProje
}
private static void updateSdk(@NotNull final Project project, @NotNull final JavaSdkVersion version) {
final Sdk sdk = findJdk(version);
Sdk sdk = JavaSdkVersionUtil.findJdkByVersion(version);
if (sdk == null) return;
ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {
@@ -107,23 +90,6 @@ public class JavaProjectDataService extends AbstractProjectDataService<JavaProje
});
}
@Nullable
private static Sdk findJdk(@NotNull JavaSdkVersion version) {
JavaSdk javaSdk = JavaSdk.getInstance();
List<Sdk> 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<JavaProje
}
});
}
}
}
@@ -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) {
@@ -0,0 +1,9 @@
class Test {
{
var r = new Runnable() {
public void run() {
System.out.println();
}
};
}
}
@@ -29,7 +29,7 @@ class Main {
<error descr="Cannot infer type: lambda expression requires an explicit target type">var</error> f = () -> "hello";
<error descr="Cannot infer type: method reference requires an explicit target type">var</error> m = Main::localVariableDeclaration;
<error descr="Cannot infer type: variable initializer is 'null'">var</error> g = null;
var runnable = true ? <error descr="<lambda expression> is not a functional interface">() -> {}</error> : <error descr="<lambda expression> is not a functional interface">() -> {}</error>;
var runnable = true ? <error descr="Lambda expression not expected here">() -> {}</error> : <error descr="Lambda expression not expected here">() -> {}</error>;
}
private void forEachType(String[] strs, Iterable<String> it, Iterable raw) {
@@ -10,6 +10,6 @@ class ReturnTypeCompatibility {
}
public static void main(String[] args) {
call("", (Str<caret>ing i) -> "");
call("", (Str<caret>ing/*comment*/ i) -> "");
}
}
@@ -10,6 +10,6 @@ class ReturnTypeCompatibility {
}
public static void main(String[] args) {
call("", i -> "");
call("", i -> /*comment*/ "");
}
}
@@ -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(); }
@@ -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.openapi.projectRoots;
@@ -36,4 +24,20 @@ public class JavaSdkVersionUtil {
public static JavaSdkVersion getJavaSdkVersion(@Nullable Sdk sdk) {
return sdk != null && sdk.getSdkType() instanceof JavaSdk ? ((JavaSdk)sdk.getSdkType()).getVersion(sdk) : null;
}
@Nullable
public static Sdk findJdkByVersion(@NotNull JavaSdkVersion version) {
JavaSdk javaSdk = JavaSdk.getInstance();
Sdk candidate = null;
for (Sdk sdk : ProjectJdkTable.getInstance().getSdksOfType(javaSdk)) {
JavaSdkVersion v = javaSdk.getVersion(sdk);
if (v == version) {
return sdk; // exact match
}
if (candidate == null && v != null && v.isAtLeast(version)) {
candidate = sdk; // first suitable
}
}
return candidate;
}
}
@@ -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);
}
}
@@ -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
@@ -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
@@ -200,8 +200,16 @@ public abstract class DiffRequestProcessor implements Disposable {
List<FrameDiffTool> 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);
@@ -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<DiffToolSubstitutor> EP_NAME =
ExtensionPointName.create("com.intellij.diff.impl.DiffToolSubstitutor");
@Nullable
DiffTool getReplacement(@NotNull DiffTool tool, @NotNull DiffContext context, @NotNull DiffRequest request);
}
@@ -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
//
@@ -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;
}
@@ -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 <code>this</code>
*/
ProgressPanelBuilder andCancelText(String cancelText);
/**
* Enables play button (icon styled) and sets action for it. Can't coexist with cancel action.
*
@@ -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);
@@ -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;
@@ -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"));
@@ -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).
@@ -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;
}
@@ -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);
@@ -259,6 +259,7 @@
<extensionPoint qualifiedName="com.intellij.diff.merge.MergeTool" interface="com.intellij.diff.merge.MergeTool"/>
<extensionPoint qualifiedName="com.intellij.diff.DiffExtension" interface="com.intellij.diff.DiffExtension"/>
<extensionPoint qualifiedName="com.intellij.diff.lang.DiffIgnoredRangeProvider" interface="com.intellij.diff.lang.DiffIgnoredRangeProvider"/>
<extensionPoint qualifiedName="com.intellij.diff.impl.DiffToolSubstitutor" interface="com.intellij.diff.impl.DiffToolSubstitutor"/>
<extensionPoint name="testStatusListener" interface="com.intellij.execution.testframework.TestStatusListener"/>
<extensionPoint name="diff.actions.ShowDiffAction.ExtensionProvider" interface="com.intellij.openapi.actionSystem.AnActionExtensionProvider"/>
@@ -41,7 +41,7 @@
<diff.merge.MergeTool implementation="com.intellij.openapi.vcs.changes.patch.tool.ApplyPatchMergeTool"/>
<diff.DiffTool implementation="com.intellij.openapi.vcs.changes.patch.tool.ApplyPatchDiffTool"/>
<diff.DiffTool implementation="com.intellij.openapi.vcs.changes.patch.tool.PatchDiffTool"/>
<diff.DiffTool implementation="com.intellij.openapi.vcs.changes.actions.diff.LocalChangeListDiffTool"/>
<diff.impl.DiffToolSubstitutor implementation="com.intellij.openapi.vcs.changes.actions.diff.LocalChangeListDiffTool"/>
<diff.actions.ShowDiffAction.ExtensionProvider implementation="com.intellij.openapi.vcs.changes.shelf.DiffShelvedChangesActionProvider"/>
<diff.actions.ShowDiffAction.ExtensionProvider implementation="com.intellij.openapi.vcs.update.ShowUpdatedDiffActionProvider"/>
@@ -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;
}
@@ -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)
@@ -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<Class<? extends DiffTool>> 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;
}
}
@@ -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.gradle.service.project.wizard;
import com.intellij.externalSystem.JavaProjectData;
@@ -42,7 +44,6 @@ import org.jetbrains.plugins.gradle.util.GradleConstants;
import javax.swing.*;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -194,30 +195,13 @@ public class GradleProjectImportBuilder extends AbstractExternalProjectImportBui
JavaProjectData data = javaProjectNode.getData();
context.setCompilerOutputDirectory(data.getCompileOutputPath());
JavaSdkVersion version = data.getJdkVersion();
Sdk jdk = findJdk(version);
Sdk jdk = JavaSdkVersionUtil.findJdkByVersion(version);
if (jdk != null) {
context.setProjectJdk(jdk);
}
}
}
@Nullable
private static Sdk findJdk(@NotNull JavaSdkVersion version) {
JavaSdk javaSdk = JavaSdk.getInstance();
List<Sdk> 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) {
@@ -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,
@@ -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);
}
@@ -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)
}
@@ -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<GrTypeDefinition> {
override fun getCodeMethods(definition: GrTypeDefinition): Array<GrMethod> {
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<GrField> {
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<GrTypeDefinition> {
val body = definition.body
return if (body == null) GrTypeDefinition.EMPTY_ARRAY else body.innerClasses
return definition.body?.innerClasses ?: GrTypeDefinition.EMPTY_ARRAY
}
}
@@ -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<GroovyScriptClass> {
override fun getCodeMethods(definition: GroovyScriptClass): Array<GrMethod> = definition.containingFile.methods
override fun getCodeFields(definition: GroovyScriptClass): Array<GrField> = GrField.EMPTY_ARRAY
override fun getCodeInnerClasses(definition: GroovyScriptClass): Array<GrTypeDefinition> = GrTypeDefinition.EMPTY_ARRAY
}
@@ -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<in T : GrTypeDefinition> {
open fun getCodeMethods(definition: T): Array<GrMethod> = GrMethod.EMPTY_ARRAY
fun getCodeMethods(definition: T): Array<GrMethod>
open fun getCodeFields(definition: T): Array<GrField> = GrField.EMPTY_ARRAY
fun getCodeFields(definition: T): Array<GrField>
open fun getCodeInnerClasses(definition: T): Array<GrTypeDefinition> = GrTypeDefinition.EMPTY_ARRAY
fun getCodeInnerClasses(definition: T): Array<GrTypeDefinition>
}
@@ -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;
@@ -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
}
@@ -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<String, CandidateInfo> myFields;
private final Map<String, List<CandidateInfo>> myMethods;
private final Map<String, CandidateInfo> myInnerClasses;
private ClassMembers(@NotNull Map<String, CandidateInfo> fields,
@NotNull Map<String, List<CandidateInfo>> methods,
@NotNull Map<String, CandidateInfo> innerClasses) {
myFields = fields;
myMethods = methods;
myInnerClasses = innerClasses;
}
public static ClassMembers create(@NotNull LinkedHashMap<String, CandidateInfo> first,
@NotNull LinkedHashMap<String, List<CandidateInfo>> second,
@NotNull LinkedHashMap<String, CandidateInfo> third) {
return new ClassMembers(first, second, third);
}
private Map<String, CandidateInfo> getFields() {
return myFields;
}
private Map<String, List<CandidateInfo>> getMethods() {
return myMethods;
}
private Map<String, CandidateInfo> getInnerClasses() {
return myInnerClasses;
}
private final Map<String, CandidateInfo> fields = ContainerUtil.newLinkedHashMap();
private final Map<String, List<CandidateInfo>> methods = ContainerUtil.newLinkedHashMap();
private final Map<String, CandidateInfo> innerClasses = ContainerUtil.newLinkedHashMap();
}
private static final Key<CachedValue<ClassMembers>> CACHED_MEMBERS = Key.create("CACHED_CLASS_MEMBERS");
private static final Key<CachedValue<ClassMembers>> CACHED_MEMBERS_INCLUDING_SYNTHETIC = Key.create("CACHED_MEMBERS_INCLUDING_SYNTHETIC");
private CollectClassMembersUtil() {
}
private CollectClassMembersUtil() {}
public static Map<String, List<CandidateInfo>> getAllMethods(final PsiClass aClass, boolean includeSynthetic) {
return getCachedMembers(aClass, includeSynthetic).getMethods();
@NotNull
public static Map<String, List<CandidateInfo>> 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<PsiClass> visited = ContainerUtil.newHashSet();
Queue<PsiClass> 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<String, CandidateInfo> getAllInnerClasses(@NotNull final PsiClass aClass, boolean includeSynthetic) {
return getCachedMembers(aClass, includeSynthetic).getInnerClasses();
return getCachedMembers(aClass, includeSynthetic).innerClasses;
}
@NotNull
public static Map<String, CandidateInfo> getAllFields(@NotNull final PsiClass aClass, boolean includeSynthetic) {
return getCachedMembers(aClass, includeSynthetic).getFields();
return getCachedMembers(aClass, includeSynthetic).fields;
}
@NotNull
public static Map<String, CandidateInfo> 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<String, CandidateInfo> allFields = ContainerUtil.newLinkedHashMap();
LinkedHashMap<String, List<CandidateInfo>> allMethods = ContainerUtil.newLinkedHashMap();
LinkedHashMap<String, CandidateInfo> 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<CachedValue<ClassMembers>> 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)
@@ -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<GroovyResolveResult> propertyCandidates = new ArrayList<>(allPropertyCandidates.length);
for (GroovyResolveResult candidate : allPropertyCandidates) {
@@ -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<GrOperatorExpression>() {
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)
}
}
@@ -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"))
}
@@ -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 = a<caret>a
}
void testDefinedVar1() throws Exception {
doTest("definedVar1/A.groovy")
disableTransformations testRootDisposable
resolve "A.groovy", GrVariable
}
void testOperatorOverload() throws Exception {
@@ -190,6 +202,7 @@ c = a<caret>a
}
void testGrvy575() throws Exception {
disableTransformations testRootDisposable
doTest("grvy575/A.groovy")
}
@@ -199,6 +212,7 @@ c = a<caret>a
}
void testClosureCall() throws Exception {
disableTransformations testRootDisposable
PsiReference ref = configureByFile("closureCall/ClosureCall.groovy")
assertTrue(ref.resolve() instanceof GrVariable)
}
@@ -624,6 +638,7 @@ set<caret>Foo(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<String, Pojo> {
assertEquals(resolved.containingClass.name, 'B')
}
void testLocalVarVsFieldInWithClosure() {
// TODO disableTransformations testRootDisposable
def ref = configureByText('''\
class Test {
def var
@@ -1071,7 +1086,8 @@ print Fie<caret>ld1
}
void testLocalVarVsClassFieldInAnonymous() {
final ref = configureByText('a.groovy', '''\
disableTransformations testRootDisposable
def resolved = resolveByText '''\
class A {
public foo
}
@@ -1083,10 +1099,8 @@ print Fie<caret>ld1
print fo<caret>o
}
}
''')
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 <caret>p
''', PsiVariable)
''', GrVariable
}
void testVarVsPackage3() {
myFixture.addClass('''package p; public class A {}''')
disableTransformations testRootDisposable
resolveByText('''\
resolveByText '''\
def p = [A:{2}]
print <caret>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 <caret>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 <caret>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 { <caret>abc }', GrVariable
}
}
@@ -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 { s<caret>1 + 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 { s<caret>2 + 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 {s<caret>1 + 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 + s<caret>2 + toUpperCase() }
}
''').with {
assert it instanceof GrVariable && !(it instanceof GrField) && !(it instanceof GrParameter)
''', GrVariable).with {
assert !(it instanceof GrField) && !(it instanceof GrParameter)
}
}
@@ -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
}
}
@@ -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}")
}
}
@@ -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<PsiClass> query = ClassInheritorsSearch.search(nodeClass, scope, true, true, false);
final Set<PsiClass> result = new THashSet<>();
query.forEach(psiClass -> {
@@ -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)) {
@@ -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<T extends JUnitConfiguration> 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<T extends JUnitConfiguration> extends SettingsEdi
configuration.setShortenCommandLine((ShortenCommandLine)myShortenClasspathModeCombo.getComponent().getSelectedItem());
}
protected String[] setArrayFromText(LabeledComponent<RawCommandLineEditor> 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));
@@ -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 {
@@ -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;
@@ -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 {