IDEADEV-31824 (Incorrect "manual array copy" warning)
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / resources / DriverManagerGetConnectionInspection.java
blob4aeee990466a53e02db1d15da0c81dcb0fc04bae
1 /*
2 * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.siyeh.ig.resources;
18 import com.intellij.psi.PsiClass;
19 import com.intellij.psi.PsiMethod;
20 import com.intellij.psi.PsiMethodCallExpression;
21 import com.intellij.psi.PsiReferenceExpression;
22 import com.siyeh.HardcodedMethodConstants;
23 import com.siyeh.InspectionGadgetsBundle;
24 import com.siyeh.ig.BaseInspection;
25 import com.siyeh.ig.BaseInspectionVisitor;
26 import org.jetbrains.annotations.NotNull;
28 public class DriverManagerGetConnectionInspection extends BaseInspection {
30 @NotNull
31 public String getID(){
32 return "CallToDriverManagerGetConnection";
35 @NotNull
36 public String getDisplayName() {
37 return InspectionGadgetsBundle.message(
38 "drivermanager.call.display.name");
41 @NotNull
42 public String buildErrorString(Object... infos) {
43 return InspectionGadgetsBundle.message(
44 "drivermanager.call.problem.descriptor");
47 public BaseInspectionVisitor buildVisitor() {
48 return new DriverManagerGetConnectionVisitor();
51 private static class DriverManagerGetConnectionVisitor
52 extends BaseInspectionVisitor {
54 @Override public void visitMethodCallExpression(
55 @NotNull PsiMethodCallExpression expression) {
56 super.visitMethodCallExpression(expression);
57 if (!isDriverManagerGetConnection(expression)) {
58 return;
60 registerMethodCallError(expression);
63 private static boolean isDriverManagerGetConnection(
64 PsiMethodCallExpression expression) {
65 final PsiReferenceExpression methodExpression =
66 expression.getMethodExpression();
68 final String methodName = methodExpression.getReferenceName();
69 if (!HardcodedMethodConstants.GET_CONNECTION.equals(methodName) ) {
70 return false;
72 final PsiMethod method = expression.resolveMethod();
73 if (method == null) {
74 return false;
76 final PsiClass aClass = method.getContainingClass();
77 if (aClass == null) {
78 return false;
80 final String className = aClass.getQualifiedName();
81 if (className == null) {
82 return false;
84 return "java.sql.DriverManager".equals(className);