Skip to content

Commit

Permalink
Simplfied API; #74
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jan 20, 2020
1 parent ba75036 commit ccb5a0e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 56 deletions.
22 changes: 20 additions & 2 deletions src/main/java/com/helger/jcodemodel/JCodeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static boolean isFileSystemCaseSensitive ()
s_aPrimitiveToBox = Collections.unmodifiableMap (m2);
}

private IFileSystemConvention m_aFSConvention = EFileSystemConvention.DEFAULT;
private IFileSystemConvention m_aFSConvention;

/** The packages that this JCodeWriter contains. */
private final Map <String, JPackage> m_aPackages = new HashMap <> ();
Expand Down Expand Up @@ -205,8 +205,26 @@ public static boolean isFileSystemCaseSensitive ()

private final Set <AbstractJClass> m_aDontImportClasses = new HashSet <> ();

/**
* Default constructor using the system default file system convention.
*/
public JCodeModel ()
{}
{
this (EFileSystemConvention.DEFAULT);
}

/**
* Constructor with parameter
*
* @param aFSConvention
* The file system convention to be used. May not be <code>null</code>.
* @since v3.4.0
*/
public JCodeModel (@Nonnull final IFileSystemConvention aFSConvention)
{
JCValueEnforcer.notNull (aFSConvention, "FSConvention");
m_aFSConvention = aFSConvention;
}

/**
* @return The file system convention to be used. Never <code>null</code>.
Expand Down
38 changes: 19 additions & 19 deletions src/test/java/com/helger/jcodemodel/JResourceDirTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void testDirectVsSubDir () throws JCodeModelException
@Test
public void testCollisionFilenameFilenameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm.resourceDir ("my").addResourceFile (JTextFile.createFully ("File1", StandardCharsets.UTF_8, "bla"));
try
{
Expand All @@ -132,7 +132,7 @@ public void testCollisionFilenameFilenameLinux () throws JCodeModelException
@Test
public void testCollisionFilenameFilenameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm.resourceDir ("my").addResourceFile (JTextFile.createFully ("File1", StandardCharsets.UTF_8, "bla"));
try
{
Expand All @@ -159,7 +159,7 @@ public void testCollisionFilenameFilenameWindows () throws JCodeModelException
@Test
public void testCollisionFilenameDirNameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm.resourceDir ("my").addResourceFile (JTextFile.createFully ("name", StandardCharsets.UTF_8, "bla"));
try
{
Expand All @@ -178,7 +178,7 @@ public void testCollisionFilenameDirNameLinux () throws JCodeModelException
@Test
public void testCollisionFilenameDirNameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm.resourceDir ("my").addResourceFile (JTextFile.createFully ("name", StandardCharsets.UTF_8, "bla"));
try
{
Expand All @@ -205,7 +205,7 @@ public void testCollisionFilenameDirNameWindows () throws JCodeModelException
@Test
public void testCollisionFilenameClassNameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm.resourceDir ("my").addResourceFile (JTextFile.createFully ("Name.java", StandardCharsets.UTF_8, "bla"));
try
{
Expand All @@ -224,7 +224,7 @@ public void testCollisionFilenameClassNameLinux () throws JCodeModelException
@Test
public void testCollisionFilenameClassNameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm.resourceDir ("my").addResourceFile (JTextFile.createFully ("Name.java", StandardCharsets.UTF_8, "bla"));
try
{
Expand All @@ -251,7 +251,7 @@ public void testCollisionFilenameClassNameWindows () throws JCodeModelException
@Test
public void testCollisionClassNameFilenameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm._package ("my")._class (JMod.PUBLIC, "Name");
try
{
Expand All @@ -270,7 +270,7 @@ public void testCollisionClassNameFilenameLinux () throws JCodeModelException
@Test
public void testCollisionClassNameFilenameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm._package ("my")._class (JMod.PUBLIC, "Name");
try
{
Expand All @@ -297,7 +297,7 @@ public void testCollisionClassNameFilenameWindows () throws JCodeModelException
@Test
public void testCollisionClassNameDirNameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm._package ("my")._class (JMod.PUBLIC, "Name");
try
{
Expand All @@ -316,7 +316,7 @@ public void testCollisionClassNameDirNameLinux () throws JCodeModelException
@Test
public void testCollisionClassNameDirNameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm._package ("my")._class (JMod.PUBLIC, "Name");
try
{
Expand All @@ -343,7 +343,7 @@ public void testCollisionClassNameDirNameWindows () throws JCodeModelException
@Test
public void testCollisionDirNameFilenameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm.resourceDir ("my").subDir ("name");
try
{
Expand All @@ -362,7 +362,7 @@ public void testCollisionDirNameFilenameLinux () throws JCodeModelException
@Test
public void testCollisionDirNameFilenameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm.resourceDir ("my").subDir ("name");
try
{
Expand All @@ -389,7 +389,7 @@ public void testCollisionDirNameFilenameWindows () throws JCodeModelException
@Test
public void testCollisionDirNameClassNameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm.resourceDir ("my").subDir ("Name.java");
try
{
Expand All @@ -408,7 +408,7 @@ public void testCollisionDirNameClassNameLinux () throws JCodeModelException
@Test
public void testCollisionDirNameClassNameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm.resourceDir ("my").subDir ("Name.java");
try
{
Expand All @@ -435,7 +435,7 @@ public void testCollisionDirNameClassNameWindows () throws JCodeModelException
@Test
public void testNoCollisionDotInDir () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
final JResourceDir rd = cm.resourceDir ("my").subDir ("dir.has.Dots.java");
assertNotNull (rd);
assertEquals ("my/dir.has.Dots.java", rd.name ());
Expand All @@ -449,7 +449,7 @@ public void testNoCollisionDotInDir () throws JCodeModelException
@Test
public void testCollisionIntermediateDirNameFilenameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm.resourceDir ("a/b/c");
try
{
Expand All @@ -468,7 +468,7 @@ public void testCollisionIntermediateDirNameFilenameLinux () throws JCodeModelEx
@Test
public void testCollisionIntermediateDirNameFilenameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm.resourceDir ("a/b/c");
try
{
Expand All @@ -495,7 +495,7 @@ public void testCollisionIntermediateDirNameFilenameWindows () throws JCodeModel
@Test
public void testCollisionIntermediateDirNameClassNameLinux () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.LINUX);
cm.resourceDir ("a/B.java/c");
try
{
Expand All @@ -514,7 +514,7 @@ public void testCollisionIntermediateDirNameClassNameLinux () throws JCodeModelE
@Test
public void testCollisionIntermediateDirNameClassNameWindows () throws JCodeModelException
{
final JCodeModel cm = new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
final JCodeModel cm = new JCodeModel (EFileSystemConvention.WINDOWS);
cm.resourceDir ("a/B.java/c");
try
{
Expand Down
35 changes: 0 additions & 35 deletions src/test/java/com/helger/jcodemodel/util/CodeModelTestsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import com.helger.jcodemodel.IJGenerable;
import com.helger.jcodemodel.IJStatement;
import com.helger.jcodemodel.JCodeModel;
import com.helger.jcodemodel.JCodeModelException;
import com.helger.jcodemodel.SourcePrintWriter;
import com.helger.jcodemodel.writer.AbstractCodeWriter;
import com.helger.jcodemodel.writer.JCMWriter;
Expand Down Expand Up @@ -353,38 +352,4 @@ public static void printCodeModel (@Nonnull final JCodeModel cm)
throw new UncheckedIOException (ex);
}
}

/**
* @return A new {@link JCodeModel} configured for Linux. Never
* <code>null</code>.
*/
@Nonnull
public static JCodeModel linuxCM ()
{
try
{
return new JCodeModel ().setFileSystemConvention (EFileSystemConvention.LINUX);
}
catch (final JCodeModelException ex)
{
throw new UnsupportedOperationException (ex);
}
}

/**
* @return A new {@link JCodeModel} configured for Linux. Never
* <code>null</code>.
*/
@Nonnull
public static JCodeModel windowsCM ()
{
try
{
return new JCodeModel ().setFileSystemConvention (EFileSystemConvention.WINDOWS);
}
catch (final JCodeModelException ex)
{
throw new UnsupportedOperationException (ex);
}
}
}

0 comments on commit ccb5a0e

Please sign in to comment.