use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class ValidatorParameterHelperTest method primitiveParam.
@Test
public void primitiveParam() throws Exception {
ExecutableElement executableElement = createMethod(int.class, Integer.class);
ElementValidation valid = new ElementValidation("", executableElement);
validator.primitiveOrWrapper(TypeKind.INT).multiple().validate(executableElement, valid);
assertTrue(valid.isValid());
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class ValidatorParameterHelperTest method inOrderFail.
@Test
public void inOrderFail() throws Exception {
ExecutableElement executableElement = createMethod(AdapterView.class, long.class, boolean.class, Bundle.class);
ElementValidation valid = new ElementValidation("", executableElement);
//
validator.inOrder().type(boolean.class.getName()).optional().type(long.class.getName()).optional().type(int.class.getName()).optional().validate(executableElement, valid);
assertFalse(valid.isValid());
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class CoreValidatorHelper method isPrefMethod.
public void isPrefMethod(Element element, ElementValidation valid) {
if (!element.getKind().equals(ElementKind.METHOD)) {
valid.addError("Only methods are allowed in an %s annotated interface");
} else {
ExecutableElement executableElement = (ExecutableElement) element;
String methodName = executableElement.getSimpleName().toString();
if (executableElement.getParameters().size() > 0) {
valid.addError("Method " + methodName + " should have no parameters in an %s annotated interface");
} else {
String returnType = executableElement.getReturnType().toString();
if (!VALID_PREF_RETURN_TYPES.contains(returnType)) {
valid.addError("Method " + methodName + " should only return preference simple types in an %s annotated interface");
} else {
if (INVALID_PREF_METHOD_NAMES.contains(methodName)) {
valid.addError("The method name " + methodName + " is forbidden in an %s annotated interface");
} else {
return;
}
}
}
}
valid.invalidate();
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class ReceiverActionHandler method process.
@Override
public void process(Element element, EReceiverHolder holder) throws Exception {
ExecutableElement executableElement = (ExecutableElement) element;
String methodName = element.getSimpleName().toString();
ReceiverAction annotation = element.getAnnotation(ReceiverAction.class);
String[] dataSchemes = annotation.dataSchemes();
String[] actions = annotation.actions();
JFieldVar actionKeyField = createStaticField(holder, "actions", methodName, actions);
JFieldVar dataSchemesField = createStaticField(holder, "dataSchemes", methodName, dataSchemes);
addActionInOnReceive(holder, executableElement, methodName, actionKeyField, dataSchemesField);
}
use of javax.lang.model.element.ExecutableElement in project androidannotations by androidannotations.
the class SeekBarProgressChangeHandler method process.
@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
String methodName = element.getSimpleName().toString();
ExecutableElement executableElement = (ExecutableElement) element;
List<? extends VariableElement> parameters = executableElement.getParameters();
int seekBarViewParameterPosition = -1;
int progressParameterPosition = -1;
int fromUserParameterPosition = -1;
for (int i = 0; i < parameters.size(); i++) {
VariableElement parameter = parameters.get(i);
TypeMirror parameterType = parameter.asType();
if (CanonicalNameConstants.SEEKBAR.equals(parameterType.toString())) {
seekBarViewParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
progressParameterPosition = i;
} else if (parameterType.getKind() == TypeKind.BOOLEAN || CanonicalNameConstants.BOOLEAN.equals(parameterType.toString())) {
fromUserParameterPosition = i;
}
}
List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
for (JFieldRef idRef : idsRefs) {
OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
JBlock methodBody = onSeekBarChangeListenerHolder.getOnProgressChangedBody();
IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == seekBarViewParameterPosition) {
JVar seekBarViewParameter = onSeekBarChangeListenerHolder.getOnProgressChangedSeekBarParam();
textChangeCall.arg(seekBarViewParameter);
} else if (i == progressParameterPosition) {
JVar progressParameter = onSeekBarChangeListenerHolder.getOnProgressChangedProgressParam();
textChangeCall.arg(progressParameter);
} else if (i == fromUserParameterPosition) {
JVar fromUserParameter = onSeekBarChangeListenerHolder.getOnProgressChangedFromUserParam();
textChangeCall.arg(fromUserParameter);
}
}
}
}
Aggregations