All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.jet.codegen.JvmSerializationBindings Maven / Gradle / Ivy

/*
 * Copyright 2010-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jetbrains.jet.codegen;

import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.Method;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.util.slicedmap.*;

import java.util.Collection;
import java.util.Map;

public final class JvmSerializationBindings {
    public static final SerializationMappingSlice METHOD_FOR_FUNCTION =
            SerializationMappingSlice.create();
    public static final SerializationMappingSlice> FIELD_FOR_PROPERTY =
            SerializationMappingSlice.create();
    public static final SerializationMappingSlice SYNTHETIC_METHOD_FOR_PROPERTY =
            SerializationMappingSlice.create();
    public static final SerializationMappingSlice IMPL_CLASS_NAME_FOR_CALLABLE =
            SerializationMappingSlice.create();
    public static final SerializationMappingSetSlice STATIC_FIELD_IN_OUTER_CLASS =
            SerializationMappingSetSlice.create();
    public static final SerializationMappingSlice INDEX_FOR_VALUE_PARAMETER =
            SerializationMappingSlice.create();

    private static final class SerializationMappingSlice extends BasicWritableSlice {
        public SerializationMappingSlice() {
            super(Slices.ONLY_REWRITE_TO_EQUAL, false);
        }

        @NotNull
        public static  SerializationMappingSlice create() {
            return new SerializationMappingSlice();
        }
    }

    private static final class SerializationMappingSetSlice extends Slices.SetSlice {
        public SerializationMappingSetSlice() {
            super(Slices.ONLY_REWRITE_TO_EQUAL, false);
        }

        @NotNull
        public static  SerializationMappingSetSlice create() {
            return new SerializationMappingSetSlice();
        }
    }

    static {
        BasicWritableSlice.initSliceDebugNames(JvmSerializationBindings.class);
    }

    private final MutableSlicedMap map;

    private JvmSerializationBindings(@NotNull MutableSlicedMap map) {
        this.map = map;
    }

    public JvmSerializationBindings() {
        this(SlicedMapImpl.create());
    }

    @NotNull
    public static JvmSerializationBindings union(@NotNull Collection bindings) {
        MutableSlicedMap result = SlicedMapImpl.create();
        for (JvmSerializationBindings binding : bindings) {
            for (Map.Entry, ?> entry : binding.map) {
                SlicedMapKey key = entry.getKey();
                result.put((WritableSlice) key.getSlice(), key.getKey(), entry.getValue());
            }
        }
        return new JvmSerializationBindings(result);
    }

    public  void put(@NotNull SerializationMappingSlice slice, @NotNull K key, @NotNull V value) {
        map.put(slice, key, value);
    }

    public  void put(@NotNull SerializationMappingSetSlice slice, @NotNull K key) {
        map.put(slice, key, true);
    }

    @Nullable
    public  V get(@NotNull SerializationMappingSlice slice, @NotNull K key) {
        return map.get(slice, key);
    }

    public  boolean get(@NotNull SerializationMappingSetSlice slice, @NotNull K key) {
        return Boolean.TRUE.equals(map.get(slice, key));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy