use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class RestHandler method setRequestFactory.
private void setRequestFactory(Element element, RestHolder holder) {
DeclaredType requestFactoryType = annotationHelper.extractAnnotationClassParameter(element, getTarget(), "requestFactory");
if (requestFactoryType != null) {
JInvocation requestFactory = codeModelHelper.newBeanOrEBean(requestFactoryType, holder.getInitContextParam());
holder.getInit().body().add(invoke(holder.getRestTemplateField(), "setRequestFactory").arg(requestFactory));
}
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class RestHandler method setInterceptors.
private void setInterceptors(Element element, RestHolder holder) {
List<DeclaredType> interceptors = annotationHelper.extractAnnotationClassArrayParameter(element, getTarget(), "interceptors");
if (interceptors != null) {
AbstractJClass listClass = getJClass(ARRAYLIST);
AbstractJClass clientInterceptorClass = getJClass(CLIENT_HTTP_REQUEST_INTERCEPTOR);
listClass = listClass.narrow(clientInterceptorClass);
JFieldVar restTemplateField = holder.getRestTemplateField();
JBlock init = holder.getInit().body();
init.add(invoke(restTemplateField, "setInterceptors").arg(_new(listClass)));
for (DeclaredType interceptorType : interceptors) {
JInvocation newInterceptor = codeModelHelper.newBeanOrEBean(interceptorType, holder.getInitContextParam());
init.add(invoke(restTemplateField, "getInterceptors").invoke("add").arg(newInterceptor));
}
}
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class RestHolder method implementSetBasicAuth.
private void implementSetBasicAuth(List<ExecutableElement> methods) {
JMethod setAuthMethod = codeModelHelper.implementMethod(this, methods, "setHttpBasicAuth", TypeKind.VOID.toString(), STRING, STRING);
if (setAuthMethod != null) {
AbstractJClass basicAuthClass = getJClass(HTTP_BASIC_AUTHENTICATION);
JInvocation basicAuthentication = JExpr._new(basicAuthClass).arg(setAuthMethod.params().get(0)).arg(setAuthMethod.params().get(1));
setAuthMethod.body().assign(_this().ref(getAuthenticationField()), basicAuthentication);
}
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class RestHolder method implementGetHeader.
private void implementGetHeader(List<ExecutableElement> methods) {
JMethod getHeaderMethod = codeModelHelper.implementMethod(this, methods, "getHeader", STRING, STRING);
if (getHeaderMethod != null) {
JInvocation headerValue = JExpr.invoke(getAvailableHeadersField(), "get").arg(getHeaderMethod.params().get(0));
getHeaderMethod.body()._return(headerValue);
}
}
use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.
the class SharedPrefHandler method createFieldMethod.
private IJExpression createFieldMethod(SharedPrefHolder holder, ExecutableElement method, Class<? extends Annotation> annotationClass, Class<? extends AbstractPrefField<?>> prefFieldClass, Object defaultValue, Res resType, String fieldHelperMethodName) {
Annotation annotation = method.getAnnotation(annotationClass);
IJExpression defaultValueExpr;
Object value = null;
if (annotation != null) {
value = annotationHelper.extractAnnotationParameter(method, annotationClass.getName(), "value");
}
if (annotation != null && method.getAnnotation(DefaultStringSet.class) == null) {
defaultValueExpr = codeModelHelper.litObject(value);
} else if (method.getAnnotation(DefaultRes.class) != null) {
defaultValueExpr = extractResValue(holder, method, resType);
annotationClass = DefaultRes.class;
} else if (method.getAnnotation(DefaultStringSet.class) != null) {
if (value != null) {
Set<String> arrayValues = new HashSet<>(Arrays.asList((String[]) value));
value = arrayValues;
if (arrayValues.isEmpty()) {
defaultValueExpr = newEmptyStringHashSet();
} else {
JInvocation arrayAsList = getClasses().ARRAYS.staticInvoke("asList");
for (String arrayValue : arrayValues) {
arrayAsList.arg(lit(arrayValue));
}
defaultValueExpr = JExpr._new(getClasses().HASH_SET.narrow(getClasses().STRING)).arg(arrayAsList);
}
} else {
defaultValueExpr = newEmptyStringHashSet();
}
annotationClass = DefaultStringSet.class;
} else {
defaultValueExpr = defaultValue != null ? codeModelHelper.litObject(defaultValue) : newEmptyStringHashSet();
annotationClass = null;
}
Integer keyResId = ResId.DEFAULT_VALUE;
if (annotationClass != null) {
keyResId = annotationHelper.extractAnnotationParameter(method, annotationClass.getName(), "keyRes");
}
IJExpression keyExpression;
String fieldName = method.getSimpleName().toString();
if (keyResId == ResId.DEFAULT_VALUE) {
keyExpression = lit(fieldName);
} else {
IRInnerClass idClass = getEnvironment().getRClass().get(IRClass.Res.STRING);
JFieldRef idRef = idClass.getIdStaticRef(keyResId, getEnvironment());
keyExpression = holder.getEditorContextField().invoke("getString").arg(idRef);
}
String docComment = getProcessingEnvironment().getElementUtils().getDocComment(method);
String defaultValueStr = value == null ? null : value.toString();
if (defaultValueStr == null) {
defaultValueStr = defaultValue == null ? null : defaultValue.toString();
}
holder.createFieldMethod(prefFieldClass, keyExpression, fieldName, fieldHelperMethodName, defaultValueExpr, docComment, defaultValueStr);
return keyExpression;
}
Aggregations