org.jboss.forge.addon.parser.java.facets.JavaSourceFacet Java Examples

The following examples show how to use org.jboss.forge.addon.parser.java.facets.JavaSourceFacet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateTestClassCommand.java    From thorntail-addon with Eclipse Public License 1.0 6 votes vote down vote up
@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()));
}
 
Example #2
Source File: NewIntegrationTestClassCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeUI(final UIBuilder builder) throws Exception {
    super.initializeUI(builder);

    Project project = getCurrentSelectedProject(builder.getUIContext());
    if (project.hasFacet(JavaSourceFacet.class)) {
        JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
        targetPackage.setCompleter(new TestPackageNameCompleter(facet));
    }
    targetPackage.addValidator(new PackageNameValidator());
    targetPackage.setDefaultValue("io.fabric8.itests");

    className.addValidator(new ClassNameValidator(false));
    className.setDefaultValue(new Callable<String>() {
        @Override
        public String call() throws Exception {
            return "IntegrationTestKT";
        }
    });

    builder.add(targetPackage).add(className).add(profile).add(integrationTestWildcard).add(itestPlugin);
}
 
Example #3
Source File: TestPackageNameCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
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
            }
        }
    });
}
 
Example #4
Source File: PackageNameCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
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
            }
        }
    });
}
 
Example #5
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
public void addSizeConstraint(Project project, JavaClassSource klass, String propertyName, boolean onAccessor,
         String message,
         String min, String max) throws FileNotFoundException
{
   PropertySource<JavaClassSource> property = klass.getProperty(propertyName);
   final AnnotationSource<JavaClassSource> constraintAnnotation = addConstraintOnProperty(property, onAccessor,
            Size.class,
            message);

   if (min != null)
   {
      constraintAnnotation.setLiteralValue("min", min);
   }

   if (max != null)
   {
      constraintAnnotation.setLiteralValue("max", max);
   }

   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   javaSourceFacet.saveJavaSource(constraintAnnotation.getOrigin());
}
 
Example #6
Source File: CamelNewComponentCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    Project project = getSelectedProject(builder.getUIContext());
    final JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);

    // filter the list of components based on consumer and producer only
    configureComponentName(project, componentName, false, false);

    targetPackage.setCompleter(new PackageNameCompleter(facet));
    targetPackage.addValidator(new PackageNameValidator());
    targetPackage.getFacet(HintsFacet.class).setInputType(InputType.JAVA_PACKAGE_PICKER);
    // if there is only one package then use that as default
    Set<String> packages = new RouteBuilderCompleter(facet).getPackages();
    if (packages.size() == 1) {
        targetPackage.setDefaultValue(first(packages));
    }

    className.addValidator(new ClassNameValidator(false));
    className.getFacet(HintsFacet.class).setInputType(InputType.JAVA_CLASS_PICKER);

    builder.add(componentName).add(instanceName).add(targetPackage).add(className);
}
 
Example #7
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected CurrentLineCompleter createCurrentLineCompleter(int lineNumber, String file, UIContext context) throws Exception {
    Project project = getSelectedProject(context);

    JavaSourceFacet sourceFacet = null;
    ResourcesFacet resourcesFacet = null;
    WebResourcesFacet webResourcesFacet = null;
    if (project.hasFacet(JavaSourceFacet.class)) {
        sourceFacet = project.getFacet(JavaSourceFacet.class);
    }
    if (project.hasFacet(ResourcesFacet.class)) {
        resourcesFacet = project.getFacet(ResourcesFacet.class);
    }
    if (project.hasFacet(WebResourcesFacet.class)) {
        webResourcesFacet = project.getFacet(WebResourcesFacet.class);
    }

    String relativeFile = asRelativeFile(context, file);
    return new CurrentLineCompleter(lineNumber, relativeFile, sourceFacet, resourcesFacet, webResourcesFacet);
}
 
Example #8
Source File: AbstractCamelProjectCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
protected String asRelativeFile(UIContext context, String currentFile) {
    Project project = getSelectedProject(context);

    JavaSourceFacet javaSourceFacet = null;
    ResourcesFacet resourcesFacet = null;
    WebResourcesFacet webResourcesFacet = null;
    if (project.hasFacet(JavaSourceFacet.class)) {
        javaSourceFacet = project.getFacet(JavaSourceFacet.class);
    }
    if (project.hasFacet(ResourcesFacet.class)) {
        resourcesFacet = project.getFacet(ResourcesFacet.class);
    }
    if (project.hasFacet(WebResourcesFacet.class)) {
        webResourcesFacet = project.getFacet(WebResourcesFacet.class);
    }
    return asRelativeFile(currentFile, javaSourceFacet, resourcesFacet, webResourcesFacet);
}
 
Example #9
Source File: RouteBuilderCompleter.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
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
            }
        }
    });
}
 
Example #10
Source File: CamelNewRouteBuilderCommand.java    From fabric8-forge with Apache License 2.0 6 votes vote down vote up
@Override
public void initializeUI(UIBuilder builder) throws Exception {
    Project project = getSelectedProject(builder.getUIContext());
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);

    targetPackage.setCompleter(new PackageNameCompleter(facet));
    targetPackage.addValidator(new PackageNameValidator());
    targetPackage.getFacet(HintsFacet.class).setInputType(InputType.JAVA_PACKAGE_PICKER);
    // if there is only one package then use that as default
    Set<String> packages = new RouteBuilderCompleter(facet).getPackages();
    if (packages.size() == 1) {
        targetPackage.setDefaultValue(first(packages));
    }

    name.addValidator(new ClassNameValidator(false));
    name.getFacet(HintsFacet.class).setInputType(InputType.JAVA_CLASS_PICKER);

    builder.add(targetPackage).add(name);
}
 
Example #11
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void addMinConstraint(Project project, JavaClassSource klass, String propertyName, boolean onAccessor,
         String message, String min)
         throws FileNotFoundException
{
   PropertySource<JavaClassSource> property = klass.getProperty(propertyName);
   final AnnotationSource<JavaClassSource> constraintAnnotation = addConstraintOnProperty(property, onAccessor,
            Min.class,
            message);
   constraintAnnotation.setLiteralValue(min);

   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   javaSourceFacet.saveJavaSource(constraintAnnotation.getOrigin());
}
 
Example #12
Source File: CreateTestClassCommandTest.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp()
{
   AddonRegistry addonRegistry = Furnace.instance(getClass().getClassLoader()).getAddonRegistry();
   projectFactory = addonRegistry.getServices(ProjectFactory.class).get();
   uiTestHarness = addonRegistry.getServices(UITestHarness.class).get();
   shellTest = addonRegistry.getServices(ShellTest.class).get();
   project = projectFactory.createTempProject(Arrays.asList(JavaSourceFacet.class, ThorntailFacet.class));
}
 
Example #13
Source File: JSONRestResourceFromEntityCommand.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initializeUI(UIBuilder builder) throws Exception
{
   UIContext context = builder.getUIContext();
   Project project = getSelectedProject(context);
   JPAFacet<PersistenceCommonDescriptor> persistenceFacet = project.getFacet(JPAFacet.class);
   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   List<String> persistenceUnits = new ArrayList<>();
   List<PersistenceUnitCommon> allUnits = persistenceFacet.getConfig().getAllPersistenceUnit();
   for (PersistenceUnitCommon persistenceUnit : allUnits)
   {
      persistenceUnits.add(persistenceUnit.getName());
   }
   if (!persistenceUnits.isEmpty())
   {
      persistenceUnit.setValueChoices(persistenceUnits).setDefaultValue(persistenceUnits.get(0));
   }

   // TODO: May detect where @Path resources are located
   packageName.setDefaultValue(javaSourceFacet.getBasePackage() + ".rest");

   RestResourceGenerator defaultResourceGenerator = null;
   for (RestResourceGenerator generator : resourceGenerators)
   {
      if (generator.getName().equals(RestGenerationConstants.JPA_ENTITY))
      {
         defaultResourceGenerator = generator;
      }
   }
   generator.setDefaultValue(defaultResourceGenerator);
   generator.setItemLabelConverter(
            context.getProvider().isGUI() ? RestResourceGenerator::getDescription : RestResourceGenerator::getName);
   builder.add(generator).add(packageName).add(persistenceUnit);
}
 
Example #14
Source File: AngularScaffoldProvider.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private String parseResourcePath(JavaClassSource klass)
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   ResourcePathVisitor visitor = new ResourcePathVisitor(klass.getName());
   java.visitJavaSources(visitor);
   return visitor.getPath();
}
 
Example #15
Source File: ScaffoldableEntitySelectionWizard.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public NavigationResult next(UINavigationContext context) throws Exception
{
   UIContext uiContext = context.getUIContext();
   Map<Object, Object> attributeMap = uiContext.getAttributeMap();
   ResourceCollection resourceCollection = new ResourceCollection();
   if (targets.getValue() != null)
   {
      for (JavaClassSource klass : targets.getValue())
      {
         Project project = getSelectedProject(uiContext);
         JavaSourceFacet javaSource = project.getFacet(JavaSourceFacet.class);
         Resource<?> resource = javaSource.getJavaResource(klass);
         if (resource != null)
         {
            resourceCollection.addToCollection(resource);
         }
      }
   }

   attributeMap.put(ResourceCollection.class, resourceCollection);
   Boolean shouldGenerateRestResources = generateRestResources.getValue();
   if (shouldGenerateRestResources.equals(Boolean.TRUE))
   {
      return Results.navigateTo(JSONRestResourceFromEntityCommand.class);
   }
   return null;
}
 
Example #16
Source File: ScaffoldableEntitySelectionWizard.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void validate(UIValidationContext context)
{
   // Verify if the selected JPA entities have corresponding JAX-RS resources.
   // If yes, then raise warnings if they will be overwritten
   Boolean shouldGenerateRestResources = generateRestResources.getValue();
   List<String> entitiesWithRestResources = new ArrayList<>();
   if (shouldGenerateRestResources.equals(Boolean.TRUE) && targets.getValue() != null)
   {
      for (JavaClassSource klass : targets.getValue())
      {
         Project project = getSelectedProject(context.getUIContext());
         JavaSourceFacet javaSource = project.getFacet(JavaSourceFacet.class);
         RestResourceTypeVisitor restTypeVisitor = new RestResourceTypeVisitor();
         String entityTable = getEntityTable(klass);
         String proposedResourcePath = "/" + inflector.pluralize(entityTable.toLowerCase());
         restTypeVisitor.setProposedPath(proposedResourcePath);
         javaSource.visitJavaSources(restTypeVisitor);
         if (restTypeVisitor.isFound())
         {
            entitiesWithRestResources.add(klass.getQualifiedName());
         }
      }
   }
   if (!entitiesWithRestResources.isEmpty())
   {
      context.addValidationWarning(targets, "Some of the selected entities " + entitiesWithRestResources.toString()
               + " already have associated REST resources that will be overwritten.");
   }
}
 
Example #17
Source File: InspectionResultProcessor.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
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);
   }
}
 
Example #18
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void addNotNullConstraint(Project project, JavaClassSource klass, String propertyName, boolean onAccessor,
         String message)
         throws FileNotFoundException
{
   PropertySource<JavaClassSource> property = klass.getProperty(propertyName);
   final Annotation<JavaClassSource> constraintAnnotation = addConstraintOnProperty(property, onAccessor,
            NotNull.class,
            message);

   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   javaSourceFacet.saveJavaSource(constraintAnnotation.getOrigin());
}
 
Example #19
Source File: FunktionArchetypeSelectionWizardStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Result execute(UIExecutionContext context) throws Exception {
    UIContext uiContext = context.getUIContext();
    Project project = (Project) uiContext.getAttributeMap().get(Project.class);
    Archetype chosenArchetype = archetype.getValue();
    String coordinate = chosenArchetype.getGroupId() + ":" + chosenArchetype.getArtifactId() + ":"
            + chosenArchetype.getVersion();
    DependencyQueryBuilder depQuery = DependencyQueryBuilder.create(coordinate);
    String repository = chosenArchetype.getRepository();
    if (!Strings.isNullOrEmpty(repository)) {
        if (repository.endsWith(".xml")) {
            int lastRepositoryPath = repository.lastIndexOf('/');
            if (lastRepositoryPath > -1)
                repository = repository.substring(0, lastRepositoryPath);
        }
        if (!repository.isEmpty()) {
            depQuery.setRepositories(new DependencyRepository("archetype", repository));
        }
    }
    Dependency resolvedArtifact = dependencyResolver.resolveArtifact(depQuery);
    FileResource<?> artifact = resolvedArtifact.getArtifact();
    MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
    File fileRoot = project.getRoot().reify(DirectoryResource.class).getUnderlyingResourceObject();
    ArchetypeHelper archetypeHelper = new ArchetypeHelper(artifact.getResourceInputStream(), fileRoot,
            metadataFacet.getProjectGroupName(), metadataFacet.getProjectName(), metadataFacet.getProjectVersion());
    JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
    archetypeHelper.setPackageName(facet.getBasePackage());
    archetypeHelper.execute();
    return Results.success();
}
 
Example #20
Source File: ProjectHelper.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
public void addMaxConstraint(Project project, JavaClassSource klass, String propertyName, boolean onAccessor,
         String message, String max)
         throws FileNotFoundException
{
   PropertySource<JavaClassSource> property = klass.getProperty(propertyName);
   final AnnotationSource<JavaClassSource> constraintAnnotation = addConstraintOnProperty(property, onAccessor,
            Max.class,
            message);
   constraintAnnotation.setLiteralValue(max);

   JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class);
   javaSourceFacet.saveJavaSource(constraintAnnotation.getOrigin());
}
 
Example #21
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
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());
}
 
Example #22
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void generateManyToOneField(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.createManyToOneField(project, entityClassResource, fieldName, type, inverseFieldName, fetchType,
            required, cascadeTypes);
   entityClass = getJavaClassFor(entityClass.getName());
}
 
Example #23
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void generateOneToManyField(String fieldName, String type, String inverseFieldName, FetchType fetchType,
         Iterable<CascadeType> cascadeTypes) throws Exception
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   JavaResource entityClassResource = java.getJavaResource(entityClass);
   projectHelper.createOneToManyField(project, entityClassResource, fieldName, type, inverseFieldName, fetchType,
            cascadeTypes);
   entityClass = getJavaClassFor(entityClass.getName());
}
 
Example #24
Source File: InspectionResultProcessorTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void generateManyToManyField(String fieldName, String type, String inverseFieldName, FetchType fetchType,
         Iterable<CascadeType> cascadeTypes) throws Exception
{
   JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
   JavaResource entityClassResource = java.getJavaResource(entityClass);
   projectHelper.createManyToManyField(project, entityClassResource, fieldName, type, inverseFieldName, fetchType,
            cascadeTypes);
   entityClass = getJavaClassFor(entityClass.getName());
}
 
Example #25
Source File: CreateTestClassCommand.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
protected String calculateDefaultPackage(UIContext context) {
    String packageName;
    Project project = getSelectedProject(context);
    if (project != null) {
        packageName = project.getFacet(JavaSourceFacet.class).getBasePackage();
    } else {
        packageName = "";
    }
    return packageName;
}
 
Example #26
Source File: FunktionProjectType.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Class<? extends ProjectFacet>> getRequiredFacets() {
    List<Class<? extends ProjectFacet>> result = new ArrayList<Class<? extends ProjectFacet>>(7);
    result.add(MetadataFacet.class);
    result.add(PackagingFacet.class);
    result.add(DependencyFacet.class);
    result.add(ResourcesFacet.class);
    result.add(WebResourcesFacet.class);
    result.add(JavaSourceFacet.class);
    result.add(JavaCompilerFacet.class);
    return result;
}
 
Example #27
Source File: NewIntegrationTestClassCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled(UIContext context) {
    // must be fabric8 and java project
    boolean answer = isFabric8Project(getSelectedProjectOrNull(context));
    if (answer) {
        Project project = getCurrentSelectedProject(context);
        answer = project.hasFacet(JavaSourceFacet.class);
    }
    return answer;
}
 
Example #28
Source File: SpringBootProjectType.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<Class<? extends ProjectFacet>> getRequiredFacets() {
    List<Class<? extends ProjectFacet>> result = new ArrayList<Class<? extends ProjectFacet>>(7);
    result.add(MetadataFacet.class);
    result.add(PackagingFacet.class);
    result.add(DependencyFacet.class);
    result.add(ResourcesFacet.class);
    result.add(WebResourcesFacet.class);
    result.add(JavaSourceFacet.class);
    result.add(JavaCompilerFacet.class);
    return result;
}
 
Example #29
Source File: ConfigureEndpointPropertiesStep.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #30
Source File: CurrentLineCompleter.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public CurrentLineCompleter(int lineNumber, String relativeFile, final JavaSourceFacet sourceFacet,
                            final ResourcesFacet resourcesFacet, final WebResourcesFacet webFacet) throws Exception {
    this.lineNumber = lineNumber;
    this.relativeFile = relativeFile;
    this.sourceFacet = sourceFacet;
    this.resourcesFacet = resourcesFacet;
    this.webFacet = webFacet;
    this.line = getCurrentCursorLineText();
    LOG.info("Created CurrentLineCompleter[lineNumber=" + lineNumber + ",relativeFile=" + relativeFile + ",line=" + line + "]");
}