Search in sources :

Example 36 with JInvocation

use of com.helger.jcodemodel.JInvocation in project RoboBinding by RoboBinding.

the class AbstractPresentationModelObjectClassGen method defineEventMethods.

/*
	  	@Override
	 	public Set<MethodDescriptor> eventMethods() {
	 		return Sets.newHashSet(
	 			createMethodDescriptor(ON_CLICK),
	 			createMethodDescriptor(ON_CLICK_WITH_EVENT, AbstractViewEvent.class));
	 	}
	 
	 */
public void defineEventMethods() {
    JMethod method = declarePublicMethodOverride("eventMethods", setClassWithMethodDescriptor);
    JInvocation invocation = codeModel.ref(Sets.class).staticInvoke("newHashSet");
    for (EventMethodInfo eventMethod : presentationModelInfo.eventMethods()) {
        JInvocation getMethodInvocation = JExpr.invoke("createMethodDescriptor").arg(eventMethod.name());
        if (eventMethod.hasEventArg()) {
            getMethodInvocation.arg(codeModel.ref(eventMethod.eventArgType()).dotclass());
        }
        invocation.arg(getMethodInvocation);
    }
    method.body()._return(invocation);
}
Also used : Sets(org.robobinding.util.Sets) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod)

Example 37 with JInvocation

use of com.helger.jcodemodel.JInvocation in project RoboBinding by RoboBinding.

the class AbstractPresentationModelObjectClassGen method defineTryToCreateDataSetProperty.

/*
	@Override
	public DataSetProperty tryToCreateDataSetProperty(String name) {
		if(name.equals(DATA_SET_PROP)) {
			PropertyDescriptor descriptor = createDataSetPropertyDescriptor(List.class, name);
			
			AbstractGetSet<?> getSet = new AbstractGetSet<List<String>>(descriptor) {
				@Override
				public List<String> getValue() {
					return presentationModel.getDataSetProp();
				}
			};
			
			RefreshableItemPresentationModelFactory factory = new RefreshableItemPresentationModelFactory() {
				
				@Override
				public RefreshableItemPresentationModel create(int itemViewType) {
					return new StringItemPresentationModel_IPM(new StringItemPresentationModel());
				}
			};	
			
			return new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet));
		}
		
		if(name.equals(DATA_SET_PROP_WITH_FACTORY_METHOD)) {
			PropertyDescriptor descriptor = createDataSetPropertyDescriptor(List.class, name);
			
			AbstractGetSet<?> getSet = new AbstractGetSet<List<String>>(descriptor) {
				@Override
				public List<String> getValue() {
					return presentationModel.getDataSetPropWithFactoryMethod();
				}
			};
			
			RefreshableItemPresentationModelFactory factory = new RefreshableItemPresentationModelFactory() {
				@Override
				public RefreshableItemPresentationModel create(int itemViewType) {
					return new StringItemPresentationModel_IPM(presentationModel.newStringItemPresentationModel());
				}
			};
			
			return new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet));
		} 
		
		
		if(name.equals(DATA_SET_PROP_WITH_VIEW_TYPE_SELECTOR)) {
			PropertyDescriptor descriptor = createDataSetPropertyDescriptor(List.class, name);
			
			AbstractGetSet<?> getSet = new AbstractGetSet<List<String>>(descriptor) {
				@Override
				public List<String> getValue() {
					return presentationModel.getDataSetPropWithViewTypeSelector();
				}
			};
			
			RefreshableItemPresentationModelFactory factory = new RefreshableItemPresentationModelFactory() {
				@Override
				public RefreshableItemPresentationModel create(int itemViewType) {
					return new StringItemPresentationModelPOC_IPM(new StringItemPresentationModelPOC());
				}
			};
			
			ViewTypeSelectable viewTypeSelector = new ViewTypeSelectable() {
				@Override
				@SuppressWarnings({ "rawtypes", "unchecked" }) 
				public int selectViewType(ViewTypeSelectionContext context) {
					return presentationModel.selectViewTypeWithParameter(context);
				}
			};
			
			return new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet), viewTypeSelector);
		} 
		
		if(name.equals(DATA_SET_PROP_WITH_FACTORY_METHOD_AND_VIEW_TYPE_SELECTOR)) {
			PropertyDescriptor descriptor = createDataSetPropertyDescriptor(List.class, name);
			
			AbstractGetSet<?> getSet = new AbstractGetSet<List<String>>(descriptor) {
				@Override
				public List<String> getValue() {
					return presentationModel.getDataSetPropWithViewTypeSelector();
				}
			};
			
			RefreshableItemPresentationModelFactory factory = new RefreshableItemPresentationModelFactory() {
				@Override
				public RefreshableItemPresentationModel create(int itemViewType) {
					return new StringItemPresentationModelPOC_IPM(
							presentationModel.createStringItemPresentationModelWithParameter(itemViewType));
				}
			};
			
			ViewTypeSelectable viewTypeSelector = new ViewTypeSelectable() {
				@Override
				@SuppressWarnings({ "rawtypes", "unchecked" }) 
				public int selectViewType(ViewTypeSelectionContext context) {
					return presentationModel.selectViewTypeWithParameter(context);
				}
			};
			
			return new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet), viewTypeSelector, PreInitializingViews.DEFAULT);
		}
		
		return null;
	}
	 */
public void defineTryToCreateDataSetProperty() {
    JMethod method = declarePublicMethodOverride("tryToCreateDataSetProperty", DataSetProperty.class);
    JVar nameParam = method.param(String.class, "name");
    JBlock body = method.body();
    for (DataSetPropertyInfo propertyInfo : presentationModelInfo.dataSetProperties()) {
        JConditional conditional = body._if(nameParam.invoke("equals").arg(propertyInfo.name()));
        JBlock conditionalBody = conditional._then();
        //create createDataSetPropertyDescriptor.
        AbstractJClass propertyClass = codeModel.ref(propertyInfo.type());
        JInvocation createDataSetPropertyDescriptor = JExpr.invoke("createDataSetPropertyDescriptor").arg(propertyClass.dotclass()).arg(nameParam);
        JVar descriptorVar = conditionalBody.decl(propertyDescriptorClass, "descriptor", createDataSetPropertyDescriptor);
        //create AbstractGetSet.
        AbstractJClass narrowedGetSet = getSetClass.narrow(codeModel.ref(propertyInfo.type()));
        JDefinedClass anonymousGetSet = codeModel.anonymousClass(narrowedGetSet);
        JMethod getter = declarePublicMethodOverride(anonymousGetSet, "getValue", propertyClass);
        getter.body()._return(presentationModelFieldWithoutThis.invoke(propertyInfo.getter()));
        JVar getSetVar = conditionalBody.decl(wildcardGetSetClass, "getSet", JExpr._new(anonymousGetSet).arg(descriptorVar));
        //JVar getSetVar = conditionalBody.decl(getSetClass, "getSet", 
        //		JExpr._new(anonymousGetSet.narrow(propertyClass)).arg(descriptorVar));
        //create RefreshableItemPresentationModelFactory.
        JDefinedClass anonymousFactory = codeModel.anonymousClass(RefreshableItemPresentationModelFactory.class);
        JMethod create = declarePublicMethodOverride(anonymousFactory, "create", RefreshableItemPresentationModel.class);
        JVar itemViewTypeParam = create.param(int.class, "itemViewType");
        AbstractJClass itemPresentationModelObjectClass = codeModel.ref(propertyInfo.itemPresentationModelObjectTypeName());
        JInvocation newItemPresentationModelObject = JExpr._new(itemPresentationModelObjectClass);
        if (propertyInfo.isCreatedByFactoryMethodWithArg()) {
            newItemPresentationModelObject.arg(presentationModelFieldWithoutThis.invoke(propertyInfo.factoryMethod()).arg(itemViewTypeParam));
        } else if (propertyInfo.isCreatedByFactoryMethodWithoutArg()) {
            newItemPresentationModelObject.arg(presentationModelFieldWithoutThis.invoke(propertyInfo.factoryMethod()));
        } else {
            newItemPresentationModelObject.arg(JExpr._new(codeModel.ref(propertyInfo.itemPresentationModelTypeName())));
        }
        create.body()._return(newItemPresentationModelObject);
        JVar factoryVar = conditionalBody.decl(refreshableItemPresentationModelFactoryClass, "factory", JExpr._new(anonymousFactory));
        //new DataSetProperty(this, descriptor, new ListDataSet(factory, getSet));
        JInvocation newDataSetProperty = JExpr._new(dataSetPropertyClass).arg(JExpr._this()).arg(descriptorVar).arg(JExpr._new(codeModel.ref(propertyInfo.dataSetImplementationType())).arg(factoryVar).arg(getSetVar));
        //create viewTypeSelector.
        if (propertyInfo.hasViewTypeSelector()) {
            JDefinedClass anonymousViewTypeSelector = codeModel.anonymousClass(ViewTypeSelectable.class);
            JMethod selectViewType = declarePublicMethodOverride(anonymousViewTypeSelector, "selectViewType", int.class);
            selectViewType.annotate(codeModel.ref(SuppressWarnings.class)).paramArray("value", "rawtypes", "unchecked");
            JVar contextParam = selectViewType.param(ViewTypeSelectionContext.class, "context");
            JInvocation userSelectViewTypeCall;
            if (propertyInfo.viewTypeSelectorAcceptsArg()) {
                userSelectViewTypeCall = presentationModelFieldWithoutThis.invoke(propertyInfo.viewTypeSelector()).arg(contextParam);
            } else {
                userSelectViewTypeCall = presentationModelFieldWithoutThis.invoke(propertyInfo.viewTypeSelector());
            }
            selectViewType.body()._return(userSelectViewTypeCall);
            JVar viewTypeSelectorVar = conditionalBody.decl(viewTypeSelectableClass, "viewTypeSelector", JExpr._new(anonymousViewTypeSelector));
            newDataSetProperty.arg(viewTypeSelectorVar);
        }
        newDataSetProperty.arg(JExpr.enumConstantRef(preInitializingViewsClass, propertyInfo.preInitializingViews().name()));
        //return DataSetProperty.
        conditionalBody._return(newDataSetProperty);
    }
    body._return(JExpr._null());
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JBlock(com.helger.jcodemodel.JBlock) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JConditional(com.helger.jcodemodel.JConditional) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 38 with JInvocation

use of com.helger.jcodemodel.JInvocation in project RoboBinding by RoboBinding.

the class ItemPresentationModelObjectClassGen method defineConstructor.

/**
	 *	public StringItemPresentationModel_IPM(StringItemPresentationModel itemPresentationModel) {
	 *		super(itemPresentationModel);
	 *		this.itemPresentationModel = itemPresentationModel;
	 *	}
	 * 
	 */
@Override
public void defineConstructor() {
    /*
		public class StringItemPresentationModel_IPM extends AbstractItemPresentationModelObject {
		 */
    definedClass._extends(AbstractItemPresentationModelObject.class);
    JMethod constructor = definedClass.constructor(JMod.PUBLIC);
    AbstractJType itemPresentationModelClass = codeModel.ref(presentationModelInfo.getPresentationModelTypeName());
    JVar itemPresentationModelParam = constructor.param(itemPresentationModelClass, "itemPresentationModel");
    JBlock block = constructor.body();
    JInvocation superInvocation = JExpr.invoke("super").arg(itemPresentationModelParam);
    block.add(superInvocation);
    block.assign(presentationModelField, itemPresentationModelParam);
}
Also used : AbstractJType(com.helger.jcodemodel.AbstractJType) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 39 with JInvocation

use of com.helger.jcodemodel.JInvocation in project RoboBinding by RoboBinding.

the class PresentationModelObjectClassGen method defineConstructor.

/**
	 * 	public PresentationModelType_PM(PresentationModelType presentationModel) {
	 *		super(presentationModel);
	 *		this.presentationModel = presentationModel;
	 *	}
	 *
	 */
@Override
public void defineConstructor() {
    /*
		 public class PresentationModelType_PM extends AbstractPresentationModelObject {
		 */
    definedClass._extends(AbstractPresentationModelObject.class);
    JMethod constructor = definedClass.constructor(JMod.PUBLIC);
    JVar presentationModelParam = constructor.param(presentationModelClass, "presentationModel");
    JBlock block = constructor.body();
    JInvocation superInvocation = JExpr.invoke("super").arg(presentationModelParam);
    block.add(superInvocation);
    block.assign(presentationModelField, presentationModelParam);
}
Also used : JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation) JMethod(com.helger.jcodemodel.JMethod) JVar(com.helger.jcodemodel.JVar)

Example 40 with JInvocation

use of com.helger.jcodemodel.JInvocation in project androidannotations by androidannotations.

the class AbstractKeyEventHandler method process.

@Override
public void process(Element element, HasKeyEventCallbackMethods holder) throws Exception {
    String methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    TypeMirror returnType = executableElement.getReturnType();
    boolean returnMethodResult = returnType.getKind() != TypeKind.VOID;
    JSwitch switchBody = getSwitchBody(holder);
    int[] keyCodes = annotationHelper.extractKeyCode(element);
    for (int keyCode : keyCodes) {
        String keyCodeFieldName = annotationHelper.getFieldNameForKeyCode(keyCode);
        JBlock switchCaseBody = switchBody._case(getClasses().KEY_EVENT.staticRef(keyCodeFieldName)).body();
        JInvocation methodCall = invoke(methodName);
        if (returnMethodResult) {
            switchCaseBody._return(methodCall);
        } else {
            switchCaseBody.add(methodCall);
            switchCaseBody._return(TRUE);
        }
        passParametersToMethodCall(element, holder, methodCall);
    }
}
Also used : JSwitch(com.helger.jcodemodel.JSwitch) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) JInvocation(com.helger.jcodemodel.JInvocation)

Aggregations

JInvocation (com.helger.jcodemodel.JInvocation)71 JVar (com.helger.jcodemodel.JVar)38 JBlock (com.helger.jcodemodel.JBlock)37 AbstractJClass (com.helger.jcodemodel.AbstractJClass)31 IJExpression (com.helger.jcodemodel.IJExpression)27 JMethod (com.helger.jcodemodel.JMethod)26 ExecutableElement (javax.lang.model.element.ExecutableElement)20 VariableElement (javax.lang.model.element.VariableElement)16 JFieldRef (com.helger.jcodemodel.JFieldRef)14 TypeMirror (javax.lang.model.type.TypeMirror)14 JConditional (com.helger.jcodemodel.JConditional)11 JDefinedClass (com.helger.jcodemodel.JDefinedClass)9 AbstractJType (com.helger.jcodemodel.AbstractJType)5 JFieldVar (com.helger.jcodemodel.JFieldVar)5 JTryBlock (com.helger.jcodemodel.JTryBlock)5 ArrayList (java.util.ArrayList)4 DeclaredType (javax.lang.model.type.DeclaredType)4 JCatchBlock (com.helger.jcodemodel.JCatchBlock)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3