IDEA-106787: long string arrays in Groovy stubs

This commit is contained in:
Max Medvedev
2013-05-14 11:03:54 +04:00
parent 841fb61e36
commit e44a4a195c
3 changed files with 17 additions and 8 deletions
@@ -44,9 +44,16 @@ import java.util.List;
*/
public class GrStubUtils {
private static final Logger LOG = Logger.getInstance(GrStubUtils.class);
public static final int TOO_LONG = -1;
public static void writeStringArray(StubOutputStream dataStream, String[] array) throws IOException {
dataStream.writeByte(array.length);
if (array.length >= Byte.MAX_VALUE) {
dataStream.writeByte(TOO_LONG);
dataStream.writeInt(array.length);
}
else {
dataStream.writeByte(array.length);
}
for (String s : array) {
LOG.assertTrue(s != null);
dataStream.writeName(s);
@@ -54,9 +61,12 @@ public class GrStubUtils {
}
public static String[] readStringArray(StubInputStream dataStream) throws IOException {
final byte b = dataStream.readByte();
final String[] annNames = new String[b];
for (int i = 0; i < b; i++) {
int length = dataStream.readByte();
if (length == TOO_LONG) {
length = dataStream.readInt();
}
final String[] annNames = new String[length];
for (int i = 0; i < length; i++) {
annNames[i] = dataStream.readName().toString();
}
return annNames;
@@ -53,8 +53,7 @@ public abstract class GrMethodElementType extends GrStubElementType<GrMethodStub
public void serialize(@NotNull GrMethodStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
GrStubUtils.writeStringArray(dataStream, stub.getAnnotations());
final String[] namedParameters = stub.getNamedParameters();
GrStubUtils.writeStringArray(dataStream, namedParameters.length <= Byte.MAX_VALUE ? namedParameters : ArrayUtil.EMPTY_STRING_ARRAY);
GrStubUtils.writeStringArray(dataStream, stub.getNamedParameters());
GrStubUtils.writeNullableString(dataStream, stub.getTypeText());
dataStream.writeByte(stub.getFlags());
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-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.
@@ -55,7 +55,7 @@ public class GrStubFileElementType extends IStubFileElementType<GrFileStub> {
@Override
public int getStubVersion() {
return super.getStubVersion() + 16;
return super.getStubVersion() + 17;
}
@NotNull