use of com.android.dx.rop.cst.CstArray in project buck by facebook.
the class AnnotationUtils method makeSignature.
/**
* Constructs a standard {@code Signature} annotation.
*
* @param signature {@code non-null;} the signature string
* @return {@code non-null;} the annotation
*/
public static Annotation makeSignature(CstString signature) {
Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);
/*
* Split the string into pieces that are likely to be common
* across many signatures and the rest of the file.
*/
String raw = signature.getString();
int rawLength = raw.length();
ArrayList<String> pieces = new ArrayList<String>(20);
for (int at = 0; at < rawLength; ) /*at*/
{
char c = raw.charAt(at);
int endAt = at + 1;
if (c == 'L') {
// Scan to ';' or '<'. Consume ';' but not '<'.
while (endAt < rawLength) {
c = raw.charAt(endAt);
if (c == ';') {
endAt++;
break;
} else if (c == '<') {
break;
}
endAt++;
}
} else {
// Scan to 'L' without consuming it.
while (endAt < rawLength) {
c = raw.charAt(endAt);
if (c == 'L') {
break;
}
endAt++;
}
}
pieces.add(raw.substring(at, endAt));
at = endAt;
}
int size = pieces.size();
CstArray.List list = new CstArray.List(size);
for (int i = 0; i < size; i++) {
list.set(i, new CstString(pieces.get(i)));
}
list.setImmutable();
result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
result.setImmutable();
return result;
}
use of com.android.dx.rop.cst.CstArray in project buck by facebook.
the class ClassDataItem method makeStaticValuesConstant.
/**
* Gets a {@link CstArray} corresponding to {@link #staticValues} if
* it contains any non-zero non-{@code null} values.
*
* @return {@code null-ok;} the corresponding constant or {@code null} if
* there are no values to encode
*/
private CstArray makeStaticValuesConstant() {
// First sort the statics into their final order.
Collections.sort(staticFields);
/*
* Get the size of staticValues minus any trailing zeros/nulls (both
* nulls per se as well as instances of CstKnownNull).
*/
int size = staticFields.size();
while (size > 0) {
EncodedField field = staticFields.get(size - 1);
Constant cst = staticValues.get(field);
if (cst instanceof CstLiteralBits) {
// Note: CstKnownNull extends CstLiteralBits.
if (((CstLiteralBits) cst).getLongBits() != 0) {
break;
}
} else if (cst != null) {
break;
}
size--;
}
if (size == 0) {
return null;
}
// There is something worth encoding, so build up a result.
CstArray.List list = new CstArray.List(size);
for (int i = 0; i < size; i++) {
EncodedField field = staticFields.get(i);
Constant cst = staticValues.get(field);
if (cst == null) {
cst = Zeroes.zeroFor(field.getRef().getType());
}
list.set(i, cst);
}
list.setImmutable();
return new CstArray(list);
}
use of com.android.dx.rop.cst.CstArray in project buck by facebook.
the class ClassDefItem method addContents.
/** {@inheritDoc} */
@Override
public void addContents(DexFile file) {
TypeIdsSection typeIds = file.getTypeIds();
MixedItemSection byteData = file.getByteData();
MixedItemSection wordData = file.getWordData();
MixedItemSection typeLists = file.getTypeLists();
StringIdsSection stringIds = file.getStringIds();
typeIds.intern(thisClass);
if (!classData.isEmpty()) {
MixedItemSection classDataSection = file.getClassData();
classDataSection.add(classData);
CstArray staticValues = classData.getStaticValuesConstant();
if (staticValues != null) {
staticValuesItem = byteData.intern(new EncodedArrayItem(staticValues));
}
}
if (superclass != null) {
typeIds.intern(superclass);
}
if (interfaces != null) {
interfaces = typeLists.intern(interfaces);
}
if (sourceFile != null) {
stringIds.intern(sourceFile);
}
if (!annotationsDirectory.isEmpty()) {
if (annotationsDirectory.isInternable()) {
annotationsDirectory = wordData.intern(annotationsDirectory);
} else {
wordData.add(annotationsDirectory);
}
}
}
use of com.android.dx.rop.cst.CstArray in project buck by facebook.
the class AnnotationParser method parseValue.
/**
* Parses an annotation value.
*
* @return {@code non-null;} the parsed value
*/
private Constant parseValue() throws IOException {
int tag = input.readUnsignedByte();
if (observer != null) {
CstString humanTag = new CstString(Character.toString((char) tag));
parsed(1, "tag: " + humanTag.toQuoted());
}
switch(tag) {
case 'B':
{
CstInteger value = (CstInteger) parseConstant();
return CstByte.make(value.getValue());
}
case 'C':
{
CstInteger value = (CstInteger) parseConstant();
int intValue = value.getValue();
return CstChar.make(value.getValue());
}
case 'D':
{
CstDouble value = (CstDouble) parseConstant();
return value;
}
case 'F':
{
CstFloat value = (CstFloat) parseConstant();
return value;
}
case 'I':
{
CstInteger value = (CstInteger) parseConstant();
return value;
}
case 'J':
{
CstLong value = (CstLong) parseConstant();
return value;
}
case 'S':
{
CstInteger value = (CstInteger) parseConstant();
return CstShort.make(value.getValue());
}
case 'Z':
{
CstInteger value = (CstInteger) parseConstant();
return CstBoolean.make(value.getValue());
}
case 'c':
{
int classInfoIndex = input.readUnsignedShort();
CstString value = (CstString) pool.get(classInfoIndex);
Type type = Type.internReturnType(value.getString());
if (observer != null) {
parsed(2, "class_info: " + type.toHuman());
}
return new CstType(type);
}
case 's':
{
return parseConstant();
}
case 'e':
{
requireLength(4);
int typeNameIndex = input.readUnsignedShort();
int constNameIndex = input.readUnsignedShort();
CstString typeName = (CstString) pool.get(typeNameIndex);
CstString constName = (CstString) pool.get(constNameIndex);
if (observer != null) {
parsed(2, "type_name: " + typeName.toHuman());
parsed(2, "const_name: " + constName.toHuman());
}
return new CstEnumRef(new CstNat(constName, typeName));
}
case '@':
{
Annotation annotation = parseAnnotation(AnnotationVisibility.EMBEDDED);
return new CstAnnotation(annotation);
}
case '[':
{
requireLength(2);
int numValues = input.readUnsignedShort();
CstArray.List list = new CstArray.List(numValues);
if (observer != null) {
parsed(2, "num_values: " + numValues);
changeIndent(1);
}
for (int i = 0; i < numValues; i++) {
if (observer != null) {
changeIndent(-1);
parsed(0, "element_value[" + i + "]:");
changeIndent(1);
}
list.set(i, parseValue());
}
if (observer != null) {
changeIndent(-1);
}
list.setImmutable();
return new CstArray(list);
}
default:
{
throw new ParseException("unknown annotation tag: " + Hex.u1(tag));
}
}
}
use of com.android.dx.rop.cst.CstArray in project J2ME-Loader by nikita36078.
the class AnnotationUtils method makeMemberClasses.
/**
* Constructs a standard {@code MemberClasses} annotation.
*
* @param types {@code non-null;} the list of (the types of) the member classes
* @return {@code non-null;} the annotation
*/
public static Annotation makeMemberClasses(TypeList types) {
CstArray array = makeCstArray(types);
Annotation result = new Annotation(MEMBER_CLASSES_TYPE, SYSTEM);
result.put(new NameValuePair(VALUE_STRING, array));
result.setImmutable();
return result;
}
Aggregations