Example usage for java.lang.reflect Method toString

List of usage examples for java.lang.reflect Method toString

Introduction

In this page you can find the example usage for java.lang.reflect Method toString.

Prototype

public String toString() 

Source Link

Document

Returns a string describing this Method .

Usage

From source file:grails.plugin.cache.CustomCacheKeyGenerator.java

public Object generate(Object target, Method method, Object... params) {
    Class<?> objClass = AopProxyUtils.ultimateTargetClass(target);

    return new CacheKey(objClass.getName().intern(), method.toString().intern(), target.hashCode(),
            innerKeyGenerator.generate(target, method, params));
}

From source file:org.wicketstuff.datatable_autocomplete.trie.LargeTrieTestCase.java

public void testTrieStructure() {

    List<String> nextCharacterList = new LinkedList<String>();
    nextCharacterList.addAll(trie.getNextNodeCharacterSet());

    Collections.sort(nextCharacterList);

    for (String c : nextCharacterList) {

        List<Method> wordList = trie.getWordList(c);

        List<Method> indexedList = builder.getListForFirstCharacter(c);

        Collections.sort(wordList, methodComparator);
        Collections.sort(indexedList, methodComparator);

        for (int i = 0; i < wordList.size(); i++) {

            Method found = wordList.get(i);
            Method indexed = wordList.get(i);

            String foundString = found.toString();
            String indexedString = indexed.toString();

            if (!foundString.equals(indexedString)) {
                System.out.println("found = " + found.toString());
                System.out.println("as indexed = " + indexed.toString());
            }/*from ww w.java2 s  .co m*/

            assertEquals(found.toString(), indexed.toString());

        }

        for (int i = wordList.size(); i < indexedList.size(); i++) {

            System.out.println("found = NONE");
            System.out.println("as indexed = " + indexedList.get(i).toString());

        }

        // get the list of elements that are not in the union of the two lists
        @SuppressWarnings("unchecked")
        Collection<Method> disjunctionList = CollectionUtils.disjunction(wordList, indexedList);

        for (Method method : disjunctionList) {

            System.out.println("missing = " + method.toString());
        }

        assertEquals(wordList.size(), indexedList.size());

    }

}

From source file:org.wicketstuff.datatable_autocomplete.tst.LargeTrieTestCase.java

public void testTrieStructure() {

    List<String> nextCharacterList = new LinkedList<String>();

    nextCharacterList.addAll(trie.getNextNodeCharacterSet());

    Collections.sort(nextCharacterList);

    for (String c : nextCharacterList) {

        List<Method> wordList = trie.getWordList(c, -1);

        List<Method> indexedList = builder.getListForFirstCharacter(c);

        Collections.sort(wordList, methodComparator);
        Collections.sort(indexedList, methodComparator);

        for (int i = 0; i < wordList.size(); i++) {

            Method found = wordList.get(i);
            Method indexed = wordList.get(i);

            String foundString = found.toString();
            String indexedString = indexed.toString();

            if (!foundString.equals(indexedString)) {
                System.out.println("found = " + found.toString());
                System.out.println("as indexed = " + indexed.toString());
            }//from   w  ww .j av  a2s.  co  m

            assertEquals(found.toString(), indexed.toString());

        }

        for (int i = wordList.size(); i < indexedList.size(); i++) {

            System.out.println("found = NONE");
            System.out.println("as indexed = " + indexedList.get(i).toString());

        }

        // get the list of elements that are not in the union of the two lists
        @SuppressWarnings("unchecked")
        Collection<Method> disjunctionList = CollectionUtils.disjunction(wordList, indexedList);

        for (Method method : disjunctionList) {

            System.out.println("missing = " + method.toString());
        }

        assertEquals(wordList.size(), indexedList.size());

    }

}

From source file:org.b3log.latke.ioc.JavassistMethodHandler.java

@Override
public Object invoke(final Object proxy, final Method method, final Method proceed, final Object[] params)
        throws Throwable {
    LOGGER.trace("Processing invocation [" + method.toString() + "]");

    AtomicInteger calls = CALLS.get();
    if (null == calls) {
        synchronized (this) {
            if (null == calls) {
                calls = new AtomicInteger(0);
                CALLS.set(calls);//from  ww w.j  av a2s .  co m
            }
        }
    }
    calls.incrementAndGet();

    // Invocation with transaction handle
    final boolean withTransactionalAnno = method.isAnnotationPresent(Transactional.class);
    JdbcTransaction transaction = JdbcRepository.TX.get();
    final boolean alreadyInTransaction = null != transaction;
    final boolean needHandleTrans = withTransactionalAnno && !alreadyInTransaction;

    // Transaction Propagation: REQUIRED (Support a current transaction, create a new one if none exists)
    if (needHandleTrans) {
        try {
            transaction = new JdbcTransaction();
        } catch (final SQLException e) {
            LOGGER.log(Level.ERROR, "Failed to initialize JDBC transaction", e);

            throw new IllegalStateException("Begin a transaction failed");
        }

        JdbcRepository.TX.set(transaction);
    }

    Object ret;
    try {
        ret = proceed.invoke(proxy, params);

        if (needHandleTrans) {
            transaction.commit();
        }
    } catch (final InvocationTargetException e) {
        if (needHandleTrans) {
            if (transaction.isActive()) {
                transaction.rollback();
            }
        }

        throw e.getTargetException();
    }

    if (0 == calls.decrementAndGet()) {
        CALLS.set(null);
        final Connection connection = JdbcRepository.CONN.get();
        if (null != connection) {
            connection.close();
            JdbcRepository.CONN.set(null);
        }
    }

    return ret;
}

From source file:net.wimpi.telnetd.shell.ShellManager.java

/**
 * Accessor method for shells that have been set up.<br>
 * Note that it uses a factory method that any shell should
 * provide via a specific class operation.<br>
 *
 * @param key String that represents a shell name.
 * @return Shell instance that has been obtained from the
 *         factory method.//from  ww w .  j av a 2s .  co  m
 */
public Shell getShell(String key) {
    Shell myShell = null;
    try {
        if (!shells.containsKey(key)) {
            return null;
        }
        Object obj = shells.get(key);
        if (obj instanceof Class) {
            Class shclass = (Class) obj;
            Method factory = shclass.getMethod("createShell", null);
            log.debug("[Factory Method] " + factory.toString());
            myShell = (Shell) factory.invoke(shclass, null);
        }
        if (obj instanceof Shell) {
            myShell = (Shell) obj.getClass().newInstance();
        }
    } catch (Exception e) {
        log.error("getShell()", e);
    }

    return myShell;
}

From source file:net.nelz.simplesm.aop.UpdateMultiCacheAdvice.java

protected void updateCache(final List<String> cacheKeys, final List<Object> returnList,
        final Method methodToCache, final AnnotationData annotationData) {
    if (returnList.size() != cacheKeys.size()) {
        throw new InvalidAnnotationException(String.format(
                "The key generation objects, and the resulting objects do not match in size for [%s].",
                methodToCache.toString()));
    }//from   w  ww  .  ja va2s  .c om

    for (int ix = 0; ix < returnList.size(); ix++) {
        final Object result = returnList.get(ix);
        final String cacheKey = cacheKeys.get(ix);
        final Object cacheObject = result != null ? result : new PertinentNegativeNull();
        cache.set(cacheKey, annotationData.getExpiration(), cacheObject);
    }
}

From source file:info.novatec.testit.livingdoc.interpreter.collection.CollectionInterpreter.java

private Object invoke(Object target, Method method) {
    LOG.trace(ENTRY_WITH_TWO, target.toString(), method.toString());
    Object result = null;/*w ww  .j  a  va2s .  c  o  m*/
    try {
        result = method.invoke(target);
        LOG.trace(EXIT_WITH, result.toString());
    } catch (InvocationTargetException e) {
        LOG.error(LOG_ERROR, e);
        LOG.trace(EXIT_WITH_NULL);
    } catch (IllegalAccessException e) {
        LOG.error(LOG_ERROR, e);
        LOG.trace(EXIT_WITH_NULL);
    }
    return result;
}

From source file:org.robotframework.remoteserver.javalib.OverloadableKeyword.java

public void addOverload(Method method) {
    Integer argCount = method.getParameterTypes().length;
    if (usesVarArgs || (!keywordMap.isEmpty() && hasVariableArgs(method))) {
        log.warn(String.format("Overloads with variable arguments not supported. Ignoring overload %s",
                method.toString()));
        return;/*from   ww w . j  av  a2  s  . co m*/
    } else if (keywordMap.containsKey(argCount)) {
        keywordMap.get(argCount).add(new KeywordOverload(keywordBean, method));
    } else {
        List<KeywordOverload> overloadList = new ArrayList<KeywordOverload>();
        overloadList.add(new KeywordOverload(keywordBean, method));
        keywordMap.put(argCount, overloadList);
    }
    if (hasVariableArgs(method)) {
        usesVarArgs = true;
    }
}

From source file:de.contentreich.instrumentation.SpringBeansHelper.java

public List<String[]> getPublicMethodSignatures(String className) {
    logger.debug("Get public method signatures for class " + className);
    ArrayList<String[]> methodSignatures = new ArrayList<String[]>();
    try {//  w  ww .  j  a  v a2  s  .c om
        Class clazz = Class.forName(className);
        List<Method> methods = (List<Method>) Arrays.asList(clazz.getMethods());
        // Filtering - a pita in java
        for (Iterator<Method> iterator = methods.iterator(); iterator.hasNext();) {
            Method method = iterator.next();
            if (!method.getDeclaringClass().getName().startsWith("java")
                    && Modifier.isPublic(method.getModifiers())) {
                methodSignatures.add(new String[] { method.toString(), method.getDeclaringClass().getName() });
            }
        }
        Collections.sort(methodSignatures, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                String s1 = ((String[]) o1)[0];
                String s2 = ((String[]) o2)[0];
                return s1.compareTo(s2);
            }

        });
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    }
    return methodSignatures;
}

From source file:org.springframework.test.context.jdbc.DatabaseInitializerTestExecutionListener.java

/**
 * Detect a default SQL script by implementing the algorithm defined in
 * {@link DatabaseInitializer#scripts}./*  w w  w.jav a2  s .  c o  m*/
 */
private String detectDefaultScript(TestContext testContext, boolean classLevel) {
    Class<?> clazz = testContext.getTestClass();
    Method method = testContext.getTestMethod();
    String elementType = (classLevel ? "class" : "method");
    String elementName = (classLevel ? clazz.getName() : method.toString());

    String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName());
    if (!classLevel) {
        resourcePath += "." + method.getName();
    }
    resourcePath += ".sql";

    String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
    ClassPathResource classPathResource = new ClassPathResource(resourcePath);

    if (classPathResource.exists()) {
        if (logger.isInfoEnabled()) {
            logger.info(String.format("Detected default SQL script \"%s\" for test %s [%s]",
                    prefixedResourcePath, elementType, elementName));
        }
        return prefixedResourcePath;
    } else {
        String msg = String.format("Could not detect default SQL script for test %s [%s]: "
                + "%s does not exist. Either declare scripts via @DatabaseInitializer or make the "
                + "default SQL script available.", elementType, elementName, classPathResource);
        logger.error(msg);
        throw new IllegalStateException(msg);
    }
}