Introduce language feature for array literals in annotations

This commit is contained in:
Mikhail Zarechenskiy
2017-03-21 02:49:03 +03:00
parent 0f1acab40d
commit bfe2ddf7c1
15 changed files with 79 additions and 4 deletions
@@ -1517,6 +1517,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
public KotlinTypeInfo visitCollectionLiteralExpression(
@NotNull KtCollectionLiteralExpression expression, ExpressionTypingContext context
) {
checkSupportsArrayLiterals(expression, context);
return resolveCollectionLiteralSpecialMethod(expression, context);
}
@@ -1781,6 +1782,20 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return resultTypeInfo.replaceType(functionResults.getResultingDescriptor().getReturnType());
}
private void checkSupportsArrayLiterals(KtCollectionLiteralExpression expression, ExpressionTypingContext context) {
if (isInsideAnnotationEntryOrClass(expression) &&
!components.languageVersionSettings.supportsFeature(LanguageFeature.ArrayLiteralsInAnnotations)) {
context.trace.report(UNSUPPORTED_FEATURE.on(
expression, TuplesKt.to(LanguageFeature.ArrayLiteralsInAnnotations, components.languageVersionSettings)));
}
}
private static boolean isInsideAnnotationEntryOrClass(KtCollectionLiteralExpression expression) {
//noinspection unchecked
PsiElement parent = PsiTreeUtil.getParentOfType(expression, KtAnnotationEntry.class, KtClass.class);
return parent instanceof KtAnnotationEntry || (parent instanceof KtClass && ((KtClass) parent).isAnnotation());
}
private KotlinTypeInfo resolveCollectionLiteralSpecialMethod(
@NotNull KtCollectionLiteralExpression collectionLiteralExpression,
@NotNull ExpressionTypingContext context