changeset 29:5c09eb900283

Cleanup of parser code visibility flags. * ClassTransformer.java: Removed prototype, we have a real rewriter now. * dex/ClassData.java: Made class package-private to hide internal API. * dex/ClassDef.java: Likewise. * dex/FieldId.java: Likewise. * dex/Header.java: Likewise. * dex/DexFile.java (getString, getTypeDescriptor, getFieldId): Likewise.
author Michael Starzinger <michi@complang.tuwien.ac.at>
date Thu, 17 Mar 2011 01:30:14 +0100
parents fe791833f7d8
children b3d251cade8a
files src/main/java/org/icedrobot/daneel/ClassTransformer.java src/main/java/org/icedrobot/daneel/dex/ClassData.java src/main/java/org/icedrobot/daneel/dex/ClassDef.java src/main/java/org/icedrobot/daneel/dex/DexFile.java src/main/java/org/icedrobot/daneel/dex/FieldId.java src/main/java/org/icedrobot/daneel/dex/Header.java
diffstat 6 files changed, 44 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/icedrobot/daneel/ClassTransformer.java	Thu Mar 17 01:07:27 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/*
- * Daneel - Dalvik to Java bytecode compiler
- * Copyright (C) 2011  IcedRobot team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.icedrobot.daneel;
-
-import org.icedrobot.daneel.dex.ClassData;
-import org.icedrobot.daneel.dex.ClassDef;
-import org.icedrobot.daneel.dex.FieldId;
-import org.icedrobot.daneel.util.TypeUtil;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Opcodes;
-
-public class ClassTransformer {
-
-    /**
-     * Transforms a given class from Dalvik representation into its equivalent
-     * Java bytecode representation.
-     * 
-     * @param classDef The given class definition as Dalvik representation.
-     * @return The generated Java bytecode representation.
-     */
-    public static byte[] transformClass(ClassDef classDef) {
-        ClassTransformer transformer = new ClassTransformer(classDef);
-        transformer.visitClass();
-        transformer.visitFields();
-        return transformer.visitEnd();
-    }
-
-    private ClassWriter writer;
-
-    private ClassDef classDef;
-
-    private ClassTransformer(ClassDef classDef) {
-        super();
-        this.writer = new ClassWriter(0);
-        this.classDef = classDef;
-    }
-
-    private void visitClass() {
-        int access = classDef.getAccessFlags();
-        String name = TypeUtil.convertDescToInternal(classDef.getClassName());
-        String superName = TypeUtil.convertDescToInternal(classDef.getSuperclass());
-        writer.visit(Opcodes.V1_6, access, name, null, superName, null);
-    }
-
-    private void visitFields() {
-        ClassData classData = classDef.getClassData();
-        for (int i = 0; i < classData.getStaticFieldsSize(); i++) {
-            int access = classData.getStaticFieldsFlag(i);
-            FieldId field = classData.getStaticFieldsId(i);
-            writer.visitField(access, field.getName(),
-                    field.getTypeDescriptor(), null, null);
-        }
-    }
-
-    private byte[] visitEnd() {
-        writer.visitEnd();
-        return writer.toByteArray();
-    }
-}
--- a/src/main/java/org/icedrobot/daneel/dex/ClassData.java	Thu Mar 17 01:07:27 2011 +0100
+++ b/src/main/java/org/icedrobot/daneel/dex/ClassData.java	Thu Mar 17 01:30:14 2011 +0100
@@ -22,7 +22,11 @@
 
 import org.icedrobot.daneel.util.BufferUtil;
 
-public class ClassData {
+/**
+ * A parser class capable of parsing {@code class_data_item} structures as part
+ * of DEX files. Keep package-private to hide internal API.
+ */
+class ClassData {
 
     /**
      * Parses a {@code class_data_item} structure in a DEX file at the buffer's
--- a/src/main/java/org/icedrobot/daneel/dex/ClassDef.java	Thu Mar 17 01:07:27 2011 +0100
+++ b/src/main/java/org/icedrobot/daneel/dex/ClassDef.java	Thu Mar 17 01:30:14 2011 +0100
@@ -20,7 +20,11 @@
 
 import java.nio.ByteBuffer;
 
-public class ClassDef {
+/**
+ * A parser class capable of parsing {@code class_def_item} structures as part
+ * of DEX files. Keep package-private to hide internal API.
+ */
+class ClassDef {
 
     /**
      * Parses a {@code class_def_item} structure in a DEX file at the buffer's
--- a/src/main/java/org/icedrobot/daneel/dex/DexFile.java	Thu Mar 17 01:07:27 2011 +0100
+++ b/src/main/java/org/icedrobot/daneel/dex/DexFile.java	Thu Mar 17 01:30:14 2011 +0100
@@ -112,11 +112,25 @@
         return header;
     }
 
-    public String getString(int idx) {
+    /**
+     * Resolves the given index value to a string value. The index is implicitly
+     * range-checked. Keep package-private to hide internal API.
+     * 
+     * @param idx The index referring to a string value inside this DEX file.
+     * @return The resolved string value.
+     */
+    String getString(int idx) {
         return strings[idx];
     }
 
-    public String getTypeDescriptor(int idx) {
+    /**
+     * Resolves the given index value to a type descriptor. The index is
+     * implicitly range-checked. Keep package-private to hide internal API.
+     * 
+     * @param idx The index referring to a type descriptor inside this DEX file.
+     * @return The resolved type descriptor as string.
+     */
+    String getTypeDescriptor(int idx) {
         return typeDescriptors[idx];
     }
 
@@ -131,7 +145,14 @@
         return protoIds[idx];
     }
 
-    public FieldId getFieldId(int idx) {
+    /**
+     * Resolves the given index value to a field id object. The index is
+     * implicitly range-checked. Keep package-private to hide internal API.
+     * 
+     * @param idx The index referring to a field id inside this DEX file.
+     * @return The resolved field id object.
+     */
+    FieldId getFieldId(int idx) {
         return fieldIds[idx];
     }
 
--- a/src/main/java/org/icedrobot/daneel/dex/FieldId.java	Thu Mar 17 01:07:27 2011 +0100
+++ b/src/main/java/org/icedrobot/daneel/dex/FieldId.java	Thu Mar 17 01:30:14 2011 +0100
@@ -20,7 +20,11 @@
 
 import java.nio.ByteBuffer;
 
-public class FieldId {
+/**
+ * A parser class capable of parsing {@code field_id_item} structures as part of
+ * DEX files. Keep package-private to hide internal API.
+ */
+class FieldId {
 
     /**
      * Parses a {@code field_id_item} structure in a DEX file at the buffer's
--- a/src/main/java/org/icedrobot/daneel/dex/Header.java	Thu Mar 17 01:07:27 2011 +0100
+++ b/src/main/java/org/icedrobot/daneel/dex/Header.java	Thu Mar 17 01:30:14 2011 +0100
@@ -22,7 +22,11 @@
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
-public class Header {
+/**
+ * A parser class capable of parsing {@code header_item} structures as part of
+ * DEX files. Keep package-private to hide internal API.
+ */
+class Header {
 
     public enum Endianess {
         ENDIAN_CONSTANT, REVERSE_ENDIAN_CONSTANT