Skip to content
GitLab
Explore
Sign in
Register
Commits on Source (2)
New upstream version 1.10.0
· e648d96f
Emmanuel Bourg
authored
Jul 07, 2019
e648d96f
New upstream version 1.11
· e085b08a
Emmanuel Bourg
authored
Jul 07, 2019
e085b08a
Show whitespace changes
Inline
Side-by-side
.travis.yml
View file @
e085b08a
language
:
java
jdk
:
-
o
racle
jdk7
-
o
racle
jdk
8
-
openjdk
6
-
o
pen
jdk7
-
o
pen
jdk
9
-
openjdk
10
-
openjdk11
# No need for preliminary install step.
install
:
true
...
...
modello-core/pom.xml
View file @
e085b08a
...
...
@@ -3,7 +3,7 @@
<parent>
<artifactId>
modello
</artifactId>
<groupId>
org.codehaus.modello
</groupId>
<version>
1.
9.
1
</version>
<version>
1.
1
1
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
modello-core/src/main/java/org/codehaus/modello/ModelloParameterConstants.java
View file @
e085b08a
...
...
@@ -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
()
{
}
...
...
modello-core/src/main/java/org/codehaus/modello/plugin/AbstractModelloGenerator.java
View file @
e085b08a
...
...
@@ -180,7 +180,7 @@ public abstract class AbstractModelloGenerator
return
str
;
}
return
new
StringBu
ff
er
(
str
.
length
()
)
return
new
StringBu
ild
er
(
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
StringBu
ff
er
(
str
.
length
()
)
return
new
StringBu
ild
er
(
str
.
length
()
)
.
append
(
Character
.
toLowerCase
(
str
.
charAt
(
0
)
)
)
.
append
(
str
.
substring
(
1
)
)
.
toString
();
...
...
modello-plugins/modello-plugin-converters/pom.xml
View file @
e085b08a
...
...
@@ -3,7 +3,7 @@
<parent>
<artifactId>
modello-plugins
</artifactId>
<groupId>
org.codehaus.modello
</groupId>
<version>
1.
9.
1
</version>
<version>
1.
1
1
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
modello-plugins/modello-plugin-converters/src/test/resources/models/maven.mdo
View file @
e085b08a
...
...
@@ -493,7 +493,7 @@
<code>
public String getId()
{
StringBu
ff
er id = new StringBu
ff
er();
StringBu
ild
er id = new StringBu
ild
er();
id.append( getGroupId() );
id.append( ":" );
...
...
modello-plugins/modello-plugin-dom4j/pom.xml
View file @
e085b08a
...
...
@@ -3,7 +3,7 @@
<parent>
<artifactId>
modello-plugins
</artifactId>
<groupId>
org.codehaus.modello
</groupId>
<version>
1.
9.
1
</version>
<version>
1.
1
1
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
modello-plugins/modello-plugin-dom4j/src/test/resources/maven.mdo
View file @
e085b08a
...
...
@@ -491,7 +491,7 @@
<code>
public String getId()
{
StringBu
ff
er id = new StringBu
ff
er();
StringBu
ild
er id = new StringBu
ild
er();
id.append( getGroupId() );
id.append( ":" );
...
...
modello-plugins/modello-plugin-jackson/pom.xml
View file @
e085b08a
...
...
@@ -3,7 +3,7 @@
<parent>
<artifactId>
modello-plugins
</artifactId>
<groupId>
org.codehaus.modello
</groupId>
<version>
1.
9.
1
</version>
<version>
1.
1
1
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
modello-plugins/modello-plugin-jackson/src/site/xdoc/index.xml
View file @
e085b08a
...
...
@@ -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>
...
...
modello-plugins/modello-plugin-jackson/src/test/resources/maven.mdo
View file @
e085b08a
...
...
@@ -515,7 +515,7 @@
<code>
public String getId()
{
StringBu
ff
er id = new StringBu
ff
er();
StringBu
ild
er id = new StringBu
ild
er();
id.append( getGroupId() );
id.append( ":" );
...
...
modello-plugins/modello-plugin-java/pom.xml
View file @
e085b08a
...
...
@@ -3,7 +3,7 @@
<parent>
<artifactId>
modello-plugins
</artifactId>
<groupId>
org.codehaus.modello
</groupId>
<version>
1.
9.
1
</version>
<version>
1.
1
1
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/AbstractJavaModelloGenerator.java
View file @
e085b08a
...
...
@@ -158,7 +158,7 @@ public abstract class AbstractJavaModelloGenerator
}
}
pr
ivate
void
addModelImport
(
JClass
jClass
,
ModelType
modelType
,
String
basePackageName
)
pr
otected
void
addModelImport
(
JClass
jClass
,
ModelType
modelType
,
String
basePackageName
)
{
String
packageName
=
modelType
.
getPackageName
(
isPackageWithVersion
(),
getGeneratedVersion
()
);
...
...
modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java
View file @
e085b08a
...
...
@@ -428,7 +428,7 @@ public class JavaModelloGenerator
}
else
{
sc
.
add
(
"StringBu
ff
er buf = new StringBu
ff
er( 128 );"
);
sc
.
add
(
"StringBu
ild
er buf = new StringBu
ild
er( 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 )
j
Method
=
J
Method
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
);
StringBu
ff
er
comment
=
new
StringBu
ff
er
(
"Get "
);
StringBu
ild
er
comment
=
new
StringBu
ild
er
(
"Get "
);
if
(
StringUtils
.
isEmpty
(
modelField
.
getDescription
()
)
)
{
comment
.
append
(
"the "
);
...
...
@@ -1286,7 +1421,7 @@ public class JavaModelloGenerator
setter
=
new
JMethod
(
"set"
+
propertyName
);
}
StringBu
ff
er
comment
=
new
StringBu
ff
er
(
"Set "
);
StringBu
ild
er
comment
=
new
StringBu
ild
er
(
"Set "
);
if
(
StringUtils
.
isEmpty
(
modelField
.
getDescription
()
)
)
{
comment
.
append
(
"the "
);
...
...
modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JClass.java
View file @
e085b08a
...
...
@@ -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
JNamed
Map
();
_methods
=
new
Vector
<
JMethod
>();
_innerClasses
=
new
Vector
<
JClass
>();
_constructors
=
new
ArrayList
<
JConstructor
>();
_fields
=
new
LinkedHash
Map
<>
();
_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
.
add
Element
(
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
.
e
lementA
t
(
i
);
JMethod
tmp
=
(
JMethod
)
_methods
.
g
et
(
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
.
add
Element
(
jMethod
);
if
(
!
added
)
_methods
.
add
(
jMethod
);
}
//-- addMethod
...
...
@@ -378,7 +379,7 @@ public class JClass extends JStructure
}
JClass
innerClass
=
new
JInnerClass
(
classname
);
_innerClasses
.
add
Element
(
innerClass
);
_innerClasses
.
add
(
innerClass
);
return
innerClass
;
}
//-- createInnerClass
...
...
@@ -391,7 +392,7 @@ public class JClass extends JStructure
*/
public
JConstructor
getConstructor
(
int
index
)
{
return
(
JConstructor
)
_constructors
.
e
lementA
t
(
index
);
return
(
JConstructor
)
_constructors
.
g
et
(
index
);
}
//-- getConstructor
/**
...
...
@@ -407,7 +408,7 @@ public class JClass extends JStructure
for
(
int
i
=
0
;
i
<
_constructors
.
size
();
i
++
)
{
jcArray
[
i
]
=
(
JConstructor
)
_constructors
.
e
lementA
t
(
i
);
jcArray
[
i
]
=
_constructors
.
g
et
(
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
.
e
lementA
t
(
i
);
marray
[
i
]
=
_methods
.
g
et
(
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
.
e
lementA
t
(
i
);
JMethod
jMethod
=
_methods
.
g
et
(
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
.
e
lementA
t
(
index
);
return
_methods
.
g
et
(
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
.
add
Element
(
classname
);
removeImports
.
add
(
classname
);
}
}
}
...
...
@@ -582,7 +573,7 @@ public class JClass extends JStructure
{
for
(
int
i
=
0
;
i
<
removeImports
.
size
();
i
++
)
{
removeImport
(
(
String
)
removeImports
.
e
lementA
t
(
i
)
);
removeImport
(
removeImports
.
g
et
(
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
.
e
lementA
t
(
i
);
JConstructor
jConstructor
=
_constructors
.
g
et
(
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
.
e
lementA
t
(
i
);
JMethod
jMethod
=
_methods
.
g
et
(
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
.
e
lementA
t
(
i
);
JClass
jClass
=
_innerClasses
.
g
et
(
i
);
jClass
.
print
(
jsw
,
true
);
jsw
.
writeln
();
}
...
...
@@ -800,7 +788,7 @@ public class JClass extends JStructure
*/
public
boolean
removeConstructor
(
JConstructor
constructor
)
{
return
_constructors
.
remove
Element
(
constructor
);
return
_constructors
.
remove
(
constructor
);
}
//-- removeConstructor
/**
...
...
@@ -850,7 +838,7 @@ public class JClass extends JStructure
*/
public
boolean
removeInnerClass
(
JClass
jClass
)
{
return
_innerClasses
.
remove
Element
(
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
{
...
...
modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JComment.java
View file @
e085b08a
...
...
@@ -124,7 +124,7 @@ public class JComment
/**
* The main comment for this JDocComment
**/
private
StringBu
ff
er
_comment
=
null
;
private
StringBu
ild
er
_comment
=
null
;
/**
* The maximum number of characters per line
...
...
@@ -138,7 +138,7 @@ public class JComment
public
JComment
()
{
super
();
_comment
=
new
StringBu
ff
er
();
_comment
=
new
StringBu
ild
er
();
}
//-- JComment
/**
...
...
@@ -279,7 +279,7 @@ class LineFormatter
String
prefix
=
null
;
private
StringBu
ff
er
sb
=
null
;
private
StringBu
ild
er
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
StringBu
ff
er
();
sb
=
new
StringBu
ild
er
();
}
//-- LineFormatter
...
...
modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JCompUnit.java
View file @
e085b08a
...
...
@@ -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
...
...
modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JConstructor.java
View file @
e085b08a
...
...
@@ -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
JNamed
Map
();
this
.
params
=
new
LinkedHash
Map
<>
();
this
.
sourceCode
=
new
JSourceCode
();
}
...
...
@@ -122,7 +127,7 @@ public class JConstructor
//-- check current params
if
(
params
.
get
(
parameter
.
getName
()
)
!=
null
)
{
StringBu
ff
er
err
=
new
StringBu
ff
er
();
StringBu
ild
er
err
=
new
StringBu
ild
er
();
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
()
{
StringBu
ff
er
sb
=
new
StringBu
ff
er
();
StringBu
ild
er
sb
=
new
StringBu
ild
er
();
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
();
...
...
modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocComment.java
View file @
e085b08a
...
...
@@ -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
StringBu
ff
er
_comment
=
null
;
private
StringBu
ild
er
_comment
=
null
;
/**
* Creates a new JavaDoc Comment
...
...
@@ -97,8 +100,8 @@ public class JDocComment
public
JDocComment
()
{
super
();
_descriptors
=
new
Vector
<
JDocDescriptor
>();
_comment
=
new
StringBu
ff
er
();
_descriptors
=
new
ArrayList
<
JDocDescriptor
>();
_comment
=
new
StringBu
ild
er
();
}
//-- JDocComment
/**
...
...
@@ -113,24 +116,24 @@ public class JDocComment
//-- on the fly sorting of descriptors
if
(
_descriptors
.
size
()
==
0
)
{
_descriptors
.
add
Element
(
jdesc
);
_descriptors
.
add
(
jdesc
);
return
;
}
for
(
int
i
=
0
;
i
<
_descriptors
.
size
();
i
++
)
{
JDocDescriptor
jdd
=
(
JDocDescriptor
)
_descriptors
.
e
lementA
t
(
i
);
=
_descriptors
.
g
et
(
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
.
add
Element
(
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
.
e
lementA
t
(
i
).
toString
()
);
jComment
.
appendComment
(
_descriptors
.
g
et
(
i
).
toString
()
);
}
jComment
.
print
(
jsw
);
}
//-- print
...
...
@@ -255,7 +256,7 @@ public class JDocComment
*/
public
String
toString
()
{
StringBu
ff
er
sb
=
new
StringBu
ff
er
();
StringBu
ild
er
sb
=
new
StringBu
ild
er
();
sb
.
append
(
"/**\n"
);
sb
.
append
(
" * "
);
...
...
modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocDescriptor.java
View file @
e085b08a
...
...
@@ -354,7 +354,7 @@ public class JDocDescriptor
**/
public
String
toString
()
{
StringBu
ff
er
sb
=
new
StringBu
ff
er
();
StringBu
ild
er
sb
=
new
StringBu
ild
er
();
boolean
allowName
=
true
;
switch
(
type
)
{
...
...
Prev
1
2
3
Next