mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ImplicitDefaultCharsetUsageInspection: support org.apache.commons.io.IOUtils (IDEA-240870)
GitOrigin-RevId: 753b98a9e7ba715281d420508dd60560b97f0a7b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2bc23faf05
commit
5398b343e8
+13
-22
@@ -17,9 +17,9 @@ import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.callMatcher.CallMatcher;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -118,32 +118,23 @@ public class ImplicitDefaultCharsetUsageInspection extends BaseInspection {
|
||||
}
|
||||
|
||||
private static class ImplicitDefaultCharsetUsageVisitor extends BaseInspectionVisitor {
|
||||
private static final CallMatcher METHODS = CallMatcher.anyOf(
|
||||
CallMatcher.exactInstanceCall(CommonClassNames.JAVA_LANG_STRING, "getBytes").parameterCount(0),
|
||||
CallMatcher.staticCall("org.apache.commons.io.IOUtils", "toByteArray").parameterTypes(CommonClassNames.JAVA_LANG_STRING),
|
||||
CallMatcher.staticCall("org.apache.commons.io.IOUtils", "toByteArray").parameterTypes("java.io.Reader"),
|
||||
CallMatcher.staticCall("org.apache.commons.io.IOUtils", "toCharArray", "toString", "readLines").parameterTypes("java.io.InputStream"),
|
||||
CallMatcher.staticCall("org.apache.commons.io.IOUtils", "toString").parameterTypes("java.net.URI"),
|
||||
CallMatcher.staticCall("org.apache.commons.io.IOUtils", "toString").parameterTypes("java.net.URL"),
|
||||
CallMatcher.staticCall("org.apache.commons.io.IOUtils", "toInputStream").parameterTypes(CommonClassNames.JAVA_LANG_CHAR_SEQUENCE),
|
||||
CallMatcher.staticCall("org.apache.commons.io.IOUtils", "toInputStream").parameterTypes(CommonClassNames.JAVA_LANG_STRING)
|
||||
);
|
||||
|
||||
@Override
|
||||
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
|
||||
@NonNls final String name = methodExpression.getReferenceName();
|
||||
if (!"getBytes".equals(name)) {
|
||||
return;
|
||||
if (METHODS.test(expression)) {
|
||||
registerMethodCallError(expression, expression);
|
||||
}
|
||||
final PsiMethod method = expression.resolveMethod();
|
||||
if (method == null) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList.getParametersCount() == 1) {
|
||||
return;
|
||||
}
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
final String qName = aClass.getQualifiedName();
|
||||
if (!CommonClassNames.JAVA_LANG_STRING.equals(qName)) {
|
||||
return;
|
||||
}
|
||||
registerMethodCallError(expression, expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user