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.NameResolver;
033 import org.jetbrains.kotlin.serialization.deserialization.TypeTable;
034
035 public class DeserializedSimpleFunctionDescriptor extends SimpleFunctionDescriptorImpl implements DeserializedCallableMemberDescriptor {
036
037 private final ProtoBuf.Function proto;
038 private final NameResolver nameResolver;
039 private final TypeTable typeTable;
040
041 private DeserializedSimpleFunctionDescriptor(
042 @NotNull DeclarationDescriptor containingDeclaration,
043 @Nullable SimpleFunctionDescriptor original,
044 @NotNull Annotations annotations,
045 @NotNull Name name,
046 @NotNull Kind kind,
047 @NotNull ProtoBuf.Function proto,
048 @NotNull NameResolver nameResolver,
049 @NotNull TypeTable typeTable
050 ) {
051 super(containingDeclaration, original, annotations, name, kind, SourceElement.NO_SOURCE);
052 this.proto = proto;
053 this.nameResolver = nameResolver;
054 this.typeTable = typeTable;
055 }
056
057 @NotNull
058 @Override
059 protected FunctionDescriptorImpl createSubstitutedCopy(
060 @NotNull DeclarationDescriptor newOwner,
061 @Nullable FunctionDescriptor original,
062 @NotNull Kind kind
063 ) {
064 return new DeserializedSimpleFunctionDescriptor(
065 newOwner,
066 (DeserializedSimpleFunctionDescriptor) original,
067 getAnnotations(),
068 getName(),
069 kind,
070 proto,
071 nameResolver,
072 typeTable
073 );
074 }
075
076 @NotNull
077 @Override
078 public DeserializedSimpleFunctionDescriptor getOriginal() {
079 return (DeserializedSimpleFunctionDescriptor) super.getOriginal();
080 }
081
082 @NotNull
083 @Override
084 public ProtoBuf.Function getProto() {
085 return proto;
086 }
087
088 @NotNull
089 @Override
090 public NameResolver getNameResolver() {
091 return nameResolver;
092 }
093
094 @NotNull
095 @Override
096 public TypeTable getTypeTable() {
097 return typeTable;
098 }
099
100 @NotNull
101 public static DeserializedSimpleFunctionDescriptor create(
102 @NotNull DeclarationDescriptor containingDeclaration,
103 @NotNull Annotations annotations,
104 @NotNull ProtoBuf.Function proto,
105 @NotNull NameResolver nameResolver,
106 @NotNull TypeTable typeTable
107 ) {
108 return new DeserializedSimpleFunctionDescriptor(
109 containingDeclaration,
110 null,
111 annotations,
112 nameResolver.getName(proto.getName()),
113 Deserialization.memberKind(Flags.MEMBER_KIND.get(proto.getFlags())),
114 proto,
115 nameResolver,
116 typeTable
117 );
118 }
119 }