[Dashg-commit] SF.net SVN: dashg:[30] trunk/dashg/src/com/mebigfatguy/dashg/DashGUtils. java
Status: Pre-Alpha
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-10-28 19:24:54
|
Revision: 30
http://dashg.svn.sourceforge.net/dashg/?rev=30&view=rev
Author: dbrosius
Date: 2008-10-28 19:24:51 +0000 (Tue, 28 Oct 2008)
Log Message:
-----------
some signature parsing utils
Added Paths:
-----------
trunk/dashg/src/com/mebigfatguy/dashg/DashGUtils.java
Added: trunk/dashg/src/com/mebigfatguy/dashg/DashGUtils.java
===================================================================
--- trunk/dashg/src/com/mebigfatguy/dashg/DashGUtils.java (rev 0)
+++ trunk/dashg/src/com/mebigfatguy/dashg/DashGUtils.java 2008-10-28 19:24:51 UTC (rev 30)
@@ -0,0 +1,114 @@
+/*
+ * dashg - A debug symbols (-g) injector
+ * Copyright (C) 2008 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.mebigfatguy.dashg;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.objectweb.asm.Opcodes;
+
+public final class DashGUtils {
+ private DashGUtils() {
+ }
+
+ public static String getAttribute(int access) {
+ StringBuilder sb = new StringBuilder();
+ if ((access & Opcodes.ACC_PUBLIC) != 0) {
+ sb.append("public ");
+ } else if ((access & Opcodes.ACC_PRIVATE) != 0) {
+ sb.append("private ");
+ } else if ((access & Opcodes.ACC_PROTECTED) != 0) {
+ sb.append("protected ");
+ }
+
+ if ((access & Opcodes.ACC_STATIC) != 0) {
+ sb.append("static ");
+ } else if ((access & Opcodes.ACC_ABSTRACT) != 0) {
+ sb.append("abstract ");
+ }
+
+ if ((access & Opcodes.ACC_FINAL) != 0) {
+ sb.append("final ");
+ }
+
+ return sb.toString();
+ }
+
+ public static String convertType(String type) {
+ char c = type.charAt(0);
+ switch (c) {
+ case 'L':
+ return type.substring(1, type.indexOf(';')).replace('/', '.');
+ case '[':
+ return convertType(type.substring(1)) + "[]";
+ case 'C':
+ return "char";
+ case 'B':
+ return "byte";
+ case 'S':
+ return "short";
+ case 'I':
+ return "int";
+ case 'J':
+ return "long";
+ case 'F':
+ return "float";
+ case 'D':
+ return "double";
+ case 'Z':
+ return "boolean";
+ case 'V':
+ return "void";
+ }
+ throw new RuntimeException("Type not processed: " + type);
+ }
+
+ public static String getReturn(String desc) {
+ int rParenPos = desc.lastIndexOf(')');
+ String type = desc.substring(rParenPos+1);
+ return convertType(type);
+ }
+
+ public static List<String> getArguments(String desc) {
+ int lParenPos = desc.indexOf('(');
+ int rParenPos = desc.lastIndexOf(')');
+ String argString = desc.substring(lParenPos+1, rParenPos);
+
+ List<String> args = new ArrayList<String>();
+ while (argString.length() > 0) {
+ args.add(convertType(argString));
+ argString = skipType(argString);
+ }
+
+ return args;
+ }
+
+ public static String skipType(String type) {
+ if (type.length() == 0)
+ return type;
+
+ if (type.charAt(0) == '[')
+ return skipType(type.substring(1));
+
+ if (type.charAt(0) == 'L')
+ return type.substring(type.indexOf(';') + 1);
+
+ return type.substring(1);
+ }
+}
Property changes on: trunk/dashg/src/com/mebigfatguy/dashg/DashGUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|