本文整理汇总了Java中com.android.dx.cf.direct.DirectClassFile.getThisClass方法的典型用法代码示例。如果您正苦于以下问题:Java DirectClassFile.getThisClass方法的具体用法?Java DirectClassFile.getThisClass怎么用?Java DirectClassFile.getThisClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.dx.cf.direct.DirectClassFile
的用法示例。
在下文中一共展示了DirectClassFile.getThisClass方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassAnnotations
import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
* Gets the annotations out of a given class, similar to {@link
* #getAnnotations}, also including annotations for translations
* of class-level attributes {@code EnclosingMethod} and
* {@code InnerClasses}, if present. Additionally, if the
* class is an annotation class, then this also includes a
* representation of all the {@code AnnotationDefault}
* values.
*
* @param cf {@code non-null;} the class in question
* @param args {@code non-null;} the high-level options
* @return {@code non-null;} the set of annotations, which may be empty
*/
public static Annotations getClassAnnotations(DirectClassFile cf,
CfOptions args) {
CstType thisClass = cf.getThisClass();
AttributeList attribs = cf.getAttributes();
Annotations result = getAnnotations(attribs);
Annotation enclosingMethod = translateEnclosingMethod(attribs);
try {
Annotations innerClassAnnotations =
translateInnerClasses(thisClass, attribs,
enclosingMethod == null);
if (innerClassAnnotations != null) {
result = Annotations.combine(result, innerClassAnnotations);
}
} catch (Warning warn) {
args.warn.println("warning: " + warn.getMessage());
}
if (enclosingMethod != null) {
result = Annotations.combine(result, enclosingMethod);
}
if (AccessFlags.isAnnotation(cf.getAccessFlags())) {
Annotation annotationDefault =
translateAnnotationDefaults(cf);
if (annotationDefault != null) {
result = Annotations.combine(result, annotationDefault);
}
}
return result;
}
示例2: translateAnnotationDefaults
import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
* Gets the {@code AnnotationDefault} attributes out of a
* given class, if any, reforming them as an
* {@code AnnotationDefault} annotation.
*
* @param cf {@code non-null;} the class in question
* @return {@code null-ok;} an appropriately-constructed
* {@code AnnotationDefault} annotation, if there were any
* annotation defaults in the class, or {@code null} if not
*/
private static Annotation translateAnnotationDefaults(DirectClassFile cf) {
CstType thisClass = cf.getThisClass();
MethodList methods = cf.getMethods();
int sz = methods.size();
Annotation result =
new Annotation(thisClass, AnnotationVisibility.EMBEDDED);
boolean any = false;
for (int i = 0; i < sz; i++) {
Method one = methods.get(i);
AttributeList attribs = one.getAttributes();
AttAnnotationDefault oneDefault = (AttAnnotationDefault)
attribs.findFirst(AttAnnotationDefault.ATTRIBUTE_NAME);
if (oneDefault != null) {
NameValuePair pair = new NameValuePair(
one.getNat().getName(),
oneDefault.getValue());
result.add(pair);
any = true;
}
}
if (! any) {
return null;
}
result.setImmutable();
return AnnotationUtils.makeAnnotationDefault(result);
}
示例3: translate0
import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
* Performs the main act of translation. This method is separated
* from {@link #translate} just to keep things a bit simpler in
* terms of exception handling.
*
* @param filePath {@code non-null;} the file path for the class,
* excluding any base directory specification
* @param bytes {@code non-null;} contents of the file
* @param cfOptions options for class translation
* @param dexOptions options for dex output
* @return {@code non-null;} the translated class
*/
private static ClassDefItem translate0(String filePath, byte[] bytes,
CfOptions cfOptions, DexOptions dexOptions) {
DirectClassFile cf =
new DirectClassFile(bytes, filePath, cfOptions.strictNameCheck);
cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
cf.getMagic();
OptimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
cfOptions.dontOptimizeListFile);
// Build up a class to output.
CstType thisClass = cf.getThisClass();
int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
cf.getSourceFile();
ClassDefItem out =
new ClassDefItem(thisClass, classAccessFlags,
cf.getSuperclass(), cf.getInterfaces(), sourceFile);
Annotations classAnnotations =
AttributeTranslator.getClassAnnotations(cf, cfOptions);
if (classAnnotations.size() != 0) {
out.setClassAnnotations(classAnnotations);
}
processFields(cf, out);
processMethods(cf, cfOptions, dexOptions, out);
return out;
}
示例4: translate0
import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
* Performs the main act of translation. This method is separated
* from {@link #translate} just to keep things a bit simpler in
* terms of exception handling.
*
* @param cf {@code non-null;} the class file
* @param bytes {@code non-null;} contents of the file
* @param cfOptions options for class translation
* @param dexOptions options for dex output
* @param dexFile {@code non-null;} dex output
* @return {@code non-null;} the translated class
*/
private static ClassDefItem translate0(DirectClassFile cf, byte[] bytes,
CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {
OptimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
cfOptions.dontOptimizeListFile);
// Build up a class to output.
CstType thisClass = cf.getThisClass();
int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
cf.getSourceFile();
ClassDefItem out =
new ClassDefItem(thisClass, classAccessFlags,
cf.getSuperclass(), cf.getInterfaces(), sourceFile);
Annotations classAnnotations =
AttributeTranslator.getClassAnnotations(cf, cfOptions);
if (classAnnotations.size() != 0) {
out.setClassAnnotations(classAnnotations, dexFile);
}
FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
MethodIdsSection methodIdsSection = dexFile.getMethodIds();
processFields(cf, out, dexFile);
processMethods(cf, cfOptions, dexOptions, out, dexFile);
// intern constant pool method, field and type references
ConstantPool constantPool = cf.getConstantPool();
int constantPoolSize = constantPool.size();
for (int i = 0; i < constantPoolSize; i++) {
Constant constant = constantPool.getOrNull(i);
if (constant instanceof CstMethodRef) {
methodIdsSection.intern((CstBaseMethodRef) constant);
} else if (constant instanceof CstInterfaceMethodRef) {
methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
} else if (constant instanceof CstFieldRef) {
fieldIdsSection.intern((CstFieldRef) constant);
} else if (constant instanceof CstEnumRef) {
fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
}
}
return out;
}
示例5: processClass
import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
* Creates an XMLVM element for the given type and appends it to the given
* root element.
*
* @param cf
* the {@link DirectClassFile} instance of this class
* @param root
* the root element to append the generated element to
* @param referencedTypes
* will be filled with the types references in this class file
* @return the generated element
*/
private Element processClass(DirectClassFile cf, Element root,
Map<String, ReferenceKind> referencedTypes) {
Element classElement = new Element("class", NS_XMLVM);
CstType type = cf.getThisClass();
PackagePlusClassName parsedClassName = parseClassName(type.getClassType().getClassName());
addReference(referencedTypes, parsedClassName.toString(), ReferenceKind.SELF);
classElement.setAttribute("name", parsedClassName.className);
classElement.setAttribute("package", parsedClassName.packageName);
String superClassName = "";
// if we are an innerclass add the enclosingMethod
AttEnclosingMethod enclosingMethodAnnotation = (AttEnclosingMethod) cf.getAttributes().findFirst(
AttEnclosingMethod.ATTRIBUTE_NAME);
if (enclosingMethodAnnotation != null) {
CstType enclosingClass=enclosingMethodAnnotation.getEnclosingClass();
CstNat enclosingMethod = enclosingMethodAnnotation.getMethod();
if(enclosingClass!=null){
addReference(referencedTypes, enclosingClass.toHuman(), ReferenceKind.USAGE);
classElement.setAttribute("enclosingClass", enclosingClass.toHuman());
}
if(enclosingMethod!=null){
classElement.setAttribute("enclosingMethod", enclosingMethod.toHuman());
}
}
//get signature annotation if availabke
AttSignature signatureAnnotation=(AttSignature) cf.getAttributes().findFirst(
AttSignature.ATTRIBUTE_NAME);
if(signatureAnnotation!=null){
classElement.setAttribute("signature", signatureAnnotation.getSignature().toHuman());
}
// This can happen for java.lang.Object.
if (cf.getSuperclass() != null) {
superClassName = parseClassName(cf.getSuperclass().getClassType().getClassName())
.toString();
addReference(referencedTypes, superClassName, ReferenceKind.SUPER_CLASS);
}
classElement.setAttribute("extends", superClassName);
processAccessFlags(cf.getAccessFlags(), classElement);
TypeList interfaces = cf.getInterfaces();
if (interfaces.size() > 0) {
String interfaceList = "";
for (int i = 0; i < interfaces.size(); ++i) {
if (i > 0) {
interfaceList += ",";
}
String interfaceName = parseClassName(interfaces.getType(i).getClassName())
.toString();
interfaceList += interfaceName;
addReference(referencedTypes, interfaceName, ReferenceKind.INTERFACE);
}
classElement.setAttribute("interfaces", interfaceList);
}
root.addContent(classElement);
return classElement;
}
示例6: translate0
import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
* Performs the main act of translation. This method is separated
* from {@link #translate} just to keep things a bit simpler in
* terms of exception handling.
*
* @param filePath {@code non-null;} the file path for the class,
* excluding any base directory specification
* @param bytes {@code non-null;} contents of the file
* @param cfOptions options for class translation
* @param dexOptions options for dex output
* @param optimizerOptions options for the optimizer
* @return {@code non-null;} the translated class
*/
private static ClassDefItem translate0(DirectClassFile cf, byte[] bytes,
CfOptions cfOptions, DexOptions dexOptions, OptimizerOptions optimizerOptions, DexFile dexFile) {
optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
cfOptions.dontOptimizeListFile);
// Build up a class to output.
CstType thisClass = cf.getThisClass();
int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
cf.getSourceFile();
ClassDefItem out =
new ClassDefItem(thisClass, classAccessFlags,
cf.getSuperclass(), cf.getInterfaces(), sourceFile);
Annotations classAnnotations =
AttributeTranslator.getClassAnnotations(cf, cfOptions);
if (classAnnotations.size() != 0) {
out.setClassAnnotations(classAnnotations);
}
FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
MethodIdsSection methodIdsSection = dexFile.getMethodIds();
TypeIdsSection typeIdsSection = dexFile.getTypeIds();
processFields(cf, out, fieldIdsSection);
processMethods(cf, cfOptions, dexOptions, optimizerOptions, out, methodIdsSection);
// intern constant pool method, field and type references
ConstantPool constantPool = cf.getConstantPool();
int constantPoolSize = constantPool.size();
for (int i = 0; i < constantPoolSize; i++) {
Constant constant = constantPool.getOrNull(i);
if (constant instanceof CstMethodRef) {
methodIdsSection.intern((CstBaseMethodRef) constant);
} else if (constant instanceof CstInterfaceMethodRef) {
methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
} else if (constant instanceof CstFieldRef) {
fieldIdsSection.intern((CstFieldRef) constant);
} else if (constant instanceof CstEnumRef) {
fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
} else if (constant instanceof CstType) {
typeIdsSection.intern((CstType) constant);
}
}
return out;
}
示例7: translate0
import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
* Performs the main act of translation. This method is separated
* from {@link #translate} just to keep things a bit simpler in
* terms of exception handling.
*
*
* @param context
* @param cf {@code non-null;} the class file
* @param bytes {@code non-null;} contents of the file
* @param cfOptions options for class translation
* @param dexOptions options for dex output
* @param dexFile {@code non-null;} dex output
* @return {@code non-null;} the translated class
*/
private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes,
CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {
context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
cfOptions.dontOptimizeListFile);
// Build up a class to output.
CstType thisClass = cf.getThisClass();
int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
cf.getSourceFile();
ClassDefItem out =
new ClassDefItem(thisClass, classAccessFlags,
cf.getSuperclass(), cf.getInterfaces(), sourceFile);
Annotations classAnnotations =
AttributeTranslator.getClassAnnotations(cf, cfOptions);
if (classAnnotations.size() != 0) {
out.setClassAnnotations(classAnnotations, dexFile);
}
FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
MethodIdsSection methodIdsSection = dexFile.getMethodIds();
processFields(cf, out, dexFile);
processMethods(context, cf, cfOptions, dexOptions, out, dexFile);
// intern constant pool method, field and type references
ConstantPool constantPool = cf.getConstantPool();
int constantPoolSize = constantPool.size();
for (int i = 0; i < constantPoolSize; i++) {
Constant constant = constantPool.getOrNull(i);
if (constant instanceof CstMethodRef) {
methodIdsSection.intern((CstBaseMethodRef) constant);
} else if (constant instanceof CstInterfaceMethodRef) {
methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
} else if (constant instanceof CstFieldRef) {
fieldIdsSection.intern((CstFieldRef) constant);
} else if (constant instanceof CstEnumRef) {
fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
}
}
return out;
}