Method getDeclaringClass - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Method getDeclaringClass method.

This code example shows how to use the following methods:isAccessible, setAccessible, equals, getDeclaringClass, getName
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
    { 
        if (constructed)
        { 
 
            String methodName = method.getName();
            int params = args.length;
 
            if (params == 0)
            { 
                if (isUninitialized() && method.equals(getIdentifierMethod))
                { 
                    return getIdentifier(); 
                } 
 
                else if ("getKunderaLazyInitializer".equals(methodName))
                { 
                    return this;
                } 
            } 

8
CodeRank
This code example shows how to use the following methods:setAccessible, getDeclaringClass, getModifiers
  } 
 
  private MethodInvoker createMethodInvoker(final Method method) {
 
    // We can't use FastMethod if the method is private. 
    int modifiers = method.getModifiers(); 
    if (!Modifier.isPrivate(modifiers) && !Modifier.isProtected(modifiers)) { 
      /*if[AOP]*/ 
      try { 
      final net.sf.cglib.reflect.FastMethod fastMethod 
          = BytecodeGen.newFastClass(method.getDeclaringClass(), Visibility.forMember(method)) 
              .getMethod(method); 
 
      return new MethodInvoker() { 
        public Object invoke(Object target, Object... parameters) 
            throws IllegalAccessException, InvocationTargetException { 
          return fastMethod.invoke(target, parameters); 
        } 
      }; 
      } catch (net.sf.cglib.core.CodeGenerationException e) {/* fall-through */} 

8
CodeRank
This code example shows how to use the following methods:getDeclaringClass, getModifiers, getName, getParameterTypes
		private final Method method;
 
		private final String identifier;
 
		public LifecycleElement(Method method) {
			if (method.getParameterTypes().length != 0) {
				throw new IllegalStateException("Lifecycle method annotation requires a no-arg method: " + method);
			} 
			this.method = method;
			this.identifier = (Modifier.isPrivate(method.getModifiers()) ?
					method.getDeclaringClass() + "." + method.getName() : method.getName());
		} 
 
		public Method getMethod() {
			return this.method;
		} 
 
		public String getIdentifier() {
			return this.identifier;
		} 
7
CodeRank
This code example shows how to use the following methods:isAccessible, setAccessible, getDeclaringClass, getModifiers
 
	/** 
	 * 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。 
	 */ 
	public static void makeAccessible(Method method) {
		if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
				&& !method.isAccessible()) {
			method.setAccessible(true);
		} 
	} 
 
	/** 
	 * 改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。 
	 */ 
	public static void makeAccessible(Field field) {
		if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) || Modifier
				.isFinal(field.getModifiers())) && !field.isAccessible()) {
			field.setAccessible(true);
		} 
	} 
7
CodeRank
This code example shows how to use the following methods:getDeclaringClass, getName
        Method method,
        Object instance, 
        ImmutableSet<Dependency<?>> dependencies,
        List<Provider<?>> parameterProviders,
        Class<? extends Annotation> scopeAnnotation) {
      super(key, method, instance, dependencies, parameterProviders, scopeAnnotation);
      // We need to generate a FastClass for the method's class, not the object's class. 
      this.fastClass =
          BytecodeGen.newFastClass(method.getDeclaringClass(), Visibility.forMember(method));
      // Use the Signature overload of getIndex because it properly uses return types to identify 
      // particular methods.  This is normally irrelevant, except in the case of covariant overrides 
      // which java implements with a compiler generated bridge method to implement the override. 
      this.methodIndex = fastClass.getIndex(
          new net.sf.cglib.core.Signature( 
              method.getName(), org.objectweb.asm.Type.getMethodDescriptor(method)));
      Preconditions.checkArgument(this.methodIndex >= 0, 
          "Could not find method %s in fast class for class %s",  
          method, 
          method.getDeclaringClass());
    } 

7
CodeRank
This code example shows how to use the following methods:getDeclaringClass, getName, getParameterTypes
	public Object invokeInContext(MethodInvocation invocation) throws Throwable {
		Object ejb = null; 
		try { 
			ejb = getSessionBeanInstance(); 
			Method method = invocation.getMethod();
			if (method.getDeclaringClass().isInstance(ejb)) {
				// directly implemented 
				return method.invoke(ejb, invocation.getArguments());
			} 
			else { 
				// not directly implemented 
				Method ejbMethod = ejb.getClass().getMethod(method.getName(), method.getParameterTypes());
				return ejbMethod.invoke(ejb, invocation.getArguments());
			} 
		} 
		catch (InvocationTargetException ex) {
			Throwable targetEx = ex.getTargetException();
			if (logger.isDebugEnabled()) { 
				logger.debug("Method of local EJB [" + getJndiName() + "] threw exception", targetEx);
			} 
7
CodeRank
This code example shows how to use the following methods:isAccessible, setAccessible, getDeclaringClass, getName
 
		for (int i = 0; i < methodInterceptors.size(); i++) { 
			if (methodInterceptors.get(i) == null) { 
				throw new IllegalArgumentException( 
					"Method interceptor " + i + " is null"); 
			} 
		} 
 
		_methodInterceptors = methodInterceptors; 
	} 
 
	@Override 
	public Object invoke(Object proxy, Method method, Object[] arguments) 
		throws Throwable { 
 
		ServiceBeanMethodInvocation serviceBeanMethodInvocation = 
			new ServiceBeanMethodInvocation( 
				_target, _targetClass, method, arguments); 
 
		serviceBeanMethodInvocation.setMethodInterceptors(_methodInterceptors); 
7
CodeRank
This code example shows how to use the following methods:getDeclaringClass, getName, getParameterTypes
            return calculateOptionType(optionMethod.getParameterTypes()[0]);
        } 
    } 
 
    private static void assertMethodTypeSupported(String optionName, Method method) {
        final Class<?>[] parameterTypes = method.getParameterTypes();
        if (parameterTypes.length > 1) {
            throw new OptionValidationException(String.format("Option '%s' cannot be linked to methods with multiple parameters in class '%s#%s'.",
                    optionName, method.getDeclaringClass().getName(), method.getName()));
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getDeclaringClass
    private TheoryTestUtils() { } 
     
    public static List<PotentialAssignment> potentialAssignments(Method method)
            throws Throwable {
        return Assignments.allUnassigned(method,
                new TestClass(method.getDeclaringClass()))
                .potentialsForNextUnassigned(); 
    } 
     
    public static Result runTheoryClass(Class<?> testClass) throws InitializationError {
        Runner theoryRunner = new Theories(testClass);
        Request request = Request.runner(theoryRunner);
        return new JUnitCore().run(request); 
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:getDeclaringClass, getName, invoke
        } 
    } 
 
    public R invoke(T target, Object... args) {
        try { 
            Object result = method.invoke(target, args);
            return returnType.cast(result);
        } catch (InvocationTargetException e) {
            throw UncheckedException.throwAsUncheckedException(e.getCause());
        } catch (Exception e) {
            throw new GradleException(String.format("Could not call %s.%s() on %s", method.getDeclaringClass().getSimpleName(), method.getName(), target), e);
        } 
    } 
 
    public Method getMethod() {
        return method;
    } 
 
    public Class<?>[] getParameterTypes(){
        return method.getParameterTypes();
7
CodeRank

Related Method getDeclaringClass Questions & Answers:

getDeclaringClass Method Overview
Returns the Class object representing the class or interface that declares the executable represented by this object.
See Code Examples for other Java 8 Method Methods: