001    /*
002     * Copyright 2010-2013 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.jet.lang.resolve.java;
018    
019    import com.google.common.base.Predicate;
020    import com.google.common.collect.Collections2;
021    import com.intellij.openapi.components.ServiceManager;
022    import com.intellij.openapi.project.Project;
023    import com.intellij.psi.PsiFile;
024    import com.intellij.psi.search.GlobalSearchScope;
025    import org.jetbrains.annotations.NotNull;
026    import org.jetbrains.jet.lang.psi.JetFile;
027    import org.jetbrains.jet.lang.resolve.name.FqName;
028    
029    import java.util.Collection;
030    
031    public abstract class JetFilesProvider {
032        @NotNull
033        public static JetFilesProvider getInstance(Project project) {
034            return ServiceManager.getService(project, JetFilesProvider.class);
035        }
036    
037        public final Collection<JetFile> allPackageFiles(@NotNull JetFile file) {
038            final FqName name = file.getPackageFqName();
039            return Collections2.filter(sampleToAllFilesInModule(file), new Predicate<PsiFile>() {
040                @Override
041                public boolean apply(PsiFile psiFile) {
042                    return ((JetFile) psiFile).getPackageFqName().equals(name);
043                }
044            });
045        }
046    
047        protected abstract Collection<JetFile> sampleToAllFilesInModule(@NotNull JetFile file);
048        @NotNull
049        public abstract Collection<JetFile> allInScope(@NotNull GlobalSearchScope scope);
050        public abstract boolean isFileInScope(@NotNull JetFile file, @NotNull GlobalSearchScope scope);
051    }