Skip to content
Commits on Source (2)
language: java
jdk:
- oraclejdk7
- oraclejdk8
- openjdk6
- openjdk7
- openjdk9
- openjdk10
- openjdk11
# No need for preliminary install step.
install: true
......
......@@ -3,7 +3,7 @@
<parent>
<artifactId>modello</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.1</version>
<version>1.11</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -65,6 +65,11 @@ public class ModelloParameterConstants
*/
public static final String DOM_AS_XPP3 = "modello.dom.xpp3";
/**
* @since 1.10
*/
public static final String EXTENDED_CLASSNAME_SUFFIX = "modello.xpp3.extended.suffix";
private ModelloParameterConstants()
{
}
......
......@@ -180,7 +180,7 @@ public abstract class AbstractModelloGenerator
return str;
}
return new StringBuffer( str.length() )
return new StringBuilder( str.length() )
.append( Character.toTitleCase( str.charAt( 0 ) ) )
.append( str.substring( 1 ) )
.toString();
......@@ -220,7 +220,7 @@ public abstract class AbstractModelloGenerator
return str;
}
return new StringBuffer( str.length() )
return new StringBuilder( str.length() )
.append( Character.toLowerCase( str.charAt( 0 ) ) )
.append( str.substring( 1 ) )
.toString();
......
......@@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.1</version>
<version>1.11</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -493,7 +493,7 @@
<code>
public String getId()
{
StringBuffer id = new StringBuffer();
StringBuilder id = new StringBuilder();
id.append( getGroupId() );
id.append( ":" );
......
......@@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.1</version>
<version>1.11</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -491,7 +491,7 @@
<code>
public String getId()
{
StringBuffer id = new StringBuffer();
StringBuilder id = new StringBuilder();
id.append( getGroupId() );
id.append( ":" );
......
......@@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.1</version>
<version>1.11</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -36,7 +36,7 @@
</subsection>
<subsection name="jackson-writer">
<p><code>stax-writer</code> generator creates
<p><code>jackson-writer</code> generator creates
<code><i>my.model.package</i><b>.io.jackson.</b><i>ModelName</i><b>JacksonWriter</b></code> class with following
public methods:
</p>
......@@ -49,6 +49,14 @@
</ul>
</subsection>
<subsection name="jackson-extended-reader">
<p><code>jackson-extended-reader</code> generator creates
<code><i>my.model.package</i><b>.io.jackson.</b><i>ModelName</i><b>JacksonReaderEx</b></code> class with same public methods
as <code>jackson-reader</code>, but with <a href="../../location-tracking.html">location tracking enabled</a>.</p>
<p>If source tracking is enabled in addition to location tracking, the public methods have an extra parameter which
is the source tracker instance.</p>
</subsection>
</section>
</body>
......
......@@ -515,7 +515,7 @@
<code>
public String getId()
{
StringBuffer id = new StringBuffer();
StringBuilder id = new StringBuilder();
id.append( getGroupId() );
id.append( ":" );
......
......@@ -3,7 +3,7 @@
<parent>
<artifactId>modello-plugins</artifactId>
<groupId>org.codehaus.modello</groupId>
<version>1.9.1</version>
<version>1.11</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -158,7 +158,7 @@ public abstract class AbstractJavaModelloGenerator
}
}
private void addModelImport( JClass jClass, ModelType modelType, String basePackageName )
protected void addModelImport( JClass jClass, ModelType modelType, String basePackageName )
{
String packageName = modelType.getPackageName( isPackageWithVersion(), getGeneratedVersion() );
......
......@@ -428,7 +428,7 @@ public class JavaModelloGenerator
}
else
{
sc.add( "StringBuffer buf = new StringBuffer( 128 );" );
sc.add( "StringBuilder buf = new StringBuilder( 128 );" );
}
sc.add( "" );
......@@ -812,14 +812,11 @@ public class JavaModelloGenerator
}
String superClass = modelClass.getSuperClass();
if ( StringUtils.isNotEmpty( superClass ) && isClassInModel( superClass, getModel() ) )
{
return;
}
ModelClassMetadata metadata = (ModelClassMetadata) locationClass.getMetadata( ModelClassMetadata.ID );
String locationField = metadata.getLocationTracker();
boolean hasModeSuperClass = StringUtils.isNotEmpty(superClass) && isClassInModel(superClass, getModel());
if (!hasModeSuperClass)
{
String fieldType = "java.util.Map" + ( useJava5 ? "<Object, " + locationClass.getName() + ">" : "" );
String fieldImpl = "java.util.LinkedHashMap" + ( useJava5 ? "<Object, " + locationClass.getName() + ">" : "" );
......@@ -827,35 +824,164 @@ public class JavaModelloGenerator
JField jField = new JField( new JType( fieldType ), locationField );
jClass.addField( jField );
JMethod jMethod;
JSourceCode sc;
// public Location getOtherLocation( Object key )
JMethod getter =
new JMethod( "getOther" + capitalise( singular( locationField ) ), new JType( locationClass.getName() ), null );
getter.addParameter( new JParameter( new JType( "Object" ), "key" ) );
getter.getModifiers().makePrivate();
JSourceCode getterSc = getter.getSourceCode();
getterSc.add( "return ( " + locationField + " != null ) ? " + locationField + ".get( key ) : null;" );
getter.setComment( "" );
jClass.addMethod( getter );
// public void setOtherLocation( Object key, Location location )
JMethod setter = new JMethod( "setOther" + capitalise( singular( locationField ) ) );
setter.addParameter( new JParameter( new JType( "Object" ), "key" ) );
setter.addParameter( new JParameter( new JType( locationClass.getName() ), singular( locationField ) ) );
JSourceCode setterSc = setter.getSourceCode();
setterSc.add( "if ( " + singular( locationField ) + " != null )" );
setterSc.add( "{" );
setterSc.indent();
setterSc.add( "if ( this." + locationField + " == null )" );
setterSc.add( "{" );
setterSc.addIndented( "this." + locationField + " = new " + fieldImpl + "();" );
setterSc.add( "}" );
setterSc.add( "this." + locationField + ".put( key, " + singular( locationField ) + " );" );
setterSc.unindent();
setterSc.add( "}" );
setter.setComment( "" );
jClass.addMethod( setter );
}
JField ownLocation = new JField( new JType( locationClass.getName() ), singular( locationField ) );
jClass.addField( ownLocation );
for (ModelField field : modelClass.getAllFields())
{
JField fieldLocation = new JField( new JType( locationClass.getName() ), field.getName() + capitalise( singular( locationField ) ) );
jClass.addField( fieldLocation );
}
// public Location getLocation( Object key )
jMethod =
JMethod getter =
new JMethod( "get" + capitalise( singular( locationField ) ), new JType( locationClass.getName() ), null );
jMethod.addParameter( new JParameter( new JType( "Object" ), "key" ) );
sc = jMethod.getSourceCode();
sc.add( "return ( " + locationField + " != null ) ? " + locationField + ".get( key ) : null;" );
jMethod.setComment( "" );
jClass.addMethod( jMethod );
getter.addParameter( new JParameter( new JType( "Object" ), "key" ) );
JSourceCode getterSc = getter.getSourceCode();
getterSc.add( "if ( key instanceof String )" );
getterSc.add( "{" );
getterSc.indent();
getterSc.add( "switch ( ( String ) key )" );
getterSc.add( "{" );
getterSc.indent();
getterSc.add( "case \"\" :" );
getterSc.add( "{" );
getterSc.indent();
getterSc.add( "return this." + singular( locationField ) + ";" );
getterSc.unindent();
getterSc.add( "}" );
for (ModelField field : modelClass.getAllFields())
{
getterSc.add( "case \"" + field.getName() + "\" :" );
getterSc.add( "{" );
getterSc.indent();
getterSc.add( "return " + field.getName() + capitalise( singular( locationField ) ) + ";" );
getterSc.unindent();
getterSc.add( "}" );
}
getterSc.add( "default :" );
getterSc.add( "{" );
getterSc.indent();
if (hasModeSuperClass)
{
getterSc.add( "return super.get" + capitalise( singular( locationField ) ) + "( key );" );
}
else
{
getterSc.add( "return getOther" + capitalise( singular( locationField ) ) + "( key );" );
}
getterSc.unindent();
getterSc.add( "}" );
getterSc.add( "}" );
getterSc.unindent();
getterSc.add( "}" );
getterSc.add( "else" );
getterSc.add( "{" );
getterSc.indent();
if (hasModeSuperClass)
{
getterSc.add( "return super.get" + capitalise( singular( locationField ) ) + "( key );" );
}
else
{
getterSc.add( "return getOther" + capitalise( singular( locationField ) ) + "( key );" );
}
getterSc.unindent();
getterSc.add( "}" );
getter.setComment( "" );
jClass.addMethod( getter );
// public void setLocation( Object key, Location location )
jMethod = new JMethod( "set" + capitalise( singular( locationField ) ) );
jMethod.addParameter( new JParameter( new JType( "Object" ), "key" ) );
jMethod.addParameter( new JParameter( new JType( locationClass.getName() ), singular( locationField ) ) );
sc = jMethod.getSourceCode();
sc.add( "if ( " + singular( locationField ) + " != null )" );
sc.add( "{" );
sc.indent();
sc.add( "if ( this." + locationField + " == null )" );
sc.add( "{" );
sc.addIndented( "this." + locationField + " = new " + fieldImpl + "();" );
sc.add( "}" );
sc.add( "this." + locationField + ".put( key, " + singular( locationField ) + " );" );
sc.unindent();
sc.add( "}" );
jMethod.setComment( "" );
jClass.addMethod( jMethod );
JMethod setter = new JMethod( "set" + capitalise( singular( locationField ) ) );
setter.addParameter( new JParameter( new JType( "Object" ), "key" ) );
setter.addParameter( new JParameter( new JType( locationClass.getName() ), singular( locationField ) ) );
JSourceCode setterSc = setter.getSourceCode();
setterSc.add( "if ( key instanceof String )" );
setterSc.add( "{" );
setterSc.indent();
setterSc.add( "switch ( ( String ) key )" );
setterSc.add( "{" );
setterSc.indent();
setterSc.add( "case \"\" :" );
setterSc.add( "{" );
setterSc.indent();
setterSc.add( "this." + singular( locationField ) + " = " + singular(locationField) + ";" );
setterSc.add("return;");
setterSc.unindent();
setterSc.add( "}" );
for (ModelField field : modelClass.getAllFields())
{
setterSc.add( "case \"" + field.getName()+ "\" :" );
setterSc.add( "{" );
setterSc.indent();
setterSc.add( field.getName() + capitalise( singular( locationField ) ) + " = " + singular(locationField) + ";" );
setterSc.add("return;");
setterSc.unindent();
setterSc.add( "}" );
}
setterSc.add( "default :" );
setterSc.add( "{" );
setterSc.indent();
if (hasModeSuperClass)
{
setterSc.add( "super.set" + capitalise( singular( locationField ) ) + "( key, " + singular(locationField) + " );" );
}
else
{
setterSc.add( "setOther" + capitalise( singular( locationField ) ) + "( key, " + singular(locationField) + " );" );
}
setterSc.add("return;");
setterSc.unindent();
setterSc.add( "}" );
setterSc.add( "}" );
setterSc.unindent();
setterSc.add( "}" );
setterSc.add( "else" );
setterSc.add( "{" );
setterSc.indent();
if (hasModeSuperClass)
{
setterSc.add( "super.set" + capitalise( singular( locationField ) ) + "( key, " + singular(locationField) + " );" );
}
else
{
setterSc.add( "setOther" + capitalise( singular( locationField ) ) + "( key, " + singular(locationField) + " );" );
}
setterSc.unindent();
setterSc.add( "}" );
setter.setComment( "" );
jClass.addMethod( setter );
}
private void generateLocationBean( JClass jClass, ModelClass locationClass, ModelClass sourceClass )
......@@ -1044,6 +1170,15 @@ public class JavaModelloGenerator
sc.add( "" );
sc.add( "return result;" );
jClass.addMethod( jMethod );
JClass stringFormatterClass = jClass.createInnerClass( "StringFormatter" );
stringFormatterClass.getModifiers().setStatic( true );
stringFormatterClass.getModifiers().setAbstract( true );
jMethod = new JMethod( "toString", new JType( "String" ), null );
jMethod.getModifiers().setAbstract( true );
jMethod.addParameter( new JParameter( new JType( locationClass.getName() ), "location" ) );
stringFormatterClass.addMethod( jMethod );
}
/**
......@@ -1246,7 +1381,7 @@ public class JavaModelloGenerator
JMethod getter = new JMethod( prefix + propertyName, returnType, null );
StringBuffer comment = new StringBuffer( "Get " );
StringBuilder comment = new StringBuilder( "Get " );
if ( StringUtils.isEmpty( modelField.getDescription() ) )
{
comment.append( "the " );
......@@ -1286,7 +1421,7 @@ public class JavaModelloGenerator
setter = new JMethod( "set" + propertyName );
}
StringBuffer comment = new StringBuffer( "Set " );
StringBuilder comment = new StringBuilder( "Set " );
if ( StringUtils.isEmpty( modelField.getDescription() ) )
{
comment.append( "the " );
......
......@@ -76,8 +76,9 @@ package org.codehaus.modello.plugin.java.javasource;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Vector;
import java.util.Map;
/**
* A representation of the Java Source code for a Java Class. This is
......@@ -96,21 +97,21 @@ public class JClass extends JStructure
/**
* The list of constructors for this JClass
*/
private Vector<JConstructor> _constructors = null;
private List<JConstructor> _constructors = null;
/**
* The list of member variables (fields) of this JClass
*/
private JNamedMap _fields = null;
private Map<String, JField> _fields = null;
private Vector<JClass> _innerClasses = null;
private List<JClass> _innerClasses = null;
/**
* The list of methods of this JClass
*/
private Vector<JMethod> _methods = null;
private List<JMethod> _methods = null;
/**
* The superclass for this JClass
......@@ -133,10 +134,10 @@ public class JClass extends JStructure
throws IllegalArgumentException
{
super( name );
_constructors = new Vector<JConstructor>();
_fields = new JNamedMap();
_methods = new Vector<JMethod>();
_innerClasses = new Vector<JClass>();
_constructors = new ArrayList<JConstructor>();
_fields = new LinkedHashMap<>();
_methods = new ArrayList<JMethod>();
_innerClasses = new ArrayList<JClass>();
//-- initialize default Java doc
getJDocComment().appendComment( "Class " + getLocalName() + "." );
......@@ -163,7 +164,7 @@ public class JClass extends JStructure
/** check signatures (add later) **/
if ( !_constructors.contains( constructor ) )
{
_constructors.addElement( constructor );
_constructors.add( constructor );
}
}
else
......@@ -276,13 +277,13 @@ public class JClass extends JStructure
for ( int i = 0; i < _methods.size(); i++ )
{
JMethod tmp = (JMethod) _methods.elementAt( i );
JMethod tmp = (JMethod) _methods.get( i );
//-- first compare modifiers
if ( tmp.getModifiers().isPrivate() )
{
if ( !modifiers.isPrivate() )
{
_methods.insertElementAt( jMethod, i );
_methods.add( i, jMethod );
added = true;
break;
}
......@@ -290,13 +291,13 @@ public class JClass extends JStructure
//-- compare names
if ( jMethod.getName().compareTo( tmp.getName() ) < 0 )
{
_methods.insertElementAt( jMethod, i );
_methods.add( i, jMethod );
added = true;
break;
}
}
//-- END SORT
if ( !added ) _methods.addElement( jMethod );
if ( !added ) _methods.add( jMethod );
} //-- addMethod
......@@ -378,7 +379,7 @@ public class JClass extends JStructure
}
JClass innerClass = new JInnerClass( classname );
_innerClasses.addElement( innerClass );
_innerClasses.add( innerClass );
return innerClass;
} //-- createInnerClass
......@@ -391,7 +392,7 @@ public class JClass extends JStructure
*/
public JConstructor getConstructor( int index )
{
return (JConstructor) _constructors.elementAt( index );
return (JConstructor) _constructors.get( index );
} //-- getConstructor
/**
......@@ -407,7 +408,7 @@ public class JClass extends JStructure
for ( int i = 0; i < _constructors.size(); i++ )
{
jcArray[i] = (JConstructor) _constructors.elementAt( i );
jcArray[i] = _constructors.get( i );
}
return jcArray;
} //-- getConstructors
......@@ -431,13 +432,7 @@ public class JClass extends JStructure
**/
public JField[] getFields()
{
int size = _fields.size();
JField[] farray = new JField[size];
for ( int i = 0; i < size; i++ )
{
farray[i] = (JField) _fields.get( i );
}
return farray;
return _fields.values().toArray( new JField[0] );
} //-- getFields
/**
......@@ -448,10 +443,7 @@ public class JClass extends JStructure
*/
public JClass[] getInnerClasses()
{
int size = _innerClasses.size();
JClass[] carray = new JClass[size];
_innerClasses.copyInto( carray );
return carray;
return _innerClasses.toArray( new JClass[0] );
} //-- getInnerClasses;
/**
......@@ -466,7 +458,7 @@ public class JClass extends JStructure
for ( int i = 0; i < _methods.size(); i++ )
{
marray[i] = (JMethod) _methods.elementAt( i );
marray[i] = _methods.get( i );
}
return marray;
} //-- getMethods
......@@ -483,7 +475,7 @@ public class JClass extends JStructure
{
for ( int i = startIndex; i < _methods.size(); i++ )
{
JMethod jMethod = (JMethod) _methods.elementAt( i );
JMethod jMethod = _methods.get( i );
if ( jMethod.getName().equals( name ) ) return jMethod;
}
return null;
......@@ -497,7 +489,7 @@ public class JClass extends JStructure
*/
public JMethod getMethod( int index )
{
return (JMethod) _methods.elementAt( index );
return _methods.get( index );
} //-- getMethod
......@@ -556,13 +548,12 @@ public class JClass extends JStructure
printPackageDeclaration( jsw );
//-- get imports from inner-classes
Vector<String> removeImports = null;
List<String> removeImports = null;
if ( _innerClasses.size() > 0 )
{
removeImports = new Vector<String>();
for ( int i = 0; i < _innerClasses.size(); i++ )
removeImports = new ArrayList<String>();
for ( JClass iClass : _innerClasses )
{
JClass iClass = (JClass) _innerClasses.elementAt( i );
Enumeration<String> e = iClass.getImports();
while ( e.hasMoreElements() )
{
......@@ -570,7 +561,7 @@ public class JClass extends JStructure
if ( !hasImport( classname ) )
{
addImport( classname );
removeImports.addElement( classname );
removeImports.add( classname );
}
}
}
......@@ -582,7 +573,7 @@ public class JClass extends JStructure
{
for ( int i = 0; i < removeImports.size(); i++ )
{
removeImport( (String) removeImports.elementAt( i ) );
removeImport( removeImports.get( i ) );
}
}
......@@ -673,11 +664,8 @@ public class JClass extends JStructure
jsw.writeln();
}
for ( int i = 0; i < _fields.size(); i++ )
for ( JField jField : _fields.values() )
{
JField jField = (JField) _fields.get( i );
//-- print Java comment
JDocComment comment = jField.getComment();
if ( comment != null ) comment.print( jsw );
......@@ -736,7 +724,7 @@ public class JClass extends JStructure
}
for ( int i = 0; i < _constructors.size(); i++ )
{
JConstructor jConstructor = (JConstructor) _constructors.elementAt( i );
JConstructor jConstructor = _constructors.get( i );
jConstructor.print( jsw );
jsw.writeln();
}
......@@ -753,7 +741,7 @@ public class JClass extends JStructure
for ( int i = 0; i < _methods.size(); i++ )
{
JMethod jMethod = (JMethod) _methods.elementAt( i );
JMethod jMethod = _methods.get( i );
jMethod.print( jsw );
jsw.writeln();
}
......@@ -769,7 +757,7 @@ public class JClass extends JStructure
}
for ( int i = 0; i < _innerClasses.size(); i++ )
{
JClass jClass = (JClass) _innerClasses.elementAt( i );
JClass jClass = _innerClasses.get( i );
jClass.print( jsw, true );
jsw.writeln();
}
......@@ -800,7 +788,7 @@ public class JClass extends JStructure
*/
public boolean removeConstructor( JConstructor constructor )
{
return _constructors.removeElement( constructor );
return _constructors.remove( constructor );
} //-- removeConstructor
/**
......@@ -850,7 +838,7 @@ public class JClass extends JStructure
*/
public boolean removeInnerClass( JClass jClass )
{
return _innerClasses.removeElement( jClass );
return _innerClasses.remove( jClass );
} //-- removeInnerClass
/**
......@@ -862,58 +850,6 @@ public class JClass extends JStructure
_superClass = superClass;
} //-- setSuperClass
/**
* Test drive method...to be removed or commented out
**/
/*public static void main( String[] args )
{
JClass testClass = new JClass( "org.acme.Test" );
testClass.addImport( "java.util.Vector" );
testClass.addMember( new JField( JType.INT, "x" ) );
JClass jcString = new JClass( "String" );
JField field = null;
field = new JField( JType.INT, "_z" );
field.getModifiers().setStatic( true );
testClass.addField( field );
testClass.getStaticInitializationCode().add( "_z = 75;" );
field = new JField( jcString, "myString" );
field.getModifiers().makePrivate();
testClass.addMember( field );
//-- create constructor
JConstructor cons = testClass.createConstructor();
cons.getSourceCode().add( "this.x = 6;" );
JMethod jMethod = new JMethod( "getX", JType.INT, null );
jMethod.setSourceCode( "return this.x;" );
testClass.addMethod( jMethod );
//-- create inner-class
JClass innerClass = testClass.createInnerClass( "Foo" );
innerClass.addImport( "java.util.Hashtable" );
innerClass.addMember( new JField( JType.INT, "_type" ) );
field = new JField( jcString, "_name" );
field.getModifiers().makePrivate();
innerClass.addMember( field );
//-- create constructor
cons = innerClass.createConstructor();
cons.getSourceCode().add( "_name = \"foo\";" );
jMethod = new JMethod( "getName", jcString, null );
jMethod.setSourceCode( "return _name;" );
innerClass.addMethod( jMethod );
testClass.print();
} //-- main
*/
final class JInnerClass extends JClass
{
......
......@@ -124,7 +124,7 @@ public class JComment
/**
* The main comment for this JDocComment
**/
private StringBuffer _comment = null;
private StringBuilder _comment = null;
/**
* The maximum number of characters per line
......@@ -138,7 +138,7 @@ public class JComment
public JComment()
{
super();
_comment = new StringBuffer();
_comment = new StringBuilder();
} //-- JComment
/**
......@@ -279,7 +279,7 @@ class LineFormatter
String prefix = null;
private StringBuffer sb = null;
private StringBuilder sb = null;
/**
* Creates a LineFormatter for the given comment
......@@ -289,7 +289,7 @@ class LineFormatter
{
this.comment = comment;
if ( comment != null ) this.length = comment.length();
sb = new StringBuffer();
sb = new StringBuilder();
} //-- LineFormatter
......
......@@ -76,10 +76,11 @@ package org.codehaus.modello.plugin.java.javasource;
*/
import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Vector;
import org.codehaus.plexus.util.WriterFactory;
......@@ -119,13 +120,13 @@ public class JCompUnit
* The set of top-level classes that live in this compilation unit.
**/
//private TypeList classes = null;
private Vector<JClass> classes = null;
private List<JClass> classes = null;
/**
* The set of top-level interfaces that live in this compilation unit.
**/
//private TypeList interfaces = null;
private Vector<JInterface> interfaces = null;
private List<JInterface> interfaces = null;
/**
* Creates a new JCompUnit
......@@ -193,8 +194,8 @@ public class JCompUnit
private void init()
{
classes = new Vector<JClass>();
interfaces = new Vector<JInterface>();
classes = new ArrayList<JClass>();
interfaces = new ArrayList<JInterface>();
}
/**
......@@ -538,44 +539,6 @@ public class JCompUnit
*/
} //-- resolveNames
/**
* Test drive method...to be removed or commented out
**
public static void main(String[] args) {
JCompUnit unit = new JCompUnit("com.acme", "Test.java");
JClass testClass = new JClass("Test");
testClass.addImport("java.util.Vector");
testClass.addMember(new JField(JType.Int, "x"));
JField field = null;
field = new JField(JType.Int, "_z");
field.getModifiers().setStatic(true);
testClass.addField(field);
testClass.getStaticInitializationCode().add("_z = 75;");
JClass jcString = new JClass("String");
field = new JField(jcString, "myString");
field.getModifiers().makePrivate();
testClass.addMember(field);
//-- create constructor
JConstructor cons = testClass.createConstructor();
testClass.addConstructor(cons);
cons.getSourceCode().add("this.x = 6;");
JMethod jMethod = new JMethod(JType.Int, "getX");
jMethod.setSourceCode("return this.x;");
testClass.addMethod(jMethod);
unit.addClass (testClass);
unit.print();
} //-- main
/* */
} //-- JCompUnit
......
......@@ -45,6 +45,11 @@
package org.codehaus.modello.plugin.java.javasource;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
/*
* Copyright (c) 2004, Codehaus.org
*
......@@ -83,7 +88,7 @@ public class JConstructor
/**
* List of parameters for this Constructor
**/
private JNamedMap params = null;
private Map<String, JParameter> params = null;
/**
* The Class in this JMember has been declared
......@@ -104,7 +109,7 @@ public class JConstructor
{
this.declaringClass = declaringClass;
this.modifiers = new JModifiers();
this.params = new JNamedMap();
this.params = new LinkedHashMap<>();
this.sourceCode = new JSourceCode();
}
......@@ -122,7 +127,7 @@ public class JConstructor
//-- check current params
if ( params.get( parameter.getName() ) != null )
{
StringBuffer err = new StringBuffer();
StringBuilder err = new StringBuilder();
err.append( "A parameter already exists for the constructor, " );
err.append( this.declaringClass.getName() );
err.append( ", with the name: " );
......@@ -160,13 +165,7 @@ public class JConstructor
**/
public JParameter[] getParameters()
{
JParameter[] jpArray = new JParameter[params.size()];
for ( int i = 0; i < jpArray.length; i++ )
{
jpArray[i] = (JParameter) params.get( i );
}
return jpArray;
return params.values().toArray( new JParameter[0] );
} //-- getParameters
public JSourceCode getSourceCode()
......@@ -190,10 +189,20 @@ public class JConstructor
jsw.write( '(' );
//-- print parameters
if ( !params.isEmpty() )
{
Enumeration<JParameter> paramEnum = Collections.enumeration( params.values() );
jsw.write( paramEnum.nextElement() );
while( paramEnum.hasMoreElements())
{
jsw.write( ", " );
jsw.write( paramEnum.nextElement() );
}
}
for ( int i = 0; i < params.size(); i++ )
{
if ( i > 0 ) jsw.write( ", " );
jsw.write( params.get( i ) );
}
jsw.writeln( ')' );
jsw.writeln( '{' );
......@@ -223,16 +232,20 @@ public class JConstructor
public String toString()
{
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append( declaringClass.getName() );
sb.append( '(' );
//-- print parameters
for ( int i = 0; i < params.size(); i++ )
if ( !params.isEmpty() )
{
Enumeration<JParameter> paramEnum = Collections.enumeration( params.values() );
sb.append( paramEnum.nextElement().getType().getName() );
while( paramEnum.hasMoreElements())
{
JParameter jp = (JParameter) params.get( i );
if ( i > 0 ) sb.append( ", " );
sb.append( jp.getType().getName() );
sb.append( ", " );
sb.append( paramEnum.nextElement().getType().getName() );
}
}
sb.append( ')' );
return sb.toString();
......
......@@ -46,6 +46,9 @@
package org.codehaus.modello.plugin.java.javasource;
import java.util.ArrayList;
import java.util.Collections;
/*
* Copyright (c) 2004, Codehaus.org
*
......@@ -69,7 +72,7 @@ package org.codehaus.modello.plugin.java.javasource;
*/
import java.util.Enumeration;
import java.util.Vector;
import java.util.List;
/**
* A class that "SOMEWHAT" represents a Java Doc Comment.
......@@ -84,12 +87,12 @@ public class JDocComment
/**
* An ordered list of descriptors
*/
private Vector<JDocDescriptor> _descriptors = null;
private List<JDocDescriptor> _descriptors = null;
/**
* The internal buffer for this JDocComment
*/
private StringBuffer _comment = null;
private StringBuilder _comment = null;
/**
* Creates a new JavaDoc Comment
......@@ -97,8 +100,8 @@ public class JDocComment
public JDocComment()
{
super();
_descriptors = new Vector<JDocDescriptor>();
_comment = new StringBuffer();
_descriptors = new ArrayList<JDocDescriptor>();
_comment = new StringBuilder();
} //-- JDocComment
/**
......@@ -113,24 +116,24 @@ public class JDocComment
//-- on the fly sorting of descriptors
if ( _descriptors.size() == 0 )
{
_descriptors.addElement( jdesc );
_descriptors.add( jdesc );
return;
}
for ( int i = 0; i < _descriptors.size(); i++ )
{
JDocDescriptor jdd
= (JDocDescriptor) _descriptors.elementAt( i );
= _descriptors.get( i );
short compare = jdesc.compareTo( jdd );
switch ( compare )
{
case 0: // equal
_descriptors.insertElementAt( jdesc, i + 1 );
_descriptors.add( i + 1, jdesc );
return;
case -1: //-- less than
_descriptors.insertElementAt( jdesc, i );
_descriptors.add( i, jdesc );
return;
case 1:
//-- keep looking
......@@ -139,7 +142,7 @@ public class JDocComment
}
//-- if we make it here we need to add
_descriptors.addElement( jdesc );
_descriptors.add( jdesc );
} //-- addException
......@@ -170,7 +173,7 @@ public class JDocComment
*/
public Enumeration<JDocDescriptor> getDescriptors()
{
return _descriptors.elements();
return Collections.enumeration( _descriptors );
} //-- getDescriptors
/**
......@@ -195,10 +198,8 @@ public class JDocComment
{
if ( name == null ) return null;
for ( int i = 0; i < _descriptors.size(); i++ )
for ( JDocDescriptor jdd : _descriptors )
{
JDocDescriptor jdd
= (JDocDescriptor) _descriptors.elementAt( i );
if ( jdd.getType() == JDocDescriptor.PARAM )
{
if ( name.equals( jdd.getName() ) )
......@@ -232,7 +233,7 @@ public class JDocComment
for ( int i = 0; i < _descriptors.size(); i++ )
{
jComment.appendComment( "\n" );
jComment.appendComment( _descriptors.elementAt( i ).toString() );
jComment.appendComment( _descriptors.get( i ).toString() );
}
jComment.print( jsw );
} //-- print
......@@ -255,7 +256,7 @@ public class JDocComment
*/
public String toString()
{
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append( "/**\n" );
sb.append( " * " );
......
......@@ -354,7 +354,7 @@ public class JDocDescriptor
**/
public String toString()
{
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
boolean allowName = true;
switch ( type )
{
......