• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JavaResource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: modifyJavaClass

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的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


示例2: TestPackageNameCompleter

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
public TestPackageNameCompleter(JavaSourceFacet facet) {
    // find package names in the source code
    facet.visitJavaTestSources(new JavaResourceVisitor() {
        @Override
        public void visit(VisitContext context, JavaResource javaResource) {
            try {
                // avoid package-info.java files
                if (!javaResource.getName().contains("package-info")) {
                    JavaClass clazz = javaResource.getJavaType();
                    String packageName = clazz.getPackage();
                    if (packageName != null && !packageNames.contains(packageName)) {
                        packageNames.add(packageName);
                    }
                }
            } catch (FileNotFoundException e) {
                // ignore
            }
        }
    });
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:21,代码来源:TestPackageNameCompleter.java


示例3: PackageNameCompleter

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
public PackageNameCompleter(JavaSourceFacet facet) {
    // find package names in the source code
    facet.visitJavaSources(new JavaResourceVisitor() {
        @Override
        public void visit(VisitContext context, JavaResource javaResource) {
            try {
                // avoid package-info.java files
                if (!javaResource.getName().contains("package-info")) {
                    JavaClass clazz = javaResource.getJavaType();
                    String packageName = clazz.getPackage();
                    if (packageName != null && !packageNames.contains(packageName)) {
                        packageNames.add(packageName);
                    }
                }
            } catch (FileNotFoundException e) {
                // ignore
            }
        }
    });
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:21,代码来源:PackageNameCompleter.java


示例4: visit

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的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


示例5: RouteBuilderCompleter

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
public RouteBuilderCompleter(JavaSourceFacet facet) {
    // find package names in the source code
    facet.visitJavaSources(new JavaResourceVisitor() {
        @Override
        public void visit(VisitContext context, JavaResource javaResource) {
            try {
                // avoid package-info.java files
                if (!javaResource.getName().contains("package-info")) {
                    JavaClass clazz = javaResource.getJavaType();
                    String superType = clazz.getSuperType();
                    if (superType != null && isRouteBuilder(superType)) {
                        routeBuilders.add(clazz.getQualifiedName());
                        packages.add(clazz.getPackage());
                    }
                }
            } catch (FileNotFoundException e) {
                // ignore
            }
        }
    });
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:22,代码来源:RouteBuilderCompleter.java


示例6: createJavaSourceForComponent

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的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


示例7: visit

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
@Override
public void visit(VisitContext context, JavaResource javaResource)
{
   if (!found)
   {
      try
      {
         JavaSource<?> javaSource = javaResource.getJavaType();
         if (javaSource instanceof JavaClass)
         {
            JavaClass<?> javaClass = (JavaClass<?>) javaSource;
            if (javaClass.getName().equals(entityName + "Endpoint") && javaClass.hasAnnotation(Path.class))
            {
               this.path = javaClass.getAnnotation(Path.class).getStringValue();
               found = true;
            }
         }
      }
      catch (FileNotFoundException e)
      {
         throw new RuntimeException(e);
      }
   }
}
 
开发者ID:forge,项目名称:angularjs-addon,代码行数:25,代码来源:ResourcePathVisitor.java


示例8: visit

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
@Override
public void visit(VisitContext context, JavaResource javaResource)
{
   if (!found)
   {
      try
      {
         JavaSource<?> javaType = javaResource.getJavaType();
         if (javaType.getAnnotation("javax.ws.rs.Path") != null)
         {
            String path = javaType.getAnnotation("javax.ws.rs.Path")
                     .getStringValue();
            String absolutePath = path.endsWith("/") ? path.substring(0, path.lastIndexOf('/')) : path;
            if (absolutePath.equals(proposedPath))
            {
               javaSource = javaType;
               found = true;
            }
         }
      }
      catch (FileNotFoundException e)
      {
         throw new RuntimeException(e);
      }
   }
}
 
开发者ID:forge,项目名称:angularjs-addon,代码行数:27,代码来源:RestResourceTypeVisitor.java


示例9: validate

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
@Override
public void validate(UIValidationContext context) {
	Project selectedProject = getSelectedProject(context);
	JavaSourceFacet javaFacet = selectedProject.getFacet(JavaSourceFacet.class);
	try {
		if (null == context.getCurrentInputComponent().getValue())
			return;
		JavaResource javaResource = javaFacet.getJavaResource((String)context.getCurrentInputComponent().getValue());
		if (javaResource.exists()) {
			if (!javaResource.getJavaType().hasAnnotation(Named.class)) {
				context.addValidationError(context.getCurrentInputComponent(), javaResource.getFullyQualifiedName() + " must be annotated with @Named");
			}
		}
	} catch (FileNotFoundException e) {
		context.addValidationError(context.getCurrentInputComponent(), e.getMessage());
	}				
}
 
开发者ID:javaee-samples,项目名称:forge-addons,代码行数:18,代码来源:BatchNewJobXmlCommand.java


示例10: getAllEntities

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
@Override
public List<JavaClassSource> getAllEntities()
{
   final List<JavaClassSource> result = new ArrayList<>();
   JavaSourceFacet javaSourceFacet = getFaceted().getFacet(JavaSourceFacet.class);
   javaSourceFacet.visitJavaSources(new JavaResourceVisitor()
   {
      @Override
      public void visit(VisitContext context, JavaResource resource)
      {
         try
         {
            JavaType<?> type = resource.getJavaType();
            if (type.hasAnnotation(Entity.class) && type.isClass())
            {
               result.add((JavaClassSource) type);
            }
         }
         catch (FileNotFoundException e)
         {
            throw new IllegalStateException(e);
         }
      }
   });

   return result;
}
 
开发者ID:forge,项目名称:springboot-addon,代码行数:28,代码来源:SpringBootJPAFacet.java


示例11: addEndpointJava

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
protected Result addEndpointJava(Project project, JavaSourceFacet facet, JavaResource file, String uri,
                                 String endpointInstanceName, String routeBuilder, String cursorPosition) throws Exception {

    JavaClassSource clazz = file.getJavaType();

    // we do not want to change the current code formatting so we need to search
    // replace the unformatted class source code
    StringBuilder sb = new StringBuilder(clazz.toUnformattedString());

    int pos = Integer.valueOf(cursorPosition);

    // move to end if pos is after the content
    pos = Math.min(sb.length(), pos);

    LOG.info("Adding endpoint at pos: " + pos + " in file: " + routeBuilder);

    // check if prev and next is a quote and if not then add it automatic
    int prev = pos - 1;
    int next = pos + 1;
    char ch = sb.charAt(prev);
    char ch2 = next < sb.length() ? sb.charAt(next) : ' ';
    if (ch != '"' && ch2 != '"') {
        uri = "\"" + uri + "\"";
    }

    // insert uri at position
    sb.insert(pos, uri);

    // use this code currently to save content unformatted
    file.setContents(sb.toString());

    return Results.success("Added endpoint " + uri + " in " + routeBuilder);
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:34,代码来源:ConfigureEndpointPropertiesStep.java


示例12: addJavaVerticle

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
private String addJavaVerticle(Project project, String packageName, String className, boolean isMain) {
  JavaSourceFacet source = project.getFacet(JavaSourceFacet.class);

  String topLevelPackage;
  if (packageName == null) {
    topLevelPackage = source.getBasePackage();
  } else {
    topLevelPackage = packageName;
  }

  if (className.endsWith(".java")) {
    className = className.substring(0, className.length() - ".java".length());
  }

  JavaClassSource mainVerticle = Roaster.create(JavaClassSource.class)
      .setPackage(topLevelPackage)
      .setAbstract(false)
      .setName(className)
      .setSuperType("io.vertx.core.AbstractVerticle");
  mainVerticle
      .addImport("io.vertx.core.*");
  mainVerticle.addMethod().setName("start").setBody(
      "vertx.createHttpServer().requestHandler(req -> req.response().end(\"Hello World!\")).listen(8080);")
      .setPublic()
      .addAnnotation(Override.class);

  JavaResource resource = source.saveJavaSource(mainVerticle.getEnclosingType());

  if (isMain) {
    ForgeUtils.addPropertyToProject(project, "vertx.verticle", topLevelPackage + "." + className);
  }
  addJavaVerticleTest(project,packageName,className);
  return resource.toString();
}
 
开发者ID:cescoffier,项目名称:vertx-forge-addon,代码行数:35,代码来源:Verticles.java


示例13: testExecution

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
@Test
public void testExecution() throws Exception
{
   Assert.assertTrue(project.hasFacet(WildFlySwarmFacet.class));
   try (CommandController controller = uiTestHarness.createCommandController(CreateMainClassCommand.class,
            project.getRoot()))
   {
      controller.initialize();
      controller.setValueFor("targetPackage", "org.example");
      Assert.assertTrue(controller.isValid());
      final AtomicBoolean flag = new AtomicBoolean();
      controller.getContext().addCommandExecutionListener(new AbstractCommandExecutionListener()
      {
         @Override
         public void postCommandExecuted(UICommand command, UIExecutionContext context, Result result)
         {
            if (result.getMessage().equals("Main Class org.example.Main was created"))
            {
               flag.set(true);
            }
         }
      });
      controller.execute();
      Assert.assertTrue("Class not created", flag.get());
   }
   JavaResource javaResource = project.getFacet(JavaSourceFacet.class).getJavaResource("org.example.Main");
   Assert.assertTrue(javaResource.exists());
   WildFlySwarmFacet facet = project.getFacet(WildFlySwarmFacet.class);
   Assert.assertEquals("org.example.Main", facet.getConfiguration().getMainClass());
}
 
开发者ID:forge,项目名称:wildfly-swarm-addon,代码行数:31,代码来源:CreateMainClassCommandTest.java


示例14: scan

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
public List<String> scan(JavaResource resource) throws FileNotFoundException {
	Set<String> result = new HashSet<>();
	
	for(Import imp : resource.getJavaSource().getImports()) {
		for(Map.Entry<String, String[]> entry : categories.entrySet()) {
			for(String pack : entry.getValue()) {
				if(imp.getPackage().startsWith(pack)) {
					result.add(entry.getKey());
				}
			}
		}
	}
	return new ArrayList<>(result);
}
 
开发者ID:javaee-samples,项目名称:javaee-samples-forge-addon,代码行数:15,代码来源:ImportScanner.java


示例15: getJavaClass

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
private JavaClassSource getJavaClass(String qualifiedType)
{
   JavaSourceFacet java = this.project.getFacet(JavaSourceFacet.class);
   try
   {
      JavaResource resource = java.getJavaResource(qualifiedType);
      JavaClassSource javaClass = resource.getJavaType();
      return javaClass;
   }
   catch (FileNotFoundException fileEx)
   {
      throw new RuntimeException(fileEx);
   }
}
 
开发者ID:forge,项目名称:angularjs-addon,代码行数:15,代码来源:InspectionResultProcessor.java


示例16: createOneToOneField

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
public void createOneToOneField(Project project, JavaResource javaResource, String fieldName,
         String type, String inverseFieldName, FetchType fetchType, boolean required,
         Iterable<CascadeType> cascadeTypes) throws FileNotFoundException
{
   jpaFieldOperations.newOneToOneRelationship(project, javaResource, fieldName, type, inverseFieldName, fetchType,
            required, cascadeTypes);
}
 
开发者ID:forge,项目名称:angularjs-addon,代码行数:8,代码来源:ProjectHelper.java


示例17: createManyToOneField

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
public void createManyToOneField(Project project, JavaResource javaResource, String fieldName,
         String type, String inverseFieldName, FetchType fetchType, boolean required,
         Iterable<CascadeType> cascadeTypes) throws FileNotFoundException
{
   jpaFieldOperations.newManyToOneRelationship(project, javaResource, fieldName, type, inverseFieldName, fetchType,
            required, cascadeTypes);
}
 
开发者ID:forge,项目名称:angularjs-addon,代码行数:8,代码来源:ProjectHelper.java


示例18: createOneToManyField

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
public void createOneToManyField(Project project, JavaResource javaResource, String fieldName,
         String type, String inverseFieldName, FetchType fetchType,
         Iterable<CascadeType> cascadeTypes) throws FileNotFoundException
{
   jpaFieldOperations.newOneToManyRelationship(project, javaResource, fieldName, type, inverseFieldName, fetchType,
            cascadeTypes);
}
 
开发者ID:forge,项目名称:angularjs-addon,代码行数:8,代码来源:ProjectHelper.java


示例19: createManyToManyField

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
public void createManyToManyField(Project project, JavaResource javaResource, String fieldName,
         String type, String inverseFieldName, FetchType fetchType,
         Iterable<CascadeType> cascadeTypes) throws FileNotFoundException
{
   jpaFieldOperations.newManyToManyRelationship(project, javaResource, fieldName, type, inverseFieldName, fetchType,
            cascadeTypes);
}
 
开发者ID:forge,项目名称:angularjs-addon,代码行数:8,代码来源:ProjectHelper.java


示例20: generateOneToOneField

import org.jboss.forge.addon.parser.java.resources.JavaResource; //导入依赖的package包/类
private void generateOneToOneField(String fieldName, String type, String inverseFieldName, FetchType fetchType,
         boolean required, Iterable<CascadeType> cascadeTypes) throws Exception
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   JavaResource entityClassResource = java.getJavaResource(entityClass);
   projectHelper.createOneToOneField(project, entityClassResource, fieldName, type, inverseFieldName, fetchType,
            required, cascadeTypes);
   entityClass = getJavaClassFor(entityClass.getName());
}
 
开发者ID:forge,项目名称:angularjs-addon,代码行数:10,代码来源:InspectionResultProcessorTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CompareGenerator类代码示例发布时间:2022-05-23
下一篇:
Java WSEndpointImpl类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap