Resolve annotations on expressions and multi-declarations
This commit is contained in:
@@ -80,6 +80,15 @@ public class AnnotationResolver {
|
|||||||
return resolveAnnotations(scope, modifierList, trace, true);
|
return resolveAnnotations(scope, modifierList, trace, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public List<AnnotationDescriptor> resolveAnnotationsWithArguments(
|
||||||
|
@NotNull JetScope scope,
|
||||||
|
@NotNull List<JetAnnotationEntry> annotationEntries,
|
||||||
|
@NotNull BindingTrace trace
|
||||||
|
) {
|
||||||
|
return resolveAnnotationEntries(scope, annotationEntries, trace, true);
|
||||||
|
}
|
||||||
|
|
||||||
private List<AnnotationDescriptor> resolveAnnotations(
|
private List<AnnotationDescriptor> resolveAnnotations(
|
||||||
@NotNull JetScope scope,
|
@NotNull JetScope scope,
|
||||||
@Nullable JetModifierList modifierList,
|
@Nullable JetModifierList modifierList,
|
||||||
@@ -91,6 +100,14 @@ public class AnnotationResolver {
|
|||||||
}
|
}
|
||||||
List<JetAnnotationEntry> annotationEntryElements = modifierList.getAnnotationEntries();
|
List<JetAnnotationEntry> annotationEntryElements = modifierList.getAnnotationEntries();
|
||||||
|
|
||||||
|
return resolveAnnotationEntries(scope, annotationEntryElements, trace, shouldResolveArguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<AnnotationDescriptor> resolveAnnotationEntries(
|
||||||
|
@NotNull JetScope scope,
|
||||||
|
@NotNull List<JetAnnotationEntry> annotationEntryElements, @NotNull BindingTrace trace,
|
||||||
|
boolean shouldResolveArguments
|
||||||
|
) {
|
||||||
if (annotationEntryElements.isEmpty()) return Collections.emptyList();
|
if (annotationEntryElements.isEmpty()) return Collections.emptyList();
|
||||||
List<AnnotationDescriptor> result = Lists.newArrayList();
|
List<AnnotationDescriptor> result = Lists.newArrayList();
|
||||||
for (JetAnnotationEntry entryElement : annotationEntryElements) {
|
for (JetAnnotationEntry entryElement : annotationEntryElements) {
|
||||||
|
|||||||
+6
-4
@@ -45,7 +45,6 @@ import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsImpl;
|
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsImpl;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil;
|
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.util.ExpressionAsFunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
||||||
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
import org.jetbrains.jet.lang.resolve.name.LabelName;
|
||||||
@@ -1169,12 +1168,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitAnnotatedExpression(JetAnnotatedExpression expression, ExpressionTypingContext data) {
|
public JetTypeInfo visitAnnotatedExpression(JetAnnotatedExpression expression, ExpressionTypingContext context) {
|
||||||
|
context.expressionTypingServices.getAnnotationResolver().resolveAnnotationsWithArguments(
|
||||||
|
context.scope, expression.getAttributes(), context.trace);
|
||||||
|
|
||||||
JetExpression baseExpression = expression.getBaseExpression();
|
JetExpression baseExpression = expression.getBaseExpression();
|
||||||
if (baseExpression == null) {
|
if (baseExpression == null) {
|
||||||
return JetTypeInfo.create(null, data.dataFlowInfo);
|
return JetTypeInfo.create(null, context.dataFlowInfo);
|
||||||
}
|
}
|
||||||
return facade.getTypeInfo(baseExpression, data);
|
return facade.getTypeInfo(baseExpression, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
@@ -145,6 +145,9 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitMultiDeclaration(JetMultiDeclaration multiDeclaration, ExpressionTypingContext context) {
|
public JetTypeInfo visitMultiDeclaration(JetMultiDeclaration multiDeclaration, ExpressionTypingContext context) {
|
||||||
|
context.expressionTypingServices.getAnnotationResolver().resolveAnnotationsWithArguments(
|
||||||
|
scope, multiDeclaration.getModifierList(), context.trace);
|
||||||
|
|
||||||
JetExpression initializer = multiDeclaration.getInitializer();
|
JetExpression initializer = multiDeclaration.getInitializer();
|
||||||
if (initializer == null) {
|
if (initializer == null) {
|
||||||
context.trace.report(INITIALIZER_REQUIRED_FOR_MULTIDECLARATION.on(multiDeclaration));
|
context.trace.report(INITIALIZER_REQUIRED_FOR_MULTIDECLARATION.on(multiDeclaration));
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() = [ann] 1
|
||||||
|
|
||||||
|
annotation class ann
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun test(): Any? {
|
||||||
|
[ann] val (a, b) = P(1, 1)
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
annotation class ann
|
||||||
|
data class P(val a: Int, val b: Int)
|
||||||
@@ -610,6 +610,16 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.kt");
|
doTest("compiler/testData/diagnostics/tests/annotations/NonAnnotationClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("onExpression.kt")
|
||||||
|
public void testOnExpression() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/annotations/onExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("onMultiDeclaration.kt")
|
||||||
|
public void testOnMultiDeclaration() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/annotations/onMultiDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/backingField")
|
@TestMetadata("compiler/testData/diagnostics/tests/backingField")
|
||||||
|
|||||||
Reference in New Issue
Block a user