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


Java JavaClassSource.addAnnotation方法代码示例

本文整理汇总了Java中org.jboss.forge.roaster.model.source.JavaClassSource.addAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java JavaClassSource.addAnnotation方法的具体用法?Java JavaClassSource.addAnnotation怎么用?Java JavaClassSource.addAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.forge.roaster.model.source.JavaClassSource的用法示例。


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

示例1: addAddressAnnotations

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
protected void addAddressAnnotations(JavaClassSource type, ClassPlan plan) {

        AddressTemplate address = plan.getAddr();

        // resource references
        if (1 == plan.getAddresses().size()) {
            type.addImport(Address.class);
            AnnotationSource<JavaClassSource> addressMeta = type.addAnnotation(Address.class);
            addressMeta.setStringValue(plan.getAddresses().get(0).toString());
        } else {
            type.addImport(Addresses.class);
            String[] addresses = new String[plan.getAddresses().size()];
            int i = 0;
            for (AddressTemplate addressTemplate : plan.getAddresses()) {
                addresses[i] = addressTemplate.toString();
                i++;
            }
            AnnotationSource<JavaClassSource> addressesMeta = type.addAnnotation(Addresses.class);
            addressesMeta.setStringArrayValue(addresses);
        }
    }
 
开发者ID:wildfly-swarm,项目名称:wildfly-config-api,代码行数:22,代码来源:ResourceFactory.java

示例2: addDefaultDeploymentAnnotation

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
private void addDefaultDeploymentAnnotation(JavaClassSource test, Project project) throws ClassNotFoundException, IOException {
   test.addImport("org.wildfly.swarm.arquillian.DefaultDeployment");
   final AnnotationSource<JavaClassSource> defaultDeploymentAnnotation = test.addAnnotation("DefaultDeployment");
   if (asClient.hasValue())
   {
      defaultDeploymentAnnotation.setLiteralValue("testable", "false");
   }

   if (mainClass.hasValue())
   {
         defaultDeploymentAnnotation.setLiteralValue("main", mainClass.getValue() + ".class");
   }

   if (archiveType.hasValue())
   {
      defaultDeploymentAnnotation.setLiteralValue("type", String.format("DefaultDeployment.Type.%s", archiveType.getValue()));
   }
}
 
开发者ID:forge,项目名称:wildfly-swarm-addon,代码行数:19,代码来源:CreateTestClassCommand.java

示例3: generateFrom

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Override
public List<JavaClassSource> generateFrom(RestGenerationContext context) throws Exception
{
   JavaClassSource entity = context.getEntity();
   Project project = context.getProject();
   if (!entity.hasAnnotation(XmlRootElement.class))
   {
      entity.addAnnotation(XmlRootElement.class);
      project.getFacet(JavaSourceFacet.class).saveJavaSource(entity);
   }

   String idType = JPAEntityUtil.resolveIdType(entity);
   String idGetterName = JPAEntityUtil.resolveIdGetterName(entity);
   String entityTable = JPAEntityUtil.getEntityTable(entity);
   String selectExpression = JPAEntityUtil.getSelectExpression(entity, entityTable);
   String idClause = JPAEntityUtil.getIdClause(entity, entityTable);
   String orderClause = JPAEntityUtil.getOrderClause(entity,
            JPAEntityUtil.getJpqlEntityVariable(entityTable));
   String resourcePath = getResourcePath(context);

   Map<Object, Object> map = new HashMap<>();
   map.put("entity", entity);
   map.put("idType", idType);
   map.put("getIdStatement", idGetterName);
   map.put("contentType", "\"application/json\""); // fixme: hardcoded JSON representation
   map.put("entityTable", entityTable);
   map.put("selectExpression", selectExpression);
   map.put("idClause", idClause);
   map.put("orderClause", orderClause);
   map.put("resourcePath", resourcePath);
   map.put("idIsPrimitive", Types.isPrimitive(idType));

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource("Endpoint.jv"));
   Template processor = templateFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(map);
   JavaClassSource resource = Roaster.parse(JavaClassSource.class, output);
   resource.addImport(entity.getQualifiedName());
   resource.setPackage(context.getTargetPackageName());
   return Arrays.asList(resource);
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:41,代码来源:SpringRestResourceGenerator.java

示例4: decorateSource

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Override
public JavaClassSource decorateSource(UIExecutionContext context, Project project, JavaClassSource source)
         throws Exception
{
   final JavaClassSource result = wrapped.decorateSource(context, project, source);
   result.addAnnotation("org.springframework.stereotype.Component");
   return result;
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:9,代码来源:RestCORSFilterCommand.java

示例5: createGreetingPropertiesClass

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
public static JavaClassSource createGreetingPropertiesClass(JavaClassSource current) {
   JavaClassSource source = Roaster.create(JavaClassSource.class).setName("GreetingProperties").setPackage(current.getPackage());
   source.addAnnotation(Component.class);
   source.addAnnotation(ConfigurationProperties.class).setStringValue("greeting");
   source.addProperty(String.class, "message").getField().setStringInitializer("Hello, %s!");
   return source;
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:8,代码来源:RestNewEndpointDecorator.java

示例6: createSpringComponentFactoryClass

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
public static void createSpringComponentFactoryClass(JavaClassSource javaClass, CamelComponentDetails details, String camelComponentName,
                                                     String componentInstanceName, String configurationCode, Set<String> extraJavaImports) {
    javaClass.addAnnotation("Component");

    javaClass.addImport("org.springframework.beans.factory.config.BeanDefinition");
    javaClass.addImport("org.springframework.beans.factory.annotation.Qualifier");
    javaClass.addImport("org.springframework.context.annotation.Bean");
    javaClass.addImport("org.springframework.context.annotation.Scope");
    javaClass.addImport("org.springframework.stereotype.Component");
    javaClass.addImport(details.getComponentClassQName());
    if (extraJavaImports != null) {
        for (String extra : extraJavaImports) {
            javaClass.addImport(extra);
        }
    }

    String componentClassName = details.getComponentClassName();
    String methodName = "create" + Strings.capitalize(componentInstanceName) + "Component";

    String body = componentClassName + " component = new " + componentClassName + "();" + configurationCode + "\nreturn component;";

    MethodSource<JavaClassSource> method = javaClass.addMethod()
            .setPublic()
            .setReturnType(componentClassName)
            .setName(methodName)
            .setBody(body);

    method.addAnnotation("Qualifier").setStringValue(camelComponentName);
    method.addAnnotation("Bean");
    method.addAnnotation("Scope").setLiteralValue("BeanDefinition.SCOPE_SINGLETON");
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:32,代码来源:CamelCommandsHelper.java

示例7: addResourceTypeAnnotation

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
protected void addResourceTypeAnnotation(JavaClassSource type, ClassPlan plan) {
    type.addImport(ResourceType.class);

    AnnotationSource<JavaClassSource> typeAnno = type.addAnnotation();
    typeAnno.setName("ResourceType");
    typeAnno.setStringValue(plan.getResourceType());

    if (plan.isSingleton()) {
        type.addImport(Implicit.class);
        AnnotationSource<JavaClassSource> implicitMeta = type.addAnnotation();
        implicitMeta.setName(Implicit.class.getSimpleName());
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-config-api,代码行数:14,代码来源:ResourceFactory.java

示例8: execute

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Override
public Result execute(UIExecutionContext context) throws Exception
{
    Project project = getSelectedProject(context);
    WildFlySwarmFacet wildFlySwarm = project.getFacet(WildFlySwarmFacet.class);
    List<FractionDescriptor> installedFractions = wildFlySwarm.getInstalledFractions();
    if (enableJAXRS(installedFractions))
    {
        JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
        JavaClassSource restEndpoint = Roaster.create(JavaClassSource.class)
                    .setPackage(facet.getBasePackage() + ".rest")
                    .setName("HelloWorldEndpoint");
        if (hasCDI(installedFractions))
        {
            restEndpoint.addAnnotation(ApplicationScoped.class);
        }
        restEndpoint.addAnnotation(Path.class).setStringValue("/hello");
        MethodSource<JavaClassSource> method = restEndpoint.addMethod().setPublic().setReturnType(Response.class)
                    .setName("doGet")
                    .setBody("return Response.ok(\"Hello from WildFly Swarm!\").build();");
        method.addAnnotation(GET.class);
        method.addAnnotation(javax.ws.rs.Produces.class).setStringArrayValue(new String[] { MediaType.TEXT_PLAIN });
        facet.saveJavaSource(restEndpoint);
    }
    if (hasTopologyJgroups(installedFractions))
    {
        WildFlySwarmConfiguration config = wildFlySwarm.getConfiguration();
        Map<String, String> props = new TreeMap<>(config.getProperties());
        props.put("swarm.bind.address", "127.0.0.1");
        props.put("java.net.preferIPv4Stack", "true");
        props.put("jboss.node.name", "${project.artifactId}");
        wildFlySwarm.setConfiguration(WildFlySwarmConfigurationBuilder.create(config).properties(props));
    }
    return Results.success();
}
 
开发者ID:forge,项目名称:wildfly-swarm-addon,代码行数:36,代码来源:SetupFractionsStep.java

示例9: decorateSource

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Override
public JavaClassSource decorateSource(UIExecutionContext context, Project project, JavaClassSource source) throws Exception {
   // Check that we have the spring-boot-starter-web dependency and add it if we don't
   SpringBootHelper.addSpringBootDependency(project, SpringBootFacet.SPRING_BOOT_STARTER_WEB_ARTIFACT);

   // Create Java Classes Greeting and GreetingProperties
   JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
   facet.saveJavaSource(createGreetingClass(source));
   facet.saveJavaSource(createGreetingPropertiesClass(source));

   final Properties properties = new Properties();
   if (wrapped.getPath().hasValue()) {
      final String value = wrapped.getPath().getValue();
      properties.put("server.contextPath", (value.startsWith("/") ? value : "/" + value));
   }
   properties.put("greeting.message", "Hello, %s!");
   SpringBootHelper.writeToApplicationProperties(project, properties);

   // Create the Controller
   source.addImport(AtomicLong.class);
   source.addAnnotation(RestController.class);
   source.addField().setPrivate().setFinal(false).setType("GreetingProperties").setName("properties").addAnnotation(Autowired.class);
   source.addField().setPrivate().setFinal(true).setType("AtomicLong").setName("counter").setLiteralInitializer("new AtomicLong()");

   for (RestMethod restMethod : wrapped.getMethods().getValue()) {
      MethodSource<?> greeting = source.addMethod()
            .setPublic()
            .setName(restMethod.getMethodName())
            .setReturnType("Greeting");

      switch (restMethod) {
         case GET:
            greeting.addAnnotation(RequestMapping.class).setStringValue("/greeting");
            greeting.addParameter(String.class, "name").addAnnotation(RequestParam.class).setLiteralValue("value", "\"name\"").setLiteralValue("defaultValue", "\"world\"");
            greeting.setBody("return new Greeting(this.counter.incrementAndGet(), String.format(this.properties.getMessage(), name));");
            break;
         case POST:
            source.addImport(UriBuilder.class);
            // TODO
            break;
         case PUT:
            // TODO
            break;
         case DELETE:
            // TODO
            break;
      }
   }

   return source;

}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:53,代码来源:RestNewEndpointDecorator.java

示例10: execute

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
@Override
public Result execute(UIExecutionContext context) throws Exception {
    Project project = getSelectedProject(context);
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);

    // does the project already have camel?
    Dependency core = findCamelCoreDependency(project);
    if (core == null) {
        return Results.fail("The project does not include camel-core");
    }

    // do we already have a class with the name
    String fqn = targetPackage.getValue() != null ? targetPackage.getValue() + "." + name.getValue() : name.getValue();

    JavaResource existing = facet.getJavaResource(fqn);
    if (existing != null && existing.exists()) {
        return Results.fail("A class with name " + fqn + " already exists");
    }

    // need to parse to be able to extends another class
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
    javaClass.setName(name.getValue());
    if (targetPackage.getValue() != null) {
        javaClass.setPackage(targetPackage.getValue());
    }
    javaClass.setSuperType("RouteBuilder");
    javaClass.addImport("org.apache.camel.builder.RouteBuilder");

    boolean cdi = CamelCommandsHelper.isCdiProject(getSelectedProject(context));
    boolean spring = CamelCommandsHelper.isSpringProject(getSelectedProject(context));

    if (cdi) {
        javaClass.addAnnotation("javax.inject.Singleton");
    } else if (spring) {
        javaClass.addAnnotation("org.springframework.stereotype.Component");
    }

    javaClass.addMethod()
            .setPublic()
            .setReturnTypeVoid()
            .setName("configure")
            .addThrows(Exception.class).setBody("");

    JavaResource javaResource = facet.saveJavaSource(javaClass);

    // if we are in an GUI editor then open the file
    if (isRunningInGui(context.getUIContext())) {
        context.getUIContext().setSelection(javaResource);
    }

    return Results.success("Created new RouteBuilder class " + name.getValue());
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:53,代码来源:CamelNewRouteBuilderCommand.java

示例11: createComponentAutoConfigurationSource

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
private void createComponentAutoConfigurationSource(String packageName, ComponentModel model) throws MojoFailureException {
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);

    int pos = model.getJavaType().lastIndexOf(".");
    String name = model.getJavaType().substring(pos + 1);
    name = name.replace("Component", "ComponentAutoConfiguration");
    javaClass.setPackage(packageName).setName(name);

    String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
    javaClass.getJavaDoc().setFullText(doc);

    javaClass.addAnnotation(Configuration.class);

    String configurationName = name.replace("ComponentAutoConfiguration", "ComponentConfiguration");
    AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
    ann.setLiteralValue("value", configurationName + ".class");

    // add method for auto configure

    javaClass.addImport("java.util.HashMap");
    javaClass.addImport("java.util.Map");
    javaClass.addImport(model.getJavaType());
    javaClass.addImport("org.apache.camel.CamelContext");
    javaClass.addImport("org.apache.camel.util.IntrospectionSupport");

    String body = createComponentBody(model.getShortJavaType());
    String methodName = "configure" + model.getShortJavaType();

    MethodSource<JavaClassSource> method = javaClass.addMethod()
            .setName(methodName)
            .setPublic()
            .setBody(body)
            .setReturnType(model.getShortJavaType())
            .addThrows(Exception.class);

    method.addParameter("CamelContext", "camelContext");
    method.addParameter(configurationName, "configuration");

    method.addAnnotation(Bean.class);
    method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
    method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");

    sortImports(javaClass);

    String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
    File target = new File(srcDir, fileName);

    try {
        InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
        String header = loadText(is);
        String code = sourceToString(javaClass);
        code = header + code;
        getLog().debug("Source code generated:\n" + code);

        if (target.exists()) {
            String existing = FileUtils.readFileToString(target);
            if (!code.equals(existing)) {
                FileUtils.write(target, code, false);
                getLog().info("Updated existing file: " + target);
            } else {
                getLog().debug("No changes to existing file: " + target);
            }
        } else {
            FileUtils.write(target, code);
            getLog().info("Created file: " + target);
        }
    } catch (Exception e) {
        throw new MojoFailureException("IOError with file " + target, e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:71,代码来源:SpringBootAutoConfigurationMojo.java

示例12: createDataFormatAutoConfigurationSource

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入方法依赖的package包/类
private void createDataFormatAutoConfigurationSource(String packageName, DataFormatModel model) throws MojoFailureException {
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);

    int pos = model.getJavaType().lastIndexOf(".");
    String name = model.getJavaType().substring(pos + 1);
    name = name.replace("DataFormat", "DataFormatAutoConfiguration");
    javaClass.setPackage(packageName).setName(name);

    String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
    javaClass.getJavaDoc().setFullText(doc);

    javaClass.addAnnotation(Configuration.class);

    String configurationName = name.replace("DataFormatAutoConfiguration", "DataFormatConfiguration");
    AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
    ann.setLiteralValue("value", configurationName + ".class");

    // add method for auto configure

    javaClass.addImport("java.util.HashMap");
    javaClass.addImport("java.util.Map");
    javaClass.addImport(model.getJavaType());
    javaClass.addImport("org.apache.camel.CamelContext");
    javaClass.addImport("org.apache.camel.CamelContextAware");
    javaClass.addImport("org.apache.camel.util.IntrospectionSupport");

    String body = createDataFormatBody(model.getShortJavaType());
    String methodName = "configure" + model.getShortJavaType();

    MethodSource<JavaClassSource> method = javaClass.addMethod()
            .setName(methodName)
            .setPublic()
            .setBody(body)
            .setReturnType(model.getShortJavaType())
            .addThrows(Exception.class);

    method.addParameter("CamelContext", "camelContext");
    method.addParameter(configurationName, "configuration");

    method.addAnnotation(Bean.class);
    method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
    method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");

    sortImports(javaClass);

    String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
    File target = new File(srcDir, fileName);

    try {
        InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt");
        String header = loadText(is);
        String code = sourceToString(javaClass);
        code = header + code;
        getLog().debug("Source code generated:\n" + code);

        if (target.exists()) {
            String existing = FileUtils.readFileToString(target);
            if (!code.equals(existing)) {
                FileUtils.write(target, code, false);
                getLog().info("Updated existing file: " + target);
            } else {
                getLog().debug("No changes to existing file: " + target);
            }
        } else {
            FileUtils.write(target, code);
            getLog().info("Created file: " + target);
        }
    } catch (Exception e) {
        throw new MojoFailureException("IOError with file " + target, e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:72,代码来源:SpringBootAutoConfigurationMojo.java


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