本文整理汇总了Java中org.reflections.ReflectionsException类的典型用法代码示例。如果您正苦于以下问题:Java ReflectionsException类的具体用法?Java ReflectionsException怎么用?Java ReflectionsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReflectionsException类属于org.reflections包,在下文中一共展示了ReflectionsException类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:crisis-economics,项目名称:CRISIS,代码行数:24,代码来源:Page_Parameters.java
示例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.");
}
开发者ID:apache,项目名称:servicemix-bundles,代码行数:21,代码来源:Vfs.java
示例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.");
}
开发者ID:ronmamo,项目名称:reflections,代码行数:21,代码来源:Vfs.java
示例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);
}
}
开发者ID:ronmamo,项目名称:reflections,代码行数:26,代码来源:JavaCodeSerializer.java
示例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;
}
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:13,代码来源:DataVecSubTypesScanner.java
示例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());
}
}
开发者ID:kompics,项目名称:kola,代码行数:15,代码来源:PackageScope.java
示例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 + "'.");
}
开发者ID:ronmamo,项目名称:reflections,代码行数:15,代码来源:UrlTypeVFS.java
示例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;
}
开发者ID:ronmamo,项目名称:reflections,代码行数:12,代码来源:AbstractScanner.java
示例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);
}
}
开发者ID:ronmamo,项目名称:reflections,代码行数:13,代码来源:JavassistAdapter.java
示例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();
}
}
开发者ID:ronmamo,项目名称:reflections,代码行数:42,代码来源:FilterBuilder.java
示例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();
}
}
开发者ID:ronmamo,项目名称:reflections,代码行数:45,代码来源:FilterBuilder.java
示例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);
}
开发者ID:ronmamo,项目名称:reflections,代码行数:36,代码来源:Utils.java
示例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;
}
开发者ID:ronmamo,项目名称:reflections,代码行数:12,代码来源:Utils.java
示例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);
}
}
开发者ID:ronmamo,项目名称:reflections,代码行数:11,代码来源:Utils.java
示例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);
}
}
开发者ID:ronmamo,项目名称:reflections,代码行数:8,代码来源:JavaCodeSerializer.java
示例16: resolveField
import org.reflections.ReflectionsException; //导入依赖的package包/类
public static Field resolveField(final Class aField) {
try {
String name = aField.getSimpleName();
Class<?> declaringClass = aField.getDeclaringClass().getDeclaringClass();
return resolveClassOf(declaringClass).getDeclaredField(name);
} catch (Exception e) {
throw new ReflectionsException("could not resolve to field " + aField.getName(), e);
}
}
开发者ID:ronmamo,项目名称:reflections,代码行数:10,代码来源:JavaCodeSerializer.java
示例17: resolveAnnotation
import org.reflections.ReflectionsException; //导入依赖的package包/类
public static Annotation resolveAnnotation(Class annotation) {
try {
String name = annotation.getSimpleName().replace(pathSeparator, dotSeparator);
Class<?> declaringClass = annotation.getDeclaringClass().getDeclaringClass();
Class<?> aClass = resolveClassOf(declaringClass);
Class<? extends Annotation> aClass1 = (Class<? extends Annotation>) ReflectionUtils.forName(name);
Annotation annotation1 = aClass.getAnnotation(aClass1);
return annotation1;
} catch (Exception e) {
throw new ReflectionsException("could not resolve to annotation " + annotation.getName(), e);
}
}
开发者ID:ronmamo,项目名称:reflections,代码行数:13,代码来源:JavaCodeSerializer.java
示例18: execute
import org.reflections.ReflectionsException; //导入依赖的package包/类
public void execute() throws MojoExecutionException, MojoFailureException {
//
if (StringUtils.isEmpty(destinations)) {
destinations = resolveOutputDirectory() + "/META-INF/reflections/" + getProject().getArtifactId() + "-reflections.xml";
}
String outputDirectory = resolveOutputDirectory();
if (!new File(outputDirectory).exists()) {
getLog().warn(String.format("Reflections plugin is skipping because %s was not found", outputDirectory));
return;
}
//
ConfigurationBuilder config = new ConfigurationBuilder();
config.setUrls(parseUrls());
if (!isEmpty(includeExclude)) {
config.filterInputsBy(FilterBuilder.parse(includeExclude));
}
config.setScanners(!isEmpty(scanners) ? parseScanners() : new Scanner[]{new SubTypesScanner(), new TypeAnnotationsScanner()});
if (!isEmpty(serializer)) {
try {
Serializer serializerInstance = (Serializer) forName(serializer, "org.reflections.serializers").newInstance();
config.setSerializer(serializerInstance);
if (serializerInstance instanceof JavaCodeSerializer) {
int size = config.getScanners().size();
config.addScanners(new TypeElementsScanner());
if (size != config.getScanners().size()) {
getLog().info("added type scanners for JavaCodeSerializer");
}
}
} catch (Exception ex) {
throw new ReflectionsException("could not create serializer instance", ex);
}
}
if (parallel != null && parallel.equals(Boolean.TRUE)) {
config.useParallelExecutor();
}
//
if (Reflections.log == null) {
try {
Reflections.log = new MavenLogAdapter(getLog());
} catch (Error e) {
//ignore
}
}
Reflections reflections = new Reflections(config);
reflections.save(destinations.trim());
}
开发者ID:ronmamo,项目名称:reflections-maven,代码行数:57,代码来源:ReflectionsMojo.java
注:本文中的org.reflections.ReflectionsException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论