Concrete header classes replaced by kinds
AS a consequence, instanceof checks removed, code simplified
This commit is contained in:
+9
-11
@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.resolve.java.resolver.ErrorReporter;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaClassResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaPackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.SerializedDataHeader;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -41,8 +40,8 @@ import java.util.Collection;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule.INCLUDE_KOTLIN_SOURCES;
|
||||
import static org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils.kotlinFqNameToJavaFqName;
|
||||
import static org.jetbrains.jet.lang.resolve.kotlin.header.SerializedDataHeader.Kind.CLASS;
|
||||
import static org.jetbrains.jet.lang.resolve.kotlin.header.SerializedDataHeader.Kind.PACKAGE;
|
||||
import static org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader.Kind.CLASS;
|
||||
import static org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader.Kind.PACKAGE_FACADE;
|
||||
|
||||
public final class DeserializedDescriptorResolver {
|
||||
private AnnotationDescriptorDeserializer annotationDeserializer;
|
||||
@@ -103,7 +102,7 @@ public final class DeserializedDescriptorResolver {
|
||||
|
||||
@Nullable
|
||||
public JetScope createKotlinPackageScope(@NotNull PackageFragmentDescriptor descriptor, @NotNull KotlinJvmBinaryClass kotlinClass) {
|
||||
String[] data = readData(kotlinClass, PACKAGE);
|
||||
String[] data = readData(kotlinClass, PACKAGE_FACADE);
|
||||
if (data != null) {
|
||||
return new DeserializedPackageMemberScope(storageManager, descriptor, annotationDeserializer, javaDescriptorFinder,
|
||||
JavaProtoBufUtil.readPackageDataFrom(data));
|
||||
@@ -112,17 +111,16 @@ public final class DeserializedDescriptorResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String[] readData(@NotNull KotlinJvmBinaryClass kotlinClass, @NotNull SerializedDataHeader.Kind expectedKind) {
|
||||
private String[] readData(@NotNull KotlinJvmBinaryClass kotlinClass, @NotNull KotlinClassHeader.Kind expectedKind) {
|
||||
KotlinClassHeader header = kotlinClass.getClassHeader();
|
||||
if (header instanceof SerializedDataHeader) {
|
||||
SerializedDataHeader serializedDataHeader = (SerializedDataHeader) header;
|
||||
if (serializedDataHeader.getKind() != expectedKind) return null;
|
||||
return serializedDataHeader.getAnnotationData();
|
||||
}
|
||||
if (header == null) return null;
|
||||
|
||||
if (header != null) {
|
||||
if (header.getKind() == KotlinClassHeader.Kind.INCOMPATIBLE_ABI_VERSION) {
|
||||
errorReporter.reportIncompatibleAbiVersion(kotlinClass, header.getVersion());
|
||||
}
|
||||
else if (header.getKind() == expectedKind) {
|
||||
return header.getAnnotationData();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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.kotlin.header;
|
||||
|
||||
public class IncompatibleAnnotationHeader extends KotlinClassHeader {
|
||||
protected IncompatibleAnnotationHeader(int version) {
|
||||
super(version);
|
||||
}
|
||||
}
|
||||
+52
-2
@@ -16,15 +16,65 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.kotlin.header;
|
||||
|
||||
public abstract class KotlinClassHeader {
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class KotlinClassHeader {
|
||||
|
||||
@NotNull
|
||||
public static KotlinClassHeader createClassHeader(int version, @NotNull String[] annotationData) {
|
||||
return new KotlinClassHeader(Kind.CLASS, version, annotationData);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KotlinClassHeader createPackageFacadeHeader(int version, @NotNull String[] annotationData) {
|
||||
return new KotlinClassHeader(Kind.PACKAGE_FACADE, version, annotationData);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KotlinClassHeader createPackageFragmentHeader(int version) {
|
||||
return new KotlinClassHeader(Kind.PACKAGE_FRAGMENT, version, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KotlinClassHeader createTraitImplHeader(int version) {
|
||||
return new KotlinClassHeader(Kind.TRAIT_IMPL, version, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static KotlinClassHeader createIncompatibleVersionErrorHeader(int version) {
|
||||
return new KotlinClassHeader(Kind.INCOMPATIBLE_ABI_VERSION, version, null);
|
||||
}
|
||||
|
||||
public enum Kind {
|
||||
CLASS,
|
||||
PACKAGE_FACADE,
|
||||
PACKAGE_FRAGMENT,
|
||||
TRAIT_IMPL,
|
||||
INCOMPATIBLE_ABI_VERSION
|
||||
}
|
||||
|
||||
private final Kind kind;
|
||||
private final int version;
|
||||
private final String[] data;
|
||||
|
||||
protected KotlinClassHeader(int version) {
|
||||
private KotlinClassHeader(@NotNull Kind kind, int version, @Nullable String[] annotationData) {
|
||||
this.kind = kind;
|
||||
this.version = version;
|
||||
this.data = annotationData;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String[] getAnnotationData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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.kotlin.header;
|
||||
|
||||
public class PackageFragmentClassHeader extends KotlinClassHeader {
|
||||
protected PackageFragmentClassHeader(int version) {
|
||||
super(version);
|
||||
}
|
||||
}
|
||||
+9
-15
@@ -83,33 +83,27 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
||||
}
|
||||
|
||||
if (!AbiVersionUtil.isAbiVersionCompatible(version)) {
|
||||
return new IncompatibleAnnotationHeader(version);
|
||||
return KotlinClassHeader.createIncompatibleVersionErrorHeader(version);
|
||||
}
|
||||
|
||||
switch (foundType) {
|
||||
case CLASS:
|
||||
return serializedDataHeader(SerializedDataHeader.Kind.CLASS);
|
||||
// This means that the annotation is found and its ABI version is compatible, but there's no "data" string array in it.
|
||||
// We tell the outside world that there's really no annotation at all
|
||||
if (annotationData == null) return null;
|
||||
return KotlinClassHeader.createClassHeader(version, annotationData);
|
||||
case PACKAGE:
|
||||
return serializedDataHeader(SerializedDataHeader.Kind.PACKAGE);
|
||||
if (annotationData == null) return null;
|
||||
return KotlinClassHeader.createPackageFacadeHeader(version, annotationData);
|
||||
case PACKAGE_FRAGMENT:
|
||||
return new PackageFragmentClassHeader(version);
|
||||
return KotlinClassHeader.createPackageFragmentHeader(version);
|
||||
case TRAIT_IMPL:
|
||||
return new TraitImplClassHeader(version);
|
||||
return KotlinClassHeader.createTraitImplHeader(version);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown compatible HeaderType: " + foundType);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private SerializedDataHeader serializedDataHeader(@NotNull SerializedDataHeader.Kind kind) {
|
||||
if (annotationData == null) {
|
||||
// This means that the annotation is found and its ABI version is compatible, but there's no "data" string array in it.
|
||||
// We tell the outside world that there's really no annotation at all
|
||||
return null;
|
||||
}
|
||||
return new SerializedDataHeader(version, annotationData, kind);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnnotationArgumentVisitor visitAnnotation(@NotNull JvmClassName annotationClassName) {
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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.kotlin.header;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SerializedDataHeader extends KotlinClassHeader {
|
||||
public enum Kind {
|
||||
CLASS,
|
||||
PACKAGE
|
||||
}
|
||||
|
||||
private final String[] data;
|
||||
private final Kind kind;
|
||||
|
||||
protected SerializedDataHeader(int version, @NotNull String[] annotationData, @NotNull Kind kind) {
|
||||
super(version);
|
||||
this.data = annotationData;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String[] getAnnotationData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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.kotlin.header;
|
||||
|
||||
/* package */ class TraitImplClassHeader extends KotlinClassHeader {
|
||||
protected TraitImplClassHeader(int version) {
|
||||
super(version);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user