Search in sources :

Example 1 with ConvertToJBColorQuickFix

use of org.jetbrains.idea.devkit.inspections.quickfix.ConvertToJBColorQuickFix in project intellij-community by JetBrains.

the class UseJBColorInspection method checkNewExpression.

@Nullable
private static ProblemDescriptor checkNewExpression(PsiNewExpression expression, InspectionManager manager, boolean isOnTheFly) {
    final Project project = manager.getProject();
    final PsiType type = expression.getType();
    final PsiExpressionList arguments = expression.getArgumentList();
    if (type != null && arguments != null && type.equalsToText("java.awt.Color")) {
        final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
        final PsiClass jbColorClass = facade.findClass(JBColor.class.getName(), GlobalSearchScope.allScope(project));
        if (jbColorClass != null && facade.getResolveHelper().isAccessible(jbColorClass, expression, jbColorClass)) {
            final PsiElement parent = expression.getParent();
            if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiNewExpression) {
                final PsiType parentType = ((PsiNewExpression) parent.getParent()).getType();
                if (parentType == null || JBColor.class.getName().equals(parentType.getCanonicalText()))
                    return null;
            }
            return manager.createProblemDescriptor(expression, "Replace with JBColor", new ConvertToJBColorQuickFix(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) ConvertToJBColorQuickFix(org.jetbrains.idea.devkit.inspections.quickfix.ConvertToJBColorQuickFix) JBColor(com.intellij.ui.JBColor) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Project (com.intellij.openapi.project.Project)1 JBColor (com.intellij.ui.JBColor)1 Nullable (org.jetbrains.annotations.Nullable)1 ConvertToJBColorQuickFix (org.jetbrains.idea.devkit.inspections.quickfix.ConvertToJBColorQuickFix)1