List of usage examples for org.apache.commons.lang StringUtils uncapitalize
public static String uncapitalize(String str)
Uncapitalizes a String changing the first letter to title case as per Character#toLowerCase(char) .
From source file:com.kalessil.phpStorm.yii2inspections.inspectors.MissingPropertyAnnotationsInspector.java
@Override @NotNull//from ww w .ja va 2 s . co m public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new PhpElementVisitor() { @Override public void visitPhpClass(PhpClass clazz) { /* check only regular named classes */ final PsiElement nameNode = NamedElementUtil.getNameIdentifier(clazz); if (null == nameNode) { return; } /* check if the class inherited from yii\base\Object */ boolean supportsPropertyFeature = false; final Set<PhpClass> parents = InheritanceChainExtractUtil.collect(clazz); if (!parents.isEmpty()) { for (final PhpClass parent : parents) { if (baseObjectClasses.contains(parent.getFQN())) { supportsPropertyFeature = true; break; } } parents.clear(); } if (!supportsPropertyFeature) { return; } /* iterate get methods, find matching set methods */ final Map<String, String> props = this.findPropertyCandidates(clazz); if (props.size() > 0) { List<String> names = new ArrayList<>(props.keySet()); Collections.sort(names); final String message = messagePattern.replace("%p%", String.join("', '", names)); holder.registerProblem(nameNode, message, ProblemHighlightType.WEAK_WARNING, new TheLocalFix(props)); } } @NotNull private Map<String, String> findPropertyCandidates(@NotNull PhpClass clazz) { final Map<String, String> properties = new HashMap<>(); /* extract methods and operate on name-methods relations */ final Method[] methods = clazz.getOwnMethods(); if (null == methods || 0 == methods.length) { return properties; } final Map<String, Method> mappedMethods = new HashMap<>(); for (Method method : methods) { mappedMethods.put(method.getName(), method); } /* process extracted methods*/ for (String candidate : mappedMethods.keySet()) { Method getterMethod = null; Method setterMethod = null; /* extract methods: get (looks up and extracts set), set (looks up get and skipped if found) */ if (candidate.startsWith("get")) { getterMethod = mappedMethods.get(candidate); if (getterMethod.isStatic() || 0 != getterMethod.getParameters().length) { getterMethod = null; } final String complimentarySetter = candidate.replaceAll("^get", "set"); if (mappedMethods.containsKey(complimentarySetter)) { setterMethod = mappedMethods.get(complimentarySetter); if (setterMethod.isStatic() || 0 == setterMethod.getParameters().length) { setterMethod = null; } } } if (candidate.startsWith("set")) { setterMethod = mappedMethods.get(candidate); if (setterMethod.isStatic() || setterMethod.getParameters().length != 1) { setterMethod = null; } final String complimentaryGetter = candidate.replaceAll("^set", "get"); if (mappedMethods.containsKey(complimentaryGetter)) { continue; } } /* ensure that strategies are reachable */ if ((null == getterMethod && null == setterMethod) || (REQUIRE_BOTH_GETTER_SETTER && (null == getterMethod || null == setterMethod))) { continue; } /* store property and it's types */ final Set<String> propertyTypesFqns = new HashSet<>(); if (null != getterMethod) { propertyTypesFqns.addAll(getterMethod.getType().filterUnknown().getTypes()); } if (null != setterMethod) { final Parameter[] setterParams = setterMethod.getParameters(); if (setterParams.length > 0) { propertyTypesFqns.addAll(setterParams[0].getType().filterUnknown().getTypes()); } } /* drop preceding \ in core types */ final Set<String> propertyTypes = new HashSet<>(); for (String type : propertyTypesFqns) { if (type.length() > 0) { if ('\\' == type.charAt(0) && 1 == StringUtils.countMatches(type, "\\")) { type = type.replace("\\", ""); } propertyTypes.add(type); } } propertyTypesFqns.clear(); final String typesAsString = propertyTypes.isEmpty() ? "mixed" : String.join("|", propertyTypes); properties.put(StringUtils.uncapitalize(candidate.replaceAll("^(get|set)", "")), typesAsString); } /* exclude annotated properties: lazy bulk operation */ if (properties.size() > 0) { final Collection<Field> fields = clazz.getFields(); for (Field candidate : fields) { /* do not process constants and static fields */ if (candidate.isConstant() || candidate.getModifier().isStatic()) { continue; } properties.remove(candidate.getName()); } fields.clear(); } return properties; } }; }
From source file:com.haulmont.cuba.gui.ControllerDependencyInjector.java
protected void doInjection(AnnotatedElement element, Class annotationClass) { Class<?> type;/* w w w . j a v a 2 s . c o m*/ String name = null; if (annotationClass == Named.class) name = element.getAnnotation(Named.class).value(); else if (annotationClass == Resource.class) name = element.getAnnotation(Resource.class).name(); else if (annotationClass == WindowParam.class) name = element.getAnnotation(WindowParam.class).name(); boolean required = true; if (element.isAnnotationPresent(WindowParam.class)) required = element.getAnnotation(WindowParam.class).required(); if (element instanceof Field) { type = ((Field) element).getType(); if (StringUtils.isEmpty(name)) name = ((Field) element).getName(); } else if (element instanceof Method) { Class<?>[] types = ((Method) element).getParameterTypes(); if (types.length != 1) throw new IllegalStateException("Can inject to methods with one parameter only"); type = types[0]; if (StringUtils.isEmpty(name)) { if (((Method) element).getName().startsWith("set")) name = StringUtils.uncapitalize(((Method) element).getName().substring(3)); else name = ((Method) element).getName(); } } else { throw new IllegalStateException("Can inject to fields and setter methods only"); } Object instance = getInjectedInstance(type, name, annotationClass, element); if (instance != null) { assignValue(element, instance); } else if (required) { Class<?> declaringClass = ((Member) element).getDeclaringClass(); Class<? extends Frame> frameClass = frame.getClass(); String msg; if (frameClass == declaringClass) { msg = String.format("CDI - Unable to find an instance of type '%s' named '%s' for instance of '%s'", type, name, frameClass.getCanonicalName()); } else { msg = String.format( "CDI - Unable to find an instance of type '%s' named '%s' declared in '%s' for instance of '%s'", type, name, declaringClass.getCanonicalName(), frameClass.getCanonicalName()); } Logger log = LoggerFactory.getLogger(ControllerDependencyInjector.class); log.warn(msg); } }
From source file:com.simplexwork.mysql.tools.utils.DocumentUtils.java
/** * ?mybatis?mapper//from ww w.j a v a2s .com * * @param tablesMap * @throws Exception */ public static void productMyBatisMapper(Map<String, TableInfo> tablesMap) throws Exception { VelocityContext context = new VelocityContext(); Template template1 = Velocity.getTemplate("mapper-java.vm"); // org/simplexwork/mysql/tools/velocity/mapper-java.vm Template template2 = Velocity.getTemplate("mapper-xml.vm"); for (Entry<String, TableInfo> entry : tablesMap.entrySet()) { TableInfo tableInfo = entry.getValue(); String tableName = getJavaBeanName(StringUtils.capitalize(tableInfo.getTableName())); String interfaceName = tableName + "Mapper"; context.put("interfaceName", interfaceName); context.put("beanName", tableName); context.put("resultMapId", getStartSmallName(tableName + "Map")); context.put("beanVarName", StringUtils.uncapitalize(tableName)); context.put("pkgMapper", pkgMapper); context.put("pkgBean", pkgBean); context.put("tableComment", tableInfo.getTableComment()); StringWriter writer1 = new StringWriter(); template1.merge(context, writer1); FileUtils.writeStringToFile(new File(generatedPath + "mapper/" + interfaceName + ".java"), writer1.toString(), "UTF-8"); String keyInBean = ""; // Bean???? String keyInColoum = ""; // ?? List<Object> fileds = new ArrayList<>(); for (Column column : tableInfo.getColumns()) { if (column.isKey()) { keyInBean = fixName(column.getName()); keyInColoum = column.getName(); } Map<String, Object> field = new HashMap<>(); String columnType = column.getType(); if (columnType.contains("(")) { columnType = columnType.substring(0, columnType.indexOf("(")); } field.put("isKey", column.isKey()); field.put("sqlName", column.getName()); field.put("name", fixName(column.getName())); fileds.add(field); } context.put("tableName", tableInfo.getTableName()); context.put("keyInBean", keyInBean); context.put("keyInColoum", keyInColoum); context.put("fields", fileds); StringWriter writer2 = new StringWriter(); template2.merge(context, writer2); FileUtils.writeStringToFile(new File(generatedPath + getMapperXmlName(interfaceName) + ".xml"), writer2.toString(), "UTF-8"); } }
From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeansGenerator.java
protected void createService(BeanDefinitionRegistry registry, ModelContext modelContext) throws NotFoundException, CannotCompileException { if (modelContext.getServiceDefinition() == null) { String newBeanClassName = modelContext.getGeneratedClassNamePrefix() + "Service"; String newBeanRegistryName = StringUtils.uncapitalize(newBeanClassName); String newBeanPackage = this.serviceBasePackage + '.'; // grab the generic types List<Class<?>> genericTypes = modelContext.getGenericTypes(); // extend the base service interface Class<?> newServiceInterface = JavassistUtil.createInterface(newBeanPackage + newBeanClassName, ModelService.class, genericTypes); ArrayList<Class<?>> interfaces = new ArrayList<Class<?>>(1); interfaces.add(newServiceInterface); // create a service implementation bean CreateClassCommand createServiceCmd = new CreateClassCommand( newBeanPackage + "impl." + newBeanClassName + "Impl", AbstractModelServiceImpl.class); createServiceCmd.setInterfaces(interfaces); createServiceCmd.setGenericTypes(genericTypes); createServiceCmd.addGenericType(modelContext.getRepositoryType()); HashMap<String, Object> named = new HashMap<String, Object>(); named.put("value", newBeanRegistryName); createServiceCmd.addTypeAnnotation(Named.class, named); // create and register a service implementation bean Class<?> serviceClass = JavassistUtil.createClass(createServiceCmd); AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(serviceClass).getBeanDefinition(); registry.registerBeanDefinition(newBeanRegistryName, def); // note in context as a dependency to a controller modelContext.setServiceDefinition(def); modelContext.setServiceInterfaceType(newServiceInterface); modelContext.setServiceImplType(serviceClass); } else {/*from w w w . j av a 2s .com*/ Class<?> serviceType = ClassUtils.getClass(modelContext.getServiceDefinition().getBeanClassName()); // grab the service interface if (!serviceType.isInterface()) { Class<?>[] serviceInterfaces = serviceType.getInterfaces(); if (ArrayUtils.isNotEmpty(serviceInterfaces)) { for (Class<?> interfaze : serviceInterfaces) { if (ModelService.class.isAssignableFrom(interfaze)) { modelContext.setServiceInterfaceType(interfaze); break; } } } } Assert.notNull(modelContext.getRepositoryType(), "Found a service bean definition for " + modelContext.getGeneratedClassNamePrefix() + " but failed to figure out the service interface type."); } }
From source file:io.jenkins.blueocean.service.embedded.rest.UserImplPermissionTest.java
private void checkPermissions(BlueUserPermission permission, boolean shouldBeAdmin, boolean shouldHaveOtherPermissions) { assertEquals("User permission does not match", permission.isAdministration(), shouldBeAdmin); Map<String, Boolean> permissions = permission.getPipelinePermission(); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(BluePipeline.CREATE_PERMISSION)); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(BluePipeline.READ_PERMISSION)); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(BluePipeline.START_PERMISSION)); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(BluePipeline.STOP_PERMISSION)); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(BluePipeline.CONFIGURE_PERMISSION)); permissions = permission.getCredentialPermission(); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(CredentialsProvider.CREATE.name.toLowerCase())); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(CredentialsProvider.VIEW.name.toLowerCase())); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(CredentialsProvider.DELETE.name.toLowerCase())); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(CredentialsProvider.UPDATE.name.toLowerCase())); assertEquals("User permission does not match", shouldHaveOtherPermissions, permissions.get(StringUtils.uncapitalize(CredentialsProvider.MANAGE_DOMAINS.name))); }
From source file:com.frameworkset.orm.engine.model.Column.java
/** * Get variable name to use in Java sources (= uncapitalised java name) */ public String getUncapitalisedJavaName() { return StringUtils.uncapitalize(getJavaName()); }
From source file:gr.abiss.calipso.tiers.processor.ModelDrivenBeanGeneratingRegistryPostProcessor.java
protected void createService(BeanDefinitionRegistry registry, ModelContext modelContext) throws NotFoundException, CannotCompileException { if (modelContext.getServiceDefinition() == null) { String newBeanClassName = modelContext.getGeneratedClassNamePrefix() + "Service"; String newBeanRegistryName = StringUtils.uncapitalize(newBeanClassName); String newBeanPackage = modelContext.getBeansBasePackage() + ".service"; // grab the generic types List<Class<?>> genericTypes = modelContext.getGenericTypes(); // extend the base service interface Class<?> newServiceInterface = JavassistUtil.createInterface(newBeanPackage + newBeanClassName, ModelService.class, genericTypes); ArrayList<Class<?>> interfaces = new ArrayList<Class<?>>(1); interfaces.add(newServiceInterface); // create a service implementation bean CreateClassCommand createServiceCmd = new CreateClassCommand( newBeanPackage + "impl." + newBeanClassName + "Impl", AbstractModelServiceImpl.class); createServiceCmd.setInterfaces(interfaces); createServiceCmd.setGenericTypes(genericTypes); createServiceCmd.addGenericType(modelContext.getRepositoryType()); HashMap<String, Object> named = new HashMap<String, Object>(); named.put("value", newBeanRegistryName); createServiceCmd.addTypeAnnotation(Named.class, named); // create and register a service implementation bean Class<?> serviceClass = JavassistUtil.createClass(createServiceCmd); AbstractBeanDefinition def = BeanDefinitionBuilder.rootBeanDefinition(serviceClass).getBeanDefinition(); registry.registerBeanDefinition(newBeanRegistryName, def); // note in context as a dependency to a controller modelContext.setServiceDefinition(def); modelContext.setServiceInterfaceType(newServiceInterface); modelContext.setServiceImplType(serviceClass); } else {/* w ww .j a va2 s . c om*/ Class<?> serviceType = ClassUtils.getClass(modelContext.getServiceDefinition().getBeanClassName()); // grab the service interface if (!serviceType.isInterface()) { Class<?>[] serviceInterfaces = serviceType.getInterfaces(); if (ArrayUtils.isNotEmpty(serviceInterfaces)) { for (Class<?> interfaze : serviceInterfaces) { if (ModelService.class.isAssignableFrom(interfaze)) { modelContext.setServiceInterfaceType(interfaze); break; } } } } Assert.notNull(modelContext.getRepositoryType(), "Found a service bean definition for " + modelContext.getGeneratedClassNamePrefix() + " but failed to figure out the service interface type."); } }
From source file:nc.noumea.mairie.appock.core.viewmodel.AbstractViewModel.java
public GenericService<T> getService() { return (GenericService<T>) ApplicationContextUtils.getApplicationContext() .getBean(StringUtils.uncapitalize(getEntityName()) + "Service"); }
From source file:com.hihsoft.baseclass.web.controller.BaseController.java
/** * CommandName--??,????.// w ww.j av a2s . c o m * * @see #bindObject(HttpServletRequest, Object) */ @Override protected String getCommandName(final Object command) { return StringUtils.uncapitalize(command.getClass().getSimpleName()); }
From source file:com.haulmont.chile.core.loader.ChileAnnotationsLoader.java
protected void initProperties(Class<?> clazz, MetaClassImpl metaClass, Collection<MetadataObjectInitTask> tasks) { if (!metaClass.getOwnProperties().isEmpty()) return;//from w w w . ja v a 2s.c om // load collection properties after non-collection in order to have all inverse properties loaded up ArrayList<Field> collectionProps = new ArrayList<>(); for (Field field : clazz.getDeclaredFields()) { if (field.isSynthetic()) continue; final String fieldName = field.getName(); if (isMetaPropertyField(field)) { MetaPropertyImpl property = (MetaPropertyImpl) metaClass.getProperty(fieldName); if (property == null) { MetadataObjectInfo<MetaProperty> info; if (isCollection(field) || isMap(field)) { collectionProps.add(field); } else { info = loadProperty(metaClass, field); tasks.addAll(info.getTasks()); MetaProperty metaProperty = info.getObject(); onPropertyLoaded(metaProperty, field); } } else { log.warn("Field " + clazz.getSimpleName() + "." + field.getName() + " is not included in metadata because property " + property + " already exists"); } } } for (Field f : collectionProps) { MetadataObjectInfo<MetaProperty> info = loadCollectionProperty(metaClass, f); tasks.addAll(info.getTasks()); MetaProperty metaProperty = info.getObject(); onPropertyLoaded(metaProperty, f); } for (Method method : clazz.getDeclaredMethods()) { if (method.isSynthetic()) continue; String methodName = method.getName(); if (!methodName.startsWith("get") || method.getReturnType() == void.class) continue; if (isMetaPropertyMethod(method)) { String name = StringUtils.uncapitalize(methodName.substring(3)); MetaPropertyImpl property = (MetaPropertyImpl) metaClass.getProperty(name); if (property == null) { MetadataObjectInfo<MetaProperty> info; if (isCollection(method) || isMap(method)) { throw new UnsupportedOperationException( String.format("Method-based property %s.%s doesn't support collections and maps", clazz.getSimpleName(), method.getName())); } else if (method.getParameterCount() != 0) { throw new UnsupportedOperationException( String.format("Method-based property %s.%s doesn't support arguments", clazz.getSimpleName(), method.getName())); } else { info = loadProperty(metaClass, method, name); tasks.addAll(info.getTasks()); } MetaProperty metaProperty = info.getObject(); onPropertyLoaded(metaProperty, method); } else { log.warn("Method " + clazz.getSimpleName() + "." + method.getName() + " is not included in metadata because property " + property + " already exists"); } } } }