use of com.android.dx.rop.annotation.Annotation in project J2ME-Loader by nikita36078.
the class Main method dumpMethod.
/**
* Dumps any method with the given name in the given file.
*
* @param dex {@code non-null;} the dex file
* @param fqName {@code non-null;} the fully-qualified name of the
* method(s)
* @param out {@code non-null;} where to dump to
*/
private void dumpMethod(DexFile dex, String fqName, OutputStreamWriter out) {
boolean wildcard = fqName.endsWith("*");
int lastDot = fqName.lastIndexOf('.');
if ((lastDot <= 0) || (lastDot == (fqName.length() - 1))) {
context.err.println("bogus fully-qualified method name: " + fqName);
return;
}
String className = fqName.substring(0, lastDot).replace('.', '/');
String methodName = fqName.substring(lastDot + 1);
ClassDefItem clazz = dex.getClassOrNull(className);
if (clazz == null) {
context.err.println("no such class: " + className);
return;
}
if (wildcard) {
methodName = methodName.substring(0, methodName.length() - 1);
}
ArrayList<EncodedMethod> allMeths = clazz.getMethods();
TreeMap<CstNat, EncodedMethod> meths = new TreeMap<CstNat, EncodedMethod>();
/*
* Figure out which methods to include in the output, and get them
* all sorted, so that the printout code is robust with respect to
* changes in the underlying order.
*/
for (EncodedMethod meth : allMeths) {
String methName = meth.getName().getString();
if ((wildcard && methName.startsWith(methodName)) || (!wildcard && methName.equals(methodName))) {
meths.put(meth.getRef().getNat(), meth);
}
}
if (meths.size() == 0) {
context.err.println("no such method: " + fqName);
return;
}
PrintWriter pw = new PrintWriter(out);
for (EncodedMethod meth : meths.values()) {
// TODO: Better stuff goes here, perhaps.
meth.debugPrint(pw, args.verboseDump);
/*
* The (default) source file is an attribute of the class, but
* it's useful to see it in method dumps.
*/
CstString sourceFile = clazz.getSourceFile();
if (sourceFile != null) {
pw.println(" source file: " + sourceFile.toQuoted());
}
Annotations methodAnnotations = clazz.getMethodAnnotations(meth.getRef());
AnnotationsList parameterAnnotations = clazz.getParameterAnnotations(meth.getRef());
if (methodAnnotations != null) {
pw.println(" method annotations:");
for (Annotation a : methodAnnotations.getAnnotations()) {
pw.println(" " + a);
}
}
if (parameterAnnotations != null) {
pw.println(" parameter annotations:");
int sz = parameterAnnotations.size();
for (int i = 0; i < sz; i++) {
pw.println(" parameter " + i);
Annotations annotations = parameterAnnotations.get(i);
for (Annotation a : annotations.getAnnotations()) {
pw.println(" " + a);
}
}
}
}
pw.flush();
}
use of com.android.dx.rop.annotation.Annotation in project J2ME-Loader by nikita36078.
the class AttributeTranslator method getAnnotations.
/**
* Gets the annotations out of a given {@link AttributeList}. This
* combines both visible and invisible annotations into a single
* result set and also adds in a system annotation for the
* {@code Signature} attribute if present.
*
* @param attribs {@code non-null;} the attributes list to search in
* @return {@code non-null;} the set of annotations, which may be empty
*/
public static Annotations getAnnotations(AttributeList attribs) {
Annotations result = getAnnotations0(attribs);
Annotation signature = getSignature(attribs);
Annotation sourceDebugExtension = getSourceDebugExtension(attribs);
if (signature != null) {
result = Annotations.combine(result, signature);
}
if (sourceDebugExtension != null) {
result = Annotations.combine(result, sourceDebugExtension);
}
return result;
}
use of com.android.dx.rop.annotation.Annotation in project J2ME-Loader by nikita36078.
the class AnnotationUtils method makeEnclosingClass.
/**
* Constructs a standard {@code EnclosingClass} annotation.
*
* @param clazz {@code non-null;} the enclosing class
* @return {@code non-null;} the annotation
*/
public static Annotation makeEnclosingClass(CstType clazz) {
Annotation result = new Annotation(ENCLOSING_CLASS_TYPE, SYSTEM);
result.put(new NameValuePair(VALUE_STRING, clazz));
result.setImmutable();
return result;
}
use of com.android.dx.rop.annotation.Annotation in project J2ME-Loader by nikita36078.
the class AnnotationUtils method makeEnclosingMethod.
/**
* Constructs a standard {@code EnclosingMethod} annotation.
*
* @param method {@code non-null;} the enclosing method
* @return {@code non-null;} the annotation
*/
public static Annotation makeEnclosingMethod(CstMethodRef method) {
Annotation result = new Annotation(ENCLOSING_METHOD_TYPE, SYSTEM);
result.put(new NameValuePair(VALUE_STRING, method));
result.setImmutable();
return result;
}
use of com.android.dx.rop.annotation.Annotation 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