Example usage for java.lang Class getSimpleName

List of usage examples for java.lang Class getSimpleName

Introduction

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

Prototype

public String getSimpleName() 

Source Link

Document

Returns the simple name of the underlying class as given in the source code.

Usage

From source file:com.thinkmore.framework.utils.ReflectionUtil.java

/**
 * ??,Class?.//from ww w .j av  a2 s .co  m
 * , Object.class.
 * 
 * public UserDao extends HibernateDao<User,Long>
 *
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be determined
 */
@SuppressWarnings({ "rawtypes" })
public static Class getSuperClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:com.reprezen.kaizen.oasparser.jsonoverlay.gen.TypeGenerator.java

private static Map<String, String> getKnownTypes() {
    Map<String, String> results = Maps.newHashMap();
    ArrayList<Class<?>> overlays = Lists.<Class<?>>newArrayList( //
            Generated.class, //
            Collection.class, //
            Map.class, //
            Optional.class, //
            JsonNode.class, //
            JsonOverlay.class, //
            JsonOverlayFactory.class, //
            Inject.class, //
            StringOverlay.class, //
            IntegerOverlay.class, //
            NumberOverlay.class, //
            BooleanOverlay.class, //
            PrimitiveOverlay.class, //
            AnyObjectOverlay.class, //
            ListOverlay.class, //
            ValListOverlay.class, //
            MapOverlay.class, //
            ValMapOverlay.class, //
            Validator.class, //
            ValidationResults.class, //
            OpenApi3Validator.class, //
            OpenApi.class, //
            Severity.class);
    for (Class<?> cls : overlays) {
        results.put(cls.getSimpleName(), cls.getName().replaceAll("\\$", "."));
    }// w w  w.  j  a v a  2 s  .c  o m
    return results;
}

From source file:com.anathema_roguelike.main.utilities.Utils.java

static String getProperty(Properties properties, Object obj, String defaultValue) {

    if (!(obj instanceof Class)) {

        if (obj instanceof String) {
            return (String) obj;
        }/*from w w w  .  j ava2  s .c  om*/

        obj = obj.getClass();
    }

    Class<?> cls = (Class<?>) obj;

    while (cls.isAnonymousClass()) {
        cls = cls.getEnclosingClass();
    }

    String property = properties.getProperty(cls.getSimpleName());

    if (property != null) {
        return property;
    } else {
        return defaultValue;
    }
}

From source file:com.alta189.bukkit.script.event.EventScanner.java

public static void scanBukkit() {
    Reflections reflections = new Reflections(new ConfigurationBuilder()
            .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.bukkit")))
            .setUrls(ClasspathHelper.forClassLoader(ClasspathHelper.contextClassLoader(),
                    ClasspathHelper.staticClassLoader())));

    Set<Class<? extends Event>> classes = reflections.getSubTypesOf(Event.class);

    BScript plugin = BScript.getInstance();
    plugin.info(//ww w . j  av a2 s .  c o  m
            "Found " + classes.size() + " classes extending " + Event.class.getCanonicalName() + " in Bukkit");
    for (Class<? extends Event> clazz : classes) {
        if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
            continue;
        }
        bukkitEvent.put(clazz.getSimpleName(), clazz);

        String className = clazz.getCanonicalName();
        if (className == null) {
            className = clazz.getName();
        }
        events.put(className, clazz);
        simpleNameEvents.put(clazz.getSimpleName(), clazz);
        plugin.debug(className);
    }
}

From source file:org.web4thejob.context.ContextUtil.java

@SuppressWarnings("unchecked")
public static <T extends Dialog> T getDefaultDialog(Class<T> type, Object... args) {
    return (T) ContextUtil.getBean(StringUtils.uncapitalize(DEFAULT_PREFFIX + type.getSimpleName()), args);
}

From source file:io.selendroid.builder.SelendroidServerBuilder.java

public static String getJarVersionNumber() {
    Class clazz = SelendroidStandaloneDriver.class;
    String className = clazz.getSimpleName() + ".class";
    String classPath = clazz.getResource(className).toString();
    if (!classPath.startsWith("jar")) {
        // Class not from JAR
        return "dev";
    }/* w  w w  . j ava 2  s.c om*/
    String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
    Manifest manifest = null;
    try {
        manifest = new Manifest(new URL(manifestPath).openStream());
    } catch (Exception e) {
        return "";
    }
    Attributes attr = manifest.getMainAttributes();
    String value = attr.getValue("version");
    return value;
}

From source file:com.manpowergroup.cn.core.utils.ReflectionUtils.java

/**
 * ??,Class?./*from ww w.ja v  a 2s.c  o  m*/
 * 
 * public UserDao extends HibernateDao<User,Long>
 *
 * @param clazz clazz The class to introspect
 * @param index the Index of the generic ddeclaration,start from 0.
 * @return the index generic declaration, or Object.class if cannot be determined
 */

@SuppressWarnings({ "rawtypes" })
public static Class getSuperClassGenricType(final Class clazz, final int index) {

    Type genType = clazz.getGenericSuperclass();

    if (!(genType instanceof ParameterizedType)) {
        logger.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType");
        return Object.class;
    }

    Type[] params = ((ParameterizedType) genType).getActualTypeArguments();

    if (index >= params.length || index < 0) {
        logger.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: "
                + params.length);
        return Object.class;
    }
    if (!(params[index] instanceof Class)) {
        logger.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter");
        return Object.class;
    }

    return (Class) params[index];
}

From source file:gr.abiss.calipso.tiers.specifications.GenericSpecifications.java

/**
 * Dynamically create a specification for the given class and search
 * parameters. This is the entry point for query specifications construction.
 * @param clazz the entity type to query for
 * @param searchTerms the search terms to match
 * @return the result specification/*from w  w w  .  j a va 2 s. c o m*/
 */
@SuppressWarnings("rawtypes")
public static Specification<Persistable> matchAll(final Class clazz, final Map<String, String[]> searchTerms) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("matchAll, entity: " + clazz.getSimpleName() + ", searchTerms: " + searchTerms);
    }
    return new Specification<Persistable>() {
        @Override
        public Predicate toPredicate(@SuppressWarnings("rawtypes") Root<Persistable> root,
                CriteriaQuery<?> query, CriteriaBuilder cb) {
            return GenericSpecifications.buildRootPredicate(clazz, searchTerms, root, cb);
        }
    };
}

From source file:cz.jirutka.validator.collection.internal.AnnotationUtils.java

@SuppressWarnings("unchecked")
public static <T> T readAttribute(Annotation annotation, String name, Class<T> requiredType)
        throws IllegalArgumentException, IllegalStateException {

    Object result = AnnotationUtils.invokeNonArgMethod(annotation, name);

    Validate.isInstanceOf(requiredType, result, "Method %s should return instance of %s", name,
            requiredType.getSimpleName());

    return (T) result;
}

From source file:baggage.BaseTestCase.java

protected static void assertFailure(Class<? extends Exception> klass, Fallible fallible) {
    try {//from  w ww  . j  a  v  a  2s  .com
        fallible.execute();
    } catch (Exception e) {
        if (!klass.isAssignableFrom(e.getClass())) {
            throw new RuntimeException(
                    "Expected a " + klass.getSimpleName() + ", got a " + e.getClass().getSimpleName(), e);
        }
        return;
    }
    Assert.fail("Expected a " + klass.getSimpleName() + ", got no exceptions at all");
}