KotlinInfo data parameter is now String[]

This is done because byte arrays in annotation arguments cannot be longer than
65535 bytes, and serialized data's length for kotlin.KotlinPackage class from
stdlib is already close to this number
This commit is contained in:
Alexander Udalov
2013-07-08 20:09:42 +04:00
parent 93d200be82
commit d0b84416b5
9 changed files with 165 additions and 26 deletions
+1
View File
@@ -17,6 +17,7 @@
<orderEntry type="library" name="idea-full" level="project" />
<orderEntry type="library" name="dx-android" level="project" />
<orderEntry type="module" module-name="serialization" />
<orderEntry type="module" module-name="serialization.java" />
</component>
</module>
@@ -19,6 +19,7 @@ package org.jetbrains.jet.codegen;
import jet.KotlinInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.descriptors.serialization.JavaProtoBufUtil;
import org.jetbrains.jet.descriptors.serialization.PackageData;
import org.jetbrains.jet.descriptors.serialization.ProtoBuf;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
@@ -29,8 +30,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.google.protobuf.ExtensionRegistryLite.getEmptyRegistry;
public class KotlinInfoForPackageTest extends CodegenTestCase {
public static final FqName NAMESPACE_NAME = new FqName("test");
@@ -54,7 +53,7 @@ public class KotlinInfoForPackageTest extends CodegenTestCase {
assertTrue(aClass.isAnnotationPresent(KotlinInfo.class));
KotlinInfo kotlinInfo = (KotlinInfo) aClass.getAnnotation(KotlinInfo.class);
PackageData data = PackageData.read(kotlinInfo.data(), getEmptyRegistry());
PackageData data = JavaProtoBufUtil.readPackageDataFrom(kotlinInfo.data());
Set<String> classNames = collectClassNames(data);
assertSameElements(Arrays.asList("A", "B", "C"), classNames);
@@ -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 com.intellij.testFramework.UsefulTestCase;
import java.util.Random;
import static org.jetbrains.jet.descriptors.serialization.JavaProtoBufUtil.decodeBytes;
import static org.jetbrains.jet.descriptors.serialization.JavaProtoBufUtil.encodeBytes;
import static org.junit.Assert.assertArrayEquals;
public class JavaProtoBufUtilTest extends UsefulTestCase {
private static final int[] LENGTHS = new int[] {0, 1, 2, 3, 7, 10, 100, 1000, 32000, 33000, 65000, 65534, 65535, 65536, 65537,
100000, 131074, 239017, 314159, 1000000};
private static void doTest(int randSeed, int length) {
byte[] a = new byte[length];
new Random(randSeed).nextBytes(a);
String message = "Failed randSeed = " + randSeed + ", length = " + length;
String[] b = encodeBytes(a);
byte[] c = decodeBytes(b);
assertArrayEquals(message, a, c);
String[] d = encodeBytes(c);
assertArrayEquals(message, d, b);
byte[] e = decodeBytes(d);
assertArrayEquals(message, a, e);
}
public void testEncodeDecode() {
for (int randSeed = 1; randSeed <= 3; randSeed++) {
for (int length : LENGTHS) {
doTest(randSeed, length);
}
}
}
}
@@ -32,8 +32,6 @@ import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import java.io.IOException;
import static com.google.protobuf.ExtensionRegistryLite.getEmptyRegistry;
public class KotlinInfoForClassTest extends CodegenTestCase {
public static final FqName NAMESPACE_NAME = new FqName("test");
public static final FqNameUnsafe CLASS_NAME = new FqNameUnsafe("A");
@@ -41,7 +39,7 @@ public class KotlinInfoForClassTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL);
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
public void testClassKotlinInfo() throws Exception {
@@ -70,7 +68,7 @@ public class KotlinInfoForClassTest extends CodegenTestCase {
public KotlinInfoBasedDescriptorFinder(@NotNull KotlinInfo kotlinInfo) throws IOException {
super(new LockBasedStorageManager(), AnnotationDeserializer.UNSUPPORTED);
this.classData = ClassData.read(kotlinInfo.data(), getEmptyRegistry());
this.classData = JavaProtoBufUtil.readClassDataFrom(kotlinInfo.data());
this.namespace = JetTestUtils.createTestNamespace(NAMESPACE_NAME.shortName());
}