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