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
.IdeBundle
;
24 import com
.intellij
.openapi
.extensions
.Extensions
;
25 import com
.intellij
.openapi
.project
.Project
;
26 import com
.intellij
.openapi
.roots
.ProjectFileIndex
;
27 import com
.intellij
.openapi
.roots
.ProjectRootManager
;
28 import com
.intellij
.openapi
.vfs
.VirtualFile
;
29 import com
.intellij
.psi
.PsiFile
;
30 import com
.intellij
.psi
.search
.scope
.packageSet
.*;
31 import org
.jetbrains
.annotations
.NotNull
;
33 import java
.util
.ArrayList
;
34 import java
.util
.List
;
36 public class PackagesScopesProvider
implements CustomScopesProvider
{
37 private NamedScope myProjectTestScope
;
38 private NamedScope myProjectProductionScope
;
41 private final Project myProject
;
43 public static PackagesScopesProvider
getInstance(Project project
) {
44 for (CustomScopesProvider provider
: Extensions
.getExtensions(CUSTOM_SCOPES_PROVIDER
, project
)) {
45 if (provider
instanceof PackagesScopesProvider
) return (PackagesScopesProvider
)provider
;
50 public PackagesScopesProvider(Project project
) {
55 public List
<NamedScope
> getCustomScopes() {
56 final List
<NamedScope
> list
= new ArrayList
<NamedScope
>();
57 list
.add(getProjectProductionScope());
58 list
.add(getProjectTestScope());
62 public NamedScope
getProjectTestScope() {
63 if (myProjectTestScope
== null) {
64 final ProjectFileIndex index
= ProjectRootManager
.getInstance(myProject
).getFileIndex();
65 myProjectTestScope
= new NamedScope(IdeBundle
.message("predefined.scope.tests.name"), new PackageSet() {
66 public boolean contains(PsiFile file
, NamedScopesHolder holder
) {
67 final VirtualFile virtualFile
= file
.getVirtualFile();
68 return file
.getProject() == myProject
&& virtualFile
!= null && index
.isInTestSourceContent(virtualFile
);
71 public PackageSet
createCopy() {
75 public String
getText() {
76 return PatternPackageSet
.SCOPE_TEST
+":*..*";
79 public int getNodePriority() {
84 return myProjectTestScope
;
87 public NamedScope
getProjectProductionScope() {
88 if (myProjectProductionScope
== null) {
89 final ProjectFileIndex index
= ProjectRootManager
.getInstance(myProject
).getFileIndex();
90 myProjectProductionScope
= new NamedScope(IdeBundle
.message("predefined.scope.production.name"), new PackageSet() {
91 public boolean contains(PsiFile file
, NamedScopesHolder holder
) {
92 final VirtualFile virtualFile
= file
.getVirtualFile();
93 return file
.getProject() == myProject
94 && virtualFile
!= null
95 && !index
.isInTestSourceContent(virtualFile
)
96 && !index
.isInLibraryClasses(virtualFile
)
97 && !index
.isInLibrarySource(virtualFile
)
101 public PackageSet
createCopy() {
105 public String
getText() {
106 return PatternPackageSet
.SCOPE_SOURCE
+":*..*";
109 public int getNodePriority() {
114 return myProjectProductionScope
;