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
.*;
19 import com
.siyeh
.InspectionGadgetsBundle
;
20 import com
.siyeh
.ig
.BaseInspection
;
21 import com
.siyeh
.ig
.BaseInspectionVisitor
;
22 import org
.jetbrains
.annotations
.NonNls
;
23 import org
.jetbrains
.annotations
.NotNull
;
25 public class UseOfSunClassesInspection
extends BaseInspection
{
28 public String
getDisplayName() {
29 return InspectionGadgetsBundle
.message("use.sun.classes.display.name");
33 public String
buildErrorString(Object
... infos
) {
34 return InspectionGadgetsBundle
.message(
35 "use.sun.classes.problem.descriptor");
38 public BaseInspectionVisitor
buildVisitor() {
39 return new UseOfSunClassesVisitor();
42 private static class UseOfSunClassesVisitor
43 extends BaseInspectionVisitor
{
45 @Override public void visitVariable(@NotNull PsiVariable variable
) {
46 super.visitVariable(variable
);
47 final PsiType type
= variable
.getType();
48 final PsiType deepComponentType
= type
.getDeepComponentType();
49 if(!(deepComponentType
instanceof PsiClassType
)) {
52 final PsiClassType classType
= (PsiClassType
) deepComponentType
;
53 @NonNls final String className
= classType
.getCanonicalText();
54 if(className
== null || !className
.startsWith("sun.")) {
57 final PsiTypeElement typeElement
= variable
.getTypeElement();
58 if (typeElement
== null) {
61 registerError(typeElement
);
64 @Override public void visitNewExpression(
65 @NotNull PsiNewExpression newExpression
) {
66 super.visitNewExpression(newExpression
);
67 final PsiType type
= newExpression
.getType();
71 if(!(type
instanceof PsiClassType
)) {
74 final PsiClassType classType
= (PsiClassType
) type
;
75 @NonNls final String className
= classType
.getCanonicalText();
76 if (className
==null || !className
.startsWith("sun.")) {
79 registerNewExpressionError(newExpression
);