private BindingDescription processMethod( final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final MethodInfo methodInfo, final AbstractComponentDescription componentDescription, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { throw new IllegalArgumentException( "injection target is invalid. Only setter methods are allowed: " + methodInfo); } final String contextNameSuffix = methodName.substring(3, 4).toLowerCase() + methodName.substring(4); final AnnotationValue declaredNameValue = annotation.value("name"); final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null; final String localContextName; if (declaredName == null || declaredName.isEmpty()) { localContextName = methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix; } else { localContextName = declaredName; } final DotName declaredType = methodInfo.returnType().name(); final DotName injectionType = declaredType == null || declaredType.toString().equals(Object.class.getName()) ? methodInfo.returnType().name() : declaredType; final BindingDescription bindingDescription = new BindingDescription(); bindingDescription.setDependency(true); bindingDescription.setBindingName(localContextName); final String injectionTypeName = injectionType.toString(); bindingDescription.setBindingType(injectionTypeName); ServiceName injectorName = getInjectorServiceName( deploymentUnit, annotation, componentDescription, phaseContext, methodName, injectionTypeName); bindingDescription.setReferenceSourceDescription( new ServiceBindingSourceDescription(injectorName)); // setup the injection target final InjectionTargetDescription targetDescription = new InjectionTargetDescription(); targetDescription.setName(methodName); targetDescription.setClassName(methodInfo.declaringClass().name().toString()); targetDescription.setType(InjectionTargetDescription.Type.METHOD); targetDescription.setValueClassName(injectionTypeName); bindingDescription.getInjectionTargetDescriptions().add(targetDescription); return bindingDescription; }
private String buildBuildKey(MethodInfo methodInfo) { final StringBuilder buff = new StringBuilder(); buff.append(methodInfo.returnType().toString()) .append(' ') .append(methodInfo.name()) .append('('); for (int i = 0; i < methodInfo.args().length; i++) { if (i > 0) { buff.append(','); } buff.append(methodInfo.args()[i].toString()); } return buff.append(')').toString(); }