Move isDeprecated function to CodegenUtil

This commit is contained in:
Natalia.Ukhorskaya
2012-10-16 13:57:54 +04:00
parent 21900b7871
commit d55a0fcacb
2 changed files with 23 additions and 20 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.jet.codegen; package org.jetbrains.jet.codegen;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.util.containers.Stack; import com.intellij.util.containers.Stack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -35,6 +36,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import java.util.*; import java.util.*;
@@ -60,6 +62,18 @@ public class CodegenUtil {
return false; return false;
} }
public static boolean isDeprecated(DeclarationDescriptor descriptor) {
for (AnnotationDescriptor annotation : descriptor.getAnnotations()) {
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(annotation.getType());
if (classDescriptor != null) {
if (DescriptorUtils.getFQName(classDescriptor).getFqName().equals(CommonClassNames.JAVA_LANG_DEPRECATED)) {
return true;
}
}
}
return false;
}
public static boolean isInterface(JetType type) { public static boolean isInterface(JetType type) {
return isInterface(type.getConstructor().getDeclarationDescriptor()); return isInterface(type.getConstructor().getDeclarationDescriptor());
} }
@@ -38,6 +38,7 @@ import org.jetbrains.jet.resolve.DescriptorRenderer;
import java.util.List; import java.util.List;
import static org.jetbrains.jet.codegen.CodegenUtil.isDeprecated;
public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisitor { public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisitor {
@@ -61,7 +62,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
if (resolvedCall != null && resolvedCall instanceof VariableAsFunctionResolvedCall) { if (resolvedCall != null && resolvedCall instanceof VariableAsFunctionResolvedCall) {
// Deprecated for invoke() // Deprecated for invoke()
JetCallExpression parent = PsiTreeUtil.getParentOfType(expression, JetCallExpression.class); JetCallExpression parent = PsiTreeUtil.getParentOfType(expression, JetCallExpression.class);
if (parent != null && isDeprecated(resolvedCall.getResultingDescriptor().getAnnotations())) { if (parent != null && isDeprecated(resolvedCall.getResultingDescriptor())) {
reportAnnotation(parent, resolvedCall.getResultingDescriptor(), true); reportAnnotation(parent, resolvedCall.getResultingDescriptor(), true);
} }
} }
@@ -94,7 +95,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
private void checkFunctionDescriptor(JetExpression expression, DeclarationDescriptor target) { private void checkFunctionDescriptor(JetExpression expression, DeclarationDescriptor target) {
// Deprecated for Function // Deprecated for Function
if (isDeprecated(target.getAnnotations())) { if (isDeprecated(target)) {
reportAnnotation(expression, target, expression instanceof JetArrayAccessExpression); reportAnnotation(expression, target, expression instanceof JetArrayAccessExpression);
} }
} }
@@ -103,7 +104,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
// Deprecated for Class and for Constructor // Deprecated for Class and for Constructor
DeclarationDescriptor containingDeclaration = target.getContainingDeclaration(); DeclarationDescriptor containingDeclaration = target.getContainingDeclaration();
if (containingDeclaration != null) { if (containingDeclaration != null) {
if (isDeprecated(containingDeclaration.getAnnotations()) || isDeprecated(target.getAnnotations())) { if (isDeprecated(containingDeclaration) || isDeprecated(target)) {
reportAnnotation(expression, containingDeclaration); reportAnnotation(expression, containingDeclaration);
} }
} }
@@ -111,13 +112,13 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
private void checkClassDescriptor(@NotNull JetExpression expression, @NotNull ClassDescriptor target) { private void checkClassDescriptor(@NotNull JetExpression expression, @NotNull ClassDescriptor target) {
// Deprecated for Class, for ClassObject (if reference isn't in UserType or in ModifierList (trait)) // Deprecated for Class, for ClassObject (if reference isn't in UserType or in ModifierList (trait))
if (isDeprecated(target.getAnnotations())) { if (isDeprecated(target)) {
reportAnnotation(expression, target); reportAnnotation(expression, target);
} }
else if (PsiTreeUtil.getParentOfType(expression, JetUserType.class) == null && else if (PsiTreeUtil.getParentOfType(expression, JetUserType.class) == null &&
PsiTreeUtil.getParentOfType(expression, JetModifierList.class) == null) { PsiTreeUtil.getParentOfType(expression, JetModifierList.class) == null) {
ClassDescriptor classObjectDescriptor = target.getClassObjectDescriptor(); ClassDescriptor classObjectDescriptor = target.getClassObjectDescriptor();
if (classObjectDescriptor != null && isDeprecated(classObjectDescriptor.getAnnotations())) { if (classObjectDescriptor != null && isDeprecated(classObjectDescriptor)) {
reportAnnotation(expression, classObjectDescriptor); reportAnnotation(expression, classObjectDescriptor);
} }
} }
@@ -128,7 +129,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
@NotNull PropertyDescriptor propertyDescriptor @NotNull PropertyDescriptor propertyDescriptor
) { ) {
// Deprecated for Property // Deprecated for Property
if (isDeprecated(propertyDescriptor.getAnnotations())) { if (isDeprecated(propertyDescriptor)) {
reportAnnotation(expression, propertyDescriptor, propertyDescriptor.isVar()); reportAnnotation(expression, propertyDescriptor, propertyDescriptor.isVar());
return; return;
} }
@@ -191,7 +192,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
@NotNull PropertyAccessorDescriptor accessor, @NotNull PropertyAccessorDescriptor accessor,
@NotNull JetExpression expression, boolean isVar @NotNull JetExpression expression, boolean isVar
) { ) {
if (isDeprecated(accessor.getAnnotations())) { if (isDeprecated(accessor)) {
reportAnnotation(expression, accessor, isVar); reportAnnotation(expression, accessor, isVar);
} }
} }
@@ -199,7 +200,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
private void checkDeprecatedForOperations(@NotNull JetReferenceExpression expression) { private void checkDeprecatedForOperations(@NotNull JetReferenceExpression expression) {
DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression); DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
if (target != null) { if (target != null) {
if (isDeprecated(target.getAnnotations())) { if (isDeprecated(target)) {
reportAnnotation(expression, target, true); reportAnnotation(expression, target, true);
} }
} }
@@ -220,18 +221,6 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
} }
} }
private static boolean isDeprecated(List<AnnotationDescriptor> list) {
for (AnnotationDescriptor annotation : list) {
ClassDescriptor descriptor = TypeUtils.getClassDescriptor(annotation.getType());
if (descriptor != null) {
if (DescriptorUtils.getFQName(descriptor).getFqName().equals(CommonClassNames.JAVA_LANG_DEPRECATED)) {
return true;
}
}
}
return false;
}
private static String renderName(DeclarationDescriptor descriptor) { private static String renderName(DeclarationDescriptor descriptor) {
if (descriptor instanceof ClassDescriptor) { if (descriptor instanceof ClassDescriptor) {
return DescriptorUtils.getFQName(descriptor).getFqName(); return DescriptorUtils.getFQName(descriptor).getFqName();