@Override public Result execute(UIExecutionContext context) throws Exception { JavaResource javaResource = targetClass.getValue(); JavaClassSource targetClass = javaResource.getJavaType(); GetSetMethodGenerator generator; if (builderPattern.getValue()) { generator = new BuilderGetSetMethodGenerator(); } else { generator = new DefaultGetSetMethodGenerator(); } List<PropertySource<JavaClassSource>> selectedProperties = new ArrayList<>(); if (properties == null || properties.getValue() == null) { return Results.fail("No properties were selected"); } for (String selectedProperty : properties.getValue()) { selectedProperties.add(targetClass.getProperty(selectedProperty)); } for (PropertySource<JavaClassSource> property : selectedProperties) { MethodSource<JavaClassSource> accessor = targetClass.getMethod("get" + Strings.capitalize(property.getName())); if (accessor == null) { generator.createAccessor(property); } else { if (!generator.isCorrectAccessor(accessor, property)) { if (promptToFixMethod(context, accessor.getName(), property.getName())) { targetClass.removeMethod(accessor); generator.createMutator(property); } } } String mutatorMethodName = "set" + Strings.capitalize(property.getName()); String mutatorMethodParameter = property.getType().getName(); MethodSource<JavaClassSource> mutator = targetClass.getMethod(mutatorMethodName, mutatorMethodParameter); if (mutator == null) { generator.createMutator(property); } else { if (!generator.isCorrectMutator(mutator, property)) { if (promptToFixMethod(context, mutator.getName(), property.getName())) { targetClass.removeMethod(mutator); generator.createMutator(property); } } } } setCurrentWorkingResource(context, targetClass); return Results.success("Mutators and accessors were generated successfully"); }
@Override public Result execute(UIExecutionContext context) throws Exception { UIContext uiContext = context.getUIContext(); Project project = getSelectedProject(uiContext); facetFactory.install(project, FurnaceVersionFacet.class); project.getFacet(FurnaceVersionFacet.class).setVersion(furnace.getVersion().toString()); facetFactory.install(project, AddonTestFacet.class); for (AddonId addonId : addonDependencies.getValue()) { DependencyBuilder dependency = DependencyBuilder.create(addonId.getName()) .setVersion(addonId.getVersion().toString()) .setScopeType("test"); if (!dependencyInstaller.isInstalled(project, dependency)) { dependencyInstaller.install(project, dependency); } } return Results.success( "Project " + project.getFacet(MetadataFacet.class).getProjectName() + " is now configured for testing"); }