Hi,
I have done a patch, which move sourcecode entries from AbstractJClass to JInterface, with it Modello "modello-plugin-java" work with Castor (because in modello we can add sourcecode to the interface too). The unit tests still works for Castor codegen component, and the unit test named org.codehaus.modello.plugin.java.javasource.JavaSourceTest in Modello succeed. More details regarding Modello are or will be on MODELLO-148 .
The patch is here because i cannot attach a file nor reopen this issue (it also fix CASTOR-2769 sorry for the mess
, i attach it as a file to 2769 if it's more easy for you ):
Index: src/main/java/org/exolab/javasource/AbstractJClass.java
===================================================================
— src/main/java/org/exolab/javasource/AbstractJClass.java (revision 8289)
+++ src/main/java/org/exolab/javasource/AbstractJClass.java (working copy)
@@ -49,17 +49,7 @@
/** A collection of inner classes for this JClass. */
private Vector<JClass> _innerClasses;
- private Vector<String> _sourceCodeEntries = new Vector<String>();
-
/**
- * Returns a collection of (complete) source code fragments.
- * @return A collection of (complete) source code fragments.
- */
- public String[] getSourceCodeEntries() {
- return _sourceCodeEntries.toArray(new String[_sourceCodeEntries.size()]);
- }
-
- /**
- Creates a new AbstractJClass with the given name.
*
- @param name The name of the AbstractJClass to create.
@@ -731,21 +721,6 @@
jsw.writeln();
}
}
- protected final void printSourceCodeFragments(final JSourceWriter sourceWriter) {
- if (!_sourceCodeEntries.isEmpty()) {
- sourceWriter.writeln();
- sourceWriter.writeln(" //----------------------------------/");
- sourceWriter.writeln(" //- Injected source code fragments -/");
- sourceWriter.writeln("//----------------------------------/");
- sourceWriter.writeln();
- }
- for (String sourceCode : _sourceCodeEntries) {
- sourceWriter.writeln(sourceCode);
- sourceWriter.writeln();
- }
- }
/**
- Writes to the JSourceWriter all inner classes belonging to this class.
@@ -767,17 +742,5 @@
}
}
}
-
- /**
- * Adds a complete source code fragment (method) to this class.
- * @param sourceCode The complete source code fragment to be added.
- */
- public void addSourceCode(final String sourceCode) {
- _sourceCodeEntries.add(sourceCode);
- }
-
- public final int getSourceCodeEntryCount() {
- return _sourceCodeEntries.size();
- }
}
Index: src/main/java/org/exolab/javasource/JInterface.java
===================================================================
— src/main/java/org/exolab/javasource/JInterface.java (revision 8289)
+++ src/main/java/org/exolab/javasource/JInterface.java (working copy)
@@ -83,7 +83,7 @@
public JInterface(final String name) {
super(name);
- _fields = null;
+ //_fields = null;
_methods = new Vector<JMethodSignature>();
//-- initialize default Java doc
Index: src/main/java/org/exolab/javasource/JStructure.java
===================================================================
--- src/main/java/org/exolab/javasource/JStructure.java (revision 8289)
+++ src/main/java/org/exolab/javasource/JStructure.java (working copy)
@@ -76,6 +76,8 @@
/** A standard complaint for a bad parameter. */
private static final String JSW_SHOULD_NOT_BE_NULL = "argument 'jsw' should not be null.";
+ private Vector<String> _sourceCodeEntries = new Vector<String>();
+
//--------------------------------------------------------------------------
/** The source header. */
@@ -591,5 +593,39 @@
return getName();
}
+ /**
+ * Returns a collection of (complete) source code fragments.
+ * @return A collection of (complete) source code fragments.
+ */
+ public String[] getSourceCodeEntries() {
+ return _sourceCodeEntries.toArray(new String[_sourceCodeEntries.size()]);
+ }
+
+ protected final void printSourceCodeFragments(final JSourceWriter sourceWriter) {
+ if (!_sourceCodeEntries.isEmpty()) {
+ sourceWriter.writeln();
+ sourceWriter.writeln(" //----------------------------------/");
+ sourceWriter.writeln(" //- Injected source code fragments -/");
+ sourceWriter.writeln("//----------------------------------/");
+ sourceWriter.writeln();
+ }
+ for (String sourceCode : _sourceCodeEntries) {
+ sourceWriter.writeln(sourceCode);
+ sourceWriter.writeln();
+ }
+
+ }
+
+ /**
+ * Adds a complete source code fragment (method) to this class.
+ * @param sourceCode The complete source code fragment to be added.
+ */
+ public void addSourceCode(final String sourceCode) {
+ _sourceCodeEntries.add(sourceCode);
+ }
+
+ public final int getSourceCodeEntryCount() {
+ return _sourceCodeEntries.size();
+ }
//--------------------------------------------------------------------------
}
I don't see a reason why this should not be added. But let le ask you one question: if we add such a method to AbstractJClass, where in the generated source code should this arbitrary code fragment be added/inserted ? What does this method look like in your fork ?
PS Is this actually ''the'' fork many folks have mentioned to me over the past three years in terms of 'Maven forked Castor ...." ?