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.analyzer;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
022 import org.jetbrains.jet.lang.resolve.BindingContext;
023 import org.jetbrains.jet.lang.resolve.BodiesResolveContext;
024 import org.jetbrains.jet.lang.types.ErrorUtils;
025
026 public class AnalyzeExhaust {
027
028 public static AnalyzeExhaust success(@NotNull BindingContext bindingContext, @NotNull ModuleDescriptor module) {
029 return new AnalyzeExhaust(bindingContext, module, null, null);
030 }
031
032 public static AnalyzeExhaust success(@NotNull BindingContext bindingContext,
033 @Nullable BodiesResolveContext bodiesResolveContext,
034 @NotNull ModuleDescriptor module
035 ) {
036 return new AnalyzeExhaust(bindingContext, module, bodiesResolveContext, null);
037 }
038
039 public static AnalyzeExhaust error(@NotNull BindingContext bindingContext, @NotNull Throwable error) {
040 return new AnalyzeExhaust(bindingContext, ErrorUtils.getErrorModule(), null, error);
041 }
042
043 private final BindingContext bindingContext;
044 private final Throwable error;
045 private final BodiesResolveContext bodiesResolveContext;
046 private final ModuleDescriptor moduleDescriptor;
047
048 private AnalyzeExhaust(
049 @NotNull BindingContext bindingContext,
050 @NotNull ModuleDescriptor moduleDescriptor,
051 @Nullable BodiesResolveContext bodiesResolveContext,
052 @Nullable Throwable error
053 ) {
054 this.bindingContext = bindingContext;
055 this.error = error;
056 this.bodiesResolveContext = bodiesResolveContext;
057 this.moduleDescriptor = moduleDescriptor;
058 }
059
060 @Nullable
061 public BodiesResolveContext getBodiesResolveContext() {
062 return bodiesResolveContext;
063 }
064
065 @NotNull
066 public BindingContext getBindingContext() {
067 return bindingContext;
068 }
069
070 @NotNull
071 public Throwable getError() {
072 return error;
073 }
074
075 public boolean isError() {
076 return error != null;
077 }
078
079 public void throwIfError() {
080 if (isError()) {
081 throw new IllegalStateException("failed to analyze: " + error, error);
082 }
083 }
084
085 @NotNull
086 public ModuleDescriptor getModuleDescriptor() {
087 return moduleDescriptor;
088 }
089 }