enhanced API for nullness
[fedora-idea.git] / java / java-impl / src / com / intellij / packageDependencies / JavaDependenciesVisitorFactory.java
blob98270dcb44f4f8b369dfafc0891c4b12d8ae695a
1 /*
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.
18 * User: anna
19 * Date: 21-Jan-2008
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 {
28 @Override
29 public PsiElementVisitor createVisitor(final DependenciesBuilder.DependencyProcessor processor) {
30 return new JavaRecursiveElementVisitor() {
32 @Override
33 public void visitReferenceExpression(PsiReferenceExpression expression) {
34 visitReferenceElement(expression);
37 @Override
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);
49 @Override
50 public void visitLiteralExpression(PsiLiteralExpression expression) {
51 // empty
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.
56 @Override
57 public void visitDocComment(PsiDocComment comment) {
58 //empty
61 @Override
62 public void visitImportStatement(PsiImportStatement statement) {
63 if (!DependencyValidationManager.getInstance(statement.getProject()).skipImportStatements()) {
64 visitElement(statement);
68 @Override
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);