Java Code Examples for net.bytebuddy.ClassFileVersion#isAtLeast()

The following examples show how to use net.bytebuddy.ClassFileVersion#isAtLeast() . 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: JavaVersionRule.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
public Statement apply(Statement base, FrameworkMethod method, Object target) {
    Enforce enforce = method.getAnnotation(Enforce.class);
    if (enforce != null) {
        ClassFileVersion version;
        try {
            version = enforce.target() == void.class
                    ? currentVersion
                    : ClassFileVersion.of(enforce.target());
        } catch (IOException exception) {
            throw new AssertionError(exception);
        }
        if (j9 && !enforce.j9()) {
            return new OpenJ9Statement();
        } else if (enforce.value() != UNDEFINED && !version.isAtLeast(ClassFileVersion.ofJavaVersion(enforce.value()))) {
            return new NoOpStatement(enforce.value(), "at least", enforce.target());
        } else if (enforce.atMost() != UNDEFINED && !version.isAtMost(ClassFileVersion.ofJavaVersion(enforce.atMost()))) {
            return new NoOpStatement(enforce.atMost(), "at most", enforce.target());
        }
    }
    return base;
}
 
Example 2
Source File: JavaVersionRule.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
public Statement apply(Statement base, FrameworkMethod method, Object target) {
    Enforce enforce = method.getAnnotation(Enforce.class);
    if (enforce != null) {
        ClassFileVersion version;
        try {
            version = enforce.target() == void.class
                    ? currentVersion
                    : ClassFileVersion.of(enforce.target());
        } catch (IOException exception) {
            throw new AssertionError(exception);
        }
        if (j9 && !enforce.j9()) {
            return new OpenJ9Statement();
        } else if (enforce.value() != UNDEFINED && !version.isAtLeast(ClassFileVersion.ofJavaVersion(enforce.value()))) {
            return new NoOpStatement(enforce.value(), "at least", enforce.target());
        } else if (enforce.atMost() != UNDEFINED && !version.isAtMost(ClassFileVersion.ofJavaVersion(enforce.atMost()))) {
            return new NoOpStatement(enforce.atMost(), "at most", enforce.target());
        }
    }
    return base;
}
 
Example 3
Source File: MethodRegistry.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public MethodRegistry.Compiled compile(Implementation.Target.Factory implementationTargetFactory, ClassFileVersion classFileVersion) {
    Map<Handler, Handler.Compiled> compilationCache = new HashMap<Handler, Handler.Compiled>();
    Map<MethodAttributeAppender.Factory, MethodAttributeAppender> attributeAppenderCache = new HashMap<MethodAttributeAppender.Factory, MethodAttributeAppender>();
    LinkedHashMap<MethodDescription, Compiled.Entry> entries = new LinkedHashMap<MethodDescription, Compiled.Entry>();
    Implementation.Target implementationTarget = implementationTargetFactory.make(instrumentedType, methodGraph, classFileVersion);
    for (Map.Entry<MethodDescription, Entry> entry : implementations.entrySet()) {
        Handler.Compiled cachedHandler = compilationCache.get(entry.getValue().getHandler());
        if (cachedHandler == null) {
            cachedHandler = entry.getValue().getHandler().compile(implementationTarget);
            compilationCache.put(entry.getValue().getHandler(), cachedHandler);
        }
        MethodAttributeAppender cachedAttributeAppender = attributeAppenderCache.get(entry.getValue().getAppenderFactory());
        if (cachedAttributeAppender == null) {
            cachedAttributeAppender = entry.getValue().getAppenderFactory().make(instrumentedType);
            attributeAppenderCache.put(entry.getValue().getAppenderFactory(), cachedAttributeAppender);
        }
        entries.put(entry.getKey(), new Compiled.Entry(cachedHandler,
                cachedAttributeAppender,
                entry.getValue().getMethodDescription(),
                entry.getValue().resolveBridgeTypes(),
                entry.getValue().getVisibility(),
                entry.getValue().isBridgeMethod()));
    }
    return new Compiled(instrumentedType,
            loadedTypeInitializer,
            typeInitializer,
            methods,
            entries,
            classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5));
}
 
Example 4
Source File: Implementation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Resolves a default method invocation depending on the class file version permitting such calls.
 *
 * @param classFileVersion The class file version to resolve for.
 * @return A suitable default method invocation mode.
 */
public static DefaultMethodInvocation of(ClassFileVersion classFileVersion) {
    return classFileVersion.isAtLeast(ClassFileVersion.JAVA_V8)
            ? ENABLED
            : DISABLED;
}