provide types for Java fields

This commit is contained in:
Dmitry Jemerov
2011-04-13 18:36:37 +02:00
parent c0cb682511
commit 2bf935862d
3 changed files with 23 additions and 7 deletions

View File

@@ -30,13 +30,21 @@ public class PyJavaTypeProvider extends PyTypeProviderBase {
}
if (referenceTarget instanceof PsiMethod) {
PsiMethod method = (PsiMethod) referenceTarget;
final PsiType type = method.getReturnType();
if (type instanceof PsiClassType) {
final PsiClassType classType = (PsiClassType)type;
final PsiClass psiClass = classType.resolve();
if (psiClass != null) {
return new PyJavaClassType(psiClass);
}
return asPyType(method.getReturnType());
}
if (referenceTarget instanceof PsiField) {
return asPyType(((PsiField)referenceTarget).getType());
}
return null;
}
@Nullable
private static PyType asPyType(PsiType type) {
if (type instanceof PsiClassType) {
final PsiClassType classType = (PsiClassType)type;
final PsiClass psiClass = classType.resolve();
if (psiClass != null) {
return new PyJavaClassType(psiClass);
}
}
return null;

View File

@@ -64,6 +64,12 @@ public class PyToJavaResolveTest extends ResolveTestCase {
Assert.assertEquals("size", ((PsiMethod) target).getName());
}
public void testFieldType() throws Exception {
PsiElement target = resolve();
Assert.assertTrue(target instanceof PsiMethod);
Assert.assertEquals("println", ((PsiMethod) target).getName());
}
@Override
protected String getTestDataPath() {
return PythonTestUtil.getTestDataPath() + "/resolve/pyToJava/";

View File

@@ -0,0 +1,2 @@
from java.lang import System as javasystem
javasystem.out.p<ref>rintln("Hello")