Rewrite KotlinClassHeader to Kotlin

This commit is contained in:
Alexander Udalov
2014-03-07 03:39:55 +04:00
parent 39cd3b1e13
commit 4937812414
7 changed files with 52 additions and 89 deletions
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyJavaTypeParamete
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader.Kind
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
trait LazyJavaClassResolver {
@@ -78,14 +77,14 @@ fun LazyJavaResolverContext.findClassInJava(fqName: FqName): JavaClassLookupResu
val kotlinClass = kotlinClassFinder.findKotlinClass(fqName)
val header = kotlinClass?.getClassHeader()
if (kotlinClass != null && header != null) {
if (header.getKind() == KotlinClassHeader.Kind.CLASS) {
if (header.kind == KotlinClassHeader.Kind.CLASS) {
val descriptor = packageFragmentProvider.resolveKotlinBinaryClass(kotlinClass)
if (descriptor != null) {
return JavaClassLookupResult(kClass = descriptor)
}
}
else if (header.getKind() == KotlinClassHeader.Kind.INCOMPATIBLE_ABI_VERSION) {
errorReporter.reportIncompatibleAbiVersion(kotlinClass, header.getVersion())
else if (header.kind == KotlinClassHeader.Kind.INCOMPATIBLE_ABI_VERSION) {
errorReporter.reportIncompatibleAbiVersion(kotlinClass, header.version)
}
else {
// This is a package or trait-impl or something like that
@@ -1,72 +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;
import org.jetbrains.annotations.Nullable;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass;
public class KotlinClassHeader {
public enum Kind {
INCOMPATIBLE_ABI_VERSION,
CLASS,
PACKAGE_FACADE,
SYNTHETIC_CLASS,
}
private final Kind kind;
private final int version;
private final String[] data;
private final KotlinSyntheticClass.Kind syntheticClassKind;
public KotlinClassHeader(
@NotNull Kind kind,
int version,
@Nullable String[] annotationData,
@Nullable KotlinSyntheticClass.Kind syntheticClassKind
) {
assert (annotationData == null) == (kind != Kind.CLASS && kind != Kind.PACKAGE_FACADE)
: "Annotation data should be not null only for CLASS and PACKAGE_FACADE (kind=" + kind + ")";
assert (syntheticClassKind == null) == (kind != Kind.SYNTHETIC_CLASS)
: "Synthetic class kind should be present for SYNTHETIC_CLASS (kind=" + kind + ")";
this.kind = kind;
this.version = version;
this.data = annotationData;
this.syntheticClassKind = syntheticClassKind;
}
@NotNull
public Kind getKind() {
return kind;
}
public int getVersion() {
return version;
}
@Nullable
public String[] getAnnotationData() {
return data;
}
@Nullable
public KotlinSyntheticClass.Kind getSyntheticClassKind() {
return syntheticClassKind;
}
}
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2014 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.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass
public class KotlinClassHeader(
public val kind: KotlinClassHeader.Kind,
public val version: Int,
public val annotationData: Array<String>?,
public val syntheticClassKind: KotlinSyntheticClass.Kind?
) {
{
assert((annotationData == null) == (kind != Kind.CLASS && kind != Kind.PACKAGE_FACADE)) {
"Annotation data should be not null only for CLASS and PACKAGE_FACADE (kind=" + kind + ")"
}
assert((syntheticClassKind == null) == (kind != Kind.SYNTHETIC_CLASS)) {
"Synthetic class kind should be present for SYNTHETIC_CLASS (kind=" + kind + ")"
}
}
public enum class Kind {
INCOMPATIBLE_ABI_VERSION
CLASS
PACKAGE_FACADE
SYNTHETIC_CLASS
}
}