Example usage for java.lang Class getName

List of usage examples for java.lang Class getName

Introduction

In this page you can find the example usage for java.lang Class getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String .

Usage

From source file:Main.java

public static String typename(Class t) {
    String brackets = "";
    while (t.isArray()) {
        brackets += "[]";
        t = t.getComponentType();//from   ww w.j  ava2 s.c  o  m
    }
    String name = t.getName();
    int pos = name.lastIndexOf('.');
    if (pos != -1)
        name = name.substring(pos + 1);
    return name + brackets;
}

From source file:MainClass.java

public static void printMethods(Class cl) {
    Method[] methods = cl.getDeclaredMethods();

    for (int i = 0; i < methods.length; i++) {
        Method m = methods[i];/*from   w  ww .  j  av a  2s .c o m*/
        Class retType = m.getReturnType();
        Class[] paramTypes = m.getParameterTypes();
        String name = m.getName();
        System.out.print(Modifier.toString(m.getModifiers()));
        System.out.print(" " + retType.getName() + " " + name + "(");
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                System.out.print(", ");
            System.out.print(paramTypes[j].getName());
        }
        System.out.println(");");
    }
}

From source file:com.textocat.textokit.dictmatcher.TaggedChunkerBuilderResource.java

public static ExternalResourceDescription createDescription(String resourceLocation,
        Class<? extends ChunkerBuilder> builderClass) {
    return createDescription(resourceLocation, builderClass.getName());
}

From source file:org.metasyntactic.utilities.ExceptionUtilities.java

public static void log(final Class<?> clazz, final String method, final Throwable e) {
    Log.e(clazz.getName(), method, e);
}

From source file:com.switchfly.inputvalidation.CobrandNameValidationStrategyTest.java

public static void assertThrowException(Class<? extends Throwable> exceptionClass, Closure closure) {
    try {/*from  w  w  w . ja v  a2  s  .  c  om*/
        closure.execute(null);
        fail("Should throw " + exceptionClass.getName());
    } catch (Exception e) {
        assertTrue(exceptionClass.isAssignableFrom(e.getClass()));
    }
}

From source file:gaffer.example.util.JavaSourceUtil.java

public static String getRawJavaSnippet(final Class<?> clazz, final String modulePath, final String marker,
        final String start, final String end) {
    String javaCode = getRawJava(clazz.getName(), modulePath);
    final int markerIndex = javaCode.indexOf(marker);
    if (markerIndex > -1) {
        javaCode = javaCode.substring(markerIndex);
        javaCode = javaCode.substring(javaCode.indexOf(start) + start.length());
        javaCode = javaCode.substring(0, javaCode.indexOf(end));
        javaCode = StringUtils.stripEnd(javaCode, " " + String.format("%n"));
    } else {//from w w  w  .  j ava  2  s  .  c  o m
        javaCode = "";
    }

    return javaCode;
}

From source file:Main.java

public static boolean invokeIn(StackTraceElement[] stackTraceElements, Class<?> cla, String methodName) {
    if (stackTraceElements == null || stackTraceElements.length == 0) {
        return false;
    }/*from w ww  .j a v  a 2  s . c om*/

    String targetClassName = cla.getName();
    StackTraceElement element;
    String elementClassName;
    String elementMethodName;
    for (StackTraceElement stackTraceElement : stackTraceElements) {
        element = stackTraceElement;

        elementClassName = element.getClassName();
        elementMethodName = element.getMethodName();
        if (targetClassName.equals(elementClassName) && methodName.equals(elementMethodName)) {
            return true;
        }
    }

    return false;
}

From source file:com.ejisto.modules.web.util.FieldSerializationUtil.java

public static List<MockedField> translateObject(Object object, String containerClassName, String fieldName,
        String contextPath) {/*from  www.  j a  v  a  2s  . co m*/
    if (object == null) {
        return emptyList();
    }
    if (isBlackListed(object.getClass())) {
        String fieldType = object.getClass().getName();
        MockedField out = buildMockedField(containerClassName, fieldName, contextPath, fieldType);
        return asList(out);
    }
    DefaultSupportedType type = DefaultSupportedType.evaluate(object);
    if (type != null && type.isPrimitiveOrSimpleValue()) {
        return asList(getSingleFieldFromDefaultSupportedType(object, type, contextPath, containerClassName,
                fieldName));
    }
    List<MockedField> out = new ArrayList<MockedField>();
    Class<?> objectClass = object.getClass();
    String className = objectClass.getName();
    for (Field field : objectClass.getDeclaredFields()) {
        if (!Modifier.isTransient(field.getModifiers()) && !isBlackListed(field.getType())) {
            out.add(translateField(field, object, className, contextPath));
        }
    }
    return out;
}

From source file:gov.nih.nci.caarray.dao.HibernateIntegrationTestCleanUpUtility.java

private static boolean doCleanUp(Class<?> c) {
    StringBuilder sb = new StringBuilder("DELETE FROM " + c.getName());
    String condition = CLASS_DELETE_CONSTRAINTS.get(c);
    if (condition != null) {
        sb.append(" where ").append(condition);
    }/*from www. ja v  a  2s  . co m*/
    return doCleanUp(sb.toString());
}

From source file:Main.java

/**
 * Get//  w w  w.  j  ava 2s . c o  m
 * 
 * @param classType
 * @return
 * @throws JAXBException
 */
@SuppressWarnings("rawtypes")
private static synchronized JAXBContext getJaxbContext(Class... classTypes) throws JAXBException {
    JAXBContext retObj = null;

    String key = "";
    for (Class classType : classTypes) {
        if (!"".equals(key)) {
            key += ";";
        }
        key += classType.getName();
    }

    retObj = jaxbContextMap.get(key);
    if (retObj == null) {
        retObj = JAXBContext.newInstance(classTypes);
        jaxbContextMap.put(key, retObj);
    }

    return retObj;
}