From 5846769b43b2ba7bd3a7595b1ea615e6949f2f62 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Mon, 7 Dec 2015 16:36:03 +0300 Subject: [PATCH] J2K NameResolverImpl: convert --- .../deserialization/NameResolverImpl.kt | 126 +++++++++--------- 1 file changed, 62 insertions(+), 64 deletions(-) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/NameResolverImpl.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/NameResolverImpl.kt index f52a8e8f9fa..b9c654f5a15 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/NameResolverImpl.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/NameResolverImpl.kt @@ -14,83 +14,81 @@ * limitations under the License. */ -package org.jetbrains.kotlin.serialization.deserialization; +/* + * Copyright 2010-2015 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. + */ -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.name.ClassId; -import org.jetbrains.kotlin.name.FqName; -import org.jetbrains.kotlin.name.Name; -import org.jetbrains.kotlin.serialization.ProtoBuf; -import org.jetbrains.kotlin.utils.ExceptionUtilsKt; +package org.jetbrains.kotlin.serialization.deserialization -import java.io.IOException; -import java.io.InputStream; -import java.util.LinkedList; +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.serialization.ProtoBuf +import org.jetbrains.kotlin.serialization.ProtoBuf.QualifiedNameTable.QualifiedName +import org.jetbrains.kotlin.utils.rethrow +import java.io.IOException +import java.io.InputStream +import java.util.* -import static org.jetbrains.kotlin.serialization.ProtoBuf.QualifiedNameTable.QualifiedName; +class NameResolverImpl private constructor( + private val strings: ProtoBuf.StringTable, + private val qualifiedNames: ProtoBuf.QualifiedNameTable) : NameResolver { -public class NameResolverImpl implements NameResolver { - @NotNull - public static NameResolverImpl read(@NotNull InputStream in) { - try { - ProtoBuf.StringTable simpleNames = ProtoBuf.StringTable.parseDelimitedFrom(in); - ProtoBuf.QualifiedNameTable qualifiedNames = ProtoBuf.QualifiedNameTable.parseDelimitedFrom(in); - return new NameResolverImpl(simpleNames, qualifiedNames); - } - catch (IOException e) { - throw ExceptionUtilsKt.rethrow(e); - } + override fun getString(index: Int): String { + return strings.getString(index) } - private final ProtoBuf.StringTable strings; - private final ProtoBuf.QualifiedNameTable qualifiedNames; - - private NameResolverImpl( - @NotNull ProtoBuf.StringTable strings, - @NotNull ProtoBuf.QualifiedNameTable qualifiedNames - ) { - this.strings = strings; - this.qualifiedNames = qualifiedNames; + override fun getName(index: Int): Name { + return Name.guess(strings.getString(index)) } - @Override - @NotNull - public String getString(int index) { - return strings.getString(index); - } - - @Override - @NotNull - public Name getName(int index) { - return Name.guess(strings.getString(index)); - } - - @Override - @NotNull - public ClassId getClassId(int index) { - LinkedList packageFqName = new LinkedList(); - LinkedList relativeClassName = new LinkedList(); - boolean local = false; + override fun getClassId(index: Int): ClassId { + var index = index + val packageFqName = LinkedList() + val relativeClassName = LinkedList() + var local = false while (index != -1) { - QualifiedName proto = qualifiedNames.getQualifiedName(index); - String shortName = strings.getString(proto.getShortName()); - switch (proto.getKind()) { - case CLASS: - relativeClassName.addFirst(shortName); - break; - case PACKAGE: - packageFqName.addFirst(shortName); - break; - case LOCAL: - relativeClassName.addFirst(shortName); - local = true; - break; + val proto = qualifiedNames.getQualifiedName(index) + val shortName = strings.getString(proto.shortName) + when (proto.kind!!) { + QualifiedName.Kind.CLASS -> relativeClassName.addFirst(shortName) + QualifiedName.Kind.PACKAGE -> packageFqName.addFirst(shortName) + QualifiedName.Kind.LOCAL -> { + relativeClassName.addFirst(shortName) + local = true + } } - index = proto.getParentQualifiedName(); + index = proto.parentQualifiedName } - return new ClassId(FqName.fromSegments(packageFqName), FqName.fromSegments(relativeClassName), local); + return ClassId(FqName.fromSegments(packageFqName), FqName.fromSegments(relativeClassName), local) + } + + companion object { + fun read(stream: InputStream): NameResolverImpl { + try { + val simpleNames = ProtoBuf.StringTable.parseDelimitedFrom(stream) + val qualifiedNames = ProtoBuf.QualifiedNameTable.parseDelimitedFrom(stream) + return NameResolverImpl(simpleNames, qualifiedNames) + } + catch (e: IOException) { + throw rethrow(e) + } + + } } }