1 /*
 2  * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 package org.openjdk.asmtools.jdis;
24 
25 /**
26  *
27  */
28 public class Utils {
29 
30     static public String javaName(String name) {
31         if (name == null) {
32             return "null";
33         }
34         int len = name.length();
35         if (len == 0) {
36             return "\"\"";
37         }
38         char cc = '/';
39 fullname:
40         { // xxx/yyy/zzz
41             for (int k = 0; k < len; k++) {
42                 char c = name.charAt(k);
43                 if (cc == '/') {
44                     if (!Character.isJavaIdentifierStart(c) && c != '-') {
45                         break fullname;
46                     }
47                 } else if (c != '/') {
48                     if (!Character.isJavaIdentifierPart(c) && c != '-') {
49                         break fullname;
50                     }
51                 }
52                 cc = c;
53             }
54             return name;
55         }
56         return "\"" + name + "\"";
57     }
58 
59     static public boolean isClassArrayDescriptor(String name) {
60         boolean retval = false;
61         if (name != null) {
62             if (name.startsWith("[")) {
63                 retval = true;
64             }
65         }
66 
67         return retval;
68     }
69 
70     static public String commentString(String  str) {
71         return commentString(str,"// ");
72     }
73 
74     static public String commentString(String  str, String prefix) {
75         return prefix + str.replace("\n", "\n" + prefix);
76     }
77 
78 }