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

The following examples show how to use java.lang.reflect.Executable#getName() . 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: CTVMUtilities.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public ClassVisitorForLabels(ClassWriter cw, Map<Label, Integer> lines,
                             Executable target) {
    super(Opcodes.ASM5, cw);
    this.lineNumbers = lines;

    StringBuilder builder = new StringBuilder("(");
    for (Parameter parameter : target.getParameters()) {
        builder.append(Utils.toJVMTypeSignature(parameter.getType()));
    }
    builder.append(")");
    if (target instanceof Constructor) {
        targetName = "<init>";
        builder.append("V");
    } else {
        targetName = target.getName();
        builder.append(Utils.toJVMTypeSignature(
                ((Method) target).getReturnType()));
    }
    targetDesc = builder.toString();
}
 
Example 2
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 3
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 4
Source File: MethodDescriptorCollector.java    From AVM with MIT License 5 votes vote down vote up
private static String getMethodName(Executable method) {
    if (method instanceof Constructor) {
        RuntimeAssertionError.assertTrue(!Modifier.isStatic(method.getModifiers()));
        return "<init>";
    } else {
        return method.getName();
    }
}
 
Example 5
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 6
Source File: FuzzStatement.java    From JQF with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ParameterTypeContext createParameterTypeContext(Parameter parameter) {
    Executable exec = parameter.getDeclaringExecutable();
    String declarerName = exec.getDeclaringClass().getName() + '.' + exec.getName();
    return new ParameterTypeContext(
                    parameter.getName(),
                    parameter.getAnnotatedType(),
                    declarerName,
                    typeVariables)
                    .allowMixedTypes(true).annotate(parameter);
}
 
Example 7
Source File: GetStackTraceElementTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void runSanityTest(Executable aMethod, int[] bcis) {
    HotSpotResolvedJavaMethod method = CTVMUtilities
            .getResolvedMethod(aMethod);
    String className = aMethod.getDeclaringClass().getName();
    String methodName = aMethod.getName().equals(className)
            ? "<init>"
            : aMethod.getName();
    String fileName = getFileName(className);
    Map<Integer, Integer> bciWithLineNumber = CTVMUtilities
            .getBciToLineNumber(aMethod);
    boolean isNative = Modifier.isNative(aMethod.getModifiers());
    int lineNumber = -1;
    for (int bci : bcis) {
        StackTraceElement ste = CompilerToVMHelper
                .getStackTraceElement(method, bci);
        Asserts.assertNotNull(ste, aMethod + " : got null StackTraceElement"
                + " at bci " + bci);
        Asserts.assertEQ(className, ste.getClassName(), aMethod
                + " : unexpected class name");
        Asserts.assertEQ(fileName, ste.getFileName(), aMethod
                + " : unexpected filename");
        Asserts.assertEQ(methodName, ste.getMethodName(), aMethod
                + " : unexpected method name");
        Asserts.assertEQ(isNative, ste.isNativeMethod(), aMethod
                + " : unexpected 'isNative' value");
        if (bciWithLineNumber.size() > 0) {
            if (bciWithLineNumber.containsKey(bci)) {
                lineNumber = bciWithLineNumber.get(bci);
            }
            Asserts.assertEQ(lineNumber, ste.getLineNumber(), aMethod
                    + " : unexpected line number");
        } else {
            // native and abstract function
            Asserts.assertGT(0, ste.getLineNumber(),
                    aMethod + " : unexpected line number for abstract "
                            + "or native method");
        }
    }

}
 
Example 8
Source File: MethodType.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public MethodType(Executable method) {
    // Use pack/subpack/Class::method separators style
    super(MethodDescriptor.Separator.DOT);
    if (method instanceof Constructor) {
        element = "<init>";
    } else {
        element = method.getName();
    }
    regexp = element;
}
 
Example 9
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;
}
 
Example 10
Source File: TypeMappingException.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
public static TypeMappingException ambiguousParameterType(Executable executable, Parameter parameter, Exception cause) {
    return new TypeMappingException("Parameter \"" + parameter.getName() + "\" of method \"" + executable.getName() +
            "\" is missing generic type parameters and can not be mapped." +
            " For details and possible solutions see " + Urls.Errors.AMBIGUOUS_PARAMETER_TYPE, cause);
}