Rewrite KotlinClassHeader to Kotlin
This commit is contained in:
+3
-4
@@ -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
|
||||
|
||||
-72
@@ -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;
|
||||
}
|
||||
}
|
||||
+42
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public fun buildDecompiledText(
|
||||
val classFqName = kotlinClass.getClassName().getFqNameForClassNameWithoutDollars()
|
||||
val classFileHeader = kotlinClass.getClassHeader()
|
||||
assert(classFileHeader != null) { "Decompiled data factory shouldn't be called on an unsupported file: " + classFile }
|
||||
val kind = classFileHeader!!.getKind()
|
||||
val kind = classFileHeader!!.kind
|
||||
val packageFqName = classFqName.parent()
|
||||
|
||||
return if (kind == KotlinClassHeader.Kind.PACKAGE_FACADE) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public fun isKotlinCompiledFile(file: VirtualFile): Boolean {
|
||||
return false
|
||||
}
|
||||
val header = KotlinBinaryClassCache.getKotlinBinaryClass(file).getClassHeader()
|
||||
return header != null && header.getSyntheticClassKind() != KotlinSyntheticClass.Kind.TRAIT_IMPL
|
||||
return header != null && header.syntheticClassKind != KotlinSyntheticClass.Kind.TRAIT_IMPL
|
||||
}
|
||||
|
||||
public fun isKotlinCompiledFileWithIncompatibleAbiVersion(file: VirtualFile): Boolean {
|
||||
@@ -39,7 +39,7 @@ public fun isKotlinCompiledFileWithIncompatibleAbiVersion(file: VirtualFile): Bo
|
||||
return false
|
||||
}
|
||||
val header = KotlinBinaryClassCache.getKotlinBinaryClass(file).getClassHeader()
|
||||
return header?.getKind() == KotlinClassHeader.Kind.INCOMPATIBLE_ABI_VERSION
|
||||
return header?.kind == KotlinClassHeader.Kind.INCOMPATIBLE_ABI_VERSION
|
||||
}
|
||||
|
||||
public fun isKotlinInternalCompiledFile(file: VirtualFile): Boolean {
|
||||
@@ -50,5 +50,5 @@ public fun isKotlinInternalCompiledFile(file: VirtualFile): Boolean {
|
||||
return true
|
||||
}
|
||||
val header = KotlinBinaryClassCache.getKotlinBinaryClass(file).getClassHeader()
|
||||
return header?.getKind() == KotlinClassHeader.Kind.SYNTHETIC_CLASS
|
||||
return header?.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils
|
||||
import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.AnnotationDescriptorDeserializer
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.ErrorReporter
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils.getErrorModule
|
||||
import org.jetbrains.jet.lang.types.error.MissingDependencyErrorClassDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
@@ -57,7 +56,7 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
assert(packageFqName == directoryPackageFqName, "Was called for $packageFqName but only $directoryPackageFqName is expected.")
|
||||
val packageClassFqName = PackageClassUtils.getPackageClassFqName(packageFqName)
|
||||
val binaryClassForPackageClass = localClassFinder.findKotlinClass(packageClassFqName)
|
||||
val annotationData = binaryClassForPackageClass?.getClassHeader()?.getAnnotationData()
|
||||
val annotationData = binaryClassForPackageClass?.getClassHeader()?.annotationData
|
||||
if (annotationData == null) {
|
||||
LOG.error("Could not read annotation data for $packageFqName from ${binaryClassForPackageClass?.getClassName()}")
|
||||
return Collections.emptyList()
|
||||
@@ -145,7 +144,7 @@ public class DeserializerForDecompiler(val packageDirectory: VirtualFile, val di
|
||||
}
|
||||
|
||||
private fun deserializeBinaryClass(kotlinClass: KotlinJvmBinaryClass): ClassDescriptor {
|
||||
val data = kotlinClass.getClassHeader()?.getAnnotationData()
|
||||
val data = kotlinClass.getClassHeader()?.annotationData
|
||||
if (data == null) {
|
||||
LOG.error("Annotation data missing for ${kotlinClass.getClassName()}")
|
||||
}
|
||||
|
||||
@@ -24,18 +24,13 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi
|
||||
import com.intellij.psi.PsiManager
|
||||
import junit.framework.Assert
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils
|
||||
import com.intellij.psi.ClassFileViewProvider
|
||||
import com.intellij.psi.impl.compiled.ClsFileImpl
|
||||
import com.intellij.psi.PsiCompiledFile
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass.Kind.*
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes
|
||||
|
||||
public class InternalCompiledClassesTest : JetLightCodeInsightFixtureTestCase() {
|
||||
|
||||
@@ -85,7 +80,7 @@ public class InternalCompiledClassesTest : JetLightCodeInsightFixtureTestCase()
|
||||
|
||||
private fun isSyntheticClassOfKind(kind: KotlinSyntheticClass.Kind) : VirtualFile.() -> Boolean = {
|
||||
val header = KotlinBinaryClassCache.getKotlinBinaryClass(this).getClassHeader()
|
||||
header?.getSyntheticClassKind() == kind
|
||||
header?.syntheticClassKind == kind
|
||||
}
|
||||
|
||||
private fun doTestNoPsiFilesAreBuiltForSyntheticClass(kind: KotlinSyntheticClass.Kind) =
|
||||
|
||||
Reference in New Issue
Block a user