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.descriptors.impl;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.lang.descriptors.*;
022    import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
023    import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
024    import org.jetbrains.jet.lang.resolve.name.Name;
025    import org.jetbrains.jet.lang.types.JetType;
026    import org.jetbrains.jet.storage.NullableLazyValue;
027    
028    import java.util.Collections;
029    import java.util.List;
030    import java.util.Set;
031    
032    public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRootImpl implements VariableDescriptor {
033        private JetType outType;
034        private NullableLazyValue<CompileTimeConstant<?>> compileTimeInitializer;
035    
036        public VariableDescriptorImpl(
037                @NotNull DeclarationDescriptor containingDeclaration,
038                @NotNull Annotations annotations,
039                @NotNull Name name,
040                @Nullable JetType outType) {
041            super(containingDeclaration, annotations, name);
042    
043            this.outType = outType;
044        }
045    
046        @NotNull
047        @Override
048        public JetType getType() {
049            return outType;
050        }
051    
052        public void setOutType(JetType outType) {
053            assert this.outType == null;
054            this.outType = outType;
055        }
056    
057        @Nullable
058        @Override
059        public CompileTimeConstant<?> getCompileTimeInitializer() {
060            if (compileTimeInitializer != null) {
061                return compileTimeInitializer.invoke();
062            }
063            return null;
064        }
065    
066        public void setCompileTimeInitializer(@NotNull NullableLazyValue<CompileTimeConstant<?>> compileTimeInitializer) {
067            assert !isVar() : "Compile-time value for property initializer should be recorded only for final variables " + getName();
068            this.compileTimeInitializer = compileTimeInitializer;
069        }
070    
071        @Override
072        @NotNull
073        public VariableDescriptor getOriginal() {
074            return (VariableDescriptor) super.getOriginal();
075        }
076    
077        @NotNull
078        @Override
079        public List<ValueParameterDescriptor> getValueParameters() {
080            return Collections.emptyList();
081        }
082    
083        @Override
084        public boolean hasStableParameterNames() {
085            return false;
086        }
087    
088        @Override
089        public boolean hasSynthesizedParameterNames() {
090            return false;
091        }
092    
093        @NotNull
094        @Override
095        public Set<? extends CallableDescriptor> getOverriddenDescriptors() {
096            return Collections.emptySet();
097        }
098    
099        @NotNull
100        @Override
101        public List<TypeParameterDescriptor> getTypeParameters() {
102            return Collections.emptyList();
103        }
104    
105        @Override
106        public ReceiverParameterDescriptor getReceiverParameter() {
107            return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
108        }
109    
110        @Override
111        public ReceiverParameterDescriptor getExpectedThisObject() {
112            return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
113        }
114    
115        @NotNull
116        @Override
117        public JetType getReturnType() {
118            return getType();
119        }
120    }