All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reflext.jlr.JavaLangReflectMethodModel Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2003-2009 eXo Platform SAS.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.reflext.jlr;

import org.reflext.spi.model.MethodModel;
import org.reflext.api.AccessScope;

import java.lang.reflect.Type;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.ArrayList;

/**
 * @author Julien Viet
 * @version $Revision$
 */
public class JavaLangReflectMethodModel implements MethodModel {

  public Iterable getDeclaredMethods(Type classType) {
    Class clazz = (Class)classType;
    MethodContainer methods = new MethodContainer();
    for (Method declaredMethod : clazz.getDeclaredMethods()) {
      int modifiers = declaredMethod.getModifiers();
      if (!Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) {
        if (!declaredMethod.isBridge()) {
          methods.add(declaredMethod);
        }
      }
    }
    return methods;
  }

  public Iterable getParameterTypes(Method method) {
    return Arrays.asList(method.getGenericParameterTypes());
  }

  public String getName(Method method) {
    return method.getName();
  }

  public Type getReturnType(Method method) {
    return method.getGenericReturnType();
  }
  
  public AccessScope getAccess(Method method) {
    return JavaLangReflectReflectionModel.getAccess(method);
  }

  public boolean isAbstract(Method method) {
    return Modifier.isAbstract(method.getModifiers());
  }

  public boolean isStatic(Method method) {
    return Modifier.isStatic(method.getModifiers());
  }

  public boolean isNative(Method method) {
    return Modifier.isNative(method.getModifiers());
  }

  public boolean isFinal(Method method) {
    return Modifier.isFinal(method.getModifiers());
  }

  public Iterable getTypeParameters(Method method) {
    ArrayList typeParameters = new ArrayList();
    for (TypeVariable typeParameter : method.getTypeParameters()) {
      typeParameters.add(typeParameter);
    }
    return typeParameters;
  }

  public Iterable getParameterNames(Method method) {
    return null;
  }

  public Type getOwner(Method method) {
    return method.getDeclaringClass();
  }

  public Method getGenericDeclaration(Type typeVariable) {
    return (Method)((TypeVariable)typeVariable).getGenericDeclaration();
  }

  public Iterable getThrownTypes(Method method) {
    return Arrays.asList(method.getGenericExceptionTypes());
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy