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.AnnotationDescriptor;
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 List<AnnotationDescriptor> annotations;
034    
035        public JetTypeImpl(List<AnnotationDescriptor> 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(Collections.<AnnotationDescriptor>emptyList(), constructor, false, Collections.<TypeProjection>emptyList(), memberScope);
050        }
051    
052        public JetTypeImpl(@NotNull ClassDescriptor classDescriptor) {
053            this(Collections.<AnnotationDescriptor>emptyList(),
054                    classDescriptor.getTypeConstructor(),
055                    false,
056                    Collections.<TypeProjection>emptyList(),
057                    classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList()));
058        }
059    
060        @Override
061        public List<AnnotationDescriptor> getAnnotations() {
062            return annotations;
063        }
064    
065        @NotNull
066        @Override
067        public TypeConstructor getConstructor() {
068            return constructor;
069        }
070    
071        @NotNull
072        @Override
073        public List<TypeProjection> getArguments() {
074            //noinspection unchecked
075            return (List) arguments;
076        }
077    
078        @Override
079        public boolean isNullable() {
080            return nullable;
081        }
082    
083        @NotNull
084        @Override
085        public JetScope getMemberScope() {
086            return memberScope;
087        }
088    
089        @Override
090        public boolean isError() {
091            return false;
092        }
093    }