001 /*
002 * Copyright 2010-2015 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.kotlin.codegen.context;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.kotlin.codegen.OwnerKind;
021 import org.jetbrains.kotlin.codegen.state.GenerationState;
022 import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
023 import org.jetbrains.kotlin.descriptors.DeclarationDescriptorVisitor;
024 import org.jetbrains.kotlin.descriptors.annotations.Annotations;
025 import org.jetbrains.kotlin.name.Name;
026 import org.jetbrains.kotlin.types.TypeSubstitutor;
027
028 public class RootContext extends CodegenContext<RootContext.FakeDescriptor> {
029 private final GenerationState state;
030
031 public RootContext(@NotNull GenerationState state) {
032 super(new FakeDescriptor(), OwnerKind.PACKAGE, null, null, null, null);
033 this.state = state;
034 }
035
036 @Override
037 @NotNull
038 public GenerationState getState() {
039 return state;
040 }
041
042 @Override
043 public String toString() {
044 return "ROOT";
045 }
046
047 static class FakeDescriptor implements DeclarationDescriptor {
048 @NotNull
049 @Override
050 public DeclarationDescriptor getOriginal() {
051 throw new IllegalStateException();
052 }
053
054 @Override
055 public DeclarationDescriptor getContainingDeclaration() {
056 throw new IllegalStateException();
057 }
058
059 @Override
060 public DeclarationDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
061 throw new IllegalStateException();
062 }
063
064 @Override
065 public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
066 throw new IllegalStateException();
067 }
068
069 @Override
070 public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
071 throw new IllegalStateException();
072 }
073
074 @NotNull
075 @Override
076 public Annotations getAnnotations() {
077 throw new IllegalStateException();
078 }
079
080 @NotNull
081 @Override
082 public Name getName() {
083 throw new IllegalStateException();
084 }
085 }
086 }