mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Groovy] convert JavaToGroovyResolveTest to Java (IDEA-327339)
GitOrigin-RevId: e43f9fab054098a6d68a623f5e76e49da801246b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9f6bae6d41
commit
41a32cfcb4
+69
-82
@@ -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 Fo<caret>o();
|
||||
}
|
||||
}''')
|
||||
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().fo<caret>o()
|
||||
}
|
||||
}''')
|
||||
|
||||
assertInstanceOf(ref.resolve(), GrReflectedMethod)
|
||||
PsiReference ref = configureByText("A.java", """
|
||||
class A {
|
||||
void foo() {
|
||||
Object o = new Fo<caret>o();
|
||||
}
|
||||
}
|
||||
""");
|
||||
TestCase.assertNotNull(ref.resolve());
|
||||
}
|
||||
|
||||
}
|
||||
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().fo<caret>o()
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
UsefulTestCase.assertInstanceOf(ref.resolve(), GrReflectedMethod.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user