From e4556e78d1afef263c26538bd02f7cebdc090f75 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Wed, 17 Jan 2018 15:51:50 +0300 Subject: [PATCH] [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) } }