當前位置: 首頁>>代碼示例>>Java>>正文


Java Method.getName方法代碼示例

本文整理匯總了Java中java.lang.reflect.Method.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java Method.getName方法的具體用法?Java Method.getName怎麽用?Java Method.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Method的用法示例。


在下文中一共展示了Method.getName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invoke

import java.lang.reflect.Method; //導入方法依賴的package包/類
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	String methodName = method.getName();
	if (methodName.equals("equals")) {
		// Only consider equal when proxies are identical.
		return (proxy == args[0]);
	}
	else if (methodName.equals("hashCode")) {
		// Use hashCode of proxy.
		return System.identityHashCode(proxy);
	}
	else if (methodName.equals("toString")) {
		return this.objectFactory.toString();
	}
	try {
		return method.invoke(this.objectFactory.getObject(), args);
	}
	catch (InvocationTargetException ex) {
		throw ex.getTargetException();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:AutowireUtils.java

示例2: Invocation

import java.lang.reflect.Method; //導入方法依賴的package包/類
public Invocation(Method method, Object[] parameters) {
  this.methodName = method.getName();
  this.parameterClasses = method.getParameterTypes();
  this.parameters = parameters;
  rpcVersion = writableRpcVersion;
  if (method.getDeclaringClass().equals(VersionedProtocol.class)) {
    //VersionedProtocol is exempted from version check.
    clientVersion = 0;
    clientMethodsHash = 0;
  } else {
    this.clientVersion = RPC.getProtocolVersion(method.getDeclaringClass());
    this.clientMethodsHash = ProtocolSignature.getFingerprint(method
        .getDeclaringClass().getMethods());
  }
  this.declaringClassProtocolName = 
      RPC.getProtocolName(method.getDeclaringClass());
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:18,代碼來源:WritableRpcEngine.java

示例3: genNewElementMethod

import java.lang.reflect.Method; //導入方法依賴的package包/類
void genNewElementMethod(String className, Method method, int indent) {
  String methodName = method.getName();
  String retName = method.getReturnType().getSimpleName();
  Class<?>[] params = method.getParameterTypes();
  echo(indent, "\n",
       "@Override\n",
       "public ", retName, "<", className, topMode ? "> " : "<T>> ",
       methodName, "(");
  if (params.length == 0) {
    puts(0, ") {");
    puts(indent,
         topMode ? "" : "  closeAttrs();\n",
         "  return ", StringUtils.toLowerCase(retName), "_" + "(this, ",
         isInline(className, retName), ");\n", "}");
  } else if (params.length == 1) {
    puts(0, "String selector) {");
    puts(indent,
         "  return setSelector(", methodName, "(), selector);\n", "}");
  } else {
    throwUnhandled(className, method);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:HamletGen.java

示例4: isLocal

import java.lang.reflect.Method; //導入方法依賴的package包/類
private static boolean isLocal(Object proxy, Method method) {
    final Class<?>[] interfaces = proxy.getClass().getInterfaces();
    if(interfaces == null) {
        return true;
    }

    final String methodName = method.getName();
    final Class<?>[] params = method.getParameterTypes();
    for (Class<?> intf : interfaces) {
        try {
            intf.getMethod(methodName, params);
            return false; // found method in one of our interfaces
        } catch (NoSuchMethodException nsme) {
            // OK.
        }
    }

    return true;  // did not find in any interface
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:MBeanServerInvocationHandler.java

示例5: getName

import java.lang.reflect.Method; //導入方法依賴的package包/類
protected String getName(Method method) {
  String methodName = method.getName();
  if (methodName.startsWith("get")) {
    return StringUtils.capitalize(methodName.substring(3));
  }
  return StringUtils.capitalize(methodName);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:8,代碼來源:MutableMetricsFactory.java

示例6: setIndexedReadMethod0

import java.lang.reflect.Method; //導入方法依賴的package包/類
private void setIndexedReadMethod0(Method readMethod) {
    this.indexedReadMethodRef.set(readMethod);
    if (readMethod == null) {
        indexedReadMethodName = null;
        return;
    }
    setClass0(readMethod.getDeclaringClass());

    indexedReadMethodName = readMethod.getName();
    setTransient(readMethod.getAnnotation(Transient.class));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:IndexedPropertyDescriptor.java

示例7: makeLabel

import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
 * Assembles method signature text for given method.
 */
private String makeLabel(Method method) {
  String methodLabel;
  methodLabel = jdbcIntf.getSimpleName() + "." + method.getName() + "(";
  boolean first = true;
  for (Class<?> paramType : method.getParameterTypes()) {
    if (! first) {
      methodLabel += ", ";
    }
    first = false;
    methodLabel += paramType.getSimpleName();
  }
  methodLabel += ")";
  return methodLabel;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:18,代碼來源:Drill2769UnsupportedReportsUseSqlExceptionTest.java

示例8: preHandle

import java.lang.reflect.Method; //導入方法依賴的package包/類
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (LOGGER.isDebugEnabled()) {
        startTime = System.currentTimeMillis();
        StringBuilder sb = new StringBuilder();

        HandlerMethod handlerMethod = (HandlerMethod) handler;
        Method method = handlerMethod.getMethod();
        String methodName = method.getName();
        sb.append(ENTER).append(methodName);

        //參數非空則打印參數
        Map<String, String[]> requestMap = request.getParameterMap();
        if (requestMap != null && !requestMap.isEmpty()) {
            sb.append("(");
            for (Map.Entry<String, String[]> entry : requestMap.entrySet()) {
                sb.append("[");
                sb.append(entry.getKey());
                sb.append("=");
                String[] valueArr = entry.getValue();
                sb.append(valueArr[0].toString());
                sb.append("]");
            }
            sb.append(")");
        }

        LOGGER.debug(sb.toString());
    }

    return true;
}
 
開發者ID:lupindong,項目名稱:xq_seckill_microservice,代碼行數:32,代碼來源:LogInterceptor.java

示例9: invoke

import java.lang.reflect.Method; //導入方法依賴的package包/類
@Override
public Object invoke(Object proxy, Method method, Object[] args)
		throws Throwable {
	String methodName = method.getName();
	if ("close".equals(methodName))
		this.close();
	else if ("getConnection".equals(methodName) && (args == null || args.length == 0))
		return this.getConnection();
	else if ("addConnectionEventListener".equals(methodName)) {
		this.addConnectionEventListener((ConnectionEventListener) args[0]);
		return null;
	} else if ("removeConnectionEventListener".equals(methodName)) {
		this.removeConnectionEventListener((ConnectionEventListener) args[0]);
		return null;
	} else if ("prepareStatement".equals(methodName)) {
		switch (args.length) {
			case 1: return DBUtil.prepareStatement(realConnection, (String) args[0], readOnly);
			case 2: 
				if (method.getParameterTypes()[1] == int.class)
					return DBUtil.prepareStatement(realConnection, (String) args[0], readOnly,
							(Integer) args[1], ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
				else
					break;
			case 3: return DBUtil.prepareStatement(realConnection, (String) args[0], readOnly,
					(Integer) args[1], (Integer) args[2], ResultSet.HOLD_CURSORS_OVER_COMMIT);
			case 4: return DBUtil.prepareStatement(realConnection, (String) args[0], readOnly, 
					(Integer) args[1], (Integer) args[2], (Integer) args[3]);
		}
	} else if ("createStatement".equals(methodName))
		return createStatement(method, args);
	return BeanUtil.invoke(realConnection, method, args);
}
 
開發者ID:aravindc,項目名稱:jdbacl,代碼行數:33,代碼來源:PooledConnectionHandler.java

示例10: verifyMethodParameterAnnotationsValue

import java.lang.reflect.Method; //導入方法依賴的package包/類
private static void verifyMethodParameterAnnotationsValue(
        String expectedValue) throws Exception {
    Class<RedefineMethodWithAnnotationsTarget> c =
            RedefineMethodWithAnnotationsTarget.class;
    Method method = c.getMethod("annotatedMethod", String.class);

    Annotation [][] parametersAnnotations =
            method.getParameterAnnotations();
    if (parametersAnnotations.length != 1) {
        throw new Exception("Incorrect number of parameters to method: " +
                method.getName() + "." +
                " Expected: 1," +
                " got: " + parametersAnnotations.length);
    }

    Annotation[] parameterAnnotations = parametersAnnotations[0];
    if (parameterAnnotations.length != 1) {
        throw new Exception("Incorrect number of annotations." +
                " Expected: 1" +
                ", got " + parameterAnnotations.length);
    }

    Annotation parameterAnnotation = parameterAnnotations[0];
    if (!(parameterAnnotation instanceof ParameterAnnotation)) {
        throw new Exception("Incorrect Annotation class." +
                " Expected: " + ParameterAnnotation.class.getName() +
                ", got: " + parameterAnnotation.getClass().getName());
    }

    ParameterAnnotation pa = (ParameterAnnotation)parameterAnnotation;
    String annotationValue = pa.value();
    if (!expectedValue.equals(annotationValue)) {
        throw new Exception("Incorrect parameter annotation value." +
                " Expected: " + expectedValue +
                ", got: " + annotationValue);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:38,代碼來源:RedefineMethodWithAnnotationsApp.java

示例11: registerObserver

import java.lang.reflect.Method; //導入方法依賴的package包/類
/**
 * 注冊事件觀察者,通過注解的事件觀察者
 *
 * @param observer 觀察者對象
 */
public void registerObserver(Object observer) {
    final Class<?> observerClass = observer.getClass();

    // 這個觀察者的接口類,可能有多個
    Set<Class> allSupperClass = Sets.filter(allAutoEventMap.keySet(), new Predicate<Class>() {
        @Override
        @SuppressWarnings("unchecked")
        public boolean apply(Class input) {
            return input.isAssignableFrom(observerClass);
        }
    });

    if (allSupperClass.size() == 0) {
        log.warn("can not registry observer:{} , observer class must implement a event interface", observer);
        return;
    }

    Method[] declaredMethods = observerClass.getDeclaredMethods();
    for (Method method : declaredMethods) {
        String topic = "";
        if (method.getAnnotation(AutoEventHandler.class) != null) {
            AutoEventHandler autoEventHandler = method.getAnnotation(AutoEventHandler.class);
            topic = autoEventHandler.topic();
        }

        // find auto Topic
        for (Class supperClazz : allSupperClass) {
            Method[] supperClazzDeclaredMethods = supperClazz.getDeclaredMethods();
            for (Method supperClazzMethod : supperClazzDeclaredMethods) {
                if (!supperClazzMethod.getName().equals(method.getName())
                        || supperClazzMethod.getAnnotation(AutoEvent.class) == null) {
                    continue;
                }
                AutoEvent annotation = supperClazzMethod.getAnnotation(AutoEvent.class);
                String eventTopic = annotation.topic();

                if (StringUtils.isEmpty(eventTopic)) {// 父類指定過topic,那麽子類必須指定topic
                    eventTopic = supperClazz.getName() + "#" + method.getName();
                }
                if (StringUtils.isEmpty(topic) || topic.equals(eventTopic)) {
                    // 注冊一個topic為eventTopic的事件觀察者
                    registerMethod(observer, method, eventTopic);
                }
            }
        }

    }
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:54,代碼來源:AutoEventRegistry.java

示例12: getSetters

import java.lang.reflect.Method; //導入方法依賴的package包/類
private static List<Resource> getSetters(Map<String, Type> lookup, Class clazz, boolean includingPrivate) {
    ArrayList<Resource> setters = new ArrayList<Resource>();
    for (Method method : ReflectKit.getAllMethods(clazz, includingPrivate)) {
        Annotation[] annotations = method.getAnnotations();
        if (annotations ==null||annotations.length==0) {//排除未注解變量
            continue;
        }
        if (Modifier.isStatic(method.getModifiers())) {
            continue;
        }
        String methodName = method.getName();
        if (methodName.length() < 4) {
            continue;
        }
        if (!methodName.startsWith("set")) {
            continue;
        }
        Type[] paramTypes = method.getGenericParameterTypes();
        if (paramTypes.length != 1) {
            continue;
        }
        if (!includingPrivate && !Modifier.isPublic(method.getParameterTypes()[0].getModifiers())) {
            continue;
        }
        if (includingPrivate) {
            method.setAccessible(true);
        }
        try {
            String fromName = translateSetterName(methodName);
            Resource resource = new Resource(clazz, lookup, paramTypes[0]);
            resource.fromNames = new String[]{fromName};
            resource.name = fromName;
            resource.method = method;
            resource.annotations = method.getAnnotations();
            setters.add(resource);
        } catch (Exception e) {
            throw new AJsoupReaderException("failed to onAttachView resource from setter: " + method, e);
        }
    }
    return setters;
}
 
開發者ID:zdongcoding,項目名稱:jsouplib,代碼行數:42,代碼來源:ClassReader.java

示例13: invoke

import java.lang.reflect.Method; //導入方法依賴的package包/類
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  String methodName = method.getName();
  if (target instanceof Doc) {
    if (methodName.equals("isIncluded")) {
      Doc doc = (Doc) target;
      return !exclude(doc) && doc.isIncluded();
    }
    if (target instanceof RootDoc) {
      if (methodName.equals("classes")) {
        return filter(((RootDoc) target).classes(), ClassDoc.class);
      } else if (methodName.equals("specifiedClasses")) {
        return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class);
      } else if (methodName.equals("specifiedPackages")) {
        return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class);
      }
    } else if (target instanceof ClassDoc) {
      if (isFiltered(args)) {
        if (methodName.equals("methods")) {
          return filter(((ClassDoc) target).methods(true), MethodDoc.class);
        } else if (methodName.equals("fields")) {
          return filter(((ClassDoc) target).fields(true), FieldDoc.class);
        } else if (methodName.equals("innerClasses")) {
          return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class);
        } else if (methodName.equals("constructors")) {
          return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class);
        }
      }
    } else if (target instanceof PackageDoc) {
      if (methodName.equals("allClasses")) {
        if (isFiltered(args)) {
          return filter(((PackageDoc) target).allClasses(true), ClassDoc.class);
        } else {
          return filter(((PackageDoc) target).allClasses(), ClassDoc.class);
        }
      } else if (methodName.equals("annotationTypes")) {
        return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class);
      } else if (methodName.equals("enums")) {
        return filter(((PackageDoc) target).enums(), ClassDoc.class);
      } else if (methodName.equals("errors")) {
        return filter(((PackageDoc) target).errors(), ClassDoc.class);
      } else if (methodName.equals("exceptions")) {
        return filter(((PackageDoc) target).exceptions(), ClassDoc.class);
      } else if (methodName.equals("interfaces")) {
        return filter(((PackageDoc) target).interfaces(), ClassDoc.class);
      } else if (methodName.equals("ordinaryClasses")) {
        return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class);
      }
    }
  }

  if (args != null) {
    if (methodName.equals("compareTo") || methodName.equals("equals")
        || methodName.equals("overrides") || methodName.equals("subclassOf")) {
      args[0] = unwrap(args[0]);
    }
  }
  try {
    return process(method.invoke(target, args), method.getReturnType());
  } catch (InvocationTargetException e) {
    throw e.getTargetException();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:64,代碼來源:RootDocProcessor.java

示例14: AnnotationRepeatException

import java.lang.reflect.Method; //導入方法依賴的package包/類
public AnnotationRepeatException(final Class<?> clazz,
                                 final Method method,
                                 final Class<? extends Annotation> annoCls,
                                 final int occurs) {
    super(clazz, method.getName(), "@" + annoCls.getSimpleName(), occurs);
}
 
開發者ID:silentbalanceyh,項目名稱:vertx-zero,代碼行數:7,代碼來源:AnnotationRepeatException.java

示例15: replaceBooleanCalls

import java.lang.reflect.Method; //導入方法依賴的package包/類
private boolean replaceBooleanCalls(MethodNode mn) {

        boolean changed = false;
        ListIterator<AbstractInsnNode> iterator = mn.instructions.iterator();

        while (iterator.hasNext()) {
            AbstractInsnNode node = iterator.next();
            if (!(node instanceof MethodInsnNode)) {
                continue;
            }

            String replacementClass = Type.getInternalName(target);

            MethodInsnNode call = (MethodInsnNode) node;
            if (!call.owner.equals(replacementClass)) {
                continue;
            }

            for (Method m : getClass().getMethods()) {
                BooleanReplacement br = m.getAnnotation(BooleanReplacement.class);
                if (br == null) {
                    continue;
                }
                if (!call.name.equals(m.getName())) {
                    continue;
                }

                /*
                    Not going to look at the full method descriptor,
                    as return types in our replacements are going to
                    be different (eg from boolean to int)
                 */
                String paramDesc = getParameterDescriptor(m, false);
                String paramReduced = getParameterDescriptor(m, true);

                if ((br.replacingStatic() && call.desc.startsWith(paramDesc)) ||
                        (!br.replacingStatic() && call.desc.startsWith(paramReduced))) {

                    MethodInsnNode replacingCall = new MethodInsnNode(
                            Opcodes.INVOKESTATIC,
                            Type.getInternalName(getClass()),
                            m.getName(),
                            Type.getMethodDescriptor(m),
                            false);
                    mn.instructions.insertBefore(node, replacingCall);
                    mn.instructions.remove(node);

                    changed = true;
                    break;
                }
            }
        }

        return changed;
    }
 
開發者ID:EMResearch,項目名稱:EvoMaster,代碼行數:56,代碼來源:BooleanMethodTransformer.java


注:本文中的java.lang.reflect.Method.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。