Recursive annotations are now possible for properties / functions / classes / primary constructors #EA-66984 Fixed #EA-63992 Fixed #EA-64272 Fixed

A set of tests provided.
This commit is contained in:
Mikhail Glukhikh
2015-06-02 10:38:25 +03:00
parent 0c1a8ab8ff
commit 98407a7c4b
31 changed files with 261 additions and 12 deletions
@@ -350,15 +350,6 @@ public class DescriptorResolver {
annotationResolver.resolveAnnotationsWithoutArguments(scope, valueParameter.getModifierList(), trace));
}
@NotNull
public ValueParameterDescriptorImpl resolveValueParameterDescriptorWithAnnotationArguments(
JetScope scope, DeclarationDescriptor declarationDescriptor,
JetParameter valueParameter, int index, JetType type, BindingTrace trace
) {
return resolveValueParameterDescriptor(declarationDescriptor, valueParameter, index, type, trace,
annotationResolver.resolveAnnotationsWithArguments(scope, valueParameter.getModifierList(), trace));
}
@NotNull
private ValueParameterDescriptorImpl resolveValueParameterDescriptor(
DeclarationDescriptor declarationDescriptor,
@@ -88,7 +88,7 @@ class FunctionDescriptorResolver(
): SimpleFunctionDescriptor {
val functionDescriptor = functionConstructor(
containingDescriptor,
annotationResolver.resolveAnnotationsWithArguments(scope, function.getModifierList(), trace),
annotationResolver.resolveAnnotationsWithoutArguments(scope, function.getModifierList(), trace),
function.getNameAsSafeName(),
CallableMemberDescriptor.Kind.DECLARATION,
function.toSourceElement()
@@ -338,7 +338,7 @@ class FunctionDescriptorResolver(
checkConstructorParameterHasNoModifier(trace, valueParameter)
}
val valueParameterDescriptor = descriptorResolver.resolveValueParameterDescriptorWithAnnotationArguments(parameterScope, functionDescriptor,
val valueParameterDescriptor = descriptorResolver.resolveValueParameterDescriptor(parameterScope, functionDescriptor,
valueParameter, i, type, trace)
parameterScope.addVariableDescriptor(valueParameterDescriptor)
result.add(valueParameterDescriptor)
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.resolve.AnnotationResolver;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
@@ -210,6 +211,7 @@ public class LazyDeclarationResolver {
throw new IllegalStateException("No descriptor resolved for " + declaration + ":\n" +
PsiUtilPackage.getElementTextWithContext(declaration));
}
AnnotationResolver.resolveAnnotationsArguments(result.getAnnotations(), trace);
return result;
}
@@ -101,7 +101,6 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
trace,
c.scopeProvider.getOuterDataFlowInfoForDeclaration(propertyDeclaration))
result.add(propertyDescriptor)
AnnotationResolver.resolveAnnotationsArguments(propertyDescriptor.getAnnotations(), trace)
}
getNonDeclaredProperties(name, result)
@@ -90,6 +90,7 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
context.trace, context.dataFlowInfo, context.expectedType
)
}
AnnotationResolver.resolveAnnotationsArguments(functionDescriptor.getAnnotations(), context.trace);
val functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace)
components.expressionTypingServices.checkFunctionReturnType(
@@ -165,6 +166,9 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
components.functionDescriptorResolver.
initializeFunctionDescriptorAndExplicitReturnType(context.scope.getContainingDeclaration(), context.scope, functionLiteral,
functionDescriptor, context.trace, context.expectedType)
for (parameterDescriptor in functionDescriptor.getValueParameters()) {
AnnotationResolver.resolveAnnotationsArguments(parameterDescriptor.getAnnotations(), context.trace)
}
BindingContextUtils.recordFunctionDeclarationToDescriptor(context.trace, functionLiteral, functionDescriptor)
return functionDescriptor
}
@@ -0,0 +1,2 @@
annotation class ann
class Annotated(ann val x: Int)
@@ -0,0 +1,16 @@
package
internal final class Annotated {
public constructor Annotated(/*0*/ ann() x: kotlin.Int)
ann() internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final annotation class ann : kotlin.Annotation {
public constructor ann()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,4 @@
// Functions can be recursively annotated
annotation class ann(val x: Int)
ann(<!ANNOTATION_PARAMETER_MUST_BE_CONST!>bar()<!>) fun foo() = 1
ann(<!ANNOTATION_PARAMETER_MUST_BE_CONST!>foo()<!>) fun bar() = 2
@@ -0,0 +1,12 @@
package
ann() internal fun bar(): kotlin.Int
ann() internal fun foo(): kotlin.Int
internal final annotation class ann : kotlin.Annotation {
public constructor ann(/*0*/ x: kotlin.Int)
internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,3 @@
// Class CAN be recursively annotated
RecursivelyAnnotated(1)
annotation class RecursivelyAnnotated(val x: Int)
@@ -0,0 +1,9 @@
package
RecursivelyAnnotated(x = IntegerValueType(1): IntegerValueType(1)) internal final annotation class RecursivelyAnnotated : kotlin.Annotation {
public constructor RecursivelyAnnotated(/*0*/ x: kotlin.Int)
internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,3 @@
// Function parameter CAN be recursively annotated
annotation class ann(val x: Int)
fun foo(@ann(<!ANNOTATION_PARAMETER_MUST_BE_CONST!>foo(1)<!>) x: Int): Int = x
@@ -0,0 +1,11 @@
package
internal fun foo(/*0*/ ann() x: kotlin.Int): kotlin.Int
internal final annotation class ann : kotlin.Annotation {
public constructor ann(/*0*/ x: kotlin.Int)
internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,3 @@
// Functions can be recursively annotated
annotation class ann(val x: Int)
ann(<!ANNOTATION_PARAMETER_MUST_BE_CONST!>foo()<!>) fun foo() = 1
@@ -0,0 +1,11 @@
package
ann() internal fun foo(): kotlin.Int
internal final annotation class ann : kotlin.Annotation {
public constructor ann(/*0*/ x: kotlin.Int)
internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,3 @@
// Properties can be recursively annotated
annotation class ann(val x: Int)
ann(x) val x: Int = 1
@@ -0,0 +1,11 @@
package
ann(x = 1: kotlin.Int) internal val x: kotlin.Int = 1
internal final annotation class ann : kotlin.Annotation {
public constructor ann(/*0*/ x: kotlin.Int)
internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,2 @@
// Class constructor parameter CAN be recursively annotated
annotation class RecursivelyAnnotated(RecursivelyAnnotated(1) val x: Int)
@@ -0,0 +1,9 @@
package
internal final annotation class RecursivelyAnnotated : kotlin.Annotation {
public constructor RecursivelyAnnotated(/*0*/ RecursivelyAnnotated(x = IntegerValueType(1): IntegerValueType(1)) x: kotlin.Int)
RecursivelyAnnotated(x = IntegerValueType(1): IntegerValueType(1)) internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,2 @@
// Class constructor parameter CAN be recursively annotated
annotation class RecursivelyAnnotated(@RecursivelyAnnotated(1) val x: Int)
@@ -0,0 +1,9 @@
package
internal final annotation class RecursivelyAnnotated : kotlin.Annotation {
public constructor RecursivelyAnnotated(/*0*/ RecursivelyAnnotated(x = IntegerValueType(1): IntegerValueType(1)) x: kotlin.Int)
RecursivelyAnnotated(x = IntegerValueType(1): IntegerValueType(1)) internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,5 @@
// Properties can be recursively annotated
annotation class ann(val x: Int)
class My {
ann(<!ANNOTATION_PARAMETER_MUST_BE_CONST!>x<!>) val x: Int = 1
}
@@ -0,0 +1,17 @@
package
internal final class My {
public constructor My()
ann(x = 1: kotlin.Int) internal final val x: kotlin.Int = 1
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final annotation class ann : kotlin.Annotation {
public constructor ann(/*0*/ x: kotlin.Int)
internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,2 @@
// Class constructor parameter CAN be recursively annotated
class RecursivelyAnnotated(<!NOT_AN_ANNOTATION_CLASS!>RecursivelyAnnotated(1)<!> val x: Int)
@@ -0,0 +1,9 @@
package
internal final class RecursivelyAnnotated {
public constructor RecursivelyAnnotated(/*0*/ RecursivelyAnnotated(x = IntegerValueType(1): IntegerValueType(1)) x: kotlin.Int)
RecursivelyAnnotated(x = IntegerValueType(1): IntegerValueType(1)) internal final val x: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,2 @@
// !DIAGNOSTICS: -NO_VALUE_FOR_PARAMETER
class Tree<T>(<!NOT_A_CLASS!>T<!> element<!SYNTAX!><!>, <!NOT_AN_ANNOTATION_CLASS!>Tree<T><!> left<!SYNTAX!><!>, <!NOT_AN_ANNOTATION_CLASS!>Tree<T><!> right<!SYNTAX!><!>) {}
@@ -0,0 +1,8 @@
package
internal final class Tree</*0*/ T> {
public constructor Tree</*0*/ T>(/*0*/ [ERROR : Not an annotation: T]() element: [ERROR : Type annotation was missing for parameter element], /*1*/ Tree<T>() left: [ERROR : Type annotation was missing for parameter left], /*2*/ Tree<T>() right: [ERROR : Type annotation was missing for parameter right])
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,7 @@
fun add(a: Int, b: Int) = a + b
interface A {
fun shuffle<T>(x: List<T>): List<T>
fun foo<T>(f : (List<T>) -> List<T>, x : List<T>)
fun f() : (Int, Int) -> Int = ::add
}
@@ -0,0 +1,12 @@
package
internal fun add(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Int
internal interface A {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal open fun f(): (kotlin.Int, kotlin.Int) -> kotlin.Int
internal abstract fun </*0*/ T> foo(/*0*/ f: (kotlin.List<T>) -> kotlin.List<T>, /*1*/ x: kotlin.List<T>): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal abstract fun </*0*/ T> shuffle(/*0*/ x: kotlin.List<T>): kotlin.List<T>
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -597,6 +597,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("AnnotatedConstructor.kt")
public void testAnnotatedConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructor.kt");
doTest(fileName);
}
@TestMetadata("AnnotatedConstructorParams.kt")
public void testAnnotatedConstructorParams() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt");
@@ -765,6 +771,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("MutuallyRecursivelyAnnotatedGlobalFunction.kt")
public void testMutuallyRecursivelyAnnotatedGlobalFunction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/MutuallyRecursivelyAnnotatedGlobalFunction.kt");
doTest(fileName);
}
@TestMetadata("noNameProperty.kt")
public void testNoNameProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/noNameProperty.kt");
@@ -813,6 +825,54 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("RecursivelyAnnotated.kt")
public void testRecursivelyAnnotated() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotated.kt");
doTest(fileName);
}
@TestMetadata("RecursivelyAnnotatedFunctionParameter.kt")
public void testRecursivelyAnnotatedFunctionParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedFunctionParameter.kt");
doTest(fileName);
}
@TestMetadata("RecursivelyAnnotatedGlobalFunction.kt")
public void testRecursivelyAnnotatedGlobalFunction() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalFunction.kt");
doTest(fileName);
}
@TestMetadata("RecursivelyAnnotatedGlobalProperty.kt")
public void testRecursivelyAnnotatedGlobalProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedGlobalProperty.kt");
doTest(fileName);
}
@TestMetadata("RecursivelyAnnotatedParameter.kt")
public void testRecursivelyAnnotatedParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameter.kt");
doTest(fileName);
}
@TestMetadata("RecursivelyAnnotatedParameterWithAt.kt")
public void testRecursivelyAnnotatedParameterWithAt() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedParameterWithAt.kt");
doTest(fileName);
}
@TestMetadata("RecursivelyAnnotatedProperty.kt")
public void testRecursivelyAnnotatedProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/RecursivelyAnnotatedProperty.kt");
doTest(fileName);
}
@TestMetadata("RecursivelyIncorrectlyAnnotatedParameter.kt")
public void testRecursivelyIncorrectlyAnnotatedParameter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/RecursivelyIncorrectlyAnnotatedParameter.kt");
doTest(fileName);
}
@TestMetadata("typeAnnotations.kt")
public void testTypeAnnotations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/typeAnnotations.kt");
@@ -10122,6 +10182,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("ea66984.kt")
public void testEa66984() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/ea66984.kt");
doTest(fileName);
}
@TestMetadata("ErrorsOnIbjectExpressionsAsParameters.kt")
public void testErrorsOnIbjectExpressionsAsParameters() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/ErrorsOnIbjectExpressionsAsParameters.kt");
@@ -713,6 +713,21 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/regression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Regression extends AbstractJetDiagnosticsTestWithStdLib {
public void testAllFilesPresentInRegression() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/regression"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ea63992.kt")
public void testEa63992() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/regression/ea63992.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/reified")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)