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
.portability
;
18 import com
.intellij
.psi
.PsiNewExpression
;
19 import com
.intellij
.psi
.PsiType
;
20 import com
.intellij
.psi
.PsiTypeElement
;
21 import com
.intellij
.psi
.PsiVariable
;
22 import com
.siyeh
.InspectionGadgetsBundle
;
23 import com
.siyeh
.ig
.BaseInspection
;
24 import com
.siyeh
.ig
.BaseInspectionVisitor
;
25 import org
.jetbrains
.annotations
.NonNls
;
26 import org
.jetbrains
.annotations
.NotNull
;
28 public class UseOfProcessBuilderInspection
extends BaseInspection
{
31 public String
getDisplayName() {
32 return InspectionGadgetsBundle
.message(
33 "use.processbuilder.class.display.name");
37 public String
buildErrorString(Object
... infos
) {
38 return InspectionGadgetsBundle
.message(
39 "use.processbuilder.class.problem.descriptor");
42 public BaseInspectionVisitor
buildVisitor() {
43 return new ProcessBuilderVisitor();
46 private static class ProcessBuilderVisitor
extends BaseInspectionVisitor
{
48 @Override public void visitVariable(@NotNull PsiVariable variable
) {
49 super.visitVariable(variable
);
50 final PsiType type
= variable
.getType();
51 final String typeString
= type
.getCanonicalText();
52 if(!"java.lang.ProcessBuilder".equals(typeString
)) {
55 final PsiTypeElement typeElement
= variable
.getTypeElement();
56 if (typeElement
== null) {
59 registerError(typeElement
);
62 @Override public void visitNewExpression(
63 @NotNull PsiNewExpression newExpression
) {
64 super.visitNewExpression(newExpression
);
65 final PsiType type
= newExpression
.getType();
69 @NonNls final String typeString
= type
.getCanonicalText();
70 if(!"java.lang.ProcessBuilder".equals(typeString
)) {
73 registerNewExpressionError(newExpression
);