当前位置: 首页>>代码示例>>Java>>正文


Java AutoService类代码示例

本文整理汇总了Java中com.google.auto.service.AutoService的典型用法代码示例。如果您正苦于以下问题:Java AutoService类的具体用法?Java AutoService怎么用?Java AutoService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AutoService类属于com.google.auto.service包,在下文中一共展示了AutoService类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import com.google.auto.service.AutoService; //导入依赖的package包/类
@Override
public String write() throws IOException {
    AnnotationSpec autoServiceAnnotation = AnnotationSpec.builder(AutoService.class)
            .addMember("value", "$T.class", ServerModuleConfiguration.class).build();
    TypeSpec.Builder serverModuleTypeBuilder = DominoTypeBuilder.build(processorElement.getAnnotation(ServerModule.class).name() +
            "ServerModule", ServerModuleAnnotationProcessor.class)
            .addAnnotation(autoServiceAnnotation)
            .addSuperinterface(ServerModuleConfiguration.class);

    writeRegisterMethods(serverModuleTypeBuilder);

    StringBuilder asString = new StringBuilder();
    JavaFile.builder(processorElement.elementPackage(), serverModuleTypeBuilder.build()).skipJavaLangImports(true)
            .build().writeTo(asString);
    return asString.toString();
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:17,代码来源:ServerModuleSourceWriter.java

示例2: write

import com.google.auto.service.AutoService; //导入依赖的package包/类
public String write() throws IOException {
    AnnotationSpec autoService = AnnotationSpec.builder(AutoService.class).addMember("value", "ModuleConfigurationProvider.class").build();
    AnnotationSpec gwtIncompatible = AnnotationSpec.builder(GwtIncompatible.class).addMember("value", "\"Unused in GWT compilation\"").build();

    TypeSpec configurationProvider = DominoTypeBuilder.build(element.getAnnotation(ClientModule.class).name() + "ModuleConfiguration_Provider", ConfigurationProviderAnnotationProcessor.class)
            .addAnnotation(gwtIncompatible)
            .addAnnotation(autoService)
            .addSuperinterface(ModuleConfigurationProvider.class)
            .addMethod(makeGetMethod())
            .build();

    JavaFile javaFile = JavaFile.builder(element.elementPackage(), configurationProvider).skipJavaLangImports(true).build();

    StringBuilder classAsString = new StringBuilder();
    javaFile.writeTo(classAsString);
    return classAsString.toString();
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:18,代码来源:ConfigurationProviderSourceWriter.java

示例3: handleAnnotatedElements

import com.google.auto.service.AutoService; //导入依赖的package包/类
@Override
protected void handleAnnotatedElements(
        final IBuilderContext builderCtx,
        final Class<? extends Annotation> annotationType,
        final Set<? extends Element> elements
) throws KernelException {
    elements.forEach(classElement -> {
        if (classElement.getKind() != ElementKind.CLASS) {
            throw new KernelException(
                    "The Service annotation only can be applied on class - {}",
                    classElement.getSimpleName().toString());
        }
        builderCtx.checkModifiers(classElement, Service.class, Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL);

        // Receive service id array
        ClassMeta.Builder classBuilder = builderCtx.findClassBuilder(classElement);
        AnnotationMirror svcAnnoMirror = MoreElements.getAnnotationMirror(classElement, Service.class).get();
        Service service = classElement.getAnnotation(Service.class);
        String[] serviceIds = mergeId(getTypesInAnnotation(svcAnnoMirror, "value", builderCtx.getLogger()), service.ids());
        if (serviceIds.length == 0) {
            final StringBuilder svcId = new StringBuilder();
            // Check service factory type argument first
            Observable.from(((TypeElement) classElement).getInterfaces())
                    .filter(declareType -> declareType.toString().startsWith(IServiceFactory.class.getName()))
                    .map(declareType -> ((DeclaredType) declareType).getTypeArguments().get(0))
                    .subscribe(svcId::append);
            if (svcId.length() == 0) {
                // If the service is not a factory, using service class type
                svcId.append(StringHelper.makeString("{}.{}",
                        classBuilder.getPackageName(), classElement.getSimpleName().toString()));
            }
            serviceIds = new String[] { svcId.toString() };
        }
        Template tempGetIds = builderCtx.loadTemplate(TEMPLATE_GET_IDS);
        this._helper.addServiceId(classBuilder, serviceIds);

        // Build class builder
        classBuilder
                .addAnnotationBuilder(AnnotationMeta.builder()
                        .setName(AutoService.class.getCanonicalName())
                        .addArgument(ArgumentMeta.builder()
                                .setName("value")
                                .setIsString(false)
                                .setValue(IService.class.getCanonicalName() + ".class")))
                .addImplement(IService.class.getCanonicalName())
                .addMethodBuilder(MethodMeta.builder()
                        .addAnnotationBuilder(AnnotationMeta.builder()
                                .setName(AnnotationMeta.OVERRIDE))
                        .setName(IService.METHOD_GETIDS)
                        .addModifier(Modifier.PUBLIC)
                        .setReturnTypeName(IService.METHOD_GETIDS_RETURN_TYPE)
                        .addCodeBuilder(CodeMeta.builder()
                                .setTemplate(tempGetIds)
                                .setModel(classBuilder.getTransience(MODEL_GET_IDS))));
    });
}
 
开发者ID:minjing,项目名称:uapi,代码行数:57,代码来源:ServiceHandler.java

示例4: writeFile

import com.google.auto.service.AutoService; //导入依赖的package包/类
private void writeFile(Map<String, TypeMirror> types,
                       PackageElement pkg) throws IOException
{
    TypeName wildcardClass = ParameterizedTypeName.get(ClassName.get(Class.class),
                                                       WildcardTypeName
                                                               .subtypeOf(Command.class));
    ParameterizedTypeName returnType =
            ParameterizedTypeName.get(ClassName.get(Map.class),
                                      ClassName.get(String.class), wildcardClass);

    MethodSpec.Builder methodBuilder =
            MethodSpec.methodBuilder("getCommands")
                      .addAnnotation(Override.class)
                      .addModifiers(Modifier.PUBLIC)
                      .returns(returnType)
                      .addStatement("$T knownTypes = new $T<>()",
                                    returnType, ClassName.get(HashMap.class));

    for (Map.Entry<String, TypeMirror> entry : types.entrySet()) {
        methodBuilder.addStatement("knownTypes.put($S, $T.class)", entry.getKey(),
                                   entry.getValue());
    }

    MethodSpec getcommands = methodBuilder.addStatement("return knownTypes")
                                          .build();

    AnnotationSpec autoServiceAnnotation =
            AnnotationSpec.builder(AutoService.class)
                          .addMember("value", "$T.class", CommandProvider.class)
                          .build();

    TypeSpec commandProvider = TypeSpec.classBuilder("CommandProviderImpl")
                                       .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
                                       .addSuperinterface(CommandProvider.class)
                                       .addAnnotation(autoServiceAnnotation)
                                       .addMethod(getcommands)
                                       .build();

    JavaFile javaFile = JavaFile.builder(pkg.getQualifiedName().toString() + ".provider",
                                         commandProvider).build();
    javaFile.writeTo(processingEnv.getFiler());
}
 
开发者ID:jeeshell,项目名称:je2sh,代码行数:43,代码来源:CommandProcessor.java


注:本文中的com.google.auto.service.AutoService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。