diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppCategoryTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppCategoryTest.groovy deleted file mode 100644 index 7ecebcdc16a7..000000000000 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppCategoryTest.groovy +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.plugins.groovy.lang - -import com.intellij.psi.PsiReference -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase -import org.jetbrains.annotations.NotNull -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod - -/** - * @author peter - */ -class GppCategoryTest extends LightCodeInsightFixtureTestCase { - @NotNull - @Override - protected LightProjectDescriptor getProjectDescriptor() { - return GppProjectDescriptor.instance - } - - public void testFromSuperClassClosureSyntax() { - assertResolves """ -abstract class Super implements Runnable { - static def category(Object foo, int bar) {} -} - -Super s = { "".category(2) } -""" - } - - public void testFromSuperClassMapSyntax() { - assertResolves """ -class Super { - static def category(Object foo, int bar) {} - void xxx() {} -} - -Super s = [xxx:{ "".category(2) }] -""" - } - - private def assertResolves(String text) { - myFixture.configureByText "a.gpp", text - assert findReference().resolve() instanceof GrGdkMethod - } - - private PsiReference findReference() { - return myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset) - } - -} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppFunctionalTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppFunctionalTest.groovy deleted file mode 100644 index d2ad4adc2261..000000000000 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GppFunctionalTest.groovy +++ /dev/null @@ -1,499 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.plugins.groovy.lang - -import com.intellij.codeInsight.lookup.LookupManager -import com.intellij.codeInspection.deadCode.UnusedDeclarationInspectionBase -import com.intellij.openapi.module.Module -import com.intellij.openapi.roots.ContentEntry -import com.intellij.openapi.roots.ModifiableRootModel -import com.intellij.openapi.roots.OrderRootType -import com.intellij.openapi.roots.libraries.Library -import com.intellij.openapi.vfs.JarFileSystem -import com.intellij.psi.* -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase -import junit.framework.ComparisonFailure -import org.jetbrains.annotations.NotNull -import org.jetbrains.plugins.groovy.codeInspection.GroovyUnusedDeclarationInspection -import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection -import org.jetbrains.plugins.groovy.codeInspection.unassignedVariable.UnassignedVariableAccessInspection -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod -import org.jetbrains.plugins.groovy.util.TestUtils - -/** - * @author peter - */ -class GppFunctionalTest extends LightCodeInsightFixtureTestCase { - - @NotNull - @Override - protected LightProjectDescriptor getProjectDescriptor() { - return GppProjectDescriptor.instance; - } - - protected void setUp() { - super.setUp() - } - - public void testCastListToIterable() throws Exception { - myFixture.addClass("class X extends java.util.ArrayList {}") - testAssignability """ -X ints = [239, 4.2d] -""" - } - - public void testCastListToAnything() throws Exception { - testAssignability """ -File f1 = ['path'] -File f2 = ['path', 2, true, 42] -""" - } - - public void testCastMapToAnotherMap() throws Exception { - myFixture.addClass """ -public class Y extends java.util.HashMap { - public Y(int initialCapacity) { - super(initialCapacity); - } -} -""" - - testAssignability """ -HashMap m1 = ['a':['b']] -Y y = [a:'b'] -""" - } - - public void testAnonymousClass() throws Exception { - myFixture.enableInspections new GroovyAssignabilityCheckInspection() - testAssignability """ -def x = new Object() { - def foo() { - HashMap m1 = ['a':['b']] - HashMap m2 = new File('aaa') - } -} -""" - } - - public void testCastMapToObject() throws Exception { - myFixture.addClass("class Foo { String name; void foo() {} }") - testAssignability """ -Foo f = [name: 'aaa', foo: { println 'hi' }, anotherProperty: 42 ] -""" - } - - void testAssignability(String text) { - myFixture.enableInspections new GroovyAssignabilityCheckInspection() - PsiFile file = configureGppScript(text) - myFixture.testHighlighting(true, false, false, file.virtualFile) - } - - private PsiFile configureScript(String text) { - return myFixture.configureByText("a.groovy", text) - } - private PsiFile configureGppScript(String text) { - return myFixture.configureByText("a.gpp", text) - } - - public void testDeclaredVariableTypeIsMoreImportantThanTheInitializerOne() throws Exception { - configureScript(""" -File f = ['path'] -f.mk -""") - myFixture.completeBasic() - assertSameElements myFixture.lookupElementStrings, "mkdir", "mkdirs" - } - - public void testDeclaredVariableTypeIsMoreImportantThanTheInitializerOne2() throws Exception { - myFixture.addClass """ -public class Some { - public int prop - - public void f_foo() {} - public void f_bar() {} -} -""" - - configureScript(""" -Some s = [prop: 239] -s.f_ -""") - myFixture.completeBasic() - assertSameElements myFixture.lookupElementStrings, "f_foo", "f_bar" - } - - public void testResolveMethod() throws Exception { - myFixture.configureByText("a.groovy", """ -def foo(File f) {} -@Typed def bar() { - foo(['path']) -} -""") - def reference = findReference() - def target = reference.resolve() - assertEquals "foo", ((GrMethod)target).name - } - - private PsiReference findReference() { - return myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset) - } - - public void testOverloadingWithConversion() throws Exception { - myFixture.configureByText("a.groovy", """ -def foo(List l) {} -def foo(File f) {} -@Typed def bar() { - foo(['path']) -} -""") - def reference = findReference() - def target = reference.resolve() - assertNotNull target - assert target.text.contains("List l") - } - - public void testWrongProperty() throws Exception { -myFixture.configureByText 'a.gpp', ''' -class ClassA { - def prop = 2 - def bar() { - def t = new Object() - t.prop - } -}''' - assert !findReference().resolve() - } - - public void testCastClosureToOneMethodClass() throws Exception { - myFixture.addClass """ -public abstract class Foo { - public abstract void foo(String s); - public abstract void bar(String s); -} -public interface Action { - void act(); -} -""" - - testAssignability """ -Foo f = { println it } -Function1 f1 = { println it } -Function1 f2 = { x=42 -> println x } -Function1 f3 = { int x -> println x } -Runnable r = { println it } -Action a = { println it } -Action a1 = { a2 = 2 -> println a2 } -""" - } - - public void testClosureParameterTypesInAssignment() throws Exception { - configureScript "Function1 f = { it.subs }" - myFixture.completeBasic() - assertSameElements myFixture.lookupElementStrings, "subSequence", "substring", "substring" - } - - public void testClosureParameterTypesInMethodInvocation() throws Exception { - myFixture.configureByText "a.groovy", """ -def foo(int a = 1, Function1 f) {} -def foo(String s) {} -def foo(Function2 f) {} - -@Typed def bar() { - foo { it.subsREF } - foo(1, { it.subsREF }) - foo 1, { it.subsREF } - foo(1) { it.subsREF } - foo { a -> a.subsREF } - foo { a, int b=2 -> a.subsREF } - foo { a, b -> b.subsREF } -} -""" - def text = myFixture.file.text - def pos = 0 - while (true) { - pos = text.indexOf("REF", pos+1) - if (pos < 0) { - break - } - myFixture.editor.caretModel.moveToOffset pos - myFixture.completeBasic() - try { - assertSameElements myFixture.lookupElementStrings, "subSequence", "substring", "substring" - } - catch (ComparisonFailure ex) { - println "at: " + text[0.." + text[pos.. bar() { - { it.subs } -} -""" - myFixture.completeBasic() - assertSameElements myFixture.lookupElementStrings, "subSequence", "substring", "substring" - } - - public void testClosureInMapInstantiation() throws Exception { - myFixture.configureByText "a.groovy", """ -class Foo { - int foo(T a) {} -} - -@Typed Foo bar() { - return [foo: { it.subs }] -} -""" - myFixture.completeBasic() - assertSameElements myFixture.lookupElementStrings, "subSequence", "substring", "substring" - } - - public void testClosureInMapInstantiationBoxPrimitives() throws Exception { - myFixture.configureByText "a.groovy", """ -class Foo { - int foo(int a) {} -} - -@Typed Foo bar() { - return [foo: { it.intVV }] -} -""" - myFixture.completeBasic() - assertSameElements myFixture.lookupElementStrings, "intValue" - } - - public void testClosureInListInstantiation() throws Exception { - myFixture.configureByText "a.groovy", """ -class Foo { - def Foo(int a, Function1 f) {} -} - -@Typed Foo foo() { - [239, { s -> s.subs }] -} -""" - myFixture.completeBasic() - assertSameElements myFixture.lookupElementStrings, "subSequence", "substring", "substring" - } - - private PsiElement resolveReference() { - return findReference().resolve() - } - - public void testResolveToSuperMethodClosureSyntax() { - configureScript """ -abstract class Super implements Runnable { - def method(int bar) {} -} - -Super s = { method(2) } as Super -""" - assert resolveReference() instanceof GrMethod - } - - public void testGotoSuperMethodFromMapLiterals() throws Exception { - PsiClass point = myFixture.addClass(""" -class Point { - Point() {} - Point(int y) {} - int y; - void setX(int x) {} - void move(int x, int y) {} - void move(int y) {} -}""") - - configureScript "Point p = [y:2]" - assertEquals point.findFieldByName("y", false), resolveReference() - - configureScript "Point p = [x:2]" - assertEquals point.findMethodsByName("setX", false)[0], resolveReference() - - configureScript "Point p = [move: { x, y -> z }]" - assertEquals point.findMethodsByName("move", false)[0], resolveReference() - - configureScript "Point p = [move: ]" - def resolveResults = multiResolveReference() - assertSameElements resolveResults.collect { it.element }, point.findMethodsByName("move", false) - } - - ResolveResult[] multiResolveReference() { - final PsiReference ref = myFixture.file.findReferenceAt(myFixture.editor.caretModel.offset) - assertNotNull(ref) - assertInstanceOf(ref, PsiPolyVariantReference) - return ((PsiPolyVariantReference)ref).multiResolve(true) - } - - public void testGotoSuperConstructorFromMapLiterals() throws Exception { - PsiClass point = myFixture.addClass(""" -class Point { - Point() {} - Point(int y) {} -}""") - - configureGppScript "Point p = [super: 2]" - assertEquals point.constructors[1], resolveReference() - - configureGppScript "Point p = [super: [2]]" - assertEquals point.constructors[1], resolveReference() - - configureGppScript "Point p = ['super': []]" - assertEquals point.constructors[0], resolveReference() - - configureGppScript "Point p = ['super': 'a']" - assertEquals 1, multiResolveReference().size() - } - - public void testGotoClassFromLiteralOnsetsWhenNoConstructorsPresent() throws Exception { - PsiClass point = myFixture.addClass(""" class Point { }""") - configureGppScript "Point p = [super: 2]" - assertEquals point, resolveReference() - - configureGppScript "Point p = []" - assertEquals point, resolveReference() - } - - public void testNoGotoObjectFromLiteral() throws Exception { - myFixture.addClass(""" class Point { }""") - - configureGppScript "def p = []" - assertNull findReference().resolve() - } - - public void testHighlightInapplicableLiteralConstructor() throws Exception { - myFixture.addClass(""" -class Point { - Point() {} -}""") - - configureGppScript """ -def foo(Point p) {} -Point p = [:] -Point p2 = [super:warning descr="Cannot find constructor of 'Point'">[4, 2]] -foo([4, 2]) -""" - } - - public void testResolveTraitMethod() throws Exception { - configureScript """ -@Trait -class Some { - public void doSmth() { println "hello" } -} -Some s -s.doSmth() -""" - assertEquals "doSmth", ((PsiMethod) findReference().resolve()).name - } - - public void testNestedLiteralConstructors() throws Exception { - configureGppScript """ - class Foo { - def Foo(Bar b) { } - } - - class Bar { - def Bar(int i) { } - } - - Foo x = [[2]] - println x -""" - myFixture.enableInspections new GroovyAssignabilityCheckInspection() - myFixture.checkHighlighting(true, false, false) - } - - public void testNoReturnTypeInferenceInTypedContext() throws Exception { - configureGppScript """ -class Foo { - def foo() { "aaa" } -} -new Foo().foo().substra -""" - assertEmpty myFixture.completeBasic() - } - - public void testDeclaredReturnTypeInTypedContext() throws Exception { - configureGppScript """ -class Foo { - String getFoo() { "aaa" } -} -new Foo().foo.substra -""" - myFixture.completeBasic() - assertOrderedEquals myFixture.lookupElementStrings, "substring", "substring" - } - - public void testNonInitializedVariable() throws Exception { - configureScript """ - -@Typed -def foo() { - int a - return a -} - -def bar() { - int a - return a -}""" - myFixture.enableInspections new UnassignedVariableAccessInspection() - myFixture.checkHighlighting(true, false, false) - } - - public void testExternalizable() throws Exception { - configureScript ''' -@Typed class Foo implements Externalizable {} -class Bar implements Externalizable {} -''' - myFixture.checkHighlighting(true, false, false) - } - - public void testUsedInterceptors() { - configureGppScript ''' -class Bar { - Object getUnresolvedProperty(String name) {} - Object getUnresolvedProperty(int name) {} - void setUnresolvedProperty(String name, String value) {} - int invokeUnresolvedMethod(String name, String arg1, boolean arg2, Object... args) {} - int invokeUnresolvedMethod(String name, Object... args) {} - int invokeUnresolvedMethod(Object... args) {} -} -println new Bar().zzz -''' - myFixture.enableInspections(new GroovyUnusedDeclarationInspection(), new UnusedDeclarationInspectionBase(true)) - myFixture.checkHighlighting(true, false, false) - } - -} - -class GppProjectDescriptor extends DefaultLightProjectDescriptor { - public static final instance = new GppProjectDescriptor() - - @Override - public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { - final Library.ModifiableModel modifiableModel = model.moduleLibraryTable.createLibrary("GROOVY++").modifiableModel; - modifiableModel.addRoot(JarFileSystem.instance.refreshAndFindFileByPath(TestUtils.absoluteTestDataPath + "mockGroovypp/groovypp-0.9.0_1.8.2.jar!/"), OrderRootType.CLASSES) - modifiableModel.addRoot(JarFileSystem.instance.refreshAndFindFileByPath(TestUtils.mockGroovy1_7LibraryName + "!/"), OrderRootType.CLASSES); - modifiableModel.commit(); - } -} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/LiteralConstructorUsagesTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/LiteralConstructorUsagesTest.groovy index a3b998321bde..db2521aac1c0 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/LiteralConstructorUsagesTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/LiteralConstructorUsagesTest.groovy @@ -28,37 +28,6 @@ class LiteralConstructorUsagesTest extends LightGroovyTestCase { null } - @Override - protected void setUp() { - super.setUp(); - myFixture.addClass("package groovy.lang; public @interface Typed {}"); - } - - public void testList_Variable() throws Exception { - def foo = myFixture.addClass("""class Foo { - Foo() {} - } -""") - myFixture.addFileToProject "a.gpp", "Foo x = []" - assertOneElement(ReferencesSearch.search(foo.constructors[0]).findAll()) - } - - public void testList_ReturnValue() throws Exception { - def foo = myFixture.addClass("""class Foo { - Foo() {} - } -""") - myFixture.addFileToProject "a.groovy", """ -@Typed Foo foo() { - if (true) [] - else return [] -} -Foo untyped() { [] } -@Typed Foo bar() { [] } -""" - assertEquals(4, ReferencesSearch.search(foo.constructors[0]).findAll().size()) - } - public void testList_AsCast() throws Exception { def foo = myFixture.addClass("""class Foo { Foo() {} @@ -77,59 +46,6 @@ Foo untyped() { [] } assertOneElement(ReferencesSearch.search(foo.constructors[0]).findAll()) } - public void testMapSuper_AsCast() throws Exception { - def foo = myFixture.addClass("""class Foo { - Foo(int a) {} - } -}""") - myFixture.addFileToProject "a.gpp", "def x = ['super':[2]] as Foo" - myFixture.addFileToProject "c.gpp", "def x = [super:2] as Foo" - - assertEquals(2, ReferencesSearch.search(foo.constructors[0]).findAll().size()) - } - - public void testOverloadedConstructorUsages() throws Exception { - def foo = myFixture.addClass(""" - class Foo { - Foo() {} - Foo(int a) {} - } - """) - - myFixture.addFileToProject "a.gpp", """ - Foo b = [] - Foo b1 = [2] - """ - assertEquals(2, MethodReferencesSearch.search(foo.constructors[0], false).findAll().size()) - assertEquals(2, MethodReferencesSearch.search(foo.constructors[1], false).findAll().size()) - } - - public void testLiteralWithinALiteral() throws Exception { - myFixture.addFileToProject "a.gpp", """ -class Foo { - Foo(Bar b) {} -} - -class Bar { - Bar(String s) {} -} - -Foo f = [new Bar('a')] -Foo f2 = ['super':['super':'a']] -""" - assertEquals 1, MethodReferencesSearch.search(myFixture.findClass("Bar").constructors[0]).findAll().size() - } - - public void testCannibalisticConstructor() throws Exception { - myFixture.addFileToProject "a.gpp", """ - class Foo { - Foo(Foo... children) {} - } - Foo f = [new Foo('a')] - """ - assertEquals 2, MethodReferencesSearch.search(myFixture.findClass("Foo").constructors[0]).findAll().size() - } - void testLiteralConstructorWithNamedArgs() { addLinkedHashMap() myFixture.addFileToProject "a.groovy", """\ diff --git a/plugins/groovy/testdata/mockGroovypp/groovypp-0.9.0_1.8.2.jar b/plugins/groovy/testdata/mockGroovypp/groovypp-0.9.0_1.8.2.jar deleted file mode 100644 index 7bea872982ff..000000000000 Binary files a/plugins/groovy/testdata/mockGroovypp/groovypp-0.9.0_1.8.2.jar and /dev/null differ diff --git a/plugins/groovy/testdata/realGroovypp/groovy-all-1.8.2.jar b/plugins/groovy/testdata/realGroovypp/groovy-all-1.8.2.jar deleted file mode 100644 index 85af249d3c12..000000000000 Binary files a/plugins/groovy/testdata/realGroovypp/groovy-all-1.8.2.jar and /dev/null differ diff --git a/plugins/groovy/testdata/realGroovypp/groovypp-all-0.9.0_1.8.2.jar b/plugins/groovy/testdata/realGroovypp/groovypp-all-0.9.0_1.8.2.jar deleted file mode 100644 index 36104681534b..000000000000 Binary files a/plugins/groovy/testdata/realGroovypp/groovypp-all-0.9.0_1.8.2.jar and /dev/null differ