J2K NameResolverImpl: convert
This commit is contained in:
+62
-64
@@ -14,83 +14,81 @@
|
|||||||
* limitations under the License.
|
* 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;
|
package org.jetbrains.kotlin.serialization.deserialization
|
||||||
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;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import java.io.InputStream;
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import java.util.LinkedList;
|
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 {
|
override fun getString(index: Int): String {
|
||||||
@NotNull
|
return strings.getString(index)
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ProtoBuf.StringTable strings;
|
override fun getName(index: Int): Name {
|
||||||
private final ProtoBuf.QualifiedNameTable qualifiedNames;
|
return Name.guess(strings.getString(index))
|
||||||
|
|
||||||
private NameResolverImpl(
|
|
||||||
@NotNull ProtoBuf.StringTable strings,
|
|
||||||
@NotNull ProtoBuf.QualifiedNameTable qualifiedNames
|
|
||||||
) {
|
|
||||||
this.strings = strings;
|
|
||||||
this.qualifiedNames = qualifiedNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun getClassId(index: Int): ClassId {
|
||||||
@NotNull
|
var index = index
|
||||||
public String getString(int index) {
|
val packageFqName = LinkedList<String>()
|
||||||
return strings.getString(index);
|
val relativeClassName = LinkedList<String>()
|
||||||
}
|
var local = false
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public Name getName(int index) {
|
|
||||||
return Name.guess(strings.getString(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public ClassId getClassId(int index) {
|
|
||||||
LinkedList<String> packageFqName = new LinkedList<String>();
|
|
||||||
LinkedList<String> relativeClassName = new LinkedList<String>();
|
|
||||||
boolean local = false;
|
|
||||||
|
|
||||||
while (index != -1) {
|
while (index != -1) {
|
||||||
QualifiedName proto = qualifiedNames.getQualifiedName(index);
|
val proto = qualifiedNames.getQualifiedName(index)
|
||||||
String shortName = strings.getString(proto.getShortName());
|
val shortName = strings.getString(proto.shortName)
|
||||||
switch (proto.getKind()) {
|
when (proto.kind!!) {
|
||||||
case CLASS:
|
QualifiedName.Kind.CLASS -> relativeClassName.addFirst(shortName)
|
||||||
relativeClassName.addFirst(shortName);
|
QualifiedName.Kind.PACKAGE -> packageFqName.addFirst(shortName)
|
||||||
break;
|
QualifiedName.Kind.LOCAL -> {
|
||||||
case PACKAGE:
|
relativeClassName.addFirst(shortName)
|
||||||
packageFqName.addFirst(shortName);
|
local = true
|
||||||
break;
|
}
|
||||||
case LOCAL:
|
|
||||||
relativeClassName.addFirst(shortName);
|
|
||||||
local = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user