EA-36935 Rewriting annotations exception when file contains object with annotation.
This commit is contained in:
+1
-5
@@ -19,14 +19,13 @@ package org.jetbrains.jet.lang.descriptors.annotations;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -51,9 +50,6 @@ public class AnnotationDescriptor {
|
||||
}
|
||||
|
||||
public void setAnnotationType(@NotNull JetType annotationType) {
|
||||
if (false && !(annotationType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +103,6 @@ public class AnnotationResolver {
|
||||
trace.report(Errors.NOT_AN_ANNOTATION_CLASS.on(entryElement, descriptor.getName().getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (results.isSuccess()) {
|
||||
JetType annotationType = results.getResultingDescriptor().getReturnType();
|
||||
annotationDescriptor.setAnnotationType(annotationType);
|
||||
resolveArguments(results, annotationDescriptor, trace);
|
||||
@@ -179,20 +177,28 @@ public class AnnotationResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<AnnotationDescriptor> createAnnotationStubs(@Nullable JetModifierList modifierList, BindingTrace trace) {
|
||||
public List<AnnotationDescriptor> getResolvedAnnotations(@Nullable JetModifierList modifierList, BindingTrace trace) {
|
||||
if (modifierList == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return createAnnotationStubs(modifierList.getAnnotationEntries(), trace);
|
||||
return getResolvedAnnotations(modifierList.getAnnotationEntries(), trace);
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
@NotNull
|
||||
public List<AnnotationDescriptor> createAnnotationStubs(List<JetAnnotationEntry> annotations, BindingTrace trace) {
|
||||
public List<AnnotationDescriptor> getResolvedAnnotations(List<JetAnnotationEntry> annotations, BindingTrace trace) {
|
||||
List<AnnotationDescriptor> result = Lists.newArrayList();
|
||||
for (JetAnnotationEntry annotation : annotations) {
|
||||
AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor();
|
||||
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);
|
||||
}
|
||||
|
||||
result.add(annotationDescriptor);
|
||||
trace.record(BindingContext.ANNOTATION, annotation, annotationDescriptor);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class DescriptorResolver {
|
||||
for (JetTypeParameter typeParameter : classElement.getTypeParameters()) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||
descriptor,
|
||||
annotationResolver.createAnnotationStubs(typeParameter.getModifierList(), trace),
|
||||
annotationResolver.getResolvedAnnotations(typeParameter.getModifierList(), trace),
|
||||
typeParameter.hasModifier(JetTokens.REIFIED_KEYWORD),
|
||||
typeParameter.getVariance(),
|
||||
JetPsiUtil.safeName(typeParameter.getName()),
|
||||
@@ -412,19 +412,15 @@ public class DescriptorResolver {
|
||||
int index,
|
||||
BindingTrace trace
|
||||
) {
|
||||
// JetTypeReference extendsBound = typeParameter.getExtendsBound();
|
||||
// JetType bound = extendsBound == null
|
||||
// ? JetStandardClasses.getDefaultBound()
|
||||
// : typeResolver.resolveType(extensibleScope, extendsBound);
|
||||
// TODO: Annotations are not resolved!
|
||||
TypeParameterDescriptorImpl typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||
containingDescriptor,
|
||||
annotationResolver.createAnnotationStubs(typeParameter.getModifierList(), trace),
|
||||
annotationResolver.getResolvedAnnotations(typeParameter.getModifierList(), trace),
|
||||
typeParameter.hasModifier(JetTokens.REIFIED_KEYWORD),
|
||||
typeParameter.getVariance(),
|
||||
JetPsiUtil.safeName(typeParameter.getName()),
|
||||
index
|
||||
);
|
||||
// typeParameterDescriptor.addUpperBound(bound);
|
||||
extensibleScope.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||
trace.record(BindingContext.TYPE_PARAMETER, typeParameter, typeParameterDescriptor);
|
||||
return typeParameterDescriptor;
|
||||
@@ -607,7 +603,7 @@ public class DescriptorResolver {
|
||||
) {
|
||||
VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
|
||||
containingDeclaration,
|
||||
annotationResolver.createAnnotationStubs(parameter.getModifierList(), trace),
|
||||
annotationResolver.getResolvedAnnotations(parameter.getModifierList(), trace),
|
||||
JetPsiUtil.safeName(parameter.getName()),
|
||||
type,
|
||||
parameter.isMutable());
|
||||
@@ -626,7 +622,7 @@ public class DescriptorResolver {
|
||||
if (JetPsiUtil.isScriptDeclaration(variable)) {
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
containingDeclaration,
|
||||
annotationResolver.createAnnotationStubs(variable.getModifierList(), trace),
|
||||
annotationResolver.getResolvedAnnotations(variable.getModifierList(), trace),
|
||||
Modality.FINAL,
|
||||
Visibilities.INTERNAL,
|
||||
variable.isVar(),
|
||||
@@ -661,7 +657,7 @@ public class DescriptorResolver {
|
||||
) {
|
||||
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
|
||||
containingDeclaration,
|
||||
annotationResolver.createAnnotationStubs(variable.getModifierList(), trace),
|
||||
annotationResolver.getResolvedAnnotations(variable.getModifierList(), trace),
|
||||
JetPsiUtil.safeName(variable.getName()),
|
||||
type,
|
||||
variable.isVar());
|
||||
@@ -694,7 +690,7 @@ public class DescriptorResolver {
|
||||
JetModifierList modifierList = objectDeclaration.getModifierList();
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
containingDeclaration,
|
||||
annotationResolver.createAnnotationStubs(modifierList, trace),
|
||||
annotationResolver.getResolvedAnnotations(modifierList, trace),
|
||||
Modality.FINAL,
|
||||
ModifiersChecker.resolveVisibilityFromModifiers(objectDeclaration),
|
||||
false,
|
||||
@@ -720,7 +716,7 @@ public class DescriptorResolver {
|
||||
) {
|
||||
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
|
||||
containingDeclaration,
|
||||
annotationResolver.createAnnotationStubs(objectDeclaration.getModifierList(), trace),
|
||||
annotationResolver.getResolvedAnnotations(objectDeclaration.getModifierList(), trace),
|
||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
||||
classDescriptor.getDefaultType(),
|
||||
/*isVar =*/ false);
|
||||
|
||||
@@ -68,7 +68,7 @@ public class TypeResolver {
|
||||
JetType cachedType = trace.getBindingContext().get(BindingContext.TYPE, typeReference);
|
||||
if (cachedType != null) return cachedType;
|
||||
|
||||
final List<AnnotationDescriptor> annotations = annotationResolver.createAnnotationStubs(typeReference.getAnnotations(), trace);
|
||||
final List<AnnotationDescriptor> annotations = annotationResolver.getResolvedAnnotations(typeReference.getAnnotations(), trace);
|
||||
|
||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
JetType type = resolveTypeElement(scope, annotations, typeElement, false, trace, checkBounds);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
// Check that there won't be "Rewrite at slice ANNOTATION key" exception - EA-36935
|
||||
<!UNRESOLVED_REFERENCE!>someErrorAnnotation<!> object Test {
|
||||
}
|
||||
@@ -514,6 +514,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationForObject.kt")
|
||||
public void testAnnotationForObject() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("AnnotationsForClasses.kt")
|
||||
public void testAnnotationsForClasses() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.kt");
|
||||
|
||||
Reference in New Issue
Block a user