diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index b2a98552b02..c75d1ba12d5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -16,6 +16,7 @@ package org.jetbrains.jet.codegen; +import com.intellij.psi.CommonClassNames; import com.intellij.psi.PsiElement; import com.intellij.util.containers.Stack; 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.name.Name; import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import java.util.*; @@ -60,6 +62,18 @@ public class CodegenUtil { 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) { return isInterface(type.getConstructor().getDeclarationDescriptor()); } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/DeprecatedAnnotationVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/DeprecatedAnnotationVisitor.java index 13896fdb420..9d9b0b4f348 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/DeprecatedAnnotationVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/DeprecatedAnnotationVisitor.java @@ -38,6 +38,7 @@ import org.jetbrains.jet.resolve.DescriptorRenderer; import java.util.List; +import static org.jetbrains.jet.codegen.CodegenUtil.isDeprecated; public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisitor { @@ -61,7 +62,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito if (resolvedCall != null && resolvedCall instanceof VariableAsFunctionResolvedCall) { // Deprecated for invoke() 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); } } @@ -94,7 +95,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito private void checkFunctionDescriptor(JetExpression expression, DeclarationDescriptor target) { // Deprecated for Function - if (isDeprecated(target.getAnnotations())) { + if (isDeprecated(target)) { reportAnnotation(expression, target, expression instanceof JetArrayAccessExpression); } } @@ -103,7 +104,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito // Deprecated for Class and for Constructor DeclarationDescriptor containingDeclaration = target.getContainingDeclaration(); if (containingDeclaration != null) { - if (isDeprecated(containingDeclaration.getAnnotations()) || isDeprecated(target.getAnnotations())) { + if (isDeprecated(containingDeclaration) || isDeprecated(target)) { reportAnnotation(expression, containingDeclaration); } } @@ -111,13 +112,13 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito private void checkClassDescriptor(@NotNull JetExpression expression, @NotNull ClassDescriptor target) { // 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); } else if (PsiTreeUtil.getParentOfType(expression, JetUserType.class) == null && PsiTreeUtil.getParentOfType(expression, JetModifierList.class) == null) { ClassDescriptor classObjectDescriptor = target.getClassObjectDescriptor(); - if (classObjectDescriptor != null && isDeprecated(classObjectDescriptor.getAnnotations())) { + if (classObjectDescriptor != null && isDeprecated(classObjectDescriptor)) { reportAnnotation(expression, classObjectDescriptor); } } @@ -128,7 +129,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito @NotNull PropertyDescriptor propertyDescriptor ) { // Deprecated for Property - if (isDeprecated(propertyDescriptor.getAnnotations())) { + if (isDeprecated(propertyDescriptor)) { reportAnnotation(expression, propertyDescriptor, propertyDescriptor.isVar()); return; } @@ -191,7 +192,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito @NotNull PropertyAccessorDescriptor accessor, @NotNull JetExpression expression, boolean isVar ) { - if (isDeprecated(accessor.getAnnotations())) { + if (isDeprecated(accessor)) { reportAnnotation(expression, accessor, isVar); } } @@ -199,7 +200,7 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito private void checkDeprecatedForOperations(@NotNull JetReferenceExpression expression) { DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression); if (target != null) { - if (isDeprecated(target.getAnnotations())) { + if (isDeprecated(target)) { reportAnnotation(expression, target, true); } } @@ -220,18 +221,6 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito } } - private static boolean isDeprecated(List 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) { if (descriptor instanceof ClassDescriptor) { return DescriptorUtils.getFQName(descriptor).getFqName();