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.resolve.java.kt;
018    
019    import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
020    import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
021    
022    public class DescriptorKindUtils {
023        private DescriptorKindUtils() {
024        }
025    
026        public static int kindToFlags(CallableMemberDescriptor.Kind kind) {
027            switch (kind) {
028                case DECLARATION: return JvmStdlibNames.FLAG_METHOD_KIND_DECLARATION;
029                case FAKE_OVERRIDE: return JvmStdlibNames.FLAG_METHOD_KIND_FAKE_OVERRIDE;
030                case DELEGATION: return JvmStdlibNames.FLAG_METHOD_KIND_DELEGATION;
031                case SYNTHESIZED: return JvmStdlibNames.FLAG_METHOD_KIND_SYNTHESIZED;
032                default: throw new IllegalArgumentException("Unknown kind: " + kind);
033            }
034        }
035    
036        public static CallableMemberDescriptor.Kind flagsToKind(int value) {
037            switch (value & JvmStdlibNames.FLAG_METHOD_KIND_MASK) {
038                case JvmStdlibNames.FLAG_METHOD_KIND_DECLARATION: return CallableMemberDescriptor.Kind.DECLARATION;
039                case JvmStdlibNames.FLAG_METHOD_KIND_FAKE_OVERRIDE: return CallableMemberDescriptor.Kind.FAKE_OVERRIDE;
040                case JvmStdlibNames.FLAG_METHOD_KIND_DELEGATION: return CallableMemberDescriptor.Kind.DELEGATION;
041                case JvmStdlibNames.FLAG_METHOD_KIND_SYNTHESIZED: return CallableMemberDescriptor.Kind.SYNTHESIZED;
042                default: throw new IllegalArgumentException("Unknown int value of kind: " + value);
043            }
044        }
045    }