Map java.land.Deprecated to jet.deprecated

Change testData for deprecated annotation
 #KT-2947 Fixed
This commit is contained in:
Natalia.Ukhorskaya
2012-10-18 19:14:04 +04:00
parent f9c1c041d7
commit 62d8153ada
42 changed files with 107 additions and 98 deletions
@@ -22,6 +22,8 @@ import com.intellij.psi.PsiModifierListOwner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.java.data.ResolverClassData;
import org.jetbrains.jet.lang.resolve.java.data.ResolverNamespaceData;
import org.jetbrains.jet.lang.resolve.java.data.ResolverScopeData;
@@ -142,4 +144,14 @@ public final class DescriptorResolverUtils {
assert psiClassQualifiedName != null : "Reading java class with no qualified name";
return new FqNameUnsafe(psiClassQualifiedName + "." + getClassObjectName(psiClass.getName()).getName());
}
@NotNull
public static AnnotationDescriptor getAnnotationDescriptorForJavaLangDeprecated(ClassDescriptor classDescriptor) {
AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor();
annotationDescriptor.setAnnotationType(classDescriptor.getDefaultType());
ValueParameterDescriptor value = getValueParameterDescriptorForAnnotationParameter(Name.identifier("value"), classDescriptor);
assert value != null : "jet.deprecated must have one parameter called value";
annotationDescriptor.setValueArgument(value, new StringValue("Deprecated in Java"));
return annotationDescriptor;
}
}
@@ -17,11 +17,13 @@
package org.jetbrains.jet.lang.resolve.java;
import com.google.common.collect.*;
import com.intellij.psi.CommonClassNames;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
@@ -89,6 +91,15 @@ public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements
return classDescriptorMap.get(fqName);
}
@Nullable
public AnnotationDescriptor mapToAnnotationClass(@NotNull FqName fqName) {
ClassDescriptor classDescriptor = classDescriptorMap.get(fqName);
if (classDescriptor != null && fqName.getFqName().equals(CommonClassNames.JAVA_LANG_DEPRECATED)) {
return DescriptorResolverUtils.getAnnotationDescriptorForJavaLangDeprecated(classDescriptor);
}
return null;
}
private static FqName getJavaClassFqName(@NotNull Class<?> javaClass) {
return new FqName(javaClass.getName().replace('$', '.'));
}
@@ -45,6 +45,7 @@ public abstract class JavaToKotlinClassMapBuilder {
register(Comparable.class, kotlinBuiltIns.getComparable());
register(Enum.class, kotlinBuiltIns.getEnum());
register(Annotation.class, kotlinBuiltIns.getAnnotation());
register(Deprecated.class, kotlinBuiltIns.getDeprecatedAnnotation(), Direction.JAVA_TO_KOTLIN);
register(Iterable.class, kotlinBuiltIns.getIterable(), kotlinBuiltIns.getMutableIterable());
register(Iterator.class, kotlinBuiltIns.getIterator(), kotlinBuiltIns.getMutableIterator());
@@ -24,10 +24,8 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.DescriptorResolverUtils;
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.java.*;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -88,6 +86,12 @@ public final class JavaAnnotationResolver {
}
FqName annotationFqName = new FqName(qname);
AnnotationDescriptor mappedClassDescriptor = JavaToKotlinClassMap.getInstance().mapToAnnotationClass(annotationFqName);
if (mappedClassDescriptor != null) {
return mappedClassDescriptor;
}
final ClassDescriptor annotationClass =
classResolver.resolveClass(annotationFqName, DescriptorSearchRule.INCLUDE_KOTLIN, postponedTasks);
if (annotationClass == null) {