# HG changeset patch # User Michael Starzinger # Date 1301525669 -7200 # Node ID 19915795c08c2bc34fca5570bb4b0e291355771e # Parent 75d12be4d1eab4effae8aad2bb7f5ac7798bfeb3 Implemented information skipping for parser. * dex/ClassData.java (accept, acceptField, acceptMethod): See above. * dex/ClassDef.java (accept): Likewise. * dex/Code.java (accept): Likewise. * dex/DexFile.java (accept): Pass skipping flags. diff -r 75d12be4d1ea -r 19915795c08c src/main/java/org/icedrobot/daneel/dex/ClassData.java --- a/src/main/java/org/icedrobot/daneel/dex/ClassData.java Thu Mar 31 00:04:19 2011 +0200 +++ b/src/main/java/org/icedrobot/daneel/dex/ClassData.java Thu Mar 31 00:54:29 2011 +0200 @@ -203,38 +203,41 @@ * Allows the given visitor to visit this class data object. * * @param visitor The given DEX class visitor object. + * @param skip Flags indicating which information to skip while visiting. */ - public void accept(DexClassVisitor visitor) { + public void accept(DexClassVisitor visitor, int skip) { // Visit all static fields. for (int i = 0; i < staticFieldsSize; i++) { int access = staticFieldsFlags[i]; FieldId field = staticFieldsIds[i]; Object value = (i < staticValues.length) ? staticValues[i] : null; - acceptField(visitor, access, field, value); + acceptField(visitor, access, field, value, skip); } // Visit all instance fields. for (int i = 0; i < instanceFieldsSize; i++) { int access = instanceFieldsFlags[i]; FieldId field = instanceFieldsIds[i]; - acceptField(visitor, access, field, null); + acceptField(visitor, access, field, null, skip); } // Visit all direct methods. for (int i = 0; i < directMethodsSize; i++) { int access = directMethodsFlags[i]; MethodId method = directMethodsIds[i]; - Code code = directMethodsCode[i]; - acceptMethod(visitor, access, method, code); + Code code = ((skip & DexReader.SKIP_CODE) == 0) ? + directMethodsCode[i] : null; + acceptMethod(visitor, access, method, code, skip); } // Visit all virtual methods. for (int i = 0; i < virtualMethodsSize; i++) { int access = virtualMethodsFlags[i]; MethodId method = virtualMethodsIds[i]; - Code code = virtualMethodsCode[i]; - acceptMethod(visitor, access, method, code); + Code code = ((skip & DexReader.SKIP_CODE) == 0) ? + virtualMethodsCode[i] : null; + acceptMethod(visitor, access, method, code, skip); } } @@ -242,14 +245,16 @@ * Helper method to visit a field. */ private void acceptField(DexClassVisitor visitor, int access, - FieldId field, Object value) { + FieldId field, Object value, int skip) { DexFieldVisitor dfv = visitor.visitField(access, field.getName(), field .getTypeDescriptor(), value); if (dfv == null) return; - AnnotationsDirectory annotations = classDef.getAnnotations(); - if (annotations != null) - annotations.acceptFieldAnnotations(dfv, field); + if ((skip & DexReader.SKIP_ANNOTATIONS) == 0) { + AnnotationsDirectory annotations = classDef.getAnnotations(); + if (annotations != null) + annotations.acceptFieldAnnotations(dfv, field); + } dfv.visitEnd(); } @@ -257,18 +262,20 @@ * Helper method to visit a method. */ private void acceptMethod(DexClassVisitor visitor, int access, - MethodId method, Code code) { + MethodId method, Code code, int skip) { ProtoId proto = method.getProtoId(); DexMethodVisitor dmv = visitor .visitMethod(access, method.getName(), proto.getShorty(), proto.getReturnType(), proto.getParameters()); if (dmv == null) return; - AnnotationsDirectory annotations = classDef.getAnnotations(); - if (annotations != null) - annotations.acceptMethodAnnotations(dmv, method); + if ((skip & DexReader.SKIP_ANNOTATIONS) == 0) { + AnnotationsDirectory annotations = classDef.getAnnotations(); + if (annotations != null) + annotations.acceptMethodAnnotations(dmv, method); + } if (code != null) - code.accept(dmv); + code.accept(dmv, skip); dmv.visitEnd(); } } diff -r 75d12be4d1ea -r 19915795c08c src/main/java/org/icedrobot/daneel/dex/ClassDef.java --- a/src/main/java/org/icedrobot/daneel/dex/ClassDef.java Thu Mar 31 00:04:19 2011 +0200 +++ b/src/main/java/org/icedrobot/daneel/dex/ClassDef.java Thu Mar 31 00:54:29 2011 +0200 @@ -148,15 +148,16 @@ * Allows the given visitor to visit this class definition. * * @param visitor The given DEX class visitor object. + * @param skip Flags indicating which information to skip while visiting. */ - public void accept(DexClassVisitor visitor) { + public void accept(DexClassVisitor visitor, int skip) { visitor.visit(accessFlags, className, superclass, interfaces); if (sourceFile != null) visitor.visitSource(sourceFile); - if (annotations != null) + if (annotations != null && (skip & DexReader.SKIP_ANNOTATIONS) == 0) annotations.acceptClassAnnotations(visitor); if (classData != null) - classData.accept(visitor); + classData.accept(visitor, skip); visitor.visitEnd(); } } diff -r 75d12be4d1ea -r 19915795c08c src/main/java/org/icedrobot/daneel/dex/Code.java --- a/src/main/java/org/icedrobot/daneel/dex/Code.java Thu Mar 31 00:04:19 2011 +0200 +++ b/src/main/java/org/icedrobot/daneel/dex/Code.java Thu Mar 31 00:54:29 2011 +0200 @@ -191,8 +191,9 @@ * Allows the given visitor to visit this code object. * * @param visitor The given DEX method visitor object. + * @param skip Flags indicating which information to skip while visiting. */ - public void accept(DexMethodVisitor visitor) { + public void accept(DexMethodVisitor visitor, int skip) { visitor.visitCode(registersSize, insSize, outsSize); // Visit try-catch block information if available. @@ -203,16 +204,14 @@ // Visit instructions. acceptInsns(visitor); - // Visit local variable information if available. - if (debugInfo != null) + // Visit debug information if available and requested. + if (debugInfo != null && (skip & DexReader.SKIP_DEBUGINFO) == 0) { for (LocalVariable local : debugInfo.getLocalVariables()) visitor.visitLocalVariable(local.name, local.type, local.startLabel, local.endLabel, local.regNum); - - // Visit line number information if available. - if (debugInfo != null) for (LineNumber line : debugInfo.getLineNumbers()) visitor.visitLineNumber(line.source, line.line, line.label); + } } /** diff -r 75d12be4d1ea -r 19915795c08c src/main/java/org/icedrobot/daneel/dex/DexFile.java --- a/src/main/java/org/icedrobot/daneel/dex/DexFile.java Thu Mar 31 00:04:19 2011 +0200 +++ b/src/main/java/org/icedrobot/daneel/dex/DexFile.java Thu Mar 31 00:54:29 2011 +0200 @@ -273,7 +273,7 @@ for (ClassDef classDef : classDefs.values()) { DexClassVisitor dcv = visitor.visitClass(classDef.getClassName()); if (dcv != null) - classDef.accept(dcv); + classDef.accept(dcv, skip); } visitor.visitEnd(); } @@ -285,6 +285,6 @@ if (classDef == null) throw new ClassNotFoundException("Class not defined in DEX file: " + className); - classDef.accept(visitor); + classDef.accept(visitor, skip); } }