001 /*
002 * Copyright 2010-2015 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.kotlin.serialization.deserialization.descriptors;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
022 import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
023 import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
024 import org.jetbrains.kotlin.descriptors.SourceElement;
025 import org.jetbrains.kotlin.descriptors.annotations.Annotations;
026 import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl;
027 import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
028 import org.jetbrains.kotlin.name.Name;
029 import org.jetbrains.kotlin.serialization.Flags;
030 import org.jetbrains.kotlin.serialization.ProtoBuf;
031 import org.jetbrains.kotlin.serialization.deserialization.Deserialization;
032 import org.jetbrains.kotlin.serialization.deserialization.DeserializationPackage;
033 import org.jetbrains.kotlin.serialization.deserialization.NameResolver;
034
035 public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescriptorImpl implements DeserializedCallableMemberDescriptor {
036
037 private final ProtoBuf.Callable proto;
038 private final NameResolver nameResolver;
039
040 private DeserializedSimpleFunctionDescriptor(
041 @NotNull DeclarationDescriptor containingDeclaration,
042 @Nullable SimpleFunctionDescriptor original,
043 @NotNull Annotations annotations,
044 @NotNull Name name,
045 @NotNull Kind kind,
046 @NotNull ProtoBuf.Callable proto,
047 @NotNull NameResolver nameResolver
048 ) {
049 super(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE);
050 this.proto = proto;
051 this.nameResolver = nameResolver;
052 }
053
054 @NotNull
055 @Override
056 protected FunctionDescriptorImpl createSubstitutedCopy(
057 @NotNull DeclarationDescriptor newOwner,
058 @Nullable FunctionDescriptor original,
059 @NotNull Kind kind
060 ) {
061 return new DeserializedSimpleFunctionDescriptor(
062 newOwner,
063 (DeserializedSimpleFunctionDescriptor) original,
064 getAnnotations(),
065 getName(),
066 kind,
067 proto,
068 nameResolver
069 );
070 }
071
072 @NotNull
073 @Override
074 public DeserializedSimpleFunctionDescriptor getOriginal() {
075 return (DeserializedSimpleFunctionDescriptor) super.getOriginal();
076 }
077
078 @NotNull
079 @Override
080 public ProtoBuf.Callable getProto() {
081 return proto;
082 }
083
084 @NotNull
085 @Override
086 public NameResolver getNameResolver() {
087 return nameResolver;
088 }
089
090 @NotNull
091 public static DeserializedSimpleFunctionDescriptor create(
092 @NotNull DeclarationDescriptor containingDeclaration,
093 @NotNull ProtoBuf.Callable proto,
094 @NotNull NameResolver nameResolver,
095 @NotNull Annotations annotations
096 ) {
097 return new DeserializedSimpleFunctionDescriptor(
098 containingDeclaration,
099 null,
100 annotations,
101 nameResolver.getName(proto.getName()),
102 Deserialization.memberKind(Flags.MEMBER_KIND.get(proto.getFlags())),
103 proto,
104 nameResolver
105 );
106 }
107 }