use of com.squareup.javapoet.ParameterSpec in project epoxy by airbnb.
the class ClassToGenerateInfo method buildParamList.
private List<ParameterSpec> buildParamList(List<? extends VariableElement> params) {
List<ParameterSpec> result = new ArrayList<>();
for (VariableElement param : params) {
Builder builder = ParameterSpec.builder(TypeName.get(param.asType()), param.getSimpleName().toString());
for (AnnotationMirror annotation : param.getAnnotationMirrors()) {
builder.addAnnotation(AnnotationSpec.get(annotation));
}
result.add(builder.build());
}
return result;
}
use of com.squareup.javapoet.ParameterSpec in project epoxy by airbnb.
the class EpoxyProcessor method generateParams.
private void generateParams(StringBuilder statementBuilder, List<ParameterSpec> params) {
boolean first = true;
for (ParameterSpec param : params) {
if (!first) {
statementBuilder.append(", ");
}
first = false;
statementBuilder.append(param.name);
}
statementBuilder.append(")");
}
use of com.squareup.javapoet.ParameterSpec in project ARouter by alibaba.
the class InterceptorProcessor method parseInterceptors.
/**
* Parse tollgate.
*
* @param elements elements of tollgate.
*/
private void parseInterceptors(Set<? extends Element> elements) throws IOException {
if (CollectionUtils.isNotEmpty(elements)) {
logger.info(">>> Found interceptors, size is " + elements.size() + " <<<");
// Verify and cache, sort incidentally.
for (Element element : elements) {
if (verify(element)) {
// Check the interceptor meta
logger.info("A interceptor verify over, its " + element.asType());
Interceptor interceptor = element.getAnnotation(Interceptor.class);
Element lastInterceptor = interceptors.get(interceptor.priority());
if (null != lastInterceptor) {
// Added, throw exceptions
throw new IllegalArgumentException(String.format(Locale.getDefault(), "More than one interceptors use same priority [%d], They are [%s] and [%s].", interceptor.priority(), lastInterceptor.getSimpleName(), element.getSimpleName()));
}
interceptors.put(interceptor.priority(), element);
} else {
logger.error("A interceptor verify failed, its " + element.asType());
}
}
// Interface of ARouter.
TypeElement type_ITollgate = elementUtil.getTypeElement(IINTERCEPTOR);
TypeElement type_ITollgateGroup = elementUtil.getTypeElement(IINTERCEPTOR_GROUP);
/**
* Build input type, format as :
*
* ```Map<Integer, Class<? extends ITollgate>>```
*/
ParameterizedTypeName inputMapTypeOfTollgate = ParameterizedTypeName.get(ClassName.get(Map.class), ClassName.get(Integer.class), ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(ClassName.get(type_ITollgate))));
// Build input param name.
ParameterSpec tollgateParamSpec = ParameterSpec.builder(inputMapTypeOfTollgate, "interceptors").build();
// Build method : 'loadInto'
MethodSpec.Builder loadIntoMethodOfTollgateBuilder = MethodSpec.methodBuilder(METHOD_LOAD_INTO).addAnnotation(Override.class).addModifiers(PUBLIC).addParameter(tollgateParamSpec);
// Generate
if (null != interceptors && interceptors.size() > 0) {
// Build method body
for (Map.Entry<Integer, Element> entry : interceptors.entrySet()) {
loadIntoMethodOfTollgateBuilder.addStatement("interceptors.put(" + entry.getKey() + ", $T.class)", ClassName.get((TypeElement) entry.getValue()));
}
}
// Write to disk(Write file even interceptors is empty.)
JavaFile.builder(PACKAGE_OF_GENERATE_FILE, TypeSpec.classBuilder(NAME_OF_INTERCEPTOR + SEPARATOR + moduleName).addModifiers(PUBLIC).addJavadoc(WARNING_TIPS).addMethod(loadIntoMethodOfTollgateBuilder.build()).addSuperinterface(ClassName.get(type_ITollgateGroup)).build()).build().writeTo(mFiler);
logger.info(">>> Interceptor group write over. <<<");
}
}
use of com.squareup.javapoet.ParameterSpec in project RxCache by VictorAlbertos.
the class BrewJavaFile method getActionProvider.
private MethodSpec getActionProvider(ClassName providersClassName, ProvidersClass.Method method) {
String methodName = method.name;
TypeName list = ClassName.get(method.enclosingTypeObservable);
TypeName enclosingTypeList = ClassName.get(method.enclosingTypeObservable.getTypeArguments().get(0));
String enclosingTypeListName = enclosingTypeList.toString();
ParameterizedTypeName action = ParameterizedTypeName.get(ClassName.get(ActionsList.class), enclosingTypeList);
ParameterizedTypeName evict = ParameterizedTypeName.get(ClassName.get(ActionsList.Evict.class), enclosingTypeList);
ParameterizedTypeName arrayList = ParameterizedTypeName.get(ClassName.get(ArrayList.class), enclosingTypeList);
ParameterizedTypeName observable = ParameterizedTypeName.get(ClassName.get(Observable.class), list);
ParameterSpec rxProvidersInstance = ParameterSpec.builder(providersClassName, "proxy").addModifiers(Modifier.FINAL).build();
MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName).addModifiers(Modifier.PUBLIC, Modifier.STATIC).addParameter(rxProvidersInstance).returns(action);
if (method.hasDynamicKey) {
builder.addParameter(DynamicKey.class, "dynamicKey", Modifier.FINAL);
} else if (method.hasDynamicKeyGroup) {
builder.addParameter(DynamicKeyGroup.class, "dynamicKeyGroup", Modifier.FINAL);
}
builder.beginControlFlow("$T evict = new $T()", evict, evict).beginControlFlow("@Override public $T call($T elements)", observable, observable);
if (method.hasDynamicKey) {
setReturnEvictForEvictDynamicKey(builder, methodName);
} else if (method.hasDynamicKeyGroup) {
setReturnEvictForEvictDynamicKeyGroup(builder, methodName);
} else {
setReturnEvictForEvictProvider(builder, methodName);
}
builder.endControlFlow().endControlFlow(";");
if (method.hasDynamicKey) {
setCacheForEvictDynamicKey(builder, observable, arrayList, methodName, enclosingTypeListName);
} else if (method.hasDynamicKeyGroup) {
setCacheForEvictDynamicKeyGroup(builder, observable, arrayList, methodName, enclosingTypeListName);
} else {
setCacheForEvictProvider(builder, observable, arrayList, methodName, enclosingTypeListName);
}
builder.addStatement("return ActionsList.with(evict, oCache)");
return builder.build();
}
Aggregations