Fix rewrite for ANNOTATION slice (EA-49336)
This commit is contained in:
@@ -94,12 +94,17 @@ public class AnnotationResolver {
|
||||
if (annotationEntryElements.isEmpty()) return Collections.emptyList();
|
||||
List<AnnotationDescriptor> result = Lists.newArrayList();
|
||||
for (JetAnnotationEntry entryElement : annotationEntryElements) {
|
||||
AnnotationDescriptor descriptor = new AnnotationDescriptor();
|
||||
resolveAnnotationStub(scope, entryElement, descriptor, trace);
|
||||
trace.record(BindingContext.ANNOTATION, entryElement, descriptor);
|
||||
AnnotationDescriptor descriptor = trace.get(BindingContext.ANNOTATION, entryElement);
|
||||
if (descriptor == null) {
|
||||
descriptor = new AnnotationDescriptor();
|
||||
resolveAnnotationStub(scope, entryElement, descriptor, trace);
|
||||
trace.record(BindingContext.ANNOTATION, entryElement, descriptor);
|
||||
}
|
||||
|
||||
if (shouldResolveArguments) {
|
||||
resolveAnnotationArguments(entryElement, scope, trace);
|
||||
}
|
||||
|
||||
result.add(descriptor);
|
||||
}
|
||||
return result;
|
||||
@@ -360,15 +365,21 @@ public class AnnotationResolver {
|
||||
for (JetAnnotationEntry annotation : annotations) {
|
||||
AnnotationDescriptor annotationDescriptor = trace.get(BindingContext.ANNOTATION, annotation);
|
||||
if (annotationDescriptor == null) {
|
||||
// TODO: Unresolved annotation
|
||||
annotationDescriptor = new AnnotationDescriptor();
|
||||
annotationDescriptor.setAnnotationType(ErrorUtils.createErrorType("Unresolved annotation type"));
|
||||
|
||||
trace.record(BindingContext.ANNOTATION, annotation, annotationDescriptor);
|
||||
throw new IllegalStateException("Annotation for annotation should have been resolved: " + annotation);
|
||||
}
|
||||
|
||||
result.add(annotationDescriptor);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void reportUnsupportedAnnotationForTypeParameter(@NotNull JetModifierListOwner modifierListOwner, BindingTrace trace) {
|
||||
JetModifierList modifierList = modifierListOwner.getModifierList();
|
||||
if (modifierList == null) return;
|
||||
|
||||
for (JetAnnotationEntry annotationEntry : modifierList.getAnnotationEntries()) {
|
||||
trace.report(Errors.UNSUPPORTED.on(annotationEntry, "Annotations for type parameters are not supported yet"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public class DeclarationResolver {
|
||||
@Override
|
||||
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(
|
||||
namespaceLike.getOwnerForChildren(), declaration, context.getObjects().get(declaration), trace);
|
||||
scopeForFunctions, namespaceLike.getOwnerForChildren(), declaration, context.getObjects().get(declaration), trace);
|
||||
|
||||
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public class DeclarationResolver {
|
||||
((MutableClassDescriptorLite)namespaceLike.getOwnerForChildren()).getClassObjectDescriptor();
|
||||
assert classObjectDescriptor != null;
|
||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(
|
||||
classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), trace);
|
||||
scopeForFunctions, classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), trace);
|
||||
classObjectDescriptor.getBuilder().addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -102,9 +102,12 @@ public class DescriptorResolver {
|
||||
List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
|
||||
int index = 0;
|
||||
for (JetTypeParameter typeParameter : classElement.getTypeParameters()) {
|
||||
// TODO: Support
|
||||
AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(typeParameter, trace);
|
||||
|
||||
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||
descriptor,
|
||||
annotationResolver.getResolvedAnnotations(typeParameter.getModifierList(), trace),
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
typeParameter.hasModifier(JetTokens.REIFIED_KEYWORD),
|
||||
typeParameter.getVariance(),
|
||||
JetPsiUtil.safeName(typeParameter.getName()),
|
||||
@@ -570,10 +573,12 @@ public class DescriptorResolver {
|
||||
trace.report(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY.on(typeParameter));
|
||||
}
|
||||
|
||||
// TODO: Annotations are not resolved!
|
||||
// TODO: Support annotation for type parameters
|
||||
AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(typeParameter, trace);
|
||||
|
||||
TypeParameterDescriptorImpl typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||
containingDescriptor,
|
||||
annotationResolver.getResolvedAnnotations(typeParameter.getModifierList(), trace),
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
typeParameter.hasModifier(JetTokens.REIFIED_KEYWORD),
|
||||
typeParameter.getVariance(),
|
||||
JetPsiUtil.safeName(typeParameter.getName()),
|
||||
@@ -822,14 +827,14 @@ public class DescriptorResolver {
|
||||
|
||||
@NotNull
|
||||
public VariableDescriptor resolveObjectDeclaration(
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetClassOrObject objectDeclaration,
|
||||
@NotNull ClassDescriptor classDescriptor, BindingTrace trace
|
||||
) {
|
||||
boolean isProperty = (containingDeclaration instanceof NamespaceDescriptor)
|
||||
|| (containingDeclaration instanceof ClassDescriptor);
|
||||
boolean isProperty = (containingDeclaration instanceof NamespaceDescriptor) || (containingDeclaration instanceof ClassDescriptor);
|
||||
if (isProperty) {
|
||||
return resolveObjectDeclarationAsPropertyDescriptor(containingDeclaration, objectDeclaration, classDescriptor, trace);
|
||||
return resolveObjectDeclarationAsPropertyDescriptor(scope, containingDeclaration, objectDeclaration, classDescriptor, trace);
|
||||
}
|
||||
else {
|
||||
return resolveObjectDeclarationAsLocalVariable(containingDeclaration, objectDeclaration, classDescriptor, trace);
|
||||
@@ -838,6 +843,7 @@ public class DescriptorResolver {
|
||||
|
||||
@NotNull
|
||||
public PropertyDescriptor resolveObjectDeclarationAsPropertyDescriptor(
|
||||
@NotNull JetScope scope,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetClassOrObject objectDeclaration,
|
||||
@NotNull ClassDescriptor classDescriptor, BindingTrace trace
|
||||
@@ -845,7 +851,7 @@ public class DescriptorResolver {
|
||||
JetModifierList modifierList = objectDeclaration.getModifierList();
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorForObjectImpl(
|
||||
containingDeclaration,
|
||||
annotationResolver.getResolvedAnnotations(modifierList, trace),
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scope, modifierList, trace),
|
||||
resolveVisibilityFromModifiers(objectDeclaration, getDefaultVisibilityForObjectPropertyDescriptor(classDescriptor)),
|
||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
||||
classDescriptor
|
||||
|
||||
+4
-1
@@ -205,8 +205,11 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
if (classifier == null) {
|
||||
throw new IllegalStateException("Object declaration " + name + " found in the DeclarationProvider " + declarationProvider + " but not in the scope " + this);
|
||||
}
|
||||
|
||||
JetScope scope = getScopeForMemberDeclarationResolution(classOrObjectDeclaration);
|
||||
|
||||
VariableDescriptor propertyDescriptor = resolveSession.getInjector().getDescriptorResolver()
|
||||
.resolveObjectDeclaration(thisDescriptor, classOrObjectDeclaration, classifier, resolveSession.getTrace());
|
||||
.resolveObjectDeclaration(scope, thisDescriptor, classOrObjectDeclaration, classifier, resolveSession.getTrace());
|
||||
result.add(propertyDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration);
|
||||
if (classDescriptor != null) {
|
||||
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver()
|
||||
.resolveObjectDeclaration(scope.getContainingDeclaration(), declaration, classDescriptor, context.trace);
|
||||
.resolveObjectDeclaration(scope, scope.getContainingDeclaration(), declaration, classDescriptor, context.trace);
|
||||
scope.addVariableDescriptor(variableDescriptor);
|
||||
}
|
||||
return DataFlowUtils.checkStatementType(declaration, context, context.dataFlowInfo);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
annotation class A1
|
||||
annotation class A2(val some: Int = 12)
|
||||
|
||||
class TopLevelClass<<!UNSUPPORTED!>A1<!> <!UNSUPPORTED!>A2(3)<!> <!UNSUPPORTED!>A2<!> <!UNSUPPORTED!>A1(12)<!> <!UNSUPPORTED!>A2("Test")<!> T> {
|
||||
class InnerClass<<!UNSUPPORTED!>A1<!> <!UNSUPPORTED!>A2(3)<!> <!UNSUPPORTED!>A2<!> <!UNSUPPORTED!>A1(12)<!> <!UNSUPPORTED!>A2("Test")<!> T> {
|
||||
fun test() {
|
||||
class InFun<<!UNSUPPORTED!>A1<!> <!UNSUPPORTED!>A2(3)<!> <!UNSUPPORTED!>A2<!> <!UNSUPPORTED!>A1(12)<!> <!UNSUPPORTED!>A2("Test")<!> T>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
annotation class A1
|
||||
annotation class A2(val some: Int = 12)
|
||||
|
||||
fun <<!UNSUPPORTED!>A1<!> <!UNSUPPORTED!>A2(3)<!> <!UNSUPPORTED!>A2<!> <!UNSUPPORTED!>A1(12)<!> <!UNSUPPORTED!>A2("Test")<!> T> topFun() = 12
|
||||
|
||||
class SomeClass {
|
||||
fun <<!UNSUPPORTED!>A1<!> <!UNSUPPORTED!>A2(3)<!> <!UNSUPPORTED!>A2<!> <!UNSUPPORTED!>A1(12)<!> <!UNSUPPORTED!>A2("Test")<!> T> method() = 12
|
||||
|
||||
fun foo() {
|
||||
fun <<!UNSUPPORTED!>A1<!> <!UNSUPPORTED!>A2(3)<!> <!UNSUPPORTED!>A2<!> <!UNSUPPORTED!>A1(12)<!> <!UNSUPPORTED!>A2("Test")<!> T> innerFun() = 12
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
annotation class A1
|
||||
annotation class A2(val some: Int = 12)
|
||||
|
||||
val <<!UNSUPPORTED!>A1<!> <!UNSUPPORTED!>A2(3)<!> <!UNSUPPORTED!>A2<!> <!UNSUPPORTED!>A1(12)<!> <!UNSUPPORTED!>A2("Test")<!> T> topProp = 12
|
||||
|
||||
class SomeClass {
|
||||
val <<!UNSUPPORTED!>A1<!> <!UNSUPPORTED!>A2(3)<!> <!UNSUPPORTED!>A2<!> <!UNSUPPORTED!>A1(12)<!> <!UNSUPPORTED!>A2("Test")<!> T> field = 12
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
// Checks that there is no rewrite error at ANNOTATION slice because of resolving annotations for object in lazy resolve and resolving
|
||||
// object as property (method tries to resolve annotations too).
|
||||
|
||||
BadAnnotation
|
||||
object SomeObject
|
||||
|
||||
val some = SomeObject
|
||||
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
[ERROR : Unresolved annotation type]() internal val SomeObject: test.SomeObject
|
||||
internal val some: test.SomeObject
|
||||
|
||||
[ERROR : Unresolved annotation type]() internal object SomeObject {
|
||||
/*primary*/ private constructor SomeObject()
|
||||
}
|
||||
@@ -545,6 +545,16 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationForClassTypeParameter.kt")
|
||||
public void testAnnotationForClassTypeParameter() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForClassTypeParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationForFunctionTypeParameter.kt")
|
||||
public void testAnnotationForFunctionTypeParameter() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationForObject.kt")
|
||||
public void testAnnotationForObject() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForObject.kt");
|
||||
@@ -560,6 +570,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationsForPropertyTypeParameter.kt")
|
||||
public void testAnnotationsForPropertyTypeParameter() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("BasicAnnotations.kt")
|
||||
public void testBasicAnnotations() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/BasicAnnotations.kt");
|
||||
|
||||
+5
@@ -2394,6 +2394,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/lazyResolve/namespaceComparator/simpleClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("UnresolvedAnnotationOnObject.kt")
|
||||
public void testUnresolvedAnnotationOnObject() throws Exception {
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/lazyResolve/namespaceComparator/UnresolvedAnnotationOnObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("varargIterator.kt")
|
||||
public void testVarargIterator() throws Exception {
|
||||
doTestCheckingPrimaryConstructors("compiler/testData/lazyResolve/namespaceComparator/varargIterator.kt");
|
||||
|
||||
Reference in New Issue
Block a user