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;
}
Aggregations