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;
018    
019    import com.google.common.base.Predicate;
020    import com.intellij.psi.PsiFile;
021    import org.jetbrains.annotations.NotNull;
022    import org.jetbrains.jet.context.GlobalContext;
023    import org.jetbrains.jet.storage.ExceptionTracker;
024    import org.jetbrains.jet.storage.StorageManager;
025    
026    /**
027     * Various junk that cannot be placed into context (yet).
028     */
029    public class TopDownAnalysisParameters implements GlobalContext {
030        private static boolean LAZY;
031    
032        static {
033            LAZY = "true".equals(System.getProperty("lazy.tda"));
034        }
035    
036        @NotNull
037        public static TopDownAnalysisParameters create(
038                @NotNull StorageManager storageManager,
039                @NotNull ExceptionTracker exceptionTracker,
040                @NotNull Predicate<PsiFile> analyzeCompletely,
041                boolean analyzingBootstrapLibrary,
042                boolean declaredLocally
043        ) {
044            return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, analyzingBootstrapLibrary,
045                                                 declaredLocally, LAZY);
046        }
047    
048        @NotNull
049        public static TopDownAnalysisParameters createForLazy(
050                @NotNull StorageManager storageManager,
051                @NotNull ExceptionTracker exceptionTracker,
052                @NotNull Predicate<PsiFile> analyzeCompletely,
053                boolean analyzingBootstrapLibrary,
054                boolean declaredLocally
055        ) {
056            return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, analyzingBootstrapLibrary,
057                                                 declaredLocally, true);
058        }
059    
060        @NotNull
061        public static TopDownAnalysisParameters createForLocalDeclarations(
062                @NotNull StorageManager storageManager,
063                @NotNull ExceptionTracker exceptionTracker,
064                @NotNull Predicate<PsiFile> analyzeCompletely
065        ) {
066            return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, false, true, false);
067        }
068    
069        @NotNull
070        private final StorageManager storageManager;
071        @NotNull
072        private final ExceptionTracker exceptionTracker;
073        @NotNull
074        private final Predicate<PsiFile> analyzeCompletely;
075        private final boolean analyzingBootstrapLibrary;
076        private final boolean declaredLocally;
077        private final boolean lazyTopDownAnalysis;
078    
079        private TopDownAnalysisParameters(
080                @NotNull StorageManager storageManager,
081                @NotNull ExceptionTracker exceptionTracker,
082                @NotNull Predicate<PsiFile> analyzeCompletely,
083                boolean analyzingBootstrapLibrary,
084                boolean declaredLocally,
085                boolean lazyTopDownAnalysis
086        ) {
087            this.storageManager = storageManager;
088            this.exceptionTracker = exceptionTracker;
089            this.analyzeCompletely = analyzeCompletely;
090            this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
091            this.declaredLocally = declaredLocally;
092            this.lazyTopDownAnalysis = lazyTopDownAnalysis;
093        }
094    
095        @Override
096        @NotNull
097        public StorageManager getStorageManager() {
098            return storageManager;
099        }
100    
101        @Override
102        @NotNull
103        public ExceptionTracker getExceptionTracker() {
104            return exceptionTracker;
105        }
106    
107        @NotNull
108        public Predicate<PsiFile> getAnalyzeCompletely() {
109            return analyzeCompletely;
110        }
111    
112        public boolean isAnalyzingBootstrapLibrary() {
113            return analyzingBootstrapLibrary;
114        }
115    
116        public boolean isDeclaredLocally() {
117            return declaredLocally;
118        }
119    
120        // Used temporarily while we are transitioning from eager to lazy analysis of headers in the IDE
121        @Deprecated
122        public boolean isLazyTopDownAnalysis() {
123            return lazyTopDownAnalysis;
124        }
125    }