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
.analysis
;
23 import com
.intellij
.ide
.impl
.dataRules
.GetDataRule
;
24 import com
.intellij
.openapi
.actionSystem
.DataProvider
;
25 import com
.intellij
.openapi
.actionSystem
.LangDataKeys
;
26 import com
.intellij
.openapi
.module
.Module
;
27 import com
.intellij
.psi
.PsiDirectory
;
28 import com
.intellij
.psi
.PsiJavaFile
;
29 import com
.intellij
.psi
.PsiPackage
;
30 import com
.intellij
.psi
.search
.GlobalSearchScope
;
32 public class AnalysisScopeRule
implements GetDataRule
{
33 public Object
getData(final DataProvider dataProvider
) {
34 final Object psiFile
= dataProvider
.getData(LangDataKeys
.PSI_FILE
.getName());
35 if (psiFile
instanceof PsiJavaFile
) {
36 return new JavaAnalysisScope((PsiJavaFile
)psiFile
);
38 Object psiTarget
= dataProvider
.getData(LangDataKeys
.PSI_ELEMENT
.getName());
39 if (psiTarget
instanceof PsiPackage
) {
40 PsiPackage pack
= (PsiPackage
)psiTarget
;
41 if (!pack
.getManager().isInProject(pack
)) return null;
42 PsiDirectory
[] dirs
= pack
.getDirectories(GlobalSearchScope
.projectScope(pack
.getProject()));
43 if (dirs
.length
== 0) return null;
44 return new JavaAnalysisScope(pack
, (Module
)dataProvider
.getData(LangDataKeys
.MODULE
.getName()));