classitem.java
来自「JiBX是一个为Java提供的XML数据绑定框架。它可以和现存的类一起运行」· Java 代码 · 共 569 行 · 第 1/2 页
JAVA
569 行
} /** * Get method signature. * * @return encoded method signature */ public String getSignature() { return m_signature; } /** * Check if item is a method. * * @return <code>true</code> if a method, <code>false</code> if a field */ public boolean isMethod() { return m_item == null || m_item instanceof Method; } /** * Check if item is an initializer. * * @return <code>true</code> if an initializer, <code>false</code> if a * field or normal method */ public boolean isInitializer() { return m_item != null && m_item.getName().equals("<init>"); } /** * Get names of exceptions thrown by method. * * @return array of exceptions thrown by method, or <code>null</code> if * a field */ public String[] getExceptions() { if (m_item instanceof Method) { ExceptionTable etab = ((Method)m_item).getExceptionTable(); if (etab != null) { return etab.getExceptionNames(); } else { return EMPTY_STRING_ARRAY; } } return null; } /** * Check if type name is a primitive. * * @return <code>true</code> if a primitive, <code>false</code> if not */ public static boolean isPrimitive(String type) { return s_primitiveMap.get(type) != null; } /** * Get the signature for a primitive. * * @return signature for a primitive type */ public static String getPrimitiveSignature(String type) { return ((String[])s_primitiveMap.get(type))[0]; } /** * Get parameter type names from method signature. * * @param sig method signature to be decoded * @return array of argument type names */ public static String[] getParametersFromSignature(String sig) { String[] types = (String[])s_signatureParamsMap.get(sig); if (types == null) { types = Utility.methodSignatureArgumentTypes(sig, false); s_signatureParamsMap.put(sig, types); } return types; } /** * Get return type names from method signature. * * @param sig method signature to be decoded * @return return type name */ public static String getTypeFromSignature(String sig) { String type = (String)s_signatureTypeMap.get(sig); if (type == null) { type = Utility.methodSignatureReturnType(sig, false); s_signatureTypeMap.put(sig, type); } return type; } /** * Create type from name. * * @param name fully qualified type name * @return corresponding type */ public static Type typeFromName(String name) { // first check for type already created Type type = (Type)s_typeMap.get(name); if (type == null) { // new type, strip off array dimensions int dimen = 0; String base = name; while (base.endsWith("[]")) { dimen++; base = base.substring(0, base.length()-2); } // check for base type defined if array if (dimen > 0) { type = (Type)s_typeMap.get(base); } // create and record base type if new if (type == null) { type = new ObjectType(base); s_typeMap.put(base, type); } // create and record array type if (dimen > 0) { type = new ArrayType(type, dimen); s_typeMap.put(name, type); } } return type; } /** * Get virtual method by fully qualified name. This splits the class * name from the method name, finds the class, and then tries to find a * matching method name in that class or a superclass. * * @param name fully qualified class and method name * @param sigs possible method signatures * @return information for the method, or <code>null</code> if not found * @throws JiBXException if configuration error */ public static ClassItem findVirtualMethod(String name, String[] sigs) throws JiBXException { // get the class containing the method int split = name.lastIndexOf('.'); String cname = name.substring(0, split); String mname = name.substring(split+1); ClassFile cf = ClassCache.getClassFile(cname); // find the method in class or superclass for (int i = 0; i < sigs.length; i++) { ClassItem method = cf.getMethod(mname, sigs[i]); if (method != null) { return method; } } return null; } /** * Get static method by fully qualified name. This splits the class * name from the method name, finds the class, and then tries to find a * matching method name in that class. * * @param name fully qualified class and method name * @param sigs possible method signatures * @return information for the method, or <code>null</code> if not found * @throws JiBXException if configuration error */ public static ClassItem findStaticMethod(String name, String[] sigs) throws JiBXException { // get the class containing the method int split = name.lastIndexOf('.'); String cname = name.substring(0, split); String mname = name.substring(split+1); ClassFile cf = ClassCache.getClassFile(cname); // find the method in class or superclass for (int i = 0; i < sigs.length; i++) { ClassItem method = cf.getStaticMethod(mname, sigs[i]); if (method != null) { return method; } } return null; } /** * Get all variant signatures for a fully qualified class name. The * returned array gives all signatures (for interfaces or classes) which * instances of the class can match. * * @param name fully qualified class name * @return possible signature variations for instances of the class * @throws JiBXException if configuration error */ public static String[] getSignatureVariants(String name) throws JiBXException { Object obj = s_primitiveMap.get(name); if (obj == null) { ClassFile cf = ClassCache.getClassFile(name); return cf.getInstanceSigs(); } else { return (String[])obj; } } /** * Check if a value of one type can be directly assigned to another type. * This is basically the equivalent of the instanceof operator, but with * application to primitive types as well as object types. * * @param from fully qualified class name of initial type * @param to fully qualified class name of assignment type * @return <code>true</code> if assignable, <code>false</code> if not * @throws JiBXException if configuration error */ public static boolean isAssignable(String from, String to) throws JiBXException { // always assignable if the two are the same if (from.equals(to)) { return true; } else { // try direct lookup for primitive types Object fobj = s_primitiveMap.get(from); Object tobj = s_primitiveMap.get(to); if (fobj == null && tobj == null) { // assignable if from type has to as a possible signature ClassFile cf = ClassCache.getClassFile(from); String[] sigs = cf.getInstanceSigs(); String match = Utility.getSignature(to); for (int i = 0; i < sigs.length; i++) { if (match.equals(sigs[i])) { return true; } } return false; } else if (fobj != null && tobj != null) { // assignable if from type has to as a possible signature String[] fsigs = (String[])fobj; String[] tsigs = (String[])tobj; if (tsigs.length == 1) { for (int i = 0; i < fsigs.length; i++) { if (fsigs[i] == tsigs[0]) { return true; } } } return false; } else { // primitive and object types never assignable return false; } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?