1 19 package org.netbeans.modules.xml.tools.generator; 20 21 import java.awt.event.ActionEvent ; 22 import java.util.*; 23 import java.text.DateFormat ; 24 25 import org.openide.filesystems.FileObject; 26 import org.openide.cookies.OpenCookie; 27 import org.openide.cookies.EditCookie; 28 import org.openide.loaders.*; 29 import org.openide.nodes.Node; 30 import org.openide.util.Utilities; 31 import org.openide.util.actions.SystemAction; 32 33 public class GenerateSupportUtils { 34 35 38 public static String getJavaName (String name) { 39 StringTokenizer st = new StringTokenizer (name, " -.:"); StringBuffer sb = new StringBuffer (); 41 if (st.hasMoreTokens()) { 42 sb.append (st.nextToken()); 43 while (st.hasMoreTokens()) { 44 sb.append ("_").append (st.nextToken()); } 46 } 47 return sb.toString(); 48 } 49 50 51 55 public static String getJavaFileHeader (String name, FileObject primFile) { 56 Date now = new Date(); 57 58 StringBuffer sb = new StringBuffer (); 59 sb.append("/*\n * File: ").append (name).append (".java"); if (primFile != null) { 61 sb.append ("\n * Generated from: ").append (primFile.getName()).append (".").append (primFile.getExt()); } 63 sb.append("\n * Date: ").append (DateFormat.getDateInstance (DateFormat.LONG).format (now)); sb.append (" ").append (DateFormat.getTimeInstance (DateFormat.SHORT).format (now)); sb.append("\n *"); sb.append("\n * @author ").append(System.getProperty ("user.name")); sb.append("\n * @version generated by NetBeans XML module"); sb.append("\n */"); return sb.toString(); 70 } 71 72 79 80 83 public static boolean isValidReturnType(String value) { 84 85 if (value == null || "".equals(value)) return false; int length = value.length(); 87 88 while (length > 2 && value.charAt(length-2) == '[' && value.charAt(length-1) == ']') { 90 value = value.substring(0, length-2); 91 length -= 2; 92 } 93 94 if (value.charAt(0) == '.' || value.charAt(value.length()-1) == '.') 95 return false; 96 97 for(int i=1; i<length-2; i++) { 98 if (value.charAt(i) == '.' && value.charAt(i+1) == '.') 99 return false; 100 } 101 102 103 StringTokenizer st = new StringTokenizer(value, "."); while (st.hasMoreTokens()) { 105 String token = st.nextToken(); 106 if (!!!isPrimitiveType(token) && !!!Utilities.isJavaIdentifier(token)) 107 return false; 108 } 109 return true; 110 } 111 112 115 public static boolean isPrimitiveType(String value) { 116 117 String val[] = {"int", "char", "boolean", "long", "float", "double", "void"}; for(int i=0;i<val.length;i++) { 119 if(val[i].equals(value)) 120 return true; 121 } 122 return false; 123 } 124 125 } 126 | Popular Tags |