Usages of

com.ibm.wala.types.TypeName.findOrCreate(?, ?, ?)
static TypeName getTypeName(TypeIdItem fieldType) { ImmutableByteArray fieldTypeArray = ImmutableByteArray.make(fieldType.getTypeDescriptor()); TypeName T = null; if (fieldTypeArray.get(fieldTypeArray.length() - 1) == ';') { T = TypeName.findOrCreate(fieldTypeArray, 0, fieldTypeArray.length() - 1); } else { T = TypeName.findOrCreate(fieldTypeArray); } return T; }
static TypeName getTypeName(String fieldType) { ImmutableByteArray fieldTypeArray = ImmutableByteArray.make(fieldType); TypeName T = null; if (fieldTypeArray.get(fieldTypeArray.length() - 1) == ';') { T = TypeName.findOrCreate(fieldTypeArray, 0, fieldTypeArray.length() - 1); } else { T = TypeName.findOrCreate(fieldTypeArray); } return T; }
protected void addFieldToList(List<FieldImpl> L, Atom name, ImmutableByteArray fieldType, int accessFlags, Collection<Annotation> annotations, TypeSignature sig) { TypeName T = null; if (fieldType.get(fieldType.length() - 1) == ';') { T = TypeName.findOrCreate(fieldType, 0, fieldType.length() - 1); } else { T = TypeName.findOrCreate(fieldType); } TypeReference type = TypeReference.findOrCreate(getClassLoader().getReference(), T); FieldReference fr = FieldReference.findOrCreate(getReference(), name, type); FieldImpl f = new FieldImpl(this, fr, accessFlags, annotations, sig); L.add(f); }
protected void addFieldToList(List<FieldImpl> L, Atom name, ImmutableByteArray fieldType, int accessFlags, Collection<Annotation> annotations, Collection<TypeAnnotation> typeAnnotations, TypeSignature sig) { TypeName T = null; if (fieldType.get(fieldType.length() - 1) == ';') { T = TypeName.findOrCreate(fieldType, 0, fieldType.length() - 1); } else { T = TypeName.findOrCreate(fieldType); } TypeReference type = TypeReference.findOrCreate(getClassLoader().getReference(), T); FieldReference fr = FieldReference.findOrCreate(getReference(), name, type); FieldImpl f = new FieldImpl(this, fr, accessFlags, annotations, typeAnnotations, sig); L.add(f); }
protected void addFieldToList(List<FieldImpl> L, Atom name, ImmutableByteArray fieldType, int accessFlags, Collection<Annotation> annotations) { TypeName T = null; if (fieldType.get(fieldType.length() - 1) == ';') { T = TypeName.findOrCreate(fieldType, 0, fieldType.length() - 1); } else { T = TypeName.findOrCreate(fieldType); } TypeReference type = TypeReference.findOrCreate(getClassLoader().getReference(), T); FieldReference fr = FieldReference.findOrCreate(getReference(), name, type); FieldImpl f = new FieldImpl(this, fr, accessFlags, annotations); L.add(f); }
public class DexIField implements IField { /* * The EncodedFied object for which this DexIField is a wrapper */ private final EncodedField eField; /** * The declaring class for this method. */ private final DexIClass myClass; /** * name of the return type for this method, * construct in the get return type method. */ //private TypeReference typeReference; /** * canonical FieldReference corresponding to this method, * construct in the getReference method. */ private FieldReference fieldReference, myFieldRef; private Atom name; public DexIField(EncodedField encodedField, DexIClass klass) { //public DexIField(EncodedField encodedField) { eField = encodedField; myClass = klass; name = Atom.findOrCreateUnicodeAtom(eField.field.getFieldName().getStringValue()); ImmutableByteArray fieldType = ImmutableByteArray.make(eField.field.getFieldType().getTypeDescriptor()); TypeName T = null; if (fieldType.get(fieldType.length() - 1) == ';') { T = TypeName.findOrCreate(fieldType, 0, fieldType.length() - 1); } else { T = TypeName.findOrCreate(fieldType); } TypeReference type = TypeReference.findOrCreate(myClass.getClassLoader().getReference(), T); myFieldRef = FieldReference.findOrCreate(myClass.getReference(), name, type); } public TypeReference getFieldTypeReference() { //compute the typeReference from the EncodedField // if (typeReference == null) { // typeReference = TypeReference.findOrCreate(myClass.getClassLoader() // .getReference(), eField.field.getFieldType().getTypeDescriptor()); // } // return typeReference; return myFieldRef.getFieldType(); } public FieldReference getReference() { if (fieldReference == null) { // fieldReference = FieldReference.findOrCreate(myClass.getReference(), // eField.field.getContainingClass().getTypeDescriptor(), eField.field.getFieldName().getStringValue(), // eField.field.getFieldType().getTypeDescriptor()); fieldReference = FieldReference.findOrCreate(myClass.getReference(), getName(), getFieldTypeReference()); } return fieldReference; } public Atom getName() { return name; } public boolean isFinal() { return (eField.accessFlags & FINAL.getValue()) != 0; } public boolean isPrivate() { return (eField.accessFlags & PRIVATE.getValue()) != 0; } public boolean isProtected() { return (eField.accessFlags & PROTECTED.getValue()) != 0; } public boolean isPublic() { return (eField.accessFlags & PUBLIC.getValue()) != 0; } public boolean isStatic() { return (eField.accessFlags & STATIC.getValue()) != 0; } public IClass getDeclaringClass() { return myClass; } public boolean isVolatile() { return (eField.accessFlags & VOLATILE.getValue()) != 0; } public IClassHierarchy getClassHierarchy() { return myClass.getClassHierarchy(); } @Override public Collection<Annotation> getAnnotations() { throw new UnsupportedOperationException(); } }
public class DexIField implements IField { /* * The EncodedFied object for which this DexIField is a wrapper */ private final EncodedField eField; /** * The declaring class for this method. */ private final DexIClass myClass; /** * name of the return type for this method, * construct in the get return type method. */ //private TypeReference typeReference; /** * canonical FieldReference corresponding to this method, * construct in the getReference method. */ private FieldReference fieldReference, myFieldRef; private Atom name; public DexIField(EncodedField encodedField, DexIClass klass) { //public DexIField(EncodedField encodedField) { eField = encodedField; myClass = klass; name = Atom.findOrCreateUnicodeAtom(eField.field.getFieldName().getStringValue()); ImmutableByteArray fieldType = ImmutableByteArray.make(eField.field.getFieldType().getTypeDescriptor()); TypeName T = null; if (fieldType.get(fieldType.length() - 1) == ';') { T = TypeName.findOrCreate(fieldType, 0, fieldType.length() - 1); } else { T = TypeName.findOrCreate(fieldType); } TypeReference type = TypeReference.findOrCreate(myClass.getClassLoader().getReference(), T); myFieldRef = FieldReference.findOrCreate(myClass.getReference(), name, type); } public TypeReference getFieldTypeReference() { //compute the typeReference from the EncodedField // if (typeReference == null) { // typeReference = TypeReference.findOrCreate(myClass.getClassLoader() // .getReference(), eField.field.getFieldType().getTypeDescriptor()); // } // return typeReference; return myFieldRef.getFieldType(); } public FieldReference getReference() { if (fieldReference == null) { // fieldReference = FieldReference.findOrCreate(myClass.getReference(), // eField.field.getContainingClass().getTypeDescriptor(), eField.field.getFieldName().getStringValue(), // eField.field.getFieldType().getTypeDescriptor()); fieldReference = FieldReference.findOrCreate(myClass.getReference(), getName(), getFieldTypeReference()); } return fieldReference; } public Atom getName() { return name; } public boolean isFinal() { return (eField.accessFlags & FINAL.getValue()) != 0; } public boolean isPrivate() { return (eField.accessFlags & PRIVATE.getValue()) != 0; } public boolean isProtected() { return (eField.accessFlags & PROTECTED.getValue()) != 0; } public boolean isPublic() { return (eField.accessFlags & PUBLIC.getValue()) != 0; } public boolean isStatic() { return (eField.accessFlags & STATIC.getValue()) != 0; } public IClass getDeclaringClass() { return myClass; } public boolean isVolatile() { return (eField.accessFlags & VOLATILE.getValue()) != 0; } public IClassHierarchy getClassHierarchy() { return myClass.getClassHierarchy(); } @Override public Collection<Annotation> getAnnotations() { // TODO Auto-generated method stub return Collections.emptySet(); } }
/** * Parse method descriptor to obtain descriptions of method's parameters. * * @return parameter descriptions, or null if there are no parameters * @throws IllegalArgumentException if b is null */ public static final TypeName[] parseForParameterNames(Language l, ImmutableByteArray b) throws IllegalArgumentException { if (b == null) { throw new IllegalArgumentException("b is null"); } if (b.length() <= 2) { throw new IllegalArgumentException("invalid descriptor: " + b); } if (b.get(0) != '(') { throw new IllegalArgumentException("invalid descriptor: " + b); } ArrayList<TypeName> sigs = new ArrayList<TypeName>(10); int i = 1; while (true) { switch (b.get(i++)) { case TypeReference.VoidTypeCode: sigs.add(TypeReference.VoidName); continue; case TypeReference.BooleanTypeCode: sigs.add(TypeReference.BooleanName); continue; case TypeReference.ByteTypeCode: sigs.add(TypeReference.ByteName); continue; case TypeReference.ShortTypeCode: sigs.add(TypeReference.ShortName); continue; case TypeReference.IntTypeCode: sigs.add(TypeReference.IntName); continue; case TypeReference.LongTypeCode: sigs.add(TypeReference.LongName); continue; case TypeReference.FloatTypeCode: sigs.add(TypeReference.FloatName); continue; case TypeReference.DoubleTypeCode: sigs.add(TypeReference.DoubleName); continue; case TypeReference.CharTypeCode: sigs.add(TypeReference.CharName); continue; case TypeReference.OtherPrimitiveTypeCode: { int off = i - 1; while (b.get(i++) != ';') ; sigs.add(l.lookupPrimitiveType(new String(b.substring(off + 1, i - off - 2)))); continue; } case TypeReference.ClassTypeCode: { int off = i - 1; while (b.get(i++) != ';') ; sigs.add(TypeName.findOrCreate(b, off, i - off - 1)); continue; } case TypeReference.ArrayTypeCode: { int off = i - 1; while (b.get(i) == TypeReference.ArrayTypeCode) { ++i; } TypeName T = null; byte c = b.get(i++); if (c == TypeReference.ClassTypeCode) { while (b.get(i++) != ';') ; T = TypeName.findOrCreate(b, off, i - off - 1); } else if (c == TypeReference.OtherPrimitiveTypeCode) { int typeOff = i; while (b.get(i++) != ';') ; T = l.lookupPrimitiveType(new String(b.substring(typeOff, i - typeOff - 1))); while (--typeOff > off) { T = T.getArrayTypeForElementType(); } } else { T = TypeName.findOrCreate(b, off, i - off); } sigs.add(T); continue; } case (byte) ')': // end of parameter list int size = sigs.size(); if (size == 0) { return null; } Iterator<TypeName> it = sigs.iterator(); TypeName[] result = new TypeName[size]; for (int j = 0; j < size; j++) { result[j] = it.next(); } return result; default: assert false : "bad descriptor " + b; } } }
/** * @param type a type as a String returned by Shrike */ public static TypeReference makeTypeReference(ClassLoaderReference loader, String type) throws IllegalArgumentException { if (type == null) { throw new IllegalArgumentException("null type"); } TypeReference p = primitiveMap.get(type); if (p != null) { return p; } ImmutableByteArray b = ImmutableByteArray.make(type); TypeName T = null; /*if (b.get(0) != '[') { T = TypeName.findOrCreate(b, 0, b.length() - 1); } else {*/ if (b.get(b.length() - 1) == ';') { T = TypeName.findOrCreate(b, 0, b.length() - 1); } else { T = TypeName.findOrCreate(b); } //} return TypeReference.findOrCreate(loader, T); }
/** * Parse method descriptor to obtain description of method's return type. TODO: tune this .. probably combine with * parseForParameters. * * @param b method descriptor - something like "(III)V" * @return type description * @throws IllegalArgumentException if b is null */ public static final TypeName parseForReturnTypeName(Language l, ImmutableByteArray b) throws IllegalArgumentException { if (b == null) { throw new IllegalArgumentException("b is null"); } if (b.length() <= 2) { throw new IllegalArgumentException("invalid descriptor: " + b); } if (b.get(0) != '(') { throw new IllegalArgumentException("invalid descriptor: " + b); } int i = 0; while (b.get(i++) != ')') ; if (b.length() < i + 1) { throw new IllegalArgumentException("invalid descriptor: " + b); } switch (b.get(i)) { case TypeReference.VoidTypeCode: return TypeReference.Void.getName(); case TypeReference.BooleanTypeCode: return TypeReference.Boolean.getName(); case TypeReference.ByteTypeCode: return TypeReference.Byte.getName(); case TypeReference.ShortTypeCode: return TypeReference.Short.getName(); case TypeReference.IntTypeCode: return TypeReference.Int.getName(); case TypeReference.LongTypeCode: return TypeReference.Long.getName(); case TypeReference.FloatTypeCode: return TypeReference.Float.getName(); case TypeReference.DoubleTypeCode: return TypeReference.Double.getName(); case TypeReference.CharTypeCode: return TypeReference.Char.getName(); case TypeReference.OtherPrimitiveTypeCode: if (b.get(b.length() - 1) == ';') { return l.lookupPrimitiveType(new String(b.substring(i + 1, b.length() - i - 2))); } else { return l.lookupPrimitiveType(new String(b.substring(i + 1, b.length() - i - 1))); } case TypeReference.ClassTypeCode: // fall through case TypeReference.ArrayTypeCode: if (b.get(b.length() - 1) == ';') { return TypeName.findOrCreate(b, i, b.length() - i - 1); } else { return TypeName.findOrCreate(b, i, b.length() - i); } default: throw new IllegalArgumentException("unexpected type in descriptor " + b); } }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes