List of usage examples for java.lang.reflect Method getName
@Override
public String getName()
From source file:com.rapid.develop.core.utils.ReflectionUtils.java
/** * ?, ?DeclaredMethod,?.//from ww w .j av a 2 s .c o m * ?Object?, null. * ???? * * <p>?. ?Method,?Method.invoke(Object obj, Object... args)</p> */ public static Method getAccessibleMethodByName(final Object obj, final String methodName) { for (Class<?> searchType = obj.getClass(); searchType != Object.class; searchType = searchType .getSuperclass()) { Method[] methods = searchType.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals(methodName)) { makeAccessible(method); return method; } } } return null; }
From source file:com.github.itoshige.testrail.store.SyncManager.java
/** * delete not existed method in testrail and caseStore. * //from ww w .j a va 2 s.c om * @param sectionId * @param testClass */ private static void deleteNotExistedMethod(String sectionId, final Class<?> testClass) { Set<String> junitMethodNames = new HashSet<String>(); for (final Method junitMethod : TestRailUnitUtil.getDeclaredTestMethods(testClass.getDeclaredMethods())) { junitMethodNames.add(junitMethod.getName()); } // find not existed titles in testrail. List<CaseStoreKey> notExistedTitles = new ArrayList<CaseStoreKey>(); for (CaseStoreKey key : CaseStore.getIns().getSectionId2Tiltes()) { if (key.getProjectId().equals(sectionId) && !junitMethodNames.contains(key.getTitle())) notExistedTitles.add(key); } for (CaseStoreKey key : notExistedTitles) { // delete testrail TestRailClient.deleteCase(CaseStore.getIns().getCaseId(key)); // remove store CaseStore.getIns().remove(key); } }
From source file:dk.netdesign.common.osgi.config.Attribute.java
private static String getAttributeName(Method classMethod) { String attributeName = classMethod.getName().replaceAll("^get", ""); if (classMethod.isAnnotationPresent(Property.class)) { Property methodProperty = classMethod.getAnnotation(Property.class); if (!methodProperty.name().isEmpty()) { attributeName = methodProperty.name(); }//from w w w.ja v a2s . c om } return attributeName; }
From source file:com.zigbee.framework.common.util.BeanCopyUtil.java
/** * ?/*w ww .j a va 2 s.c om*/ * @author tun.tan * @Date 2011-9-29 ?11:18:42 */ public static void copyProps(Object source, Object target, String[] igonre) { Assert.notNull(source, "Source must not be null"); Assert.notNull(target, "Target must not be null"); Class<?> actualEditable = target.getClass(); PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable); Object methodName = null; // Object targetValue=null; //? for (PropertyDescriptor targetPd : targetPds) { if (targetPd.getWriteMethod() != null) { try { PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName()); if (igonre != null) { boolean jump = false; // for (int i = 0; i < igonre.length; i++) { if (igonre[i] == null) {// continue; } if (targetPd.getName().equals(igonre[i])) {//? logger.info(targetPd.getName()); jump = true; } } if (jump) {// continue; } } if (sourcePd != null && sourcePd.getReadMethod() != null) {// Method readMethod = sourcePd.getReadMethod(); if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } Object value = readMethod.invoke(source); //Check whether the value is empty, only copy the properties which are not empty // targetValue=value; if (value != null) {// Method writeMethod = targetPd.getWriteMethod(); methodName = writeMethod.getName(); if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } writeMethod.invoke(target, value); } } } catch (BeansException e) { e.printStackTrace(); String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage(); logger.error(errMsg); throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause()); } catch (SecurityException e) { e.printStackTrace(); String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage(); logger.error(errMsg); throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause()); } catch (IllegalArgumentException e) { e.printStackTrace(); String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage(); logger.error(errMsg); throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause()); } catch (IllegalAccessException e) { e.printStackTrace(); String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage(); logger.error(errMsg); throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause()); } catch (InvocationTargetException e) { e.printStackTrace(); String errMsg = "BEAN COPY Exception! methodName=" + methodName + " ;" + e.getMessage(); logger.error(errMsg); throw new ZigbeeSystemException("beanCopyException", errMsg, e.getCause()); } } } }
From source file:com.revolsys.util.JavaBeanUtil.java
public static List<Method> getMethods(final Class<?> clazz) { final Method[] methods = clazz.getMethods(); Arrays.sort(methods, new Comparator<Method>() { @Override//from w ww. jav a2s. c om public int compare(final Method method1, final Method method2) { final String name1 = method1.getName().replaceAll("^(set|get|is)", "").toLowerCase(); final String name2 = method2.getName().replaceAll("^(set|get|is)", "").toLowerCase(); final int nameCompare = name1.compareTo(name2); return nameCompare; } }); return Arrays.asList(methods); }
From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.importer.XmiHelper.java
public static Object invokeReadMethod(IdEntity instance, EStructuralFeature esf) { Method m = getReadMethod(esf, instance.getClass()); if (m == null || (instance.getClass().equals(AttributeValue.class) && m.getName().equals(IGNORE_CASE_AVAS))) { return null; }/* ww w . j a va 2s. c om*/ try { return m.invoke(instance); } catch (IllegalArgumentException e) { LOGGER.error(e); } catch (IllegalAccessException e) { LOGGER.error(e); } catch (InvocationTargetException e) { LOGGER.error(e); } return null; }
From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java
private static <T extends Object> void optInitMethod(T vo) throws IllegalAccessException, InvocationTargetException { Method[] methods = vo.getClass().getDeclaredMethods(); for (Method method : methods) { if (StringUtils.equals("init", method.getName())) { method.invoke(vo);/* w w w . ja va 2 s . co m*/ } } }
From source file:com.amalto.core.metadata.ClassRepository.java
private static boolean isBooleanGetter(Method declaredMethod) { String name = declaredMethod.getName(); return name.startsWith(BOOLEAN_PREFIX) && name.length() > BOOLEAN_PREFIX.length(); }
From source file:com.amalto.core.metadata.ClassRepository.java
private static boolean isGetter(Method declaredMethod) { String name = declaredMethod.getName(); return name.startsWith(GETTER_PREFIX) && name.length() > GETTER_PREFIX.length(); }
From source file:com.googlecode.xtecuannet.framework.catalina.manager.tomcat.constants.Constants.java
public static String invokeStringFunction(Method m, String[] params) { String out = null;//from www. ja va2 s. c o m try { out = (String) m.invoke(null, (Object[]) params); } catch (Exception e) { logger.error("Error invoking function: " + m.getName() + " with params: " + Arrays.asList(params), e); } return out; }