本文整理汇总了Java中org.reflections.ReflectionsException类的典型用法代码示例。如果您正苦于以下问题:Java ReflectionsException类的具体用法?Java ReflectionsException怎么用?Java ReflectionsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReflectionsException类属于org.reflections包,在下文中一共展示了ReflectionsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSubtypes
import org.reflections.ReflectionsException; //导入依赖的package包/类
private Set<Class<?>> getSubtypes(final Class<?> type) throws ComboBoxIsTooFullException {
final ClassLoader[] classloaders = new ClassLoader[] { currentModelHandler.getCustomClassLoader(),
currentModelHandler.getCustomClassLoader().getParent() };
final ConfigurationBuilder builder = new ConfigurationBuilder().
addUrls(ClasspathHelper.forClassLoader(currentModelHandler.getCustomClassLoader())).
addClassLoaders(classloaders).
setScanners(new SubTypesScanner(false));
final Reflections ref = new Reflections(builder);
final Set<Class<?>> result = new HashSet<Class<?>>();
final Set<String> subTypesStr = ref.getStore().getSubTypesOf(type.getName());
if (subTypesStr.size() > MAX_SIZE_OF_SUBPARAMETER_COMBOBOX)
throw new ComboBoxIsTooFullException();
for (final String clsName : subTypesStr) {
try {
result.add(ReflectionUtils.forName(clsName,classloaders));
} catch (final ReflectionsException e) {
// intentionally blank
}
}
return result;
}
示例2: fromURL
import org.reflections.ReflectionsException; //导入依赖的package包/类
/** tries to create a Dir from the given url, using the given urlTypes*/
public static Dir fromURL(final URL url, final List<UrlType> urlTypes) {
for (UrlType type : urlTypes) {
try {
if (type.matches(url)) {
Dir dir = type.createDir(url);
if (dir != null) return dir;
}
} catch (Throwable e) {
/*if (Reflections.log != null) {
Reflections.log.warn("could not create Dir using " + type + " from url " + url.toExternalForm() + ". skipping.", e);
}*/
}
}
throw new ReflectionsException("could not create Vfs.Dir from url, no matching UrlType was found [" + url.toExternalForm() + "]\n" +
"either use fromURL(final URL url, final List<UrlType> urlTypes) or " +
"use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) " +
"with your specialized UrlType.");
}
示例3: fromURL
import org.reflections.ReflectionsException; //导入依赖的package包/类
/** tries to create a Dir from the given url, using the given urlTypes*/
public static Dir fromURL(final URL url, final List<UrlType> urlTypes) {
for (UrlType type : urlTypes) {
try {
if (type.matches(url)) {
Dir dir = type.createDir(url);
if (dir != null) return dir;
}
} catch (Throwable e) {
if (Reflections.log != null) {
Reflections.log.warn("could not create Dir using " + type + " from url " + url.toExternalForm() + ". skipping.", e);
}
}
}
throw new ReflectionsException("could not create Vfs.Dir from url, no matching UrlType was found [" + url.toExternalForm() + "]\n" +
"either use fromURL(final URL url, final List<UrlType> urlTypes) or " +
"use the static setDefaultURLTypes(final List<UrlType> urlTypes) or addDefaultURLTypes(UrlType urlType) " +
"with your specialized UrlType.");
}
示例4: resolveMethod
import org.reflections.ReflectionsException; //导入依赖的package包/类
public static Method resolveMethod(final Class aMethod) {
String methodOgnl = aMethod.getSimpleName();
try {
String methodName;
Class<?>[] paramTypes;
if (methodOgnl.contains(tokenSeparator)) {
methodName = methodOgnl.substring(0, methodOgnl.indexOf(tokenSeparator));
String[] params = methodOgnl.substring(methodOgnl.indexOf(tokenSeparator) + 1).split(doubleSeparator);
paramTypes = new Class<?>[params.length];
for (int i = 0; i < params.length; i++) {
String typeName = params[i].replace(arrayDescriptor, "[]").replace(pathSeparator, dotSeparator);
paramTypes[i] = ReflectionUtils.forName(typeName);
}
} else {
methodName = methodOgnl;
paramTypes = null;
}
Class<?> declaringClass = aMethod.getDeclaringClass().getDeclaringClass();
return resolveClassOf(declaringClass).getDeclaredMethod(methodName, paramTypes);
} catch (Exception e) {
throw new ReflectionsException("could not resolve to method " + aMethod.getName(), e);
}
}
示例5: scan
import org.reflections.ReflectionsException; //导入依赖的package包/类
@Override
public Object scan(Vfs.File file, Object classObject) {
if (classObject == null) {
try {
classObject = configuration.getMetadataAdapter().getOfCreateClassObject(file);
} catch (Exception e) {
throw new ReflectionsException("could not create class object from file " + file.getRelativePath());
}
}
scan(classObject);
return classObject;
}
示例6: PackageScope
import org.reflections.ReflectionsException; //导入依赖的package包/类
PackageScope(JPackage pack, GlobalScope parent) {
super(pack.name(), parent);
this.pack = pack;
Reflections reflections = new Reflections(name(), new SubTypesScanner(false));
try {
for (String s : reflections.getAllTypes()) {
Optional<JClass> ojc = Optional.absent();
externalTypes.put(s, ojc);
}
} catch (ReflectionsException ex) { // it's ok for this to happen...a new package will indeed be empty
Logger.warn("No types in package " + name());
}
}
示例7: replaceZipSeparators
import org.reflections.ReflectionsException; //导入依赖的package包/类
URL replaceZipSeparators(String path, Predicate<File> acceptFile)
throws MalformedURLException {
int pos = 0;
while (pos != -1) {
pos = findFirstMatchOfDeployableExtention(path, pos);
if (pos > 0) {
File file = new File(path.substring(0, pos - 1));
if (acceptFile.apply(file)) { return replaceZipSeparatorStartingFrom(path, pos); }
}
}
throw new ReflectionsException("Unable to identify the real zip file in path '" + path + "'.");
}
示例8: scan
import org.reflections.ReflectionsException; //导入依赖的package包/类
public Object scan(Vfs.File file, Object classObject) {
if (classObject == null) {
try {
classObject = configuration.getMetadataAdapter().getOrCreateClassObject(file);
} catch (Exception e) {
throw new ReflectionsException("could not create class object from file " + file.getRelativePath(), e);
}
}
scan(classObject);
return classObject;
}
示例9: getOrCreateClassObject
import org.reflections.ReflectionsException; //导入依赖的package包/类
public ClassFile getOrCreateClassObject(final Vfs.File file) {
InputStream inputStream = null;
try {
inputStream = file.openInputStream();
DataInputStream dis = new DataInputStream(new BufferedInputStream(inputStream));
return new ClassFile(dis);
} catch (IOException e) {
throw new ReflectionsException("could not create class file from " + file.getName(), e);
} finally {
Utils.close(inputStream);
}
}
示例10: parse
import org.reflections.ReflectionsException; //导入依赖的package包/类
/**
* Parses a string representation of an include/exclude filter.
* <p>
* The given includeExcludeString is a comma separated list of regexes,
* each starting with either + or - to indicate include/exclude.
* <p>
* For example parsePackages("-java\\..*, -javax\\..*, -sun\\..*, -com\\.sun\\..*")
* or parse("+com\\.myn\\..*,-com\\.myn\\.excluded\\..*").
* Note that "-java\\..*" will block "java.foo" but not "javax.foo".
* <p>
* See also the more useful {@link FilterBuilder#parsePackages(String)} method.
*/
public static FilterBuilder parse(String includeExcludeString) {
List<Predicate<String>> filters = new ArrayList<Predicate<String>>();
if (!Utils.isEmpty(includeExcludeString)) {
for (String string : includeExcludeString.split(",")) {
String trimmed = string.trim();
char prefix = trimmed.charAt(0);
String pattern = trimmed.substring(1);
Predicate<String> filter;
switch (prefix) {
case '+':
filter = new Include(pattern);
break;
case '-':
filter = new Exclude(pattern);
break;
default:
throw new ReflectionsException("includeExclude should start with either + or -");
}
filters.add(filter);
}
return new FilterBuilder(filters);
} else {
return new FilterBuilder();
}
}
示例11: parsePackages
import org.reflections.ReflectionsException; //导入依赖的package包/类
/**
* Parses a string representation of an include/exclude filter.
* <p>
* The given includeExcludeString is a comma separated list of package name segments,
* each starting with either + or - to indicate include/exclude.
* <p>
* For example parsePackages("-java, -javax, -sun, -com.sun") or parse("+com.myn,-com.myn.excluded").
* Note that "-java" will block "java.foo" but not "javax.foo".
* <p>
* The input strings "-java" and "-java." are equivalent.
*/
public static FilterBuilder parsePackages(String includeExcludeString) {
List<Predicate<String>> filters = new ArrayList<Predicate<String>>();
if (!Utils.isEmpty(includeExcludeString)) {
for (String string : includeExcludeString.split(",")) {
String trimmed = string.trim();
char prefix = trimmed.charAt(0);
String pattern = trimmed.substring(1);
if (pattern.endsWith(".") == false) {
pattern += ".";
}
pattern = prefix(pattern);
Predicate<String> filter;
switch (prefix) {
case '+':
filter = new Include(pattern);
break;
case '-':
filter = new Exclude(pattern);
break;
default:
throw new ReflectionsException("includeExclude should start with either + or -");
}
filters.add(filter);
}
return new FilterBuilder(filters);
} else {
return new FilterBuilder();
}
}
示例12: getMemberFromDescriptor
import org.reflections.ReflectionsException; //导入依赖的package包/类
public static Member getMemberFromDescriptor(String descriptor, ClassLoader... classLoaders) throws ReflectionsException {
int p0 = descriptor.lastIndexOf('(');
String memberKey = p0 != -1 ? descriptor.substring(0, p0) : descriptor;
String methodParameters = p0 != -1 ? descriptor.substring(p0 + 1, descriptor.lastIndexOf(')')) : "";
int p1 = Math.max(memberKey.lastIndexOf('.'), memberKey.lastIndexOf("$"));
String className = memberKey.substring(memberKey.lastIndexOf(' ') + 1, p1);
String memberName = memberKey.substring(p1 + 1);
Class<?>[] parameterTypes = null;
if (!isEmpty(methodParameters)) {
String[] parameterNames = methodParameters.split(",");
List<Class<?>> result = new ArrayList<Class<?>>(parameterNames.length);
for (String name : parameterNames) {
result.add(forName(name.trim(), classLoaders));
}
parameterTypes = result.toArray(new Class<?>[result.size()]);
}
Class<?> aClass = forName(className, classLoaders);
while (aClass != null) {
try {
if (!descriptor.contains("(")) {
return aClass.isInterface() ? aClass.getField(memberName) : aClass.getDeclaredField(memberName);
} else if (isConstructor(descriptor)) {
return aClass.isInterface() ? aClass.getConstructor(parameterTypes) : aClass.getDeclaredConstructor(parameterTypes);
} else {
return aClass.isInterface() ? aClass.getMethod(memberName, parameterTypes) : aClass.getDeclaredMethod(memberName, parameterTypes);
}
} catch (Exception e) {
aClass = aClass.getSuperclass();
}
}
throw new ReflectionsException("Can't resolve member named " + memberName + " for class " + className);
}
示例13: getMembersFromDescriptors
import org.reflections.ReflectionsException; //导入依赖的package包/类
public static Set<Member> getMembersFromDescriptors(Iterable<String> values, ClassLoader... classLoaders) {
Set<Member> result = Sets.newHashSet();
for (String value : values) {
try {
result.add(Utils.getMemberFromDescriptor(value, classLoaders));
} catch (ReflectionsException e) {
throw new ReflectionsException("Can't resolve member named " + value, e);
}
}
return result;
}
示例14: getFieldFromString
import org.reflections.ReflectionsException; //导入依赖的package包/类
public static Field getFieldFromString(String field, ClassLoader... classLoaders) {
String className = field.substring(0, field.lastIndexOf('.'));
String fieldName = field.substring(field.lastIndexOf('.') + 1);
try {
return forName(className, classLoaders).getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
throw new ReflectionsException("Can't resolve field named " + fieldName, e);
}
}
示例15: resolveClass
import org.reflections.ReflectionsException; //导入依赖的package包/类
public static Class<?> resolveClass(final Class aClass) {
try {
return resolveClassOf(aClass);
} catch (Exception e) {
throw new ReflectionsException("could not resolve to class " + aClass.getName(), e);
}
}