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
017package org.jetbrains.jet.lang.resolve.java;
018
019import com.intellij.psi.PsiClass;
020import org.jetbrains.annotations.NotNull;
021import org.jetbrains.jet.lang.resolve.BindingTrace;
022import org.jetbrains.jet.lang.resolve.java.kt.PsiAnnotationWithAbiVersion;
023import org.jetbrains.jet.util.slicedmap.BasicWritableSlice;
024import org.jetbrains.jet.util.slicedmap.Slices;
025import org.jetbrains.jet.util.slicedmap.WritableSlice;
026
027public class AbiVersionUtil {
028    public static final WritableSlice<PsiClass, Integer> ABI_VERSION_ERRORS =
029            new BasicWritableSlice<PsiClass, Integer>(Slices.ONLY_REWRITE_TO_EQUAL, true);
030    public static final int INVALID_VERSION = -1;
031
032    public static boolean isAbiVersionCompatible(int abiVersion) {
033        return abiVersion == JvmAbi.VERSION;
034    }
035
036    public static void checkAbiVersion(
037            @NotNull PsiClass psiClass,
038            @NotNull PsiAnnotationWithAbiVersion versionAnnotation,
039            @NotNull BindingTrace trace) {
040        if (!versionAnnotation.isDefined()) return;
041
042        int abiVersion = versionAnnotation.getAbiVersion();
043        if (isAbiVersionCompatible(abiVersion)) return;
044
045        trace.record(ABI_VERSION_ERRORS, psiClass, abiVersion);
046    }
047}