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.types;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
021 import org.jetbrains.jet.lang.resolve.name.Name;
022 import org.jetbrains.jet.lang.resolve.scopes.JetScope;
023 import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
024
025 import java.util.List;
026
027 /**
028 * This is a fake type assigned to namespace expressions. Only member lookup is
029 * supposed to be done on these types.
030 */
031 public class NamespaceType implements JetType {
032 private final Name name;
033 private final JetScope memberScope;
034 private final ReceiverValue receiver;
035
036 public NamespaceType(@NotNull Name name, @NotNull JetScope memberScope, @NotNull ReceiverValue receiver) {
037 this.name = name;
038 this.memberScope = memberScope;
039 this.receiver = receiver;
040 }
041
042 @NotNull
043 @Override
044 public JetScope getMemberScope() {
045 return memberScope;
046 }
047
048 @Override
049 public boolean isError() {
050 return false;
051 }
052
053 @NotNull
054 public ReceiverValue getReceiverValue() {
055 return receiver;
056 }
057
058 @NotNull
059 @Override
060 public TypeConstructor getConstructor() {
061 return throwException();
062 }
063
064 private TypeConstructor throwException() {
065 throw new UnsupportedOperationException("Only member lookup is allowed on a namespace type " + name);
066 }
067
068 @NotNull
069 @Override
070 public List<TypeProjection> getArguments() {
071 throwException();
072 return null;
073 }
074
075 @Override
076 public boolean isNullable() {
077 throwException();
078 return false;
079 }
080
081 @NotNull
082 @Override
083 public List<AnnotationDescriptor> getAnnotations() {
084 throwException();
085 return null;
086 }
087 }