From 41a32cfcb4520c2e61a42cad95ec1c7aa42b285e Mon Sep 17 00:00:00 2001 From: Aleksey Dobrynin Date: Thu, 17 Oct 2024 14:18:01 +0200 Subject: [PATCH] [Groovy] convert JavaToGroovyResolveTest to Java (IDEA-327339) GitOrigin-RevId: e43f9fab054098a6d68a623f5e76e49da801246b --- .../lang/resolve/JavaToGroovyResolveTest.java | 151 ++++++++---------- 1 file changed, 69 insertions(+), 82 deletions(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/JavaToGroovyResolveTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/JavaToGroovyResolveTest.java index 5308408a0052..70486eda91e8 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/JavaToGroovyResolveTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/JavaToGroovyResolveTest.java @@ -1,103 +1,90 @@ -/* - * 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-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package org.jetbrains.plugins.groovy.lang.resolve; -package org.jetbrains.plugins.groovy.lang.resolve +import com.intellij.psi.JavaResolveResult; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiJavaReference; +import com.intellij.psi.PsiReference; +import com.intellij.psi.impl.light.LightMethodBuilder; +import com.intellij.testFramework.UsefulTestCase; +import junit.framework.TestCase; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod; +import org.jetbrains.plugins.groovy.util.TestUtils; - -import com.intellij.psi.JavaResolveResult -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiJavaReference -import com.intellij.psi.PsiReference -import com.intellij.psi.impl.light.LightMethodBuilder -import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod -import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod -import org.jetbrains.plugins.groovy.util.TestUtils - -class JavaToGroovyResolveTest extends GroovyResolveTestCase { +public class JavaToGroovyResolveTest extends GroovyResolveTestCase { @Override protected String getBasePath() { - return "${TestUtils.testDataPath}resolve/javaToGroovy/" + return TestUtils.getTestDataPath() + "resolve/javaToGroovy/"; } - void testField1() throws Exception { - PsiReference ref = configureByFile("field1/A.java") - PsiElement resolved = ref.resolve() - assertTrue(resolved instanceof GrField) + public void testField1() throws Exception { + PsiReference ref = configureByFile("field1/A.java"); + PsiElement resolved = ref.resolve(); + TestCase.assertTrue(resolved instanceof GrField); } - void testAccessorRefToProperty() throws Exception { - PsiReference ref = configureByFile("accessorRefToProperty/A.java") - PsiElement resolved = ref.resolve() - assertTrue(resolved instanceof GrAccessorMethod) + public void testAccessorRefToProperty() throws Exception { + PsiReference ref = configureByFile("accessorRefToProperty/A.java"); + PsiElement resolved = ref.resolve(); + TestCase.assertTrue(resolved instanceof GrAccessorMethod); } - void testMethod1() throws Exception { - PsiJavaReference ref = (PsiJavaReference) configureByFile("method1/A.java") - JavaResolveResult resolveResult = ref.advancedResolve(false) - assertTrue(resolveResult.element instanceof GrMethod) - assertTrue(resolveResult.validResult) + public void testMethod1() throws Exception { + PsiJavaReference ref = (PsiJavaReference)configureByFile("method1/A.java"); + JavaResolveResult resolveResult = ref.advancedResolve(false); + TestCase.assertTrue(resolveResult.getElement() instanceof GrMethod); + TestCase.assertTrue(resolveResult.isValidResult()); } - void testScriptMain() throws Exception { - PsiJavaReference ref = (PsiJavaReference) configureByFile("scriptMain/A.java") - JavaResolveResult resolveResult = ref.advancedResolve(false) - assertInstanceOf(resolveResult.element, LightMethodBuilder.class) - assertTrue(resolveResult.validResult) + public void testScriptMain() throws Exception { + PsiJavaReference ref = (PsiJavaReference)configureByFile("scriptMain/A.java"); + JavaResolveResult resolveResult = ref.advancedResolve(false); + UsefulTestCase.assertInstanceOf(resolveResult.getElement(), LightMethodBuilder.class); + TestCase.assertTrue(resolveResult.isValidResult()); } - void testScriptMethod() throws Exception { - PsiJavaReference ref = (PsiJavaReference) configureByFile("scriptMethod/A.java") - JavaResolveResult resolveResult = ref.advancedResolve(false) - assertTrue(resolveResult.element instanceof GrMethod) - assertTrue(resolveResult.validResult) + public void testScriptMethod() throws Exception { + PsiJavaReference ref = (PsiJavaReference)configureByFile("scriptMethod/A.java"); + JavaResolveResult resolveResult = ref.advancedResolve(false); + TestCase.assertTrue(resolveResult.getElement() instanceof GrMethod); + TestCase.assertTrue(resolveResult.isValidResult()); } - void testNoDGM() throws Exception { - PsiJavaReference ref = (PsiJavaReference) configureByFile("noDGM/A.java") - assertNull(ref.advancedResolve(false).element) - } - - void testPrivateTopLevelClass() { - myFixture.addFileToProject('Foo.groovy', 'private class Foo{}') - - def ref = configureByText('A.java', ''' -class A { - void foo() { - Object o = new Foo(); - } -}''') - assertNotNull(ref.resolve()) + public void testNoDGM() throws Exception { + PsiJavaReference ref = (PsiJavaReference)configureByFile("noDGM/A.java"); + TestCase.assertNull(ref.advancedResolve(false).getElement()); } - void testScriptMethods() { - myFixture.addFileToProject('Foo.groovy', '''\ -void foo(int x = 5) {} -void foo(String s) {} -''') + public void testPrivateTopLevelClass() { + myFixture.addFileToProject("Foo.groovy", "private class Foo{}"); - final ref = configureByText('A.java', '''\ -class A { - void bar() { - new Foo().foo() - } -}''') - - assertInstanceOf(ref.resolve(), GrReflectedMethod) + PsiReference ref = configureByText("A.java", """ + class A { + void foo() { + Object o = new Foo(); + } + } + """); + TestCase.assertNotNull(ref.resolve()); } -} \ No newline at end of file + public void testScriptMethods() { + myFixture.addFileToProject("Foo.groovy", """ + void foo(int x = 5) {} + void foo(String s) {} + """); + + final PsiReference ref = configureByText("A.java", """ + class A { + void bar() { + new Foo().foo() + } + } + """); + + UsefulTestCase.assertInstanceOf(ref.resolve(), GrReflectedMethod.class); + } +}