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.descriptors.serialization.descriptors;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.jet.descriptors.serialization.NameResolver;
021    import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
022    import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
023    import org.jetbrains.jet.lang.descriptors.ClassOrNamespaceDescriptor;
024    import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
025    
026    import java.util.List;
027    
028    public interface AnnotationDeserializer {
029        AnnotationDeserializer UNSUPPORTED = new AnnotationDeserializer() {
030            @NotNull
031            @Override
032            public List<AnnotationDescriptor> loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto) {
033                return notSupported();
034            }
035    
036            @NotNull
037            @Override
038            public List<AnnotationDescriptor> loadCallableAnnotations(
039                    @NotNull ClassOrNamespaceDescriptor container,
040                    @NotNull ProtoBuf.Callable proto,
041                    @NotNull NameResolver nameResolver,
042                    @NotNull AnnotatedCallableKind kind
043            ) {
044                return notSupported();
045            }
046    
047            @NotNull
048            @Override
049            public List<AnnotationDescriptor> loadValueParameterAnnotations(
050                    @NotNull ClassOrNamespaceDescriptor container,
051                    @NotNull ProtoBuf.Callable callable,
052                    @NotNull NameResolver nameResolver,
053                    @NotNull AnnotatedCallableKind kind,
054                    @NotNull ProtoBuf.Callable.ValueParameter proto
055            ) {
056                return notSupported();
057            }
058    
059            @NotNull
060            private List<AnnotationDescriptor> notSupported() {
061                throw new UnsupportedOperationException("Annotations are not supported");
062            }
063        };
064    
065        enum AnnotatedCallableKind {
066            FUNCTION,
067            PROPERTY,
068            PROPERTY_GETTER,
069            PROPERTY_SETTER
070        }
071    
072        @NotNull
073        List<AnnotationDescriptor> loadClassAnnotations(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class classProto);
074    
075        @NotNull
076        List<AnnotationDescriptor> loadCallableAnnotations(
077                @NotNull ClassOrNamespaceDescriptor container,
078                @NotNull ProtoBuf.Callable proto,
079                @NotNull NameResolver nameResolver,
080                @NotNull AnnotatedCallableKind kind
081        );
082    
083        @NotNull
084        List<AnnotationDescriptor> loadValueParameterAnnotations(
085                @NotNull ClassOrNamespaceDescriptor container,
086                @NotNull ProtoBuf.Callable callable,
087                @NotNull NameResolver nameResolver,
088                @NotNull AnnotatedCallableKind kind,
089                @NotNull ProtoBuf.Callable.ValueParameter proto
090        );
091    }