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 com
.siyeh
.ig
.psiutils
.ClassUtils
;
23 import org
.jetbrains
.annotations
.NotNull
;
25 public class UseOfAWTPeerClassInspection
extends BaseInspection
{
28 public String
getDisplayName() {
29 return InspectionGadgetsBundle
.message(
30 "use.of.awt.peer.class.display.name");
34 public String
buildErrorString(Object
... infos
) {
35 return InspectionGadgetsBundle
.message(
36 "use.of.awt.peer.class.problem.descriptor");
39 public BaseInspectionVisitor
buildVisitor() {
40 return new UseOfAWTPeerClassVisitor();
43 private static class UseOfAWTPeerClassVisitor
extends BaseInspectionVisitor
{
46 @Override public void visitVariable(@NotNull PsiVariable variable
) {
47 super.visitVariable(variable
);
48 final PsiType type
= variable
.getType();
49 if (!(type
instanceof PsiClassType
)) {
52 final PsiType deepComponentType
= type
.getDeepComponentType();
53 if(!(deepComponentType
instanceof PsiClassType
)) {
56 final PsiClassType classType
= (PsiClassType
)deepComponentType
;
57 final PsiClass resolveClass
= classType
.resolve();
58 if(resolveClass
== null) {
61 if(resolveClass
.isEnum()||resolveClass
.isInterface() ||
62 resolveClass
.isAnnotationType()) {
65 if(resolveClass
instanceof PsiTypeParameter
){
68 if(!ClassUtils
.isSubclass(resolveClass
,
69 "java.awt.peer.ComponentPeer")) {
72 final PsiTypeElement typeElement
= variable
.getTypeElement();
73 if (typeElement
== null) {
76 registerError(typeElement
);
79 @Override public void visitNewExpression(
80 @NotNull PsiNewExpression newExpression
) {
81 super.visitNewExpression(newExpression
);
82 final PsiType type
= newExpression
.getType();
86 if(!(type
instanceof PsiClassType
)) {
89 final PsiClass resolveClass
= ((PsiClassType
) type
).resolve();
90 if(resolveClass
== null) {
93 if(resolveClass
.isEnum() || resolveClass
.isInterface() ||
94 resolveClass
.isAnnotationType()) {
97 if(resolveClass
instanceof PsiTypeParameter
) {
100 if(!ClassUtils
.isSubclass(resolveClass
,
101 "java.awt.peer.ComponentPeer")) {
104 registerNewExpressionError(newExpression
);