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