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.ClassDescriptor;
021 import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
022 import org.jetbrains.jet.lang.resolve.scopes.JetScope;
023
024 import java.util.Collections;
025 import java.util.List;
026
027 public final class JetTypeImpl extends AbstractJetType {
028
029 private final TypeConstructor constructor;
030 private final List<? extends TypeProjection> arguments;
031 private final boolean nullable;
032 private final JetScope memberScope;
033 private final Annotations annotations;
034
035 public JetTypeImpl(Annotations annotations, TypeConstructor constructor, boolean nullable, @NotNull List<? extends TypeProjection> arguments, JetScope memberScope) {
036 this.annotations = annotations;
037
038 if (memberScope instanceof ErrorUtils.ErrorScope) {
039 throw new IllegalStateException("JetTypeImpl should not be created for error type: " + memberScope + "\n" + constructor);
040 }
041
042 this.constructor = constructor;
043 this.nullable = nullable;
044 this.arguments = arguments;
045 this.memberScope = memberScope;
046 }
047
048 public JetTypeImpl(TypeConstructor constructor, JetScope memberScope) {
049 this(Annotations.EMPTY, constructor, false, Collections.<TypeProjection>emptyList(), memberScope);
050 }
051
052 public JetTypeImpl(@NotNull ClassDescriptor classDescriptor) {
053 this(Annotations.EMPTY,
054 classDescriptor.getTypeConstructor(),
055 false,
056 Collections.<TypeProjection>emptyList(),
057 classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList()));
058 }
059
060 @NotNull
061 @Override
062 public Annotations getAnnotations() {
063 return annotations;
064 }
065
066 @NotNull
067 @Override
068 public TypeConstructor getConstructor() {
069 return constructor;
070 }
071
072 @NotNull
073 @Override
074 public List<TypeProjection> getArguments() {
075 //noinspection unchecked
076 return (List) arguments;
077 }
078
079 @Override
080 public boolean isNullable() {
081 return nullable;
082 }
083
084 @NotNull
085 @Override
086 public JetScope getMemberScope() {
087 return memberScope;
088 }
089
090 @Override
091 public boolean isError() {
092 return false;
093 }
094 }