Serialize package members and class names
Write KotlinInfo annotation to the facade package class
This commit is contained in:
@@ -30,6 +30,9 @@ import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.descriptors.serialization.DescriptorSerializer;
|
||||
import org.jetbrains.jet.descriptors.serialization.NameSerializationUtil;
|
||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
@@ -42,12 +45,17 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.asm4.Opcodes.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DECLARATION_TO_DESCRIPTOR;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getNotNull;
|
||||
|
||||
public class NamespaceCodegen extends MemberCodegen {
|
||||
@NotNull
|
||||
@@ -91,11 +99,14 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
|
||||
public void generate(CompilationErrorHandler errorHandler) {
|
||||
if (shouldGenerateNSClass(files)) {
|
||||
AnnotationVisitor packageClassAnnotation = v.getClassBuilder().newAnnotation(JvmStdlibNames.JET_PACKAGE_CLASS.getDescriptor(), true);
|
||||
AnnotationVisitor packageClassAnnotation =
|
||||
v.getClassBuilder().newAnnotation(JvmStdlibNames.JET_PACKAGE_CLASS.getDescriptor(), true);
|
||||
packageClassAnnotation.visit(JvmStdlibNames.ABI_VERSION_NAME, JvmAbi.VERSION);
|
||||
packageClassAnnotation.visitEnd();
|
||||
}
|
||||
|
||||
writeKotlinInfoIfNeeded();
|
||||
|
||||
for (JetFile file : files) {
|
||||
VirtualFile vFile = file.getVirtualFile();
|
||||
try {
|
||||
@@ -117,6 +128,53 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
assert v.isActivated() == shouldGenerateNSClass(files) : "Different algorithms for generating namespace class and for heuristics";
|
||||
}
|
||||
|
||||
private void writeKotlinInfoIfNeeded() {
|
||||
DescriptorSerializer serializer = new DescriptorSerializer();
|
||||
ProtoBuf.Package.Builder packageProto = ProtoBuf.Package.newBuilder();
|
||||
boolean writeAnnotation = false;
|
||||
|
||||
for (JetFile file : files) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
writeAnnotation = true;
|
||||
DeclarationDescriptor descriptor = getNotNull(state.getBindingContext(), DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
ProtoBuf.Callable proto = serializer.callableProto((CallableMemberDescriptor) descriptor).build();
|
||||
packageProto.addMember(proto);
|
||||
}
|
||||
else if (declaration instanceof JetClassOrObject) {
|
||||
DeclarationDescriptor descriptor = getNotNull(state.getBindingContext(), DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
if (declaration instanceof JetObjectDeclaration) {
|
||||
writeAnnotation = true;
|
||||
JetObjectDeclarationName nameAsDeclaration = ((JetObjectDeclaration) declaration).getNameAsDeclaration();
|
||||
assert nameAsDeclaration != null : "Should be a named object";
|
||||
PropertyDescriptor propertyForObject = getNotNull(state.getBindingContext(), BindingContext.OBJECT_DECLARATION,
|
||||
nameAsDeclaration);
|
||||
ProtoBuf.Callable proto = serializer.callableProto((CallableMemberDescriptor) propertyForObject).build();
|
||||
packageProto.addMember(proto);
|
||||
}
|
||||
int name = serializer.getNameTable().getSimpleNameIndex(descriptor.getName());
|
||||
packageProto.addClassName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!writeAnnotation) return;
|
||||
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
|
||||
NameSerializationUtil.serializeNameTable(stream, serializer.getNameTable());
|
||||
try {
|
||||
packageProto.build().writeTo(stream);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
|
||||
AnnotationVisitor kotlinInfo = v.getClassBuilder().newAnnotation(JvmStdlibNames.KOTLIN_INFO_CLASS.getDescriptor(), true);
|
||||
kotlinInfo.visit("data", stream.toByteArray());
|
||||
kotlinInfo.visitEnd();
|
||||
}
|
||||
|
||||
private void generate(JetFile file) {
|
||||
NamespaceDescriptor descriptor = state.getBindingContext().get(BindingContext.FILE_TO_NAMESPACE, file);
|
||||
assert descriptor != null : "No namespace found for file " + file + " declared package: " + file.getPackageName();
|
||||
@@ -137,7 +195,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
|
||||
if (countOfDeclarationsInSrcClass > 0) {
|
||||
String namespaceInternalName = JvmClassName.byFqNameWithoutInnerClasses(
|
||||
PackageClassUtils.getPackageClassFqName(name)).getInternalName();
|
||||
PackageClassUtils.getPackageClassFqName(name)).getInternalName();
|
||||
String className = getMultiFileNamespaceInternalName(namespaceInternalName, file);
|
||||
ClassBuilder builder = state.getFactory().forNamespacepart(className, file);
|
||||
|
||||
@@ -184,7 +242,9 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
|
||||
for (JetFile file : namespaceFiles) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
if (declaration instanceof JetProperty ||
|
||||
declaration instanceof JetNamedFunction ||
|
||||
declaration instanceof JetObjectDeclaration) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -248,7 +308,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
List<JetProperty> result = Lists.newArrayList();
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty &&
|
||||
ImplementationBodyCodegen.shouldInitializeProperty((JetProperty) declaration, typeMapper)) {
|
||||
ImplementationBodyCodegen.shouldInitializeProperty((JetProperty) declaration, typeMapper)) {
|
||||
result.add((JetProperty) declaration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,12 @@ message Class {
|
||||
repeated int32 enum_entry = 12;
|
||||
}
|
||||
|
||||
message Package {
|
||||
repeated Callable member = 1;
|
||||
|
||||
repeated int32 class_name = 2;
|
||||
}
|
||||
|
||||
message Callable {
|
||||
enum MemberKind {
|
||||
// 2 bits
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.descriptors.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PackageData {
|
||||
@NotNull
|
||||
public static PackageData readPackageDataFrom(@NotNull byte[] bytes) {
|
||||
try {
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
|
||||
NameResolver nameResolver = NameSerializationUtil.deserializeNameResolver(in);
|
||||
ProtoBuf.Package packageProto = ProtoBuf.Package.parseFrom(in);
|
||||
return new PackageData(nameResolver, packageProto);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
private final NameResolver nameResolver;
|
||||
|
||||
private final ProtoBuf.Package packageProto;
|
||||
|
||||
public PackageData(@NotNull NameResolver resolver, @NotNull ProtoBuf.Package proto) {
|
||||
nameResolver = resolver;
|
||||
packageProto = proto;
|
||||
}
|
||||
|
||||
public ProtoBuf.Package getPackageProto() {
|
||||
return packageProto;
|
||||
}
|
||||
|
||||
public NameResolver getNameResolver() {
|
||||
return nameResolver;
|
||||
}
|
||||
}
|
||||
+490
@@ -4772,6 +4772,496 @@ public final class ProtoBuf {
|
||||
// @@protoc_insertion_point(class_scope:org.jetbrains.jet.descriptors.serialization.Class)
|
||||
}
|
||||
|
||||
public interface PackageOrBuilder
|
||||
extends com.google.protobuf.MessageLiteOrBuilder {
|
||||
|
||||
// repeated .org.jetbrains.jet.descriptors.serialization.Callable member = 1;
|
||||
java.util.List<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable>
|
||||
getMemberList();
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getMember(int index);
|
||||
int getMemberCount();
|
||||
|
||||
// repeated int32 class_name = 2;
|
||||
java.util.List<java.lang.Integer> getClassNameList();
|
||||
int getClassNameCount();
|
||||
int getClassName(int index);
|
||||
}
|
||||
public static final class Package extends
|
||||
com.google.protobuf.GeneratedMessageLite
|
||||
implements PackageOrBuilder {
|
||||
// Use Package.newBuilder() to construct.
|
||||
private Package(Builder builder) {
|
||||
super(builder);
|
||||
}
|
||||
private Package(boolean noInit) {}
|
||||
|
||||
private static final Package defaultInstance;
|
||||
public static Package getDefaultInstance() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
public Package getDefaultInstanceForType() {
|
||||
return defaultInstance;
|
||||
}
|
||||
|
||||
// repeated .org.jetbrains.jet.descriptors.serialization.Callable member = 1;
|
||||
public static final int MEMBER_FIELD_NUMBER = 1;
|
||||
private java.util.List<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable> member_;
|
||||
public java.util.List<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable> getMemberList() {
|
||||
return member_;
|
||||
}
|
||||
public java.util.List<? extends org.jetbrains.jet.descriptors.serialization.ProtoBuf.CallableOrBuilder>
|
||||
getMemberOrBuilderList() {
|
||||
return member_;
|
||||
}
|
||||
public int getMemberCount() {
|
||||
return member_.size();
|
||||
}
|
||||
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getMember(int index) {
|
||||
return member_.get(index);
|
||||
}
|
||||
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.CallableOrBuilder getMemberOrBuilder(
|
||||
int index) {
|
||||
return member_.get(index);
|
||||
}
|
||||
|
||||
// repeated int32 class_name = 2;
|
||||
public static final int CLASS_NAME_FIELD_NUMBER = 2;
|
||||
private java.util.List<java.lang.Integer> className_;
|
||||
public java.util.List<java.lang.Integer>
|
||||
getClassNameList() {
|
||||
return className_;
|
||||
}
|
||||
public int getClassNameCount() {
|
||||
return className_.size();
|
||||
}
|
||||
public int getClassName(int index) {
|
||||
return className_.get(index);
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
member_ = java.util.Collections.emptyList();
|
||||
className_ = java.util.Collections.emptyList();;
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized != -1) return isInitialized == 1;
|
||||
|
||||
for (int i = 0; i < getMemberCount(); i++) {
|
||||
if (!getMember(i).isInitialized()) {
|
||||
memoizedIsInitialized = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
getSerializedSize();
|
||||
for (int i = 0; i < member_.size(); i++) {
|
||||
output.writeMessage(1, member_.get(i));
|
||||
}
|
||||
for (int i = 0; i < className_.size(); i++) {
|
||||
output.writeInt32(2, className_.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSerializedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
for (int i = 0; i < member_.size(); i++) {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(1, member_.get(i));
|
||||
}
|
||||
{
|
||||
int dataSize = 0;
|
||||
for (int i = 0; i < className_.size(); i++) {
|
||||
dataSize += com.google.protobuf.CodedOutputStream
|
||||
.computeInt32SizeNoTag(className_.get(i));
|
||||
}
|
||||
size += dataSize;
|
||||
size += 1 * getClassNameList().size();
|
||||
}
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
@java.lang.Override
|
||||
protected java.lang.Object writeReplace()
|
||||
throws java.io.ObjectStreamException {
|
||||
return super.writeReplace();
|
||||
}
|
||||
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return newBuilder().mergeFrom(data).buildParsed();
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return newBuilder().mergeFrom(data, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return newBuilder().mergeFrom(data).buildParsed();
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return newBuilder().mergeFrom(data, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeFrom(input).buildParsed();
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeFrom(input, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
Builder builder = newBuilder();
|
||||
if (builder.mergeDelimitedFrom(input)) {
|
||||
return builder.buildParsed();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
Builder builder = newBuilder();
|
||||
if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
|
||||
return builder.buildParsed();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeFrom(input).buildParsed();
|
||||
}
|
||||
public static org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return newBuilder().mergeFrom(input, extensionRegistry)
|
||||
.buildParsed();
|
||||
}
|
||||
|
||||
public static Builder newBuilder() { return Builder.create(); }
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package prototype) {
|
||||
return newBuilder().mergeFrom(prototype);
|
||||
}
|
||||
public Builder toBuilder() { return newBuilder(this); }
|
||||
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessageLite.Builder<
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package, Builder>
|
||||
implements org.jetbrains.jet.descriptors.serialization.ProtoBuf.PackageOrBuilder {
|
||||
// Construct using org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private void maybeForceBuilderInitialization() {
|
||||
}
|
||||
private static Builder create() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
member_ = java.util.Collections.emptyList();
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
className_ = java.util.Collections.emptyList();;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder clone() {
|
||||
return create().mergeFrom(buildPartial());
|
||||
}
|
||||
|
||||
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package getDefaultInstanceForType() {
|
||||
return org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package.getDefaultInstance();
|
||||
}
|
||||
|
||||
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package build() {
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package buildParsed()
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(
|
||||
result).asInvalidProtocolBufferException();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package buildPartial() {
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package result = new org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package(this);
|
||||
int from_bitField0_ = bitField0_;
|
||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
member_ = java.util.Collections.unmodifiableList(member_);
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
}
|
||||
result.member_ = member_;
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
className_ = java.util.Collections.unmodifiableList(className_);
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
}
|
||||
result.className_ = className_;
|
||||
return result;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package other) {
|
||||
if (other == org.jetbrains.jet.descriptors.serialization.ProtoBuf.Package.getDefaultInstance()) return this;
|
||||
if (!other.member_.isEmpty()) {
|
||||
if (member_.isEmpty()) {
|
||||
member_ = other.member_;
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
} else {
|
||||
ensureMemberIsMutable();
|
||||
member_.addAll(other.member_);
|
||||
}
|
||||
|
||||
}
|
||||
if (!other.className_.isEmpty()) {
|
||||
if (className_.isEmpty()) {
|
||||
className_ = other.className_;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
} else {
|
||||
ensureClassNameIsMutable();
|
||||
className_.addAll(other.className_);
|
||||
}
|
||||
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public final boolean isInitialized() {
|
||||
for (int i = 0; i < getMemberCount(); i++) {
|
||||
if (!getMember(i).isInitialized()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
while (true) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
|
||||
return this;
|
||||
default: {
|
||||
if (!parseUnknownField(input, extensionRegistry, tag)) {
|
||||
|
||||
return this;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.Builder subBuilder = org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.newBuilder();
|
||||
input.readMessage(subBuilder, extensionRegistry);
|
||||
addMember(subBuilder.buildPartial());
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
ensureClassNameIsMutable();
|
||||
className_.add(input.readInt32());
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
int length = input.readRawVarint32();
|
||||
int limit = input.pushLimit(length);
|
||||
while (input.getBytesUntilLimit() > 0) {
|
||||
addClassName(input.readInt32());
|
||||
}
|
||||
input.popLimit(limit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int bitField0_;
|
||||
|
||||
// repeated .org.jetbrains.jet.descriptors.serialization.Callable member = 1;
|
||||
private java.util.List<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable> member_ =
|
||||
java.util.Collections.emptyList();
|
||||
private void ensureMemberIsMutable() {
|
||||
if (!((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
member_ = new java.util.ArrayList<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable>(member_);
|
||||
bitField0_ |= 0x00000001;
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.List<org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable> getMemberList() {
|
||||
return java.util.Collections.unmodifiableList(member_);
|
||||
}
|
||||
public int getMemberCount() {
|
||||
return member_.size();
|
||||
}
|
||||
public org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getMember(int index) {
|
||||
return member_.get(index);
|
||||
}
|
||||
public Builder setMember(
|
||||
int index, org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ensureMemberIsMutable();
|
||||
member_.set(index, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder setMember(
|
||||
int index, org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.Builder builderForValue) {
|
||||
ensureMemberIsMutable();
|
||||
member_.set(index, builderForValue.build());
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addMember(org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ensureMemberIsMutable();
|
||||
member_.add(value);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addMember(
|
||||
int index, org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ensureMemberIsMutable();
|
||||
member_.add(index, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addMember(
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.Builder builderForValue) {
|
||||
ensureMemberIsMutable();
|
||||
member_.add(builderForValue.build());
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addMember(
|
||||
int index, org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable.Builder builderForValue) {
|
||||
ensureMemberIsMutable();
|
||||
member_.add(index, builderForValue.build());
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addAllMember(
|
||||
java.lang.Iterable<? extends org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable> values) {
|
||||
ensureMemberIsMutable();
|
||||
super.addAll(values, member_);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder clearMember() {
|
||||
member_ = java.util.Collections.emptyList();
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder removeMember(int index) {
|
||||
ensureMemberIsMutable();
|
||||
member_.remove(index);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// repeated int32 class_name = 2;
|
||||
private java.util.List<java.lang.Integer> className_ = java.util.Collections.emptyList();;
|
||||
private void ensureClassNameIsMutable() {
|
||||
if (!((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
className_ = new java.util.ArrayList<java.lang.Integer>(className_);
|
||||
bitField0_ |= 0x00000002;
|
||||
}
|
||||
}
|
||||
public java.util.List<java.lang.Integer>
|
||||
getClassNameList() {
|
||||
return java.util.Collections.unmodifiableList(className_);
|
||||
}
|
||||
public int getClassNameCount() {
|
||||
return className_.size();
|
||||
}
|
||||
public int getClassName(int index) {
|
||||
return className_.get(index);
|
||||
}
|
||||
public Builder setClassName(
|
||||
int index, int value) {
|
||||
ensureClassNameIsMutable();
|
||||
className_.set(index, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addClassName(int value) {
|
||||
ensureClassNameIsMutable();
|
||||
className_.add(value);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addAllClassName(
|
||||
java.lang.Iterable<? extends java.lang.Integer> values) {
|
||||
ensureClassNameIsMutable();
|
||||
super.addAll(values, className_);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder clearClassName() {
|
||||
className_ = java.util.Collections.emptyList();;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:org.jetbrains.jet.descriptors.serialization.Package)
|
||||
}
|
||||
|
||||
static {
|
||||
defaultInstance = new Package(true);
|
||||
defaultInstance.initFields();
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:org.jetbrains.jet.descriptors.serialization.Package)
|
||||
}
|
||||
|
||||
public interface CallableOrBuilder
|
||||
extends com.google.protobuf.MessageLiteOrBuilder {
|
||||
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.codegen;
|
||||
|
||||
import jet.KotlinInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.descriptors.serialization.PackageData;
|
||||
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class KotlinInfoForPackageTest extends CodegenTestCase {
|
||||
public static final FqName NAMESPACE_NAME = new FqName("test");
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
public void testPackageKotlinInfo() throws Exception {
|
||||
loadText("package " + NAMESPACE_NAME + "\n" +
|
||||
"\n" +
|
||||
"fun foo() = 42\n" +
|
||||
"val bar = 239\n" +
|
||||
"\n" +
|
||||
"class A\n" +
|
||||
"class B\n" +
|
||||
"object C\n");
|
||||
Class aClass = generateClass(PackageClassUtils.getPackageClassFqName(NAMESPACE_NAME).asString());
|
||||
|
||||
assertTrue(aClass.isAnnotationPresent(KotlinInfo.class));
|
||||
KotlinInfo kotlinInfo = (KotlinInfo) aClass.getAnnotation(KotlinInfo.class);
|
||||
|
||||
PackageData data = PackageData.readPackageDataFrom(kotlinInfo.data());
|
||||
|
||||
Set<String> classNames = collectClassNames(data);
|
||||
assertSameElements(Arrays.asList("A", "B", "C"), classNames);
|
||||
|
||||
Set<String> callableNames = collectCallableNames(data);
|
||||
assertSameElements(Arrays.asList("foo", "bar", "C"), callableNames);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<String> collectCallableNames(@NotNull PackageData data) {
|
||||
Set<String> callableNames = new HashSet<String>();
|
||||
List<ProtoBuf.Callable> list = data.getPackageProto().getMemberList();
|
||||
for (ProtoBuf.Callable callable : list) {
|
||||
callableNames.add(data.getNameResolver().getName(callable.getName()).asString());
|
||||
}
|
||||
return callableNames;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Set<String> collectClassNames(@NotNull PackageData data) {
|
||||
Set<String> classNames = new HashSet<String>();
|
||||
for (int name : data.getPackageProto().getClassNameList()) {
|
||||
classNames.add(data.getNameResolver().getName(name).asString());
|
||||
}
|
||||
return classNames;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -32,7 +32,7 @@ import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class WriteSerializedInfoTest extends CodegenTestCase {
|
||||
public class KotlinInfoForClassTest extends CodegenTestCase {
|
||||
public static final FqName NAMESPACE_NAME = new FqName("test");
|
||||
public static final FqNameUnsafe CLASS_NAME = new FqNameUnsafe("A");
|
||||
|
||||
@@ -42,7 +42,7 @@ public class WriteSerializedInfoTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL);
|
||||
}
|
||||
|
||||
public void testKotlinInfo() throws Exception {
|
||||
public void testClassKotlinInfo() throws Exception {
|
||||
loadText("package " + NAMESPACE_NAME + "\n" +
|
||||
"\n" +
|
||||
"class " + CLASS_NAME + " {\n" +
|
||||
Reference in New Issue
Block a user