2 * Copyright 2000-2009 JetBrains s.r.o.
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.
21 package com
.intellij
.packageDependencies
;
23 import com
.intellij
.psi
.*;
24 import com
.intellij
.psi
.javadoc
.PsiDocComment
;
25 import com
.intellij
.psi
.util
.PsiUtil
;
27 public class JavaDependenciesVisitorFactory
extends DependenciesVisitorFactory
{
29 public PsiElementVisitor
createVisitor(final DependenciesBuilder
.DependencyProcessor processor
) {
30 return new JavaRecursiveElementVisitor() {
33 public void visitReferenceExpression(PsiReferenceExpression expression
) {
34 visitReferenceElement(expression
);
38 public void visitElement(PsiElement element
) {
39 super.visitElement(element
);
40 PsiReference
[] refs
= element
.getReferences();
41 for (PsiReference ref
: refs
) {
42 PsiElement resolved
= ref
.resolve();
43 if (resolved
!= null) {
44 processor
.process(ref
.getElement(), resolved
);
50 public void visitLiteralExpression(PsiLiteralExpression expression
) {
52 // TODO: thus we'll skip property references and references to file resources. We can't validate them anyway now since
53 // TODO: rule syntax does not allow this.
57 public void visitDocComment(PsiDocComment comment
) {
62 public void visitImportStatement(PsiImportStatement statement
) {
63 if (!DependencyValidationManager
.getInstance(statement
.getProject()).skipImportStatements()) {
64 visitElement(statement
);
69 public void visitMethodCallExpression(PsiMethodCallExpression expression
) {
70 super.visitMethodCallExpression(expression
);
71 PsiMethod psiMethod
= expression
.resolveMethod();
72 if (psiMethod
!= null) {
73 PsiType returnType
= psiMethod
.getReturnType();
74 if (returnType
!= null) {
75 PsiClass psiClass
= PsiUtil
.resolveClassInType(returnType
);
76 if (psiClass
!= null) {
77 processor
.process(expression
, psiClass
);