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