use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method defineTryToCreateFunction.
/*
@Override
public Function tryToCreateFunction(MethodDescriptor methodDescriptor) {
if(methodDescriptor.equals(createMethodDescriptor(ON_CLICK))) {
return new Function() {
@Override
public Object call(Object... args) {
presentationModel.onClick();
return null;
}
};
}
if(methodDescriptor.equals(createMethodDescriptor(ON_CLICK_WITH_EVENT, AbstractViewEvent.class))){
return new Function() {
@Override
public Object call(Object... args) {
boolean result = presentationModel.onLongClickWithEvent((AbstractViewEvent)args[0]);
return (Boolean)result;
}
};
}
return null;
}
*/
public void defineTryToCreateFunction() {
JMethod method = declarePublicMethodOverride("tryToCreateFunction", Function.class);
JVar methodDescriptorParam = method.param(MethodDescriptor.class, "methodDescriptor");
JBlock body = method.body();
for (EventMethodInfo eventMethodInfo : presentationModelInfo.eventMethods()) {
JInvocation getMethod = JExpr.invoke("createMethodDescriptor").arg(eventMethodInfo.name());
if (eventMethodInfo.hasEventArg()) {
getMethod.arg(codeModel.ref(eventMethodInfo.eventArgType()).dotclass());
}
JConditional conditional = body._if(methodDescriptorParam.invoke("equals").arg(getMethod));
JBlock conditionalBody = conditional._then();
//create Function.
JDefinedClass anonymousFunction = codeModel.anonymousClass(Function.class);
JMethod call = declarePublicMethodOverride(anonymousFunction, "call", Object.class);
JVar argsVar = call.varParam(Object.class, "args");
JBlock callBody = call.body();
//call event method.
JInvocation onEvent = presentationModelFieldWithoutThis.invoke(eventMethodInfo.name());
if (eventMethodInfo.hasEventArg()) {
AbstractJClass eventArgClass = codeModel.ref(eventMethodInfo.eventArgType());
onEvent.arg(JExpr.cast(eventArgClass, argsVar.component(JExpr.lit(0))));
}
//call return.
if (eventMethodInfo.hasReturn()) {
JVar returnVar = callBody.decl(codeModel.ref(eventMethodInfo.nonPrimitiveReturnType()), "result", onEvent);
callBody._return(returnVar);
} else {
callBody.add(onEvent);
callBody._return(JExpr._null());
}
//return Function.
conditionalBody._return(JExpr._new(anonymousFunction));
}
body._return(JExpr._null());
}
use of com.helger.jcodemodel.JMethod in project RoboBinding by RoboBinding.
the class AbstractPresentationModelObjectClassGen method defineDataSetPropertyNames.
/*
@Override
public Set<String> dataSetPropertyNames() {
return Sets.newHasSet("dataSetProp1", "dataSetProp2");
}
*/
public void defineDataSetPropertyNames() {
JMethod method = declarePublicMethodOverride("dataSetPropertyNames", setClassWithString);
method.body()._return(newHashSetInvocation(presentationModelInfo.dataSetPropertyNames()));
}
use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.
the class APTCodeModelHelper method findAlreadyGeneratedMethod.
private JMethod findAlreadyGeneratedMethod(ExecutableElement executableElement, GeneratedClassHolder holder) {
JDefinedClass definedClass = holder.getGeneratedClass();
String methodName = executableElement.getSimpleName().toString();
List<? extends VariableElement> parameters = executableElement.getParameters();
// TODO: refactor the nasty label jump
method: for (JMethod method : definedClass.methods()) {
if (method.name().equals(methodName) && method.params().size() == parameters.size()) {
int i = 0;
for (JVar param : method.params()) {
String searchedParamType = typeMirrorToJClass(parameters.get(i).asType()).fullName();
if (!param.type().fullName().equals(searchedParamType)) {
continue method;
}
i++;
}
return method;
}
}
// CHECKSTYLE:ON
return null;
}
use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.
the class APTCodeModelHelper method overrideAnnotatedMethod.
public JMethod overrideAnnotatedMethod(ExecutableElement executableElement, GeneratedClassHolder holder) {
TypeMirror annotatedClass = holder.getAnnotatedElement().asType();
DeclaredType baseClass = (DeclaredType) executableElement.getEnclosingElement().asType();
Types typeUtils = environment.getProcessingEnvironment().getTypeUtils();
Map<String, TypeMirror> actualTypes = getActualTypes(typeUtils, baseClass, annotatedClass);
Map<String, List<AbstractJClass>> methodTypes = new LinkedHashMap<>();
for (TypeParameterElement typeParameter : executableElement.getTypeParameters()) {
List<? extends TypeMirror> bounds = typeParameter.getBounds();
List<AbstractJClass> addedBounds = typeBoundsToJClass(bounds, actualTypes);
methodTypes.put(typeParameter.toString(), addedBounds);
}
actualTypes.keySet().removeAll(methodTypes.keySet());
JMethod existingMethod = findAlreadyGeneratedMethod(executableElement, holder);
if (existingMethod != null) {
return existingMethod;
}
String methodName = executableElement.getSimpleName().toString();
AbstractJClass returnType = typeMirrorToJClass(executableElement.getReturnType(), actualTypes);
int modifier = elementVisibilityModifierToJMod(executableElement);
JMethod method = holder.getGeneratedClass().method(modifier, returnType, methodName);
copyNonAAAnnotations(method, executableElement.getAnnotationMirrors());
if (!hasAnnotation(method, Override.class)) {
method.annotate(Override.class);
}
for (Map.Entry<String, List<AbstractJClass>> typeDeclaration : methodTypes.entrySet()) {
List<AbstractJClass> bounds = typeDeclaration.getValue();
addTypeBounds(method, bounds, typeDeclaration.getKey());
}
int i = 0;
for (VariableElement parameter : executableElement.getParameters()) {
boolean varParam = i == executableElement.getParameters().size() - 1 && executableElement.isVarArgs();
addParamToMethod(method, parameter, JMod.FINAL, actualTypes, varParam);
i++;
}
for (TypeMirror superThrownType : executableElement.getThrownTypes()) {
AbstractJClass thrownType = typeMirrorToJClass(superThrownType, actualTypes);
method._throws(thrownType);
}
callSuperMethod(method, holder, method.body());
return method;
}
use of com.helger.jcodemodel.JMethod in project androidannotations by androidannotations.
the class EFragmentHolder method setOnDestroyView.
private void setOnDestroyView() {
JMethod onDestroyView = generatedClass.method(PUBLIC, getCodeModel().VOID, "onDestroyView");
onDestroyView.annotate(Override.class);
JBlock body = onDestroyView.body();
body.invoke(_super(), onDestroyView);
body.assign(contentView, _null());
onDestroyViewAfterSuperBlock = body.blockSimple();
}
Aggregations