@Override public boolean isSatisfied(VariableElement param) { return param.getAnnotation(annotationClass) != null; }
@Override public Stream<CompilationMessage> visitVariable( VariableElement parameter, Void ignored ) { Name annotation = parameter.getAnnotation( Name.class ); if ( annotation == null ) { return Stream.of( new ParameterMissingAnnotationError( parameter, annotationMirror( parameter.getAnnotationMirrors() ), "@%s usage error: missing on parameter <%s>", Name.class.getName(), nameOf( parameter ) ) ); } if ( !parameterTypeVisitor.visit( parameter.asType() ) ) { Element method = parameter.getEnclosingElement(); return Stream.of( new ParameterTypeError( parameter, "Unsupported parameter type <%s> of " + "procedure|function" + " %s#%s", parameter.asType().toString(), method.getEnclosingElement().getSimpleName(), method.getSimpleName() ) ); } return Stream.empty(); }
public int numberOfElementParameterHasAnnotation(ExecutableElement element, Class<? extends Annotation> annotation) { int count = 0; for (VariableElement parameter : element.getParameters()) { if (parameter.getAnnotation(annotation) != null) { count++; } } return count; }
public boolean multipartHeaderRequired(ExecutableElement executableElement) { for (VariableElement parameter : executableElement.getParameters()) { if (parameter.getAnnotation(Part.class) != null) { return true; } } return false; }
public PropertyGenerator(ModelSpec<?> modelSpec, VariableElement field, AptUtils utils) { this.modelSpec = modelSpec; this.field = field; this.utils = utils; this.isDeprecated = field != null && field.getAnnotation(Deprecated.class) != null; }
private static List<Annotation> getLibraryAnnotations( VariableElement param, List<Class<? extends Annotation>> permittedAnnotations) { List<Annotation> paramAnnotations = new ArrayList<>(); for (Class<? extends Annotation> possibleMethodParamAnnotation : permittedAnnotations) { final Annotation paramAnnotation = param.getAnnotation(possibleMethodParamAnnotation); if (paramAnnotation != null) { paramAnnotations.add(paramAnnotation); } } return paramAnnotations; }
public JVar getEntitySentToServer(ExecutableElement element, SortedMap<String, JVar> params) { for (VariableElement parameter : element.getParameters()) { if (parameter.getAnnotation(Body.class) != null) { return params.get(parameter.getSimpleName().toString()); } } return null; }
@Override public String getAnnotationValue(VariableElement parameter) { return parameter.getAnnotation(Receiver.Extra.class).value(); } }
public void doesNotMixRequestEntityAnnotations(ExecutableElement element, ElementValidation validation) { int numberOfRequestEntityFound = 0; boolean partFound = false; boolean fieldFound = false; boolean bodyFound = false; for (VariableElement parameter : element.getParameters()) { Part part = parameter.getAnnotation(Part.class); if (part != null && !partFound) { partFound = true; numberOfRequestEntityFound++; } Field field = parameter.getAnnotation(Field.class); if (field != null && !fieldFound) { fieldFound = true; numberOfRequestEntityFound++; } Body body = parameter.getAnnotation(Body.class); if (body != null && !bodyFound) { bodyFound = true; numberOfRequestEntityFound++; } } if (numberOfRequestEntityFound > 1) { validation.addError(element, "Only one of @Part, @Field and @Body annotations can be used on the same method's parameters, not both."); } }
@Override public String getAnnotationValue(VariableElement parameter) { return parameter.getAnnotation(OnActivityResult.Extra.class).value(); }
@Override public String getAnnotationValue(VariableElement parameter) { return parameter.getAnnotation(ReceiverAction.Extra.class).value(); }
/** * Returns the post parameter name to method parameter name mapping, or null if * duplicate names found. */ public Map<String, String> extractFieldAndPartParameters(ExecutableElement element) { Map<String, String> postParameterNameToElementName = new HashMap<String, String>(); for (VariableElement parameter : element.getParameters()) { String parameterName = null; if (parameter.getAnnotation(Field.class) != null) { parameterName = extractParameter(parameter, Field.class); } else if (parameter.getAnnotation(Part.class) != null) { parameterName = extractParameter(parameter, Part.class); } if (parameterName != null) { if (postParameterNameToElementName.containsKey(parameterName)) { return null; } postParameterNameToElementName.put(parameterName, parameter.getSimpleName().toString()); } } return postParameterNameToElementName; }
@Override public boolean isBlockedField(VariableElement field) { if (field.getAnnotation(QueryType.class) != null) { return false; } else { return field.getAnnotation(skipAnn) != null || field.getModifiers().contains(Modifier.TRANSIENT) || field.getModifiers().contains(Modifier.STATIC); } }
@Override public boolean isValidField(VariableElement field) { if (field.getAnnotation(QueryType.class) != null) { return true; } else { return field.getAnnotation(skipAnn) == null && !field.getModifiers().contains(Modifier.TRANSIENT) && !field.getModifiers().contains(Modifier.STATIC); } }
private void collectTypedefs(TypeElement type, Map<String, TypeMirror> collected) { for (VariableElement field : ElementFilter.fieldsIn(elements.getAllMembers(type))) { if (field.getAnnotation(Generator.Typedef.class) != null) { collected.put(field.getSimpleName().toString(), field.asType()); } } }
@Override public Stream<CompilationMessage> visitVariable( VariableElement field, Void ignored ) { if ( field.getAnnotation( Context.class ) != null ) { return contextFieldVisitor.visitVariable( field, ignored ); } return validateNonContextField( field ); }
@Override protected boolean hasPropertyGeneratorForField(VariableElement field, DeclaredTypeName fieldType) { if (field.getAnnotation(JSONColumn.class) == null) { return false; } if (field.getModifiers().containsAll(TypeConstants.PUBLIC_STATIC_FINAL)) { // Might be a constant, ignore return false; } // Check that all type args are concrete types return recursivelyCheckTypes(field, fieldType, new AtomicBoolean(false)); }
public void urlVariableNamesExistInParameters(ExecutableElement element, Set<String> variableNames, ElementValidation valid) { List<? extends VariableElement> parameters = element.getParameters(); Set<String> parametersName = new HashSet<>(); for (VariableElement parameter : parameters) { if (parameter.getAnnotation(Path.class) == null) { continue; } String nameToAdd = restAnnotationHelper.getUrlVariableCorrespondingTo(parameter); if (parametersName.contains(nameToAdd)) { valid.addError(element, "%s has multiple method parameters which correspond to the same url variable"); return; } parametersName.add(nameToAdd); } String[] cookiesToUrl = restAnnotationHelper.requiredUrlCookies(element); if (cookiesToUrl != null) { Collections.addAll(parametersName, cookiesToUrl); } for (String variableName : variableNames) { if (!parametersName.contains(variableName)) { valid.addError("%s annotated method has an url variable which name could not be found in the method parameters: " + variableName); return; } } }
private Type getType(VariableElement element) { Type rv = typeFactory.getType(element.asType(), true); if (element.getAnnotation(QueryType.class) != null) { QueryType qt = element.getAnnotation(QueryType.class); if (qt.value() != PropertyType.NONE) { TypeCategory typeCategory = TypeCategory.valueOf(qt.value().name()); rv = rv.as(typeCategory); } } return rv; }
private JFieldVar createReceiverField(HasReceiverRegistration holder, String receiverName, String methodName, ExecutableElement executableElement) { JDefinedClass anonymousReceiverClass = getCodeModel().anonymousClass(getClasses().BROADCAST_RECEIVER); JMethod onReceiveMethod = anonymousReceiverClass.method(PUBLIC, getCodeModel().VOID, "onReceive"); JVar contextVar = onReceiveMethod.param(getClasses().CONTEXT, "context"); JVar intentVar = onReceiveMethod.param(getClasses().INTENT, "intent"); JBlock body = onReceiveMethod.body(); IJExpression receiverRef = holder.getGeneratedClass().staticRef("this"); JInvocation methodCall = receiverRef.invoke(methodName); JVar extras = null; List<? extends VariableElement> methodParameters = executableElement.getParameters(); for (VariableElement param : methodParameters) { AbstractJClass extraParamClass = codeModelHelper.typeMirrorToJClass(param.asType()); if (extraParamClass.equals(getClasses().CONTEXT)) { methodCall.arg(contextVar); } else if (extraParamClass.equals(getClasses().INTENT) && param.getAnnotation(Receiver.Extra.class) == null) { methodCall.arg(intentVar); } else if (param.getAnnotation(Receiver.Extra.class) != null) { if (extras == null) { extras = body.decl(getClasses().BUNDLE, "extras_", JOp.cond(intentVar.invoke("getExtras").ne(_null()), intentVar.invoke("getExtras"), _new(getClasses().BUNDLE))); } methodCall.arg(extraHandler.getExtraValue(param, extras, body, onReceiveMethod, anonymousReceiverClass)); } } body.add(methodCall); IJExpression receiverInit = _new(anonymousReceiverClass); return holder.getGeneratedClass().field(PRIVATE | FINAL, getClasses().BROADCAST_RECEIVER, receiverName, receiverInit); }