List of usage examples for org.apache.commons.lang3 ClassUtils getPackageCanonicalName
public static String getPackageCanonicalName(final String canonicalName)
Gets the package name from the canonical name.
From source file:com.wavemaker.tools.apidocs.tools.parser.util.DataTypeUtil.java
public static String getFullyQualifiedName(Class<?> type) { String packageName = ClassUtils.getPackageCanonicalName(type); String prefix = StringUtils.isNotBlank(packageName) ? packageName + ClassUtils.PACKAGE_SEPARATOR : ""; return prefix + ClassUtils.getShortCanonicalName(type); }
From source file:org.lambdamatic.mongodb.apt.template.MetadataTemplateContext.java
/** * Finds all required import statements that need to be included in the target template. * // w w w.j a v a 2s. c o m * @return the {@link List} of class imports (excluding those in the same package) */ public List<String> getRequiredImports() { // combining required types on annotations and fields final List<String> requiredImports = Stream .concat(this.templateFields.stream().flatMap(f -> f.getRequiredJavaTypes().stream()), this.annotations.stream().flatMap(a -> a.getRequiredJavaTypes().stream())) .filter(i -> { final String packageCanonicalName = ClassUtils.getPackageCanonicalName(i); return !packageCanonicalName.equals(getPackageName()) && !packageCanonicalName.equals("java.lang"); }).distinct().sorted().collect(Collectors.toList()); return requiredImports; }
From source file:uk.q3c.krail.core.validation.DefaultKrailInterpolator.java
/** * Returns true if the annotation in the {@code context} is in the javax.validation.constraints package * * @param context/*w w w .ja v a2 s. com*/ * * @return */ protected boolean isJavaxAnnotation(Context context) { String annotationClassName = annotationClass(context).getName(); String javaxPackageName = ClassUtils.getPackageCanonicalName(Min.class); return annotationClassName.startsWith(javaxPackageName); }
From source file:uk.q3c.krail.core.validation.DefaultKrailInterpolator.java
/** * Find a an I18NKey from its full string representation (for example uk.q3c.krail.i18n.LabelKey.Yes). The full * string representation can be obtained using {@link I18NKey#fullName(I18NKey)} * * @param keyName//from ww w .j a va 2 s .c o m * * @return the I18NKey for the supplied name, or null if not found for any reason */ protected I18NKey findI18NKey(String keyName) { String k = keyName.replace("{", "").replace("}", "").trim(); //This is cheating, using ClassUtils to split by '.', these are not package and class names String enumClassName = ClassUtils.getPackageCanonicalName(k); String constantName = ClassUtils.getShortClassName(k); Enum<?> enumConstant; try { Class<Enum> enumClass = (Class<Enum>) Class.forName(enumClassName); enumConstant = Enum.valueOf(enumClass, constantName); } catch (Exception e) { log.warn("Could not find an I18NKey for {}", k); enumConstant = null; } I18NKey key = (I18NKey) enumConstant; return key; }
From source file:uk.q3c.krail.core.validation.KrailInterpolator.java
/** * Find a an I18NKey from its full string representation (for example uk.q3c.krail.core.entity.LabelKey.Yes). The full * string representation can be obtained using {@link I18NKey#fullName(I18NKey)} * * @param keyName/*from w ww . j av a 2 s .co m*/ * * @return the I18NKey for the supplied name, or null if not found for any reason */ protected I18NKey findI18NKey(String keyName) { String k = keyName.replace("{", "").replace("}", "").trim(); //This is cheating, using ClassUtils to split by '.', these are not package and class names String enumClassName = ClassUtils.getPackageCanonicalName(k); String constantName = ClassUtils.getShortClassName(k); Enum<?> enumConstant; try { Class<Enum> enumClass = (Class<Enum>) Class.forName(enumClassName); enumConstant = Enum.valueOf(enumClass, constantName); } catch (Exception e) { log.warn("Could not find an I18NKey for {}", k); enumConstant = null; } return (I18NKey) enumConstant; }
From source file:uk.q3c.krail.core.validation.KrailInterpolator.java
/** * Returns true if the annotation in the {@code context} is in the org.apache.bval.constraints package * * @param context// w w w . ja va 2 s.c om * * @return */ protected boolean isBValAnnotation(Context context) { String annotationClassName = annotationClass(context).getName(); String bvalPackageName = ClassUtils.getPackageCanonicalName(Email.class); return annotationClassName.startsWith(bvalPackageName); }
From source file:uk.q3c.krail.i18n.BundleReaderBase.java
/** * Allows the setting of paths for location of class and property files. The bundle base name is taken from {@link * I18NKey#bundleName()}.// ww w. j a v a2 s .co m * <p> * {@link Option} entries determine how the bundle name is expanded. If USE_KEY_PATH is true, the bundle name is * appended to the package path of the {@code sampleKey} * <p> * If USE_KEY_PATH is false, the bundle name is appended to {@link Option} PATH * * @param source * the name of the source being used, as provided via {@link I18NModule#addBundleReader(String, Class)} * @param sampleKey * any key from the I18NKey class, to give access to bundleName() * * @return */ protected String expandFromKey(String source, I18NKey sampleKey) { String baseName = sampleKey.bundleName(); String packageName; //use sub-class names to qualify the options, so they get their own, and not the base class if (option.get(true, getOptionKeyUseKeyPath().qualifiedWith(source))) { packageName = ClassUtils.getPackageCanonicalName(sampleKey.getClass()); } else { packageName = option.get("", getOptionKeyPath().qualifiedWith(source)); } String expanded = packageName.isEmpty() ? baseName : packageName + "." + baseName; return expanded; }
From source file:uk.q3c.krail.i18n.ClassBundleWriter.java
@Override public void setBundle(EnumResourceBundle<E> bundle) { super.setBundle(bundle); this.clazz = bundle.getClass(); this.keyClass = bundle.getKeyClass(); this.superClass = clazz.getSuperclass(); this.entryMap = bundle.getMap(); this.pkg = ClassUtils.getPackageCanonicalName(clazz); classJavaDoc = "Generated by Krail " + LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); }
From source file:yoyo.framework.standard.shared.commons.lang.ClassUtilsTest.java
@Test public void test() throws ClassNotFoundException, SecurityException, NoSuchMethodException { List<Class<?>> classes = new ArrayList<Class<?>>() { {//from w w w . j a v a2 s . c o m add(Integer.class); add(Long.class); } }; assertThat(ClassUtils.convertClassesToClassNames(classes).toArray(), is(new Object[] { "java.lang.Integer", "java.lang.Long" })); List<String> classNames = new ArrayList<String>() { { add("java.lang.Integer"); add("java.lang.Long"); } }; assertThat(ClassUtils.convertClassNamesToClasses(classNames).toArray(), is(classes.toArray())); assertThat(ClassUtils.getAllInterfaces(String.class).toArray(), is(new Object[] { java.io.Serializable.class, java.lang.Comparable.class, java.lang.CharSequence.class })); assertThat(ClassUtils.getAllSuperclasses(HashMap.class).toArray(), is(new Object[] { java.util.AbstractMap.class, java.lang.Object.class })); assertThat(ClassUtils.getClass("java.lang.String").toString(), is("class java.lang.String")); assertThat(ClassUtils.getPackageCanonicalName(String.class), is("java.lang")); assertThat(ClassUtils.getPackageName(String.class), is("java.lang")); assertThat(ClassUtils.getPublicMethod(String.class, "length", new Class[] {}), is(not(nullValue()))); assertThat(ClassUtils.getShortCanonicalName(String.class), is("String")); assertThat(ClassUtils.getShortClassName(String.class), is("String")); assertThat(ClassUtils.getSimpleName(String.class), is("String")); assertThat(ClassUtils.isAssignable(String.class, Object.class), is(true)); assertThat(ClassUtils.isInnerClass(Foo.class), is(true)); assertThat(ClassUtils.isInnerClass(String.class), is(false)); assertThat(ClassUtils.isPrimitiveOrWrapper(Integer.class), is(true)); assertThat(ClassUtils.isPrimitiveOrWrapper(String.class), is(false)); assertThat(ClassUtils.isPrimitiveWrapper(Integer.class), is(true)); assertThat(ClassUtils.isPrimitiveWrapper(String.class), is(false)); assertThat(ClassUtils.primitivesToWrappers(new Class[] { Integer.class, Long.class }), is(not(nullValue()))); assertThat(ClassUtils.primitiveToWrapper(Integer.class), is(not(nullValue()))); assertThat(ClassUtils.toClass(1L, 2L), is(not(nullValue()))); assertThat(ClassUtils.wrappersToPrimitives(new Class[] { Integer.class, Long.class }), is(not(nullValue()))); assertThat(ClassUtils.wrapperToPrimitive(Integer.class), is(not(nullValue()))); }