Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2014 - Present Rafael Winterhalter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.bytebuddy.utility;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.annotation.AnnotationList;
import net.bytebuddy.description.annotation.AnnotationSource;
import net.bytebuddy.description.type.PackageDescription;
import java.io.InputStream;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
/**
* Type-safe representation of a {@code java.lang.Module}. On platforms that do not support the module API, modules are represented by {@code null}.
*/
public class JavaModule implements NamedElement.WithOptionalName, AnnotationSource {
/**
* Canonical representation of a Java module on a JVM that does not support the module API.
*/
public static final JavaModule UNSUPPORTED = null;
/**
* The dispatcher to use for accessing Java modules, if available.
*/
private static final Dispatcher DISPATCHER = AccessController.doPrivileged(Dispatcher.CreationAction.INSTANCE);
/**
* The {@code java.lang.Module} instance this wrapper represents.
*/
private final AnnotatedElement module;
/**
* Creates a new Java module representation.
*
* @param module The {@code java.lang.Module} instance this wrapper represents.
*/
protected JavaModule(AnnotatedElement module) {
this.module = module;
}
/**
* Returns a representation of the supplied type's {@code java.lang.Module} or {@code null} if the current VM does not support modules.
*
* @param type The type for which to describe the module.
* @return A representation of the type's module or {@code null} if the current VM does not support modules.
*/
public static JavaModule ofType(Class> type) {
return DISPATCHER.moduleOf(type);
}
/**
* Represents the supplied {@code java.lang.Module} as an instance of this class and validates that the
* supplied instance really represents a Java {@code Module}.
*
* @param module The module to represent.
* @return A representation of the supplied Java module.
*/
public static JavaModule of(Object module) {
if (!JavaType.MODULE.isInstance(module)) {
throw new IllegalArgumentException("Not a Java module: " + module);
}
return new JavaModule((AnnotatedElement) module);
}
/**
* Checks if the current VM supports the {@code java.lang.Module} API.
*
* @return {@code true} if the current VM supports modules.
*/
public static boolean isSupported() {
return DISPATCHER.isAlive();
}
/**
* {@inheritDoc}
*/
public boolean isNamed() {
return DISPATCHER.isNamed(module);
}
/**
* {@inheritDoc}
*/
public String getActualName() {
return DISPATCHER.getName(module);
}
/**
* Returns a resource stream for this module for a resource of the given name or {@code null} if such a resource does not exist.
*
* @param name The name of the resource.
* @return An input stream for the resource or {@code null} if it does not exist.
*/
public InputStream getResourceAsStream(String name) {
return DISPATCHER.getResourceAsStream(module, name);
}
/**
* Returns the class loader of this module.
*
* @return The class loader of the represented module.
*/
public ClassLoader getClassLoader() {
return DISPATCHER.getClassLoader(module);
}
/**
* Unwraps this instance to a {@code java.lang.Module}.
*
* @return The represented {@code java.lang.Module}.
*/
public Object unwrap() {
return module;
}
/**
* Checks if this module can read the exported packages of the supplied module.
*
* @param module The module to check for its readability by this module.
* @return {@code true} if this module can read the supplied module.
*/
public boolean canRead(JavaModule module) {
return DISPATCHER.canRead(this.module, module.unwrap());
}
/**
* Returns {@code true} if this module exports the supplied package to this module.
*
* @param packageDescription The package to check for
* @param module The target module.
* @return {@code true} if this module exports the supplied package to this module.
*/
public boolean isExported(PackageDescription packageDescription, JavaModule module) {
return packageDescription == null || DISPATCHER.isExported(this.module, module.unwrap(), packageDescription.getName());
}
/**
* Returns {@code true} if this module opens the supplied package to this module.
*
* @param packageDescription The package to check for.
* @param module The target module.
* @return {@code true} if this module opens the supplied package to this module.
*/
public boolean isOpened(PackageDescription packageDescription, JavaModule module) {
return packageDescription == null || DISPATCHER.isOpened(this.module, module.unwrap(), packageDescription.getName());
}
/**
* {@inheritDoc}
*/
public AnnotationList getDeclaredAnnotations() {
return new AnnotationList.ForLoadedAnnotations(module.getDeclaredAnnotations());
}
/**
* Modifies this module's properties.
*
* @param instrumentation The instrumentation instace to use for applying the modification.
* @param reads A set of additional modules this module should read.
* @param exports A map of packages to export to a set of modules.
* @param opens A map of packages to open to a set of modules.
* @param uses A set of provider interfaces to use by this module.
* @param provides A map of provider interfaces to provide by this module mapped to the provider implementations.
*/
public void modify(Instrumentation instrumentation,
Set reads,
Map> exports,
Map> opens,
Set> uses,
Map, List>> provides) {
Set