Search in sources :

Example 46 with ExecutableElement

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());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) ElementValidation(org.androidannotations.ElementValidation) Test(org.junit.Test)

Example 47 with ExecutableElement

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());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) ElementValidation(org.androidannotations.ElementValidation) Test(org.junit.Test)

Example 48 with ExecutableElement

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();
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) DefaultString(org.androidannotations.annotations.sharedpreferences.DefaultString)

Example 49 with ExecutableElement

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);
}
Also used : ReceiverAction(org.androidannotations.annotations.ReceiverAction) JFieldVar(com.helger.jcodemodel.JFieldVar) ExecutableElement(javax.lang.model.element.ExecutableElement)

Example 50 with ExecutableElement

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);
            }
        }
    }
}
Also used : OnSeekBarChangeListenerHolder(org.androidannotations.holder.OnSeekBarChangeListenerHolder) JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) TypeMirror(javax.lang.model.type.TypeMirror) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Aggregations

ExecutableElement (javax.lang.model.element.ExecutableElement)345 TypeElement (javax.lang.model.element.TypeElement)158 TypeMirror (javax.lang.model.type.TypeMirror)97 VariableElement (javax.lang.model.element.VariableElement)85 Element (javax.lang.model.element.Element)72 Test (org.junit.Test)41 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)32 DeclaredType (javax.lang.model.type.DeclaredType)31 ArrayList (java.util.ArrayList)26 JBlock (com.helger.jcodemodel.JBlock)25 JInvocation (com.helger.jcodemodel.JInvocation)20 MethodDeclaration (com.google.devtools.j2objc.ast.MethodDeclaration)18 JVar (com.helger.jcodemodel.JVar)18 Map (java.util.Map)18 HashSet (java.util.HashSet)17 IJExpression (com.helger.jcodemodel.IJExpression)16 ElementValidation (org.androidannotations.ElementValidation)15 Block (com.google.devtools.j2objc.ast.Block)13 JMethod (com.helger.jcodemodel.JMethod)13 Elements (javax.lang.model.util.Elements)13