提交 bf54dc54 编写于 作者: S Stepan Koltsov

test nullable return types are read from .class files

上级 a9d1cea9
......@@ -479,7 +479,7 @@ public class JavaDescriptorResolver {
DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor),
typeParameters,
semanticServices.getDescriptorResolver().resolveParameterDescriptors(functionDescriptorImpl, parameters),
semanticServices.getTypeTransformer().transformToType(returnType),
semanticServices.getDescriptorResolver().makeReturnType(returnType, method),
Modality.convertFromFlags(method.hasModifierProperty(PsiModifier.ABSTRACT), !method.hasModifierProperty(PsiModifier.FINAL)),
resolveVisibilityFromPsiModifiers(method)
);
......@@ -491,6 +491,30 @@ public class JavaDescriptorResolver {
return substitutedFunctionDescriptor;
}
private JetType makeReturnType(PsiType returnType, PsiMethod method) {
boolean changeNullable = false;
boolean nullable = true;
for (PsiAnnotation annotation : method.getModifierList().getAnnotations()) {
if (annotation.getQualifiedName().equals("jet.typeinfo.JetMethod")) {
PsiLiteralExpression nullableExpression = (PsiLiteralExpression) annotation.findAttributeValue("nullableReturnType");
if (nullableExpression != null) {
nullable = (Boolean) nullableExpression.getValue();
} else {
// default value of parameter
nullable = false;
changeNullable = true;
}
}
}
JetType transformedType = semanticServices.getTypeTransformer().transformToType(returnType);
if (changeNullable) {
return TypeUtils.makeNullableAsSpecified(transformedType, nullable);
} else {
return transformedType;
}
}
private static Visibility resolveVisibilityFromPsiModifiers(PsiModifierListOwner modifierListOwner) {
//TODO report error
return modifierListOwner.hasModifierProperty(PsiModifier.PUBLIC) ? Visibility.PUBLIC :
......
namespace test
fun ff(): String = ""
namespace test
fun ff(): String? = ""
......@@ -105,8 +105,6 @@ public class ReadClassDataTest extends UsefulTestCase {
@Override
public void runTest() throws Exception {
if (true) return;
createMockCoreEnvironment();
LanguageASTFactory.INSTANCE.addExplicitExtension(JavaLanguage.INSTANCE, new JavaASTFactory());
......@@ -184,7 +182,8 @@ public class ReadClassDataTest extends UsefulTestCase {
for (int i = 0; i < a.getValueParameters().size(); ++i) {
compareAnything(ValueParameterDescriptor.class, a.getValueParameters().get(i), b.getValueParameters().get(i));
}
System.out.println("function " + a.getName());
Assert.assertEquals(a.getReturnType(), b.getReturnType());
System.out.println("fun " + a.getName() + "(...): " + a.getReturnType());
}
private <T> void compareAnything(Class<T> clazz, T a, T b) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册