KT-3268 Check binary format version in the compiler

This commit is contained in:
Andrey Breslav
2013-01-21 20:01:23 -08:00
parent 2cb530a6d1
commit 0dc24bcd92
12 changed files with 130 additions and 3 deletions
@@ -0,0 +1,46 @@
/*
* 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.lang.resolve.java;
import com.intellij.psi.PsiClass;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.java.kt.PsiAnnotationWithAbiVersion;
import org.jetbrains.jet.util.slicedmap.BasicWritableSlice;
import org.jetbrains.jet.util.slicedmap.Slices;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
public class AbiVersionUtil {
public static final WritableSlice<PsiClass, Integer> ABI_VERSION_ERRORS =
new BasicWritableSlice<PsiClass, Integer>(Slices.ONLY_REWRITE_TO_EQUAL, true);
public static boolean isAbiVersionCompatible(int abiVersion) {
return abiVersion == JvmAbi.VERSION;
}
public static void checkAbiVersion(
@NotNull PsiClass psiClass,
@NotNull PsiAnnotationWithAbiVersion versionAnnotation,
@NotNull BindingTrace trace) {
if (!versionAnnotation.isDefined()) return;
int abiVersion = versionAnnotation.getAbiVersion();
if (isAbiVersionCompatible(abiVersion)) return;
trace.record(ABI_VERSION_ERRORS, psiClass, abiVersion);
}
}
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
public class JetClassAnnotation extends PsiAnnotationWithFlags {
public class JetClassAnnotation extends PsiAnnotationWithAbiVersion {
private static final JetClassAnnotation NULL_ANNOTATION = new JetClassAnnotation(null);
static {
NULL_ANNOTATION.checkInitialized();
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
public class JetPackageClassAnnotation extends PsiAnnotationWithFlags {
public class JetPackageClassAnnotation extends PsiAnnotationWithAbiVersion {
private static final JetPackageClassAnnotation NULL_ANNOTATION = new JetPackageClassAnnotation(null);
static {
NULL_ANNOTATION.checkInitialized();
@@ -0,0 +1,31 @@
/*
* 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.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
public abstract class PsiAnnotationWithAbiVersion extends PsiAnnotationWithFlags {
protected PsiAnnotationWithAbiVersion(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation);
}
public int getAbiVersion() {
return getIntAttribute(JvmStdlibNames.ABI_VERSION_NAME, -1);
}
}
@@ -217,6 +217,8 @@ public final class JavaClassResolver {
@NotNull ClassOrNamespaceDescriptor containingDeclaration
) {
JetClassAnnotation jetClassAnnotation = JetClassAnnotation.get(psiClass);
AbiVersionUtil.checkAbiVersion(psiClass, jetClassAnnotation, trace);
ClassKind kind = getClassKind(psiClass, jetClassAnnotation);
ClassPsiDeclarationProvider classData = semanticServices.getPsiDeclarationProviderFactory().createBinaryClassData(psiClass);
ClassDescriptorFromJvmBytecode classDescriptor = new ClassDescriptorFromJvmBytecode(containingDeclaration, kind,
@@ -31,12 +31,12 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.*;
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaNamespaceDescriptor;
import org.jetbrains.jet.lang.resolve.java.kt.JetPackageClassAnnotation;
import org.jetbrains.jet.lang.resolve.java.scope.JavaBaseScope;
import org.jetbrains.jet.lang.resolve.java.scope.JavaClassStaticMembersScope;
import org.jetbrains.jet.lang.resolve.java.scope.JavaPackageScopeWithoutMembers;
import org.jetbrains.jet.lang.resolve.java.scope.JavaScopeForKotlinNamespace;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import javax.inject.Inject;
import java.util.Collections;
@@ -153,6 +153,8 @@ public final class JavaNamespaceResolver {
javaSemanticServices.getPsiDeclarationProviderFactory().createDeclarationProviderForNamespaceWithoutMembers(psiPackage),
fqName, javaSemanticServices);
}
AbiVersionUtil.checkAbiVersion(psiClass, JetPackageClassAnnotation.get(psiClass), trace);
return new JavaScopeForKotlinNamespace(
namespaceDescriptor,
javaSemanticServices.getPsiDeclarationProviderFactory().createDeclarationForKotlinNamespace(psiPackage, psiClass),