diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/kotlin/ReadClassHeader.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/kotlin/ReadClassHeader.java deleted file mode 100644 index 451ba6fa6ca..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/kotlin/ReadClassHeader.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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; - -import com.intellij.openapi.util.Pair; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.resolve.java.JvmClassName; -import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader; - -public class ReadClassHeader { - @Nullable - public static KotlinClassHeader readClassHeader(@NotNull byte[] fileContents) { - Pair pair = VirtualFileKotlinClass.readClassNameAndHeader(fileContents); - return pair == null ? null : pair.second; - } -} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/kotlin/VirtualFileKotlinClass.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/kotlin/VirtualFileKotlinClass.java index 16b2edbc9e6..9c2b41c30c0 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/kotlin/VirtualFileKotlinClass.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/kotlin/VirtualFileKotlinClass.java @@ -49,7 +49,7 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass { } @Nullable - /* package */ static Pair readClassNameAndHeader(@NotNull byte[] fileContents) { + private static Pair readClassNameAndHeader(@NotNull byte[] fileContents) { final ReadKotlinClassHeaderAnnotationVisitor readHeaderVisitor = new ReadKotlinClassHeaderAnnotationVisitor(); final Ref classNameRef = Ref.create(); new ClassReader(fileContents).accept(new ClassVisitor(ASM4) { @@ -95,6 +95,12 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass { } } + @Nullable + public static KotlinClassHeader readClassHeader(@NotNull byte[] fileContents) { + Pair pair = readClassNameAndHeader(fileContents); + return pair == null ? null : pair.second; + } + @NotNull public VirtualFile getFile() { return file; diff --git a/jps-plugin/jps-plugin.iml b/jps-plugin/jps-plugin.iml index 37590a836e4..1b4d326d32d 100644 --- a/jps-plugin/jps-plugin.iml +++ b/jps-plugin/jps-plugin.iml @@ -16,6 +16,10 @@ + + + + diff --git a/jps-plugin/test/org/jetbrains/jet/jps/build/classFilesComparison.kt b/jps-plugin/test/org/jetbrains/jet/jps/build/classFilesComparison.kt index 8cd431c2296..6af1c8a34d2 100644 --- a/jps-plugin/test/org/jetbrains/jet/jps/build/classFilesComparison.kt +++ b/jps-plugin/test/org/jetbrains/jet/jps/build/classFilesComparison.kt @@ -28,10 +28,6 @@ import com.google.common.hash.Hashing import com.intellij.openapi.util.io.FileUtil import com.google.common.collect.Sets import java.util.HashSet -import com.intellij.openapi.vfs.local.CoreLocalFileSystem -import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass -import org.jetbrains.jet.storage.LockBasedStorageManager -import org.jetbrains.jet.lang.resolve.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader import org.jetbrains.jet.descriptors.serialization.BitEncoding import org.jetbrains.jet.descriptors.serialization.DebugJavaProtoBuf @@ -39,6 +35,7 @@ import com.google.protobuf.ExtensionRegistry import java.io.ByteArrayInputStream import org.jetbrains.jet.descriptors.serialization.DebugProtoBuf import java.util.Arrays +import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClass fun File.hash() = Files.hash(this, Hashing.crc32()) @@ -114,13 +111,42 @@ fun assertEqualDirectories(expected: File, actual: File, ignore: (File) -> Boole fun classFileToString(classFile: File): String { val out = StringWriter() - val traceVisitor = TraceClassVisitor(PrintWriter(out)) - ClassReader(classFile.readBytes()).accept(traceVisitor, 0) - // TODO serialize protobuf + val classBytes = classFile.readBytes() + + val traceVisitor = TraceClassVisitor(PrintWriter(out)) + ClassReader(classBytes).accept(traceVisitor, 0) + + val classHeader = VirtualFileKotlinClass.readClassHeader(classBytes) + + val annotationDataEncoded = classHeader?.annotationData + if (annotationDataEncoded != null) { + ByteArrayInputStream(BitEncoding.decodeBytes(annotationDataEncoded)).use { + input -> + + out.write("\n------ simpleNames proto -----\n${DebugProtoBuf.SimpleNameTable.parseDelimitedFrom(input)}") + out.write("\n------ qualifiedNames proto -----\n${DebugProtoBuf.QualifiedNameTable.parseDelimitedFrom(input)}") + + when (classHeader!!.kind) { + KotlinClassHeader.Kind.PACKAGE_FACADE -> + out.write("\n------ package proto -----\n${DebugProtoBuf.Package.parseFrom(input, getExtensionRegistry())}") + + KotlinClassHeader.Kind.CLASS -> + out.write("\n------ class proto -----\n${DebugProtoBuf.Class.parseFrom(input, getExtensionRegistry())}") + else -> throw IllegalStateException() + } + } + } + return out.toString() } +fun getExtensionRegistry(): ExtensionRegistry { + val registry = ExtensionRegistry.newInstance()!! + DebugJavaProtoBuf.registerAllExtensions(registry) + return registry +} + fun fileToStringRepresentation(file: File): String { return when { file.name.endsWith(".class") -> {