Java Code Examples for io.micronaut.core.naming.NameUtils#decapitalize()
The following examples show how to use
io.micronaut.core.naming.NameUtils#decapitalize() .
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: ProjectionMethodExpression.java From micronaut-data with Apache License 2.0 | 6 votes |
@Override protected ProjectionMethodExpression initProjection(@NonNull MethodMatchContext matchContext, String remaining) { if (StringUtils.isEmpty(remaining)) { this.expectedType = matchContext.getRootEntity().getType(); return this; } else { this.property = NameUtils.decapitalize(remaining); SourcePersistentProperty pp = matchContext.getRootEntity().getPropertyByName(property); if (pp == null || pp.getType() == null) { matchContext.fail("Cannot project on non-existent property " + property); return null; } this.expectedType = pp.getType(); return this; } }
Example 2
Source File: ProjectionMethodExpression.java From micronaut-data with Apache License 2.0 | 6 votes |
@Override protected ProjectionMethodExpression initProjection(@NonNull MethodMatchContext matchContext, String remaining) { if (StringUtils.isEmpty(remaining)) { matchContext.fail(getClass().getSimpleName() + " projection requires a property name"); return null; } else { this.property = NameUtils.decapitalize(remaining); this.persistentProperty = (SourcePersistentProperty) matchContext.getRootEntity().getPropertyByPath(property).orElse(null); if (persistentProperty == null || persistentProperty.getType() == null) { matchContext.fail("Cannot project on non-existent property " + property); return null; } this.expectedType = resolveExpectedType(matchContext, persistentProperty.getType()); return this; } }
Example 3
Source File: ProjectionMethodExpression.java From micronaut-data with Apache License 2.0 | 4 votes |
/** * Match a projection. * @param matchContext The context * @param projection The projection to match * @return An expression or null if no match is possible or an error occurred. */ public static @Nullable ProjectionMethodExpression matchProjection(@NonNull MethodMatchContext matchContext, @NonNull String projection) { Class<?>[] innerClasses = ProjectionMethodExpression.class.getClasses(); SourcePersistentEntity entity = matchContext.getRootEntity(); String decapitilized = NameUtils.decapitalize(projection); Optional<String> path = entity.getPath(decapitilized); if (path.isPresent()) { return new Property().init(matchContext, projection); } else { for (Class<?> innerClass : innerClasses) { String simpleName = innerClass.getSimpleName(); if (projection.startsWith(simpleName)) { Object o; try { o = innerClass.newInstance(); } catch (Throwable e) { continue; } if (o instanceof ProjectionMethodExpression) { ProjectionMethodExpression pme = (ProjectionMethodExpression) o; ProjectionMethodExpression initialized = pme.init(matchContext, projection); if (initialized != null) { return initialized; } } } } // allow findAllBy as an alternative to findBy if (!Arrays.asList("all", "one").contains(decapitilized)) { Matcher topMatcher = Pattern.compile("^(top|first)(\\d*)$").matcher(decapitilized); if (topMatcher.find()) { return new RestrictMaxResultProjection(topMatcher, matchContext).initProjection(matchContext, decapitilized); } // if the return type simple name is the same then we assume this is ok // this allows for Optional findOptionalByName if (!projection.equals(matchContext.getReturnType().getSimpleName())) { matchContext.fail("Cannot project on non-existent property: " + decapitilized); } } return null; } }
Example 4
Source File: PersistentEntity.java From micronaut-data with Apache License 2.0 | 4 votes |
/** * @return Returns the name of the class decapitalized form */ default @NonNull String getDecapitalizedName() { return NameUtils.decapitalize(getSimpleName()); }