use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.
the class AnnotationLister method process.
/** Processes based on configuration specified in constructor. */
void process() {
for (String path : args.files) {
ClassPathOpener opener;
opener = new ClassPathOpener(path, true, new ClassPathOpener.Consumer() {
public boolean processFileBytes(String name, long lastModified, byte[] bytes) {
if (!name.endsWith(".class")) {
return true;
}
ByteArray ba = new ByteArray(bytes);
DirectClassFile cf = new DirectClassFile(ba, name, true);
cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
AttributeList attributes = cf.getAttributes();
Attribute att;
String cfClassName = cf.getThisClass().getClassType().getClassName();
if (cfClassName.endsWith(PACKAGE_INFO)) {
att = attributes.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
for (; att != null; att = attributes.findNext(att)) {
BaseAnnotations ann = (BaseAnnotations) att;
visitPackageAnnotation(cf, ann);
}
att = attributes.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
for (; att != null; att = attributes.findNext(att)) {
BaseAnnotations ann = (BaseAnnotations) att;
visitPackageAnnotation(cf, ann);
}
} else if (isMatchingInnerClass(cfClassName) || isMatchingPackage(cfClassName)) {
printMatch(cf);
} else {
att = attributes.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
for (; att != null; att = attributes.findNext(att)) {
BaseAnnotations ann = (BaseAnnotations) att;
visitClassAnnotation(cf, ann);
}
att = attributes.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
for (; att != null; att = attributes.findNext(att)) {
BaseAnnotations ann = (BaseAnnotations) att;
visitClassAnnotation(cf, ann);
}
}
return true;
}
public void onException(Exception ex) {
throw new RuntimeException(ex);
}
public void onProcessArchiveStart(File file) {
}
});
opener.process();
}
}
use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.
the class ClassDumper method dump.
/**
* Does the dumping.
*/
public void dump() {
byte[] bytes = getBytes();
ByteArray ba = new ByteArray(bytes);
DirectClassFile cf = new DirectClassFile(ba, getFilePath(), getStrictParse());
cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
cf.setObserver(this);
// Force parsing to happen.
cf.getMagic();
int at = getAt();
if (at != bytes.length) {
parsed(ba, at, bytes.length - at, "<extra data at end of file>");
}
}
use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.
the class ClassReferenceListBuilder method addClassWithHierachy.
private void addClassWithHierachy(String classBinaryName) {
if (classNames.contains(classBinaryName)) {
return;
}
try {
DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
classNames.add(classBinaryName);
CstType superClass = classFile.getSuperclass();
if (superClass != null) {
addClassWithHierachy(superClass.getClassType().getClassName());
}
TypeList interfaceList = classFile.getInterfaces();
int interfaceNumber = interfaceList.size();
for (int i = 0; i < interfaceNumber; i++) {
addClassWithHierachy(interfaceList.getType(i).getClassName());
}
} catch (FileNotFoundException e) {
// Ignore: The referenced type is not in the path it must be part of the libraries.
}
}
use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.
the class ClassReferenceListBuilder method addRoots.
/**
* @param jarOfRoots Archive containing the class files resulting of the tracing, typically
* this is the result of running ProGuard.
*/
public void addRoots(ZipFile jarOfRoots) throws IOException {
// keep roots
for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = entries.nextElement();
String name = entry.getName();
if (name.endsWith(CLASS_EXTENSION)) {
classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length()));
}
}
// keep direct references of roots (+ direct references hierarchy)
for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = entries.nextElement();
String name = entry.getName();
if (name.endsWith(CLASS_EXTENSION)) {
DirectClassFile classFile;
try {
classFile = path.getClass(name);
} catch (FileNotFoundException e) {
throw new IOException("Class " + name + " is missing form original class path " + path, e);
}
addDependencies(classFile.getConstantPool());
}
}
}
use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.
the class Path method getClass.
synchronized DirectClassFile getClass(String path) throws FileNotFoundException {
DirectClassFile classFile = null;
for (ClassPathElement element : elements) {
try {
InputStream in = element.open(path);
try {
byte[] bytes = readStream(in, baos, readBuffer);
baos.reset();
classFile = new DirectClassFile(bytes, path, false);
classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
break;
} finally {
in.close();
}
} catch (IOException e) {
// search next element
}
}
if (classFile == null) {
throw new FileNotFoundException("File \"" + path + "\" not found");
}
return classFile;
}
Aggregations