Java Code Examples for java.lang.reflect.Executable#getDeclaringClass()

The following examples show how to use java.lang.reflect.Executable#getDeclaringClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCompilerInlining.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public MethodDesc(Executable executable) {
    Class<?> aClass = executable.getDeclaringClass();
    className = Type.getInternalName(aClass).replace('.', '/');

    if (executable instanceof Constructor<?>) {
        methodName = "<init>";
        descriptor = Type.getConstructorDescriptor((Constructor<?>) executable);
    } else {
        methodName = executable.getName();
        descriptor = Type.getMethodDescriptor((Method) executable);
    }

}
 
Example 2
Source File: AvmDetails.java    From AVM with MIT License 5 votes vote down vote up
private static boolean hasValidParamTypes(Executable method) {
    for (Class<?> c : method.getParameterTypes()) {
        if (!isShadowClass(c.getName()) &&
                !isArrayWrapperClass(c.getName()) &&
                !isPrimitive(c) &&
                !isSupportedInternalType(c.getName())) {
            if (method instanceof Method) {
                throw new AssertionError("transformed method " + method.getDeclaringClass() + "." + method.getName() + " should not have an unsupported parameter type: " + c.getName());
            }
            return false;
        }
    }
    return true;
}
 
Example 3
Source File: TestCompilerInlining.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public MethodDesc(Executable executable) {
    Class<?> aClass = executable.getDeclaringClass();
    className = Type.getInternalName(aClass).replace('.', '/');

    if (executable instanceof Constructor<?>) {
        methodName = "<init>";
        descriptor = Type.getConstructorDescriptor((Constructor<?>) executable);
    } else {
        methodName = executable.getName();
        descriptor = Type.getMethodDescriptor((Method) executable);
    }

}
 
Example 4
Source File: ClassType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public ClassType(Executable method) {
    // Use pack/subpack/Class::method separators style
    super(MethodDescriptor.Separator.SLASH);
    // Get package
    aClass = method.getDeclaringClass();
    Package aPackage = method.getDeclaringClass().getPackage();
    if (aPackage != null) {
        // split into directories
        packageDirs = aPackage.getName().split("\\.");
    } else {
        packageDirs = null;
    }
    setPackage = true;
    buildElement(setPackage);
}
 
Example 5
Source File: AnnotatedServiceFactory.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the description of the specified {@link AnnotatedElement}.
 */
@Nullable
static String findDescription(AnnotatedElement annotatedElement) {
    requireNonNull(annotatedElement, "annotatedElement");
    final Description description = AnnotationUtil.findFirst(annotatedElement, Description.class);
    if (description != null) {
        final String value = description.value();
        if (DefaultValues.isSpecified(value)) {
            checkArgument(!value.isEmpty(), "value is empty.");
            return value;
        }
    } else if (annotatedElement instanceof Parameter) {
        // JavaDoc/KDoc descriptions only exist for method parameters
        final Parameter parameter = (Parameter) annotatedElement;
        final Executable executable = parameter.getDeclaringExecutable();
        final Class<?> clazz = executable.getDeclaringClass();
        final String fileName = getFileName(clazz.getCanonicalName());
        final String propertyName = executable.getName() + '.' + parameter.getName();
        final Properties cachedProperties = DOCUMENTATION_PROPERTIES_CACHE.getIfPresent(fileName);
        if (cachedProperties != null) {
            return cachedProperties.getProperty(propertyName);
        }
        try (InputStream stream = AnnotatedServiceFactory.class.getClassLoader()
                                                               .getResourceAsStream(fileName)) {
            if (stream == null) {
                return null;
            }
            final Properties properties = new Properties();
            properties.load(stream);
            DOCUMENTATION_PROPERTIES_CACHE.put(fileName, properties);
            return properties.getProperty(propertyName);
        } catch (IOException exception) {
            logger.warn("Failed to load an API description file: {}", fileName, exception);
        }
    }
    return null;
}