Skip to content

Commit

Permalink
FORGE-768
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 23, 2013
1 parent 45deba0 commit fde4c5c
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 6 deletions.
56 changes: 52 additions & 4 deletions dev-plugins/src/main/java/org/jboss/forge/dev/java/JavaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public void newClass(
description = "source package",
type = PromptType.JAVA_PACKAGE,
name = "package") final String pckg,
@Option(name = "named",
required = false,
description = "The class name",
type = PromptType.JAVA_CLASS) final String className,
@Option(required = false,
help = "the class definition: surround with quotes",
description = "class definition") final String... def) throws FileNotFoundException
Expand All @@ -121,6 +125,10 @@ else if (in != null)
{
jc = JavaParser.parse(JavaClass.class, in);
}
else if (className != null)
{
jc = JavaParser.create(JavaClass.class).setName(className);
}
else
{
throw new RuntimeException("arguments required");
Expand Down Expand Up @@ -148,13 +156,18 @@ else if (in != null)
{
java.saveJavaSource(jc);
}
else
{
return;
}
}
pickUp.fire(new PickupResource(java.getJavaResource(jc)));
}

@Command("new-interface")
public void newInterface(
@PipeIn final InputStream in,
@Option(name = "named", required = false, description = "The interface name", type = PromptType.JAVA_CLASS) final String interfaceName,
@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
Expand All @@ -170,10 +183,15 @@ else if (in != null)
{
jc = JavaParser.parse(JavaInterface.class, in);
}
else if (interfaceName != null)
{
jc = JavaParser.create(JavaInterface.class).setName(interfaceName);
}
else
{
throw new RuntimeException("arguments required");
}

if (pckg != null)
{
jc.setPackage(pckg);
Expand All @@ -195,6 +213,10 @@ else if (in != null)
{
java.saveJavaSource(jc);
}
else
{
return;
}
}
pickUp.fire(new PickupResource(java.getJavaResource(jc)));
}
Expand All @@ -207,6 +229,11 @@ public void newEnumType(
description = "source package",
type = PromptType.JAVA_PACKAGE,
name = "package") final String pckg,
@Option(name = "named",
required = false,
description = "The enum name",
type = PromptType.JAVA_CLASS) final String enumName,

@Option(required = false,
help = "the class definition: surround with quotes",
description = "class definition") final String... def) throws FileNotFoundException
Expand All @@ -224,6 +251,10 @@ else if (in != null)
{
je = JavaParser.parse(JavaEnum.class, in);
}
else if (enumName != null)
{
je = JavaParser.create(JavaEnum.class).setName(enumName);
}
else
{
throw new RuntimeException("arguments required");
Expand Down Expand Up @@ -251,6 +282,10 @@ else if (in != null)
{
java.saveJavaSource(je);
}
else
{
return;
}
}

pickUp.fire(new PickupResource(java.getJavaResource(je)));
Expand All @@ -264,6 +299,10 @@ public void newAnnotationType(
description = "source package",
type = PromptType.JAVA_PACKAGE,
name = "package") final String pckg,
@Option(name = "named",
required = false,
description = "The annotation name",
type = PromptType.JAVA_CLASS) final String annotationName,
@Option(required = false,
help = "the @Retention policy for this annotation",
description = "retention policy",
Expand All @@ -273,9 +312,9 @@ public void newAnnotationType(
description = "documented",
name = "documented") final boolean documented,
@Option(required = false,
help = "whether to omit the @Target annotation (if omitted the user will be prompted for the target types)",
description = "omit @Target",
name = "no-target") final boolean noTarget,
help = "whether to omit the @Target annotation (if omitted the user will be prompted for the target types)",
description = "omit @Target",
name = "no-target") final boolean noTarget,
@Option(required = false,
help = "the annotation definition: surround with quotes",
description = "annotation definition") final String... def) throws FileNotFoundException
Expand All @@ -292,6 +331,10 @@ else if (in != null)
{
type = JavaParser.parse(JavaAnnotation.class, in);
}
else if (annotationName != null)
{
type = JavaParser.create(JavaAnnotation.class).setName(annotationName);
}
else
{
throw new RuntimeException("arguments required");
Expand Down Expand Up @@ -346,6 +389,10 @@ else if (in != null)
{
java.saveJavaSource(type);
}
else
{
return;
}
}

pickUp.fire(new PickupResource(java.getJavaResource(type)));
Expand Down Expand Up @@ -514,7 +561,8 @@ else if (Strings.isNullOrEmpty(name) || Strings.isNullOrEmpty(type))
String addName;
if (elementDef != null)
{
addName = JavaParser.parse(JavaAnnotation.class, "public @interface Temp{}").addAnnotationElement(elementDef).getName();
addName = JavaParser.parse(JavaAnnotation.class, "public @interface Temp{}")
.addAnnotationElement(elementDef).getName();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public void testCreateJavaClass() throws Exception
assertNotNull(javaClass);
}

@Test
public void testCreateJavaClassNamed() throws Exception
{
getShell().execute(
"java new-class --named TestingClassCreation --package org.jboss.forge.test.classes");
getShell().execute("build");
JavaClass javaClass = (JavaClass) getProject().getFacet(JavaSourceFacet.class)
.getJavaResource(Packages.toFileSyntax("org.jboss.forge.test.classes.TestingClassCreation"))
.getJavaSource();
assertNotNull(javaClass);
}

@Test
public void testCreateJavaInterface() throws Exception
{
Expand All @@ -72,6 +84,21 @@ public void testCreateJavaInterface() throws Exception
assertNotNull(javaInterface);
}

@Test
public void testCreateJavaInterfaceNamed() throws Exception
{
getShell()
.execute(
"java new-interface --named TestingInterfaceCreation --package org.jboss.forge.test.interfaces");
getShell().execute("build");
JavaInterface javaInterface = (JavaInterface) getProject()
.getFacet(JavaSourceFacet.class)
.getJavaResource(
Packages.toFileSyntax("org.jboss.forge.test.interfaces.TestingInterfaceCreation"))
.getJavaSource();
assertNotNull(javaInterface);
}

@Test
public void testCreateJavaMethodOnInterface() throws Exception
{
Expand Down Expand Up @@ -118,6 +145,19 @@ public void testCreateEnumType() throws Exception
assertNotNull(javaEnum);
}

@Test
public void testCreateEnumTypeNamed() throws Exception
{
getShell().execute(
"java new-enum-type --named TestingEnumTypeCreation --package org.jboss.forge.test.types");
getShell().execute("ls");
getShell().execute("build");
JavaEnum javaEnum = (JavaEnum) getProject().getFacet(JavaSourceFacet.class)
.getJavaResource(Packages.toFileSyntax("org.jboss.forge.test.types.TestingEnumTypeCreation"))
.getJavaSource();
assertNotNull(javaEnum);
}

@Test
public void testCreateEnumConst() throws Exception
{
Expand Down Expand Up @@ -258,7 +298,13 @@ public void testCreateAnnotationInRootFolder() throws Exception
queueInputLines("");
getShell()
.execute(
"java new-annotation-type \"public @interface TestingAnnotationTypeCreation {}\"");
"java new-annotation-type --named TestingAnnotationTypeCreation");
assertTrue(getProject()
.getFacet(JavaSourceFacet.class)
.getJavaResource(
Packages.toFileSyntax("TestingAnnotationTypeCreation"))
.exists());

}

@Test
Expand All @@ -267,8 +313,43 @@ public void testCreateEnumInRootFolder() throws Exception
queueInputLines("");
getShell()
.execute(
"java new-enum-type \"public enum TestingEnumTypeCreation {}\"");
"java new-enum-type --named TestingEnumTypeCreation");
assertTrue(getProject()
.getFacet(JavaSourceFacet.class)
.getJavaResource(
Packages.toFileSyntax("TestingEnumTypeCreation"))
.exists());
}

@Test
public void testCreateAnnotationWithoutBrackets() throws Exception
{
queueInputLines("", "N");
getShell()
.execute(
"java new-annotation-type \"public @interface TestingAnnotationTypeCreation\"");
assertFalse(getProject()
.getFacet(JavaSourceFacet.class)
.getJavaResource(
Packages.toFileSyntax("TestingAnnotationTypeCreation"))
.exists());

}

@Test
public void testCreateAnnotationNamed() throws Exception
{
queueInputLines("");
getShell()
.execute(
"java new-annotation-type --named TestingAnnotationTypeCreation --package org.jboss.forge.test.annotations");
getShell().execute("build");

assertNotNull(getProject()
.getFacet(JavaSourceFacet.class)
.getJavaResource(
Packages.toFileSyntax("org.jboss.forge.test.annotations.TestingAnnotationTypeCreation"))
.getJavaSource());
}

}

0 comments on commit fde4c5c

Please sign in to comment.