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


Java JavaClassSource类代码示例

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


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

示例1: createCRUDRepository

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
private void createCRUDRepository(JavaClassSource entitySource, Project project) {
   // build interface declaration
   final String name = entitySource.getName();
   final String idFieldType = entitySource.getFields().stream()
         .filter(field -> field.hasAnnotation(Id.class))
         .findFirst()
         .orElseThrow(IllegalArgumentException::new)
         .getType()
         .getSimpleName();
   final String repoInterfaceDeclaration = "public interface " + name
            + "Repository extends PagingAndSortingRepository<"
         + name + "," + idFieldType + "> {}";

   JavaInterfaceSource repoSource = Roaster.parse(JavaInterfaceSource.class, repoInterfaceDeclaration)
         .setPackage(entitySource.getPackage());
   repoSource.addImport("org.springframework.data.repository.PagingAndSortingRepository");
   Roaster.format(repoSource.toString());

   // Create Java Classes Greeting and GreetingProperties
   JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
   facet.saveJavaSource(repoSource);
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:23,代码来源:CreateSpringBootJPASupportDecorator.java

示例2: modifyJavaClass

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
public static void modifyJavaClass(Project project, String className, Optional<String> packageName,
                                   JavaClassSourceDecorator decorator) {

   final String packageLocation = packageName.orElseGet(() -> project.getFacet(MetadataFacet.class).getProjectGroupName());
   final JavaSourceFacet sourceFacet = project.getFacet(JavaSourceFacet.class);
   final DirectoryResource targetPackage = sourceFacet.getPackage(packageLocation);

   final JavaResource sbAppResource = targetPackage.getChild(className).as(JavaResource.class);
   if (sbAppResource.exists()) {
      JavaClassSource sbApp = Roaster.parse(JavaClassSource.class, sbAppResource.getResourceInputStream());

      decorator.modify(sbApp);

      sourceFacet.saveJavaSource(sbApp);
   }
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:17,代码来源:SpringBootHelper.java

示例3: findConfigureMethod

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
public static MethodSource<JavaClassSource> findConfigureMethod(JavaClassSource clazz) {
    MethodSource<JavaClassSource> method = clazz.getMethod("configure");
    // must be public void configure()
    if (method != null && method.isPublic() && method.getParameters().isEmpty() && method.getReturnType().isType("void")) {
        return method;
    }

    // maybe the route builder is from unit testing with camel-test as an anonymous inner class
    // there is a bit of code to dig out this using the eclipse jdt api
    method = findCreateRouteBuilderMethod(clazz);
    if (method != null) {
        return findConfigureMethodInCreateRouteBuilder(clazz, method);
    }

    return null;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:17,代码来源:CamelJavaParserHelper.java

示例4: findInlinedConfigureMethods

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
public static List<MethodSource<JavaClassSource>> findInlinedConfigureMethods(JavaClassSource clazz) {
    List<MethodSource<JavaClassSource>> answer = new ArrayList<>();

    List<MethodSource<JavaClassSource>> methods = clazz.getMethods();
    if (methods != null) {
        for (MethodSource<JavaClassSource> method : methods) {
            if (method.isPublic()
                    && (method.getParameters() == null || method.getParameters().isEmpty())
                    && (method.getReturnType() == null || method.getReturnType().isType("void"))) {
                // maybe the method contains an inlined createRouteBuilder usually from an unit test method
                MethodSource<JavaClassSource> builder = findConfigureMethodInCreateRouteBuilder(clazz, method);
                if (builder != null) {
                    answer.add(builder);
                }
            }
        }
    }

    return answer;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:21,代码来源:CamelJavaParserHelper.java

示例5: parseCamelSimpleExpressions

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
public static List<ParserResult> parseCamelSimpleExpressions(MethodSource<JavaClassSource> method) {
    List<ParserResult> answer = new ArrayList<ParserResult>();

    MethodDeclaration md = (MethodDeclaration) method.getInternal();
    Block block = md.getBody();
    if (block != null) {
        for (Object statement : block.statements()) {
            // must be a method call expression
            if (statement instanceof ExpressionStatement) {
                ExpressionStatement es = (ExpressionStatement) statement;
                Expression exp = es.getExpression();

                List<ParserResult> expressions = new ArrayList<ParserResult>();
                parseExpression(null, method.getOrigin(), block, exp, expressions);
                if (!expressions.isEmpty()) {
                    // reverse the order as we will grab them from last->first
                    Collections.reverse(expressions);
                    answer.addAll(expressions);
                }
            }
        }
    }

    return answer;
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:26,代码来源:CamelJavaParserHelper.java

示例6: createJavaComponentFactoryClass

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
public static void createJavaComponentFactoryClass(JavaClassSource javaClass, CamelComponentDetails details, String camelComponentName,
                                                   String componentInstanceName, String configurationCode, Set<String> extraJavaImports) {
    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;";

    javaClass.addMethod()
            .setPublic()
            .setReturnType(componentClassName)
            .setName(methodName)
            .setBody(body);
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:21,代码来源:CamelCommandsHelper.java

示例7: visit

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
@Override
public void visit(VisitContext visitContext, JavaResource resource) {
    try {
        // avoid package-info.java files
        if (!resource.getName().contains("package-info")) {
            JavaClassSource clazz = resource.getJavaType();
            String fqn = resource.getFullyQualifiedName();
            String name = clazz.getQualifiedName();
            String baseDir = facet.getSourceDirectory().getFullyQualifiedName();

            boolean include = true;
            if (filter != null) {
                Boolean out = filter.apply(name);
                LOG.info("Filter " + name + " -> " + out);
                include = out == null || out;
            }

            if (include) {
                RouteBuilderParser.parseRouteBuilderEndpoints(clazz, baseDir, fqn, endpoints);
            }
        }
    } catch (Throwable e) {
        // ignore
    }
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:26,代码来源:RouteBuilderCamelEndpointsVisitor.java

示例8: getEventHandler

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
private void getEventHandler(final MethodSource<JavaClassSource> method, final String listenerName) {
   final String eventTypeName = method.getParameters()
         .get(0)
         .getType()
         .getName();

   String eventHandlerType = null;

   for (AnnotationSource<JavaClassSource> annotation : method.getAnnotations()) {
      eventHandlerType = axonUtil.getEventHandlerType(annotation.getName());
   }

   if (eventHandlerType == null) {
      throw new VisualAxonException(method.getName() + " is not a valid Axon EventHandler");
   }

   eventBus.post(EventHandlerSpotted.builder()
         .eventName(eventTypeName)
         .type(eventHandlerType)
         .listener(listenerName)
         .build());
}
 
开发者ID:Herumgeisterer,项目名称:visualaxon,代码行数:23,代码来源:AxonSpotter.java

示例9: shouldFindCommandHandler

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
@Test
public void shouldFindCommandHandler() throws Exception {
   final JavaClassSource javaClassSource = getJavaClassSource("SomeAggregate.java");

   javaFileParser.getAggregate(javaClassSource);

   Mockito.verify(testHandler, Mockito.times(1))
         .handle(CommandHandlerSpotted.builder()
               .aggregate("SomeAggregate")
               .command("SomeCommand")
               .event("SomeEvent")
               .build());

   Mockito.verify(testHandler, Mockito.times(1))
         .handle(CommandHandlerSpotted.builder()
               .aggregate("SomeAggregate")
               .command("AnotherCommand")
               .event("AnotherEvent")
               .build());
}
 
开发者ID:Herumgeisterer,项目名称:visualaxon,代码行数:21,代码来源:AxonSpotterTest.java

示例10: createJavaSourceForComponent

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
private void createJavaSourceForComponent(Project project, String schemeName, String packageName, String className) {
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    String fqn = packageName + "." + className;

    JavaResource existing = facet.getJavaResource(fqn);
    if (existing != null && existing.exists()) {
        // override existing
        existing.delete();
    }

    // need to parse to be able to extends another class
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
    javaClass.setName(className);
    javaClass.setPackage(packageName);
    javaClass.setSuperType("DjangoComponent");
    javaClass.addImport("io.fabric8.django.component.connector.DjangoComponent");

    // add public no-arg constructor
    javaClass.addMethod().setPublic().setConstructor(true).setBody("super(\"" + schemeName + "\", \"" + fqn + "\");");

    facet.saveJavaSource(javaClass);
}
 
开发者ID:fabric8io,项目名称:django,代码行数:23,代码来源:ConnectorSelectComponentStep.java

示例11: 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

示例12: generateIndicesLookup

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
private JavaClassSource generateIndicesLookup(String poolName, List<ComponentInfo> componentInfos, String pkgDestiny) {
        JavaClassSource javaClass = Roaster.parse(JavaClassSource.class, String.format("public class %1$s {}",
                CodeGeneratorOld.capitalize(poolName) + CodeGeneratorOld.DEFAULT_COMPONENT_LOOKUP_TAG));

//        if(componentInfos.size() > 0 && componentInfos.get(0).directory !=null) {
//            pkgDestiny+= "."+componentInfos.get(0).directory;
//
//        }
        if (componentInfos.size() > 0 && !pkgDestiny.endsWith(componentInfos.get(0).subDir)) {
            pkgDestiny += "." + componentInfos.get(0).subDir;

        }
        javaClass.setPackage(pkgDestiny);

        addIndices(componentInfos, javaClass);
        addComponentNames(componentInfos, javaClass);
        addComponentTypes(componentInfos, javaClass);
        System.out.println(javaClass);
        return javaClass;
    }
 
开发者ID:Rubentxu,项目名称:Entitas-Java,代码行数:21,代码来源:ComponentIndicesGenerator.java

示例13: main

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
public static void main(String [] args) throws Exception {
String someOutputPackageName = "com.systematic.healthcare.fhir.generator.generated";
String [] fileNames = {"FunctioningCondition.xml"};

String someReadingDirectory = new File(".").getAbsolutePath() + "\\dstu2\\src\\test\\resources";
String someWritingDirectory = new File(".").getAbsolutePath() + "\\dstu2\\src\\test\\java\\" + someOutputPackageName.replaceAll("\\.", "/");
new File(someWritingDirectory).mkdirs();


      for (String s : fileNames) {
          StructureDefinitionProvider provider = new FileStructureDefinitionProvider(
                  someOutputPackageName,
                  new File(someReadingDirectory, s));
          JavaClassSource javaClass = Generator.generate(provider);
          Files.write(new File(new File(someWritingDirectory), javaClass.getName()+".java").toPath(), javaClass.toString().getBytes("UTF-8"));
      }
      System.out.println("Success");
  }
 
开发者ID:botunge,项目名称:hapi-fhir-forge-profile-converter,代码行数:19,代码来源:Main.java

示例14: addContextGetMethods

import org.jboss.forge.roaster.model.source.JavaClassSource; //导入依赖的package包/类
private void addContextGetMethods(String contextName, ComponentInfo info, JavaClassSource source) {
    source.addMethod()
            .setName(String.format("get%1$sEntity", info.typeName))
            .setReturnType(contextName + "Entity")
            .setPublic()
            .setBody(String.format("return getGroup(%1$sMatcher.%2$s()).getSingleEntity();"
                    , CodeGeneratorOld.capitalize(info.contexts.get(0)), info.typeName));

    if (!info.isSingletonComponent) {
        source.addMethod()
                .setName(String.format("get%1$s", info.typeName))
                .setReturnType(info.typeName)
                .setPublic()
                .setBody(String.format("return get%1$sEntity().get%1$s();"
                        , info.typeName));

    }
}
 
开发者ID:Rubentxu,项目名称:Entitas-Java,代码行数:19,代码来源:ContextGenerator.java

示例15: execute

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

   final DependencyFacet dependencyFacet = project.getFacet(DependencyFacet.class);
   if (!isArquillianWildflySwarmDependencyInstalled(dependencyFacet)) {
      installArquillianWildflySwarmDependency(dependencyFacet);
   }

   JavaClassSource test = Roaster.create(JavaClassSource.class)
           .setPackage(targetPackage.getValue())
           .setName(named.getValue());

   addArquillianRunner(test);
   addDefaultDeploymentAnnotation(test, project);
   addArquillianResourceEnricher(test);
   addTestMethod(test);

   JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
   facet.saveTestJavaSource(test);

   return Results.success(String.format("Test Class %s.%s was created", targetPackage.getValue(), named.getValue()));
}
 
开发者ID:forge,项目名称:wildfly-swarm-addon,代码行数:24,代码来源:CreateTestClassCommand.java


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