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 @NotNull SourceElement source
042 ) {
043 super(containingDeclaration, annotations, name, source);
044
045 this.outType = outType;
046 }
047
048 @NotNull
049 @Override
050 public JetType getType() {
051 return outType;
052 }
053
054 public void setOutType(JetType outType) {
055 assert this.outType == null;
056 this.outType = outType;
057 }
058
059 @Nullable
060 @Override
061 public CompileTimeConstant<?> getCompileTimeInitializer() {
062 if (compileTimeInitializer != null) {
063 return compileTimeInitializer.invoke();
064 }
065 return null;
066 }
067
068 public void setCompileTimeInitializer(@NotNull NullableLazyValue<CompileTimeConstant<?>> compileTimeInitializer) {
069 assert !isVar() : "Compile-time value for property initializer should be recorded only for final variables " + getName();
070 this.compileTimeInitializer = compileTimeInitializer;
071 }
072
073 @Override
074 @NotNull
075 public VariableDescriptor getOriginal() {
076 return (VariableDescriptor) super.getOriginal();
077 }
078
079 @NotNull
080 @Override
081 public List<ValueParameterDescriptor> getValueParameters() {
082 return Collections.emptyList();
083 }
084
085 @Override
086 public boolean hasStableParameterNames() {
087 return false;
088 }
089
090 @Override
091 public boolean hasSynthesizedParameterNames() {
092 return false;
093 }
094
095 @NotNull
096 @Override
097 public Set<? extends CallableDescriptor> getOverriddenDescriptors() {
098 return Collections.emptySet();
099 }
100
101 @NotNull
102 @Override
103 public List<TypeParameterDescriptor> getTypeParameters() {
104 return Collections.emptyList();
105 }
106
107 @Override
108 public ReceiverParameterDescriptor getReceiverParameter() {
109 return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
110 }
111
112 @Override
113 public ReceiverParameterDescriptor getExpectedThisObject() {
114 return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
115 }
116
117 @NotNull
118 @Override
119 public JetType getReturnType() {
120 return getType();
121 }
122 }