[forge-issues] [JBoss JIRA] (FORGE-674) JavaPlugin: add new command 'new-interface'
George Gastaldi (JIRA)
jira-events at lists.jboss.org
Tue Oct 23 16:39:01 EDT 2012
[ https://issues.jboss.org/browse/FORGE-674?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
George Gastaldi closed FORGE-674.
---------------------------------
Resolution: Done
> JavaPlugin: add new command 'new-interface'
> -------------------------------------------
>
> Key: FORGE-674
> URL: https://issues.jboss.org/browse/FORGE-674
> Project: Forge
> Issue Type: Enhancement
> Components: Builtin Plugins
> Affects Versions: 1.1.1.Final
> Reporter: fiorenzo pizza
> Assignee: fiorenzo pizza
> Labels: annoying
> Fix For: 1.1.2.FInal
>
>
> javaplugin lacks an useful method to create java interfaces.
> very similar to 'new-class', this is my implementation:
> @Command("new-interface")
> public void newInterface(
> @PipeIn final InputStream in,
> @Option(required = false, help = "the package in which to build this Interface", description = "source package", type = PromptType.JAVA_PACKAGE, name = "package") final String pckg,
> @Option(required = false, help = "the interface definition: surround with quotes", description = "interface definition") final String... def)
> throws FileNotFoundException {
> JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
> JavaInterface jc = null;
> if (def != null) {
> String classDef = Strings.join(Arrays.asList(def), " ");
> jc = JavaParser.parse(JavaInterface.class, classDef);
> } else if (in != null) {
> jc = JavaParser.parse(JavaInterface.class, in);
> } else {
> throw new RuntimeException("arguments required");
> }
> if (pckg != null) {
> jc.setPackage(pckg);
> }
> if (!jc.hasSyntaxErrors()) {
> java.saveJavaSource(jc);
> } else {
> writer.println(ShellColor.RED, "Syntax Errors:");
> for (SyntaxError error : jc.getSyntaxErrors()) {
> writer.println(error.toString());
> }
> writer.println();
> if (prompt.promptBoolean(
> "Your class has syntax errors, create anyway?", true)) {
> java.saveJavaSource(jc);
> }
> }
> pickUp.fire(new PickupResource(java.getJavaResource(jc)));
> }
> i tested this and also the command 'new-method' works nicely:
> @Test
> public void testCreateJavaInterface() throws Exception {
> getShell()
> .execute(
> "java new-interface --package org.jboss.forge.test.interfaces \"public interface TestingInterfaceCreation {}\"");
> getShell().execute("build");
> JavaInterface javaClass = (JavaInterface) getProject()
> .getFacet(JavaSourceFacet.class)
> .getJavaResource(
> Packages.toFileSyntax("org.jboss.forge.test.interfaces.TestingInterfaceCreation"))
> .getJavaSource();
> assertNotNull(javaClass);
> }
> and
> @Test
> public void testCreateJavaMethodOnInterface() throws Exception {
> getShell()
> .execute(
> "java new-interface --package org.jboss.forge.test.interfaces \"public interface TestingInterfaceCreation {}\"");
> getShell().execute("java new-method \"public void testing();\"");
> getShell().execute("ls");
> getShell().execute("build");
> JavaInterface javaClass = (JavaInterface) getProject()
> .getFacet(JavaSourceFacet.class)
> .getJavaResource(
> Packages.toFileSyntax("org.jboss.forge.test.interfaces.TestingInterfaceCreation"))
> .getJavaSource();
> Method<JavaInterface> method = javaClass.getMethod("testing");
> assertNotNull(method);
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the forge-issues
mailing list