From 49604f62982c56aa204c14176f54f6acc8a90fc7 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 16 Jul 2013 22:33:50 +0400 Subject: [PATCH] Minor, move anonymous class to private inner --- .../lang/BuiltinsNamespaceDescriptorImpl.java | 144 +++++++++--------- 1 file changed, 74 insertions(+), 70 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/BuiltinsNamespaceDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/BuiltinsNamespaceDescriptorImpl.java index 894f9a34b2b..d63603f1dfc 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/BuiltinsNamespaceDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/BuiltinsNamespaceDescriptorImpl.java @@ -25,7 +25,6 @@ import java.util.List; import static org.jetbrains.jet.descriptors.serialization.descriptors.AnnotationDeserializer.UNSUPPORTED; class BuiltinsNamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl { - private final DeserializedPackageMemberScope members; private final NameResolver nameResolver; @@ -34,75 +33,8 @@ class BuiltinsNamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl { nameResolver = NameSerializationUtil.deserializeNameResolver(getStream(BuiltInsSerializationUtil.getNameTableFilePath(this))); - final NotNullLazyValue> classNames = storageManager.createLazyValue(new Computable>() { - @Override - @NotNull - public Collection compute() { - InputStream in = getStream(BuiltInsSerializationUtil.getClassNamesFilePath(BuiltinsNamespaceDescriptorImpl.this)); - - try { - DataInputStream data = new DataInputStream(in); - try { - int size = data.readInt(); - List result = new ArrayList(size); - for (int i = 0; i < size; i++) { - result.add(nameResolver.getName(data.readInt())); - } - return result; - } - finally { - data.close(); - } - } - catch (IOException e) { - throw new IllegalStateException(e); - } - } - }); - - DescriptorFinder descriptorFinder = new AbstractDescriptorFinder(storageManager, UNSUPPORTED) { - @Nullable - @Override - protected ClassData getClassData(@NotNull ClassId classId) { - InputStream stream = getStreamNullable(BuiltInsSerializationUtil.getClassMetadataPath(classId)); - if (stream == null) { - return null; - } - - try { - ProtoBuf.Class classProto = ProtoBuf.Class.parseFrom(stream); - - Name expectedShortName = classId.getRelativeClassName().shortName(); - Name actualShortName = nameResolver.getName(classProto.getName()); - if (!actualShortName.isSpecial() && !actualShortName.equals(expectedShortName)) { - // Workaround for case-insensitive file systems, - // otherwise we'd find "Collection" for "collection" etc - return null; - } - - return new ClassData(nameResolver, classProto); - } - catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Nullable - @Override - public NamespaceDescriptor findPackage(@NotNull FqName fqName) { - return fqName.equals(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) ? BuiltinsNamespaceDescriptorImpl.this : null; - } - - @NotNull - @Override - public Collection getClassNames(@NotNull FqName packageName) { - return packageName.equals(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) - ? classNames.compute() - : Collections.emptyList(); - } - }; - - members = new DeserializedPackageMemberScope(storageManager, this, UNSUPPORTED, descriptorFinder, loadPackage(), nameResolver); + members = new DeserializedPackageMemberScope(storageManager, this, UNSUPPORTED, new BuiltInsDescriptorFinder(storageManager), + loadPackage(), nameResolver); } @NotNull @@ -142,4 +74,76 @@ class BuiltinsNamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl { private static InputStream getStreamNullable(@NotNull String path) { return KotlinBuiltIns.class.getClassLoader().getResourceAsStream(path); } + + private class BuiltInsDescriptorFinder extends AbstractDescriptorFinder { + private final NotNullLazyValue> classNames; + + public BuiltInsDescriptorFinder(@NotNull StorageManager storageManager) { + super(storageManager, UNSUPPORTED); + + classNames = storageManager.createLazyValue(new Computable>() { + @Override + @NotNull + public Collection compute() { + InputStream in = getStream(BuiltInsSerializationUtil.getClassNamesFilePath(BuiltinsNamespaceDescriptorImpl.this)); + + try { + DataInputStream data = new DataInputStream(in); + try { + int size = data.readInt(); + List result = new ArrayList(size); + for (int i = 0; i < size; i++) { + result.add(nameResolver.getName(data.readInt())); + } + return result; + } + finally { + data.close(); + } + } + catch (IOException e) { + throw new IllegalStateException(e); + } + } + }); + } + + @Nullable + @Override + protected ClassData getClassData(@NotNull ClassId classId) { + InputStream stream = getStreamNullable(BuiltInsSerializationUtil.getClassMetadataPath(classId)); + if (stream == null) { + return null; + } + + try { + ProtoBuf.Class classProto = ProtoBuf.Class.parseFrom(stream); + + Name expectedShortName = classId.getRelativeClassName().shortName(); + Name actualShortName = nameResolver.getName(classProto.getName()); + if (!actualShortName.isSpecial() && !actualShortName.equals(expectedShortName)) { + // Workaround for case-insensitive file systems, + // otherwise we'd find "Collection" for "collection" etc + return null; + } + + return new ClassData(nameResolver, classProto); + } + catch (IOException e) { + throw new IllegalStateException(e); + } + } + + @Nullable + @Override + public NamespaceDescriptor findPackage(@NotNull FqName fqName) { + return fqName.equals(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) ? BuiltinsNamespaceDescriptorImpl.this : null; + } + + @NotNull + @Override + public Collection getClassNames(@NotNull FqName packageName) { + return packageName.equals(KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME) ? classNames.compute() : Collections.emptyList(); + } + } }