Resolve annotation class constructors before other constructors
This commit is contained in:
@@ -373,6 +373,9 @@ public class BodyResolver {
|
||||
JetClass klass = entry.getKey();
|
||||
MutableClassDescriptor classDescriptor = entry.getValue();
|
||||
ConstructorDescriptor unsubstitutedPrimaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||
|
||||
annotationResolver.resolveAnnotationsArguments(classDescriptor.getScopeForSupertypeResolution(), klass.getPrimaryConstructorModifierList(), trace);
|
||||
|
||||
if (unsubstitutedPrimaryConstructor != null) {
|
||||
WritableScope parameterScope = new WritableScopeImpl(classDescriptor.getScopeForSupertypeResolution(), unsubstitutedPrimaryConstructor,
|
||||
RedeclarationHandler.DO_NOTHING, "Scope with value parameters of a constructor");
|
||||
|
||||
@@ -89,6 +89,7 @@ public class DeclarationResolver {
|
||||
|
||||
|
||||
public void process(@NotNull JetScope rootScope) {
|
||||
resolveAnnotationConstructors();
|
||||
resolveConstructorHeaders();
|
||||
resolveAnnotationStubsOnClassesAndConstructors();
|
||||
resolveFunctionAndPropertyHeaders();
|
||||
@@ -98,14 +99,23 @@ public class DeclarationResolver {
|
||||
checkRedeclarationsInInnerClassNames();
|
||||
}
|
||||
|
||||
private void resolveAnnotationConstructors() {
|
||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||
MutableClassDescriptor classDescriptor = entry.getValue();
|
||||
|
||||
if (DescriptorUtils.isAnnotationClass(classDescriptor)) {
|
||||
processPrimaryConstructor(classDescriptor, entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveConstructorHeaders() {
|
||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||
JetClass jetClass = entry.getKey();
|
||||
MutableClassDescriptor classDescriptor = entry.getValue();
|
||||
|
||||
processPrimaryConstructor(classDescriptor, jetClass);
|
||||
if (!DescriptorUtils.isAnnotationClass(classDescriptor)) {
|
||||
processPrimaryConstructor(classDescriptor, entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package test
|
||||
|
||||
ANNOTATION class MyClass {
|
||||
ANNOTATION class MyClass [ANNOTATION]([ANNOTATION] param: Int, [ANNOTATION] val consProp: Int) {
|
||||
ANNOTATION class object {
|
||||
}
|
||||
|
||||
|
||||
+21
@@ -101,6 +101,9 @@ public class AnnotationDescriptorResolveTest extends JetLiteFixture {
|
||||
checkDescriptor(expectedAnnotation, topProp.getSetter());
|
||||
|
||||
checkDescriptor(expectedAnnotation, getObjectDescriptor(test, "MyObject"));
|
||||
|
||||
checkDescriptor(expectedAnnotation, getConstructorParameterDescriptor(myClass, "consProp"));
|
||||
checkDescriptor(expectedAnnotation, getConstructorParameterDescriptor(myClass, "param"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -235,6 +238,24 @@ public class AnnotationDescriptorResolveTest extends JetLiteFixture {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ValueParameterDescriptor getConstructorParameterDescriptor(
|
||||
@NotNull ClassDescriptor classDescriptor,
|
||||
@NotNull String name
|
||||
) {
|
||||
ConstructorDescriptor constructorDescriptor = getConstructorDescriptor(classDescriptor);
|
||||
ValueParameterDescriptor parameter = findValueParameter(constructorDescriptor.getValueParameters(), name);
|
||||
assertNotNull("Cannot find constructor parameter with name " + name, parameter);
|
||||
return parameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ConstructorDescriptor getConstructorDescriptor(@NotNull ClassDescriptor classDescriptor) {
|
||||
Collection<ConstructorDescriptor> constructors = classDescriptor.getConstructors();
|
||||
assert constructors.size() == 1;
|
||||
return constructors.iterator().next();
|
||||
}
|
||||
|
||||
private static ValueParameterDescriptor findValueParameter(List<ValueParameterDescriptor> parameters, String name) {
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
if (parameter.getName().asString().equals(name)) {
|
||||
|
||||
Reference in New Issue
Block a user