();
//-- initialize default Java doc
getJDocComment().appendComment( "Interface " + getLocalName() + "." );
} //-- JInterface
/**
* Adds the given JField to this JStructure.
*
* This method is implemented by subclasses and
* should only accept the proper fields for the
* subclass otherwise an IllegalArgumentException
* will be thrown. For example a JInterface will
* only accept static fields.
*
* @param jField, the JField to add
* @exception java.lang.IllegalArgumentException when the given
* JField has a name of an existing JField
*/
public void addField( JField jField )
throws IllegalArgumentException
{
if ( jField == null )
{
throw new IllegalArgumentException( "argument 'jField' cannot be null" );
}
String name = jField.getName();
//-- check for duplicate field name
if ( ( fields != null ) && ( fields.get( name ) != null ) )
{
String err = "duplicate name found: " + name;
throw new IllegalArgumentException( err );
}
//-- check for proper modifiers
JModifiers modifiers = jField.getModifiers();
if ( !modifiers.isStatic() )
{
throw new IllegalArgumentException( "Fields added to a JInterface must be static." );
}
if ( modifiers.isPrivate() )
{
throw new IllegalArgumentException( "Fields added to a JInterface must not be private." );
}
//-- only initialize fields if we need it, many interfaces
//-- don't contain any fields, no need to waste space
if ( fields == null )
{
fields = new JNamedMap( 3 );
}
fields.put( name, jField );
}
/**
* Adds the given JMember to this JStructure.
*
* This method is implemented by subclasses and
* should only accept the proper types for the
* subclass otherwise an IllegalArgumentException
* will be thrown.
*
* @param jMember the JMember to add to this JStructure.
* @throws java.lang.IllegalArgumentException when the given
* JMember has the same name of an existing JField
* or JMethod respectively.
*/
public void addMember( JMember jMember )
throws IllegalArgumentException
{
if ( jMember == null )
{
throw new IllegalArgumentException( "argument 'jMember' may not be null." );
}
if ( jMember instanceof JField )
{
addField( (JField) jMember );
}
else
{
throw new IllegalArgumentException( "invalid member for JInterface: " +
jMember.toString() );
}
} //-- addMember
/**
* Adds the given JMethodSignature to this JClass
*
* @param jMethodSig the JMethodSignature to add.
* @throws java.lang.IllegalArgumentException when the given
* JMethodSignature conflicts with an existing
* method signature.
*/
public void addMethod( JMethodSignature jMethodSig )
throws IllegalArgumentException
{
if ( jMethodSig == null )
{
String err = "The JMethodSignature cannot be null.";
throw new IllegalArgumentException( err );
}
//-- check method name and signatures *add later*
//-- keep method list sorted for esthetics when printing
//-- START SORT :-)
boolean added = false;
// short modifierVal = 0;
JModifiers modifiers = jMethodSig.getModifiers();
for ( int i = 0; i < methods.size(); i++ )
{
JMethodSignature tmp = (JMethodSignature) methods.elementAt( i );
//-- first compare modifiers
if ( tmp.getModifiers().isProtected() )
{
if ( !modifiers.isProtected() )
{
methods.insertElementAt( jMethodSig, i );
added = true;
break;
}
}
//-- compare names
if ( jMethodSig.getName().compareTo( tmp.getName() ) < 0 )
{
methods.insertElementAt( jMethodSig, i );
added = true;
break;
}
}
//-- END SORT
if ( !added ) methods.addElement( jMethodSig );
//-- check return type to make sure it's included in the
//-- import list
JType jType = jMethodSig.getReturnType();
if ( jType != null )
{
while ( jType.isArray() )
jType = jType.getComponentType();
if ( !jType.isPrimitive() )
addImport( jType.getName() );
}
//-- check exceptions
JClass[] exceptions = jMethodSig.getExceptions();
for ( int i = 0; i < exceptions.length; i++ )
{
addImport( exceptions[i].getName() );
}
} //-- addMethod
/**
* Returns the field with the given name, or null if no field
* was found with the given name.
*
* @param name the name of the field to return.
* @return the field with the given name, or null if no field
* was found with the given name.
*/
public JField getField( String name )
{
if ( fields == null ) return null;
return (JField) fields.get( name );
} //-- getField
/**
* Returns an array of all the JFields of this JStructure
*
* @return an array of all the JFields of this JStructure
*/
public JField[] getFields()
{
if ( fields == null )
{
return new JField[0];
}
int size = fields.size();
JField[] farray = new JField[size];
for ( int i = 0; i < size; i++ )
{
farray[i] = (JField) fields.get( i );
}
return farray;
} //-- getFields
/**
* Returns an array of all the JMethodSignatures of this JInterface.
*
* @return an array of all the JMethodSignatures of this JInterface.
**/
public JMethodSignature[] getMethods()
{
JMethodSignature[] marray = new JMethodSignature[methods.size()];
methods.copyInto( marray );
return marray;
} //-- getMethods
/**
* Returns the JMethodSignature with the given name,
* and occuring at or after the given starting index.
*
* @param name the name of the JMethodSignature to return.
* @param startIndex the starting index to begin searching
* from.
* @return the JMethodSignature, or null if not found.
**/
public JMethodSignature getMethod( String name, int startIndex )
{
for ( int i = startIndex; i < methods.size(); i++ )
{
JMethodSignature jMethod = (JMethodSignature) methods.elementAt( i );
if ( jMethod.getName().equals( name ) ) return jMethod;
}
return null;
} //-- getMethod
/**
* Returns the JMethodSignature at the given index.
*
* @param index the index of the JMethodSignature to return.
* @return the JMethodSignature at the given index.
**/
public JMethodSignature getMethod( int index )
{
return (JMethodSignature) methods.elementAt( index );
} //-- getMethod
/**
* Prints the source code for this JInterface to the given JSourceWriter
*
* @param jsw the JSourceWriter to print to. [May not be null]
*/
public void print( JSourceWriter jsw )
{
print( jsw, false );
}
/**
* Prints the source code for this JInterface to the given JSourceWriter
*
* @param jsw the JSourceWriter to print to. [May not be null]
*/
public void print( JSourceWriter jsw, boolean classOnly )
{
if ( jsw == null )
{
throw new IllegalArgumentException( "argument 'jsw' should not be null." );
}
StringBuffer buffer = new StringBuffer();
if ( !classOnly )
{
printHeader( jsw );
printPackageDeclaration( jsw );
printImportDeclarations( jsw );
}
//------------/
//- Java Doc -/
//------------/
getJDocComment().print( jsw );
JAnnotations annotations = getAnnotations();
if ( annotations != null ) annotations.print( jsw );
//-- print class information
//-- we need to add some JavaDoc API adding comments
buffer.setLength( 0 );
JModifiers modifiers = getModifiers();
if ( modifiers.isPrivate() )
{
buffer.append( "private " );
}
else if ( modifiers.isPublic() )
{
buffer.append( "public " );
}
if ( modifiers.isAbstract() )
{
buffer.append( "abstract " );
}
buffer.append( "interface " );
buffer.append( getLocalName() );
jsw.writeln( buffer.toString() );
buffer.setLength( 0 );
jsw.indent();
if ( getInterfaceCount() > 0 )
{
Enumeration e = getInterfaces();
buffer.append( "extends " );
while ( e.hasMoreElements() )
{
buffer.append( e.nextElement() );
if ( e.hasMoreElements() ) buffer.append( ", " );
}
jsw.writeln( buffer.toString() );
buffer.setLength( 0 );
}
jsw.unindent();
jsw.writeln( '{' );
jsw.indent();
//-- declare static members
if ( fields != null )
{
if ( fields.size() > 0 )
{
jsw.writeln();
jsw.writeln( " //--------------------------/" );
jsw.writeln( " //- Class/Member Variables -/" );
jsw.writeln( "//--------------------------/" );
jsw.writeln();
}
for ( int i = 0; i < fields.size(); i++ )
{
JField jField = (JField) fields.get( i );
//-- print Java comment
JDocComment comment = jField.getComment();
if ( comment != null ) comment.print( jsw );
// -- print member
jsw.write( jField.getModifiers().toString() );
jsw.write( ' ' );
JType type = jField.getType();
String typeName = type.toString();
//-- for esthetics use short name in some cases
if ( typeName.equals( toString() ) )
{
typeName = type.getLocalName();
}
jsw.write( typeName );
jsw.write( ' ' );
jsw.write( jField.getName() );
String init = jField.getInitString();
if ( init != null )
{
jsw.write( " = " );
jsw.write( init );
}
jsw.writeln( ';' );
jsw.writeln();
}
}
//-- print method signatures
if ( methods.size() > 0 )
{
jsw.writeln();
jsw.writeln( " //-----------/" );
jsw.writeln( " //- Methods -/" );
jsw.writeln( "//-----------/" );
jsw.writeln();
}
for ( int i = 0; i < methods.size(); i++ )
{
JMethodSignature signature = (JMethodSignature) methods.elementAt( i );
signature.print( jsw );
jsw.writeln( ';' );
}
for ( String sourceCodeEntry : sourceCodeEntries )
{
jsw.writeln( sourceCodeEntry );
}
jsw.unindent();
jsw.writeln( '}' );
jsw.flush();
jsw.close();
} //-- printSource
private List sourceCodeEntries = new ArrayList();
public void addSourceCode( String sourceCode )
{
sourceCodeEntries.add( sourceCode );
}
/**
* Test drive method...to be removed or commented out
**
public static void main(String[] args) {
JInterface jInterface = new JInterface("Test");
//-- add an import
jInterface.addImport("java.util.Vector");
JClass jString = new JClass("String");
//-- add an interface
jInterface.addInterface("java.io.Serializable");
//-- add a static field
JField jField = new JField(new JClass("java.lang.String"), "TEST");
jField.setInitString("\"Test\"");
jField.getModifiers().setStatic(true);
jField.getModifiers().makePublic();
jInterface.addField(jField);
//-- add a method signature
JMethodSignature jMethodSig = new JMethodSignature("getName", jString);
jInterface.addMethod(jMethodSig);
jInterface.print();
} //-- main
/* */
} //-- JInterface
JMember.java 0000664 0000000 0000000 00000010000 11666547660 0037522 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999-2000 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JMember.java 1297 2009-07-23 01:17:35Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* An interface which represents a Member of a JClass,
* modelled closely after the Java Reflection API.
* This class is part of a package used to represent
* source code.
* @author Keith Visco
* @version $Revision: 1297 $ $Date: 2009-07-23 03:17:35 +0200 (jeu. 23 juil. 2009) $
**/
interface JMember
{
/**
* Returns the class in which this JMember has been declared
* @return the class in which this JMember has been declared
**/
//public JClass getDeclaringClass();
/**
* Returns the modifiers for this JMember
* @return the modifiers for this JMember
**/
public JModifiers getModifiers();
/**
* Returns the name of this JMember
* @return the name of this JMember
**/
public String getName();
public JAnnotations getAnnotations();
} //-- JMember
JMethod.java 0000664 0000000 0000000 00000033131 11666547660 0037545 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JMethod.java 1413 2010-02-13 21:23:01Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.util.Vector;
/**
* A class which holds information about the methods of
* a JClass.
* Modelled closely after the Java Reflection API.
* This class is part of package which is used to
* create source code.
* @author Keith Visco
* @version $Revision: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $
**/
public class JMethod implements JMember
{
/**
* The set of classes that contain this JMethod.
**/
private Vector _classes = null;
/**
* The JavaDoc comment for this JMethod. This
* will overwrite the JavaDoc for the
* JMethodSignature.
**/
private JDocComment jdc = null;
/**
* The source code for this method
**/
private JSourceCode source = null;
/**
* The signature for this method.
**/
private JMethodSignature _signature = null;
/**
* The annotation(s) for this method.
*/
private JAnnotations annotations = null;
/**
* Creates a new JMethod with the given name and "void" return type.
*
* @param name, the method name. Must not be null.
**/
public JMethod( String name )
{
this( name, null, null );
} //-- JMethod
/**
* Creates a new JMethod with the given name and returnType.
* For "void" return types, simply pass in null as the returnType.
*
* @param name, the method name. Must not be null.
* @param returnType the return type of the method. May be null.
* @deprecated removed in future version of javasource
**/
public JMethod( JType returnType, String name )
{
this( name, returnType, null );
} //-- JMethod
/**
* Creates a new JMethod with the given name and returnType.
* For "void" return types, simply pass in null as the returnType.
*
* @param name, the method name. Must not be null.
* @param returnType the return type of the method. May be null.
* @param returnDoc Javadoc comment for the @return annotation. If
* null, a default (and mostly useless) javadoc comment will be
* generated.
**/
public JMethod( final String name, final JType returnType, final String returnDoc )
{
if ( ( name == null ) || ( name.length() == 0 ) )
{
String err = "The method name must not be null or zero-length";
throw new IllegalArgumentException( err );
}
_classes = new Vector( 1 );
this.source = new JSourceCode();
_signature = new JMethodSignature( name, returnType );
this.jdc = _signature.getJDocComment();
jdc.appendComment( "Method " + name + "." );
//-- create comment
if ( returnType != null )
{
if ( returnDoc != null && returnDoc.length() > 0 )
{
jdc.addDescriptor( JDocDescriptor.createReturnDesc( returnDoc ) );
}
else
{
jdc.addDescriptor( JDocDescriptor.createReturnDesc( returnType.getLocalName() ) );
}
}
}
/**
* Adds the given Exception to this Method's throws clause.
*
* @param exp the JClass representing the Exception
**/
public void addException( JClass exp )
{
_signature.addException( exp );
} //-- addException
/**
* Adds the given parameter to this JMethod's list of parameters.
*
* @param parameter the parameter to add to the this Methods
* list of parameters.
* @throws java.lang.IllegalArgumentException when a parameter already
* exists for this Method with the same name as the new parameter
**/
public void addParameter( JParameter parameter )
throws IllegalArgumentException
{
_signature.addParameter( parameter );
} //-- addParameter
/**
* Returns the JDocComment describing this member.
* @return the JDocComment describing this member.
**/
public JDocComment getJDocComment()
{
return this.jdc;
} //-- getJDocComment
/**
* Returns the class in which this JMember has been declared
* @return the class in which this JMember has been declared
**
public JClass getDeclaringClass() {
return _declaringClass;
} //-- getDeclaringClass
*/
/**
* Returns the exceptions that this JMember throws.
*
* @return the exceptions that this JMember throws.
**/
public JClass[] getExceptions()
{
return _signature.getExceptions();
} //-- getExceptions
/**
* Returns the modifiers for this JMember.
*
* @return the modifiers for this JMember.
**/
public JModifiers getModifiers()
{
return _signature.getModifiers();
} //-- getModifiers
/**
* Returns the name of this JMember.
*
* @return the name of this JMember.
**/
public String getName()
{
return _signature.getName();
} //-- getName
/**
* Returns the JParameter at the given index.
*
* @param index the index of the JParameter to return.
* @return the JParameter at the given index.
**/
public JParameter getParameter( int index )
{
return _signature.getParameter( index );
} //-- getParameter
/**
* Returns the set of JParameters for this JMethod.
*
* Note: the array is a copy, the params in the array
* are the actual references.
*
* @return the set of JParameters for this JMethod
**/
public JParameter[] getParameters()
{
return _signature.getParameters();
} //-- getParameters
/**
* Returns the JType that represents the return type of the method.
*
* @return the JType that represents the return type of the method.
**/
public JType getReturnType()
{
return _signature.getReturnType();
} //-- getReturnType
/**
* Returns the JMethodSignature for this JMethod.
*
* @return the JMethodSignature for this JMethod.
**/
public JMethodSignature getSignature()
{
return _signature;
} //-- getSignature
/**
* Returns the JSourceCode for the method body.
*
* @return the JSourceCode for the method body.
**/
public JSourceCode getSourceCode()
{
return this.source;
} //-- getSourceCode
/**
* Sets the comment describing this member. The comment
* will be printed when this member is printed with the
* Class Printer.
*
* @param comment the comment for this member
* @see #getJDocComment
**/
public void setComment( String comment )
{
jdc.setComment( comment );
} //-- setComment
/**
* Sets the JModifiers for this JMethod. This
* JMethod will use only a copy of the JModifiers.
* Note: The JModifiers will be set in the
* containing JMethodSignature. If the JMethodSignature
* is used by other methods, keep in mind that it will be
* changed.
*
* @param modifiers the JModifiers to set.
**/
public void setModifiers( JModifiers modifiers )
{
_signature.setModifiers( modifiers );
} //-- setModifiers
/**
* Sets the given string as the source code (method body)
* for this JMethod.
*
* @param source the String that represents the method body.
**/
public void setSourceCode( String source )
{
this.source = new JSourceCode( source );
} //-- setSource
/**
* Sets the given JSourceCode as the source code (method body)
* for this JMethod.
*
* @param source the JSourceCode that represents the method body.
**/
public void setSourceCode( JSourceCode source )
{
this.source = source;
} //-- setSource;
/**
* Prints this JMethod to the given JSourceWriter.
*
* @param jsw the JSourceWriter to print to.
**/
public void print( JSourceWriter jsw )
{
//------------/
//- Java Doc -/
//------------/
jdc.print( jsw );
//--------------------/
// - Annotations -/
//--------------------/
JAnnotations annotations = getAnnotations();
if ( annotations != null ) annotations.print( jsw );
//--------------------/
//- Method Signature -/
//--------------------/
_signature.print( jsw, false );
if ( _signature.getModifiers().isAbstract() )
{
jsw.writeln( ";" );
}
else
{
jsw.writeln();
jsw.writeln( "{" );
source.print( jsw );
jsw.write( "} //-- " );
jsw.writeln( toString() );
}
} //-- print
/**
* Returns the String representation of this JMethod,
* which is the method prototype.
* @return the String representation of this JMethod, which
* is simply the method prototype
**/
public String toString()
{
return _signature.toString();
} //-- toString
//---------------------/
//- PROTECTED METHODS -/
//---------------------/
/**
* Adds the given JClass to the set of classes that
* contain this method.
*
* @param jClass the JClass to add as one of
* the JClasses that contain this method.
**/
protected void addDeclaringClass( JClass jClass )
{
_classes.addElement( jClass );
} //-- addDeclaringClass
/**
* Removes the given JClass from the set of classes that
* contain this method.
*
* @param jClass the JClass to add as one of
* the JClasses that contain this method.
**/
protected void removeDeclaringClass( JClass jClass )
{
_classes.removeElement( jClass );
} //-- removeDeclaringClass
protected String[] getParameterClassNames()
{
return _signature.getParameterClassNames();
} //-- getParameterClassNames
/**
* @return the annotations
*/
public JAnnotations getAnnotations()
{
return annotations;
}
/**
* @param annotation the annotation to append
*/
public void appendAnnotation( String annotation )
{
if ( annotations == null )
{
annotations = new JAnnotations();
}
annotations.appendAnnotation( annotation );
}
/**
* @param annotations the annotations to set
*/
public void setAnnotations( JAnnotations annotations )
{
this.annotations = annotations;
}
} //-- JMember
JMethodSignature.java 0000664 0000000 0000000 00000032142 11666547660 0041430 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JMethodSignature.java 1413 2010-02-13 21:23:01Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.util.Vector;
/**
* A class which holds information about the signature
* of a JMethod.
*
* The code in this package was modelled after the Java Reflection API
* as much as possible to reduce the learning curve.
*
* @author Keith Visco
* @version $Id: JMethodSignature.java 1413 2010-02-13 21:23:01Z hboutemy $
**/
public final class JMethodSignature
{
/**
* The set of modifiers for this JMethod
**/
private JModifiers modifiers = null;
/**
* The return type of this Method
**/
private JType returnType = null;
/**
* The name of this method
**/
private String name = null;
/**
* The list of parameters of this JMethodSignature in declared
* order
**/
private JNamedMap params = null;
/**
* The JavaDoc comment for this method signature.
**/
private JDocComment jdc = null;
/**
* The exceptions that this method throws
**/
private Vector exceptions = null;
/**
* Creates a new method with the given name and return type.
* For "void" return types, simply pass in null as the returnType
*
* @param name, the method name. Must not be null.
* @param returnType the return type of the method. May be null.
**/
public JMethodSignature( String name, JType returnType )
{
if ( ( name == null ) || ( name.length() == 0 ) )
{
String err = "The method name must not be null or zero-length";
throw new IllegalArgumentException( err );
}
this.jdc = new JDocComment();
this.returnType = returnType;
this.name = name;
this.modifiers = new JModifiers();
this.params = new JNamedMap( 3 );
this.exceptions = new Vector( 1 );
} //-- JMethodSignature
/**
* Adds the given Exception to this JMethodSignature's throws clause.
*
* @param exp the JClass representing the Exception
**/
public void addException( JClass exp )
{
if ( exp == null ) return;
//-- make sure exception is not already added
String expClassName = exp.getName();
for ( int i = 0; i < exceptions.size(); i++ )
{
JClass jClass = (JClass) exceptions.elementAt( i );
if ( expClassName.equals( jClass.getName() ) ) return;
}
//-- add exception
exceptions.addElement( exp );
//-- create comment
jdc.addDescriptor( JDocDescriptor.createExceptionDesc( expClassName, null ) );
} //-- addException
/**
* Adds the given parameter to this JMethodSignature's list of
* parameters.
*
* @param parameter the parameter to add to the this Methods
* list of parameters.
* @throws java.lang.IllegalArgumentException when a parameter already
* exists for this Method with the same name as the new
* parameter.
**/
public void addParameter( JParameter parameter )
throws IllegalArgumentException
{
if ( parameter == null ) return;
String pName = parameter.getName();
//-- check current params
if ( params.get( pName ) != null )
{
StringBuffer err = new StringBuffer();
err.append( "A parameter already exists for this method, " );
err.append( name );
err.append( ", with the name: " );
err.append( pName );
throw new IllegalArgumentException( err.toString() );
}
params.put( pName, parameter );
//-- create comment
jdc.addDescriptor( JDocDescriptor.createParamDesc( pName, null ) );
} //-- addParameter
/**
* Returns the exceptions that this JMethodSignature lists
* in it's throws clause.
*
* @return the exceptions that this JMethodSignature lists
* in it's throws clause.
**/
public JClass[] getExceptions()
{
JClass[] jclasses = new JClass[exceptions.size()];
exceptions.copyInto( jclasses );
return jclasses;
} //-- getExceptions
/**
* Returns the JDocComment describing this JMethodSignature
*
* @return the JDocComment describing this JMethodSignature
**/
public JDocComment getJDocComment()
{
return this.jdc;
} //-- getJDocComment
/**
* Returns the modifiers for this JMethodSignature.
*
* @return the modifiers for this JMethodSignature.
**/
public JModifiers getModifiers()
{
return this.modifiers;
} //-- getModifiers
/**
* Returns the name of the method.
*
* @return the name of the method.
**/
public String getName()
{
return this.name;
} //-- getName
/**
* Returns the JParameter at the given index.
*
* @param index the index of the JParameter to return.
* @return the JParameter at the given index.
**/
public JParameter getParameter( int index )
{
return (JParameter) params.get( index );
} //-- getParameter
/**
* Returns the set of JParameters for this JMethodSignature
*
* Note: the array is a copy, the params in the array
* are the actual references.
* @return the set of JParameters for this JMethod
**/
public synchronized JParameter[] getParameters()
{
JParameter[] pArray = new JParameter[params.size()];
for ( int i = 0; i < pArray.length; i++ )
{
pArray[i] = (JParameter) params.get( i );
}
return pArray;
} //-- getParameters
/**
* Returns the JType that represents the return type for the
* method signature.
*
* @return the JType that represents the return type for the
* method signature.
**/
public JType getReturnType()
{
return returnType;
} //-- getReturnType
/**
* Sets the comment describing this JMethodSignature.
*
* @param comment the comment for this member
* @see #getJDocComment
**/
public void setComment( String comment )
{
jdc.setComment( comment );
} //-- setComment
/**
* Sets the JModifiers for this method signature.
*
* @param modifiers the JModifiers for this method signature.
**/
public void setModifiers( JModifiers modifiers )
{
this.modifiers = modifiers.copy();
this.modifiers.setFinal( false );
} //-- setModifiers
/**
* Prints the method signature. A semi-colon (end-of-statement
* terminator ';') will Not be printed.
*
* @param jsw the JSourceWriter to print to.
**/
public void print( JSourceWriter jsw )
{
print( jsw, true );
} //-- print
/**
* Prints the method signature. A semi-colon (end-of-statement
* terminator ';') will Not be printed.
*
* @param jsw the JSourceWriter to print to.
* @param printJavaDoc a boolean that when true prints the JDocComment
* associated with this method signature.
**/
public void print( JSourceWriter jsw, boolean printJavaDoc )
{
//------------/
//- Java Doc -/
//------------/
if ( printJavaDoc ) jdc.print( jsw );
//-----------------/
//- Method Source -/
//-----------------/
jsw.write( modifiers.toString() );
if ( modifiers.toString().length() > 0 )
{
jsw.write( ' ' );
}
if ( returnType != null )
{
jsw.write( returnType );
}
else
jsw.write( "void" );
jsw.write( ' ' );
jsw.write( name );
jsw.write( '(' );
//-- print parameters
if ( params.size() > 0 )
{
jsw.write( ' ' );
for ( int i = 0; i < params.size(); i++ )
{
if ( i > 0 ) jsw.write( ", " );
jsw.write( params.get( i ) );
}
jsw.write( ' ' );
}
jsw.write( ')' );
if ( exceptions.size() > 0 )
{
jsw.writeln();
jsw.write( " throws " );
for ( int i = 0; i < exceptions.size(); i++ )
{
if ( i > 0 ) jsw.write( ", " );
JClass jClass = (JClass) exceptions.elementAt( i );
jsw.write( jClass.getName() );
}
}
} //-- print
/**
* Returns the String representation of this JMethod,
* which is the method prototype.
* @return the String representation of this JMethod, which
* is simply the method prototype
**/
public String toString()
{
StringBuffer sb = new StringBuffer();
if ( returnType != null )
{
sb.append( returnType );
}
else
sb.append( "void" );
sb.append( ' ' );
sb.append( name );
sb.append( '(' );
//-- print parameters
if ( params.size() > 0 )
{
sb.append( ' ' );
for ( int i = 0; i < params.size(); i++ )
{
JParameter jParam = (JParameter) params.get( i );
if ( i > 0 ) sb.append( ", " );
sb.append( jParam.getType().getName() );
}
sb.append( ' ' );
}
sb.append( ')' );
return sb.toString();
} //-- toString
protected String[] getParameterClassNames()
{
Vector names = new Vector( params.size() );
for ( int i = 0; i < params.size(); i++ )
{
JType jType = ( (JParameter) params.get( i ) ).getType();
while ( jType.isArray() ) jType = jType.getComponentType();
if ( !jType.isPrimitive() )
{
JClass jclass = (JClass) jType;
names.addElement( jclass.getName() );
}
}
String[] names_array = new String[names.size()];
names.copyInto( names_array );
return names_array;
} //-- getParameterClassNames
} //-- JMethodSignature JModifiers.java 0000664 0000000 0000000 00000026217 11666547660 0040255 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999-2000 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JModifiers.java 1437 2010-04-15 21:46:36Z bentmann $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* The set of modifiers for a Method or Member variable
* @author Keith Visco
* @version $Revision: 1437 $ $Date: 2010-04-15 23:46:36 +0200 (jeu. 15 avril 2010) $
**/
public class JModifiers
{
/* static members */
private static final String sAbstract = "abstract";
private static final String sFinal = "final";
private static final String sPrivate = "private";
private static final String sProtected = "protected";
private static final String sPackage = "";
private static final String sPublic = "public";
private static final String sStatic = "static";
private static final String sTransient = "transient";
private static final short vPrivate = 1;
private static final short vProtected = 2;
private static final short vPublic = 3;
private static final short vPackage = 4;
/* local members */
/**
* The visibility
**/
private short visibility = vPublic;
/**
* A flag indicating whether or not the object associated
* with this JModifiers is static
**/
private boolean isStatic = false;
/**
* A flag indicating whether or not the object associated
* with this JModifiers is final
**/
private boolean isFinal = false;
/**
* A flag indicating whether or not the object associated
* with this JModifiers is abstract
**/
private boolean isAbstract = false;
/**
* A flag indicating whether or not the object associated
* with this JModifiers is transient
**/
private boolean isTransient = false;
/**
* Creates a new JModifiers class, by default the
* modifiers presented are public.
**/
public JModifiers()
{
super();
} //-- JModifiers
/**
* Creates a new JModifiers
* @param visibility the visibile qualifier
* @param isStatic a boolean indicating the static qualifier.
* A value of true indicates that this static qualifier is present.
* @param isFinal a boolean indicating the final qualifier. A value
* of true indicates that the final qualifier is present.
**/
private JModifiers( short visibility, boolean isStatic, boolean isFinal )
{
this.visibility = visibility;
this.isStatic = isStatic;
this.isFinal = isFinal;
} //-- JModifiers
/**
* Creates a copy of this JModifiers
* @return the copy of this JModifiers
**/
public JModifiers copy()
{
JModifiers mods = new JModifiers( visibility, isStatic, isFinal );
mods.setAbstract( isAbstract );
mods.setTransient( isTransient );
return mods;
} //-- copy
/**
* Changes the visibility qualifier to "private"
**/
public void makePrivate()
{
this.visibility = vPrivate;
} //-- makePrivate
/**
* Changes the visibility qualifier to "protected"
**/
public void makeProtected()
{
this.visibility = vProtected;
} //-- makeProtected
/**
* Changes the visibility qualifier to "public"
**/
public void makePublic()
{
this.visibility = vPublic;
} //-- makePublic
/**
* Changes the visibility qualifier to package (= without qualifier).
**/
public void makePackage()
{
this.visibility = vPackage;
} //-- makePackage
/**
* Returns true if the abstract qualifier is present.
* This is only applicable to methods and classes.
* @return true if the abstract qualifier is present
**/
public boolean isAbstract()
{
return isAbstract;
} //-- isAbstract
/**
* Returns true if the final qualifier is present.
* This is only applicable to methods and classes.
* @return true if the final qualifier is present
**/
public boolean isFinal()
{
return isFinal;
} //-- isFinal
/**
* Returns true if the modifier represented is private.
* @return true if the modifier represented is private.
**/
public boolean isPrivate()
{
return ( visibility == vPrivate );
} //-- isPrivate
/**
* Returns true if the modifier represented is protected.
* @return true if the modifier represented is protected.
**/
public boolean isProtected()
{
return ( visibility == vProtected );
} //-- isProtected
/**
* Returns true if the modifier represented is public.
* @return true if the modifier represented is public.
**/
public boolean isPublic()
{
return ( visibility == vPublic );
} //-- isPublic
/**
* Returns true if the modifier represented is package (= without qualifier).
* @return true if the modifier represented is package (= without qualifier).
**/
public boolean isPackage()
{
return ( visibility == vPackage );
} //-- isPackage
/**
* Returns true if the modifier represented is static.
* @return true if the modifier represented is static.
**/
public boolean isStatic()
{
return this.isStatic;
} //-- isPublic
/**
* Returns true if the modifier represented is transient.
* @return true if the modifier represented is transient.
**/
public boolean isTransient()
{
return this.isTransient;
} //-- isTransient
/**
* Sets whether or not the "abstract" qualifier is present
* This applies only to methods or classes.
* @param isAbstract is a boolean which when true will indicate
* that the abstract qualifier should be present
**/
public void setAbstract( boolean isAbstract )
{
this.isAbstract = isAbstract;
} //-- setAbstract
/**
* Sets whether or not the "final" qualifier is present
* @param isFinal is a boolean which when true will indicate
* the final qualifiter is present
**/
public void setFinal( boolean isFinal )
{
this.isFinal = isFinal;
} //-- setFinal
/**
* Sets whether or not the "static" qualifier is present
* @param isStatic is a boolean which when true will indicate
* the "static" qualifiter is present
**/
public void setStatic( boolean isStatic )
{
this.isStatic = isStatic;
} //-- setStatic
/**
* Sets whether or not the "transient" qualifier is present
* @param isTransient is a boolean which when true will indicate
* the "transient" qualifiter is present
**/
public void setTransient( boolean isTransient )
{
this.isTransient = isTransient;
} //-- setTransient
/**
* Returns the String represetation of this JModifiers
* @return the String represetation of this JModifiers
**/
public String toString()
{
StringBuffer sb = new StringBuffer();
//-- visibility
switch ( visibility )
{
case vPrivate:
sb.append( sPrivate );
break;
case vProtected:
sb.append( sProtected );
break;
case vPackage:
sb.append( sPackage );
break;
default:
sb.append( sPublic );
break;
}
//-- static
if ( isStatic )
{
if ( sb.length() > 0 )
{
sb.append( ' ' );
}
sb.append( sStatic );
}
//-- final
if ( isFinal )
{
if ( sb.length() > 0 )
{
sb.append( ' ' );
}
sb.append( sFinal );
}
//-- abstract
if ( isAbstract )
{
if ( sb.length() > 0 )
{
sb.append( ' ' );
}
sb.append( sAbstract );
}
//-- transient
if ( isTransient )
{
if ( sb.length() > 0 )
{
sb.append( ' ' );
}
sb.append( sTransient );
}
return sb.toString();
} //-- toString
} //-- JModifiers
JNamedMap.java 0000664 0000000 0000000 00000017247 11666547660 0040021 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JNamedMap.java 1415 2010-02-13 22:23:37Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.util.Vector;
/**
* A simple String to Object mapping which preserves order.
*
*
* Note:
* This class is not synchronized. So be careful. :-)
*
* @author Keith Visco
**/
public class JNamedMap
{
private Vector names = null;
private Vector objects = null;
/**
* Creates a new JNamedMap
**/
public JNamedMap()
{
names = new Vector();
objects = new Vector();
} //-- JNamedMap
/**
* Creates a new JNamedMap with the given size.
*
* @param size the initial size for this NamedMap
**/
public JNamedMap( int size )
{
names = new Vector( size );
objects = new Vector( size );
} //-- JNamedMap
/**
* Returns the Object associated with the given name.
*
* @param name the name to search for
* @return the Object associated with the given name
**/
public Object get( String name )
{
int i = indexOf( name );
if ( i >= 0 ) return objects.elementAt( i );
return null;
} //-- get
/**
* Returns the Object at the given index.
*
* @param index the index of the Object to return
* @return the Object at the given index
**/
public Object get( int index )
throws IndexOutOfBoundsException
{
return objects.elementAt( index );
} //-- get
/**
* Returns the name associated with the given Object
*
* @param obj the Object to search for
* @return the name of the given Object
**/
public String getNameByObject( Object obj )
{
int i = objects.indexOf( obj );
if ( i >= 0 ) return (String) names.elementAt( i );
return null;
} //-- getNameByObject
/**
* Return a Vector of names
*
* @return a Vector of names
**/
@SuppressWarnings( "unchecked" )
public Vector getNames()
{
return (Vector) names.clone();
} //-- getNames
/**
* Return a Vector of Objects
*
* @return a Vector of Objects
**/
@SuppressWarnings( "unchecked" )
public Vector getObjects()
{
return (Vector) objects.clone();
} //-- getObjects
/**
* Returns the index of the Object which has been
* mapped (associated) with the given name
*
* @return the index of the Object which has been mapped (associated)
* to the given name
**/
public int indexOf( String name )
{
for ( int i = 0; i < names.size(); i++ )
{
String iName = (String) names.elementAt( i );
if ( iName.equals( name ) ) return i;
}
return -1;
} //-- indexOf
/**
* Maps (associates) an Object with a name
*
* @param name the name to associate with the given Object
* @param obj the Object to be mapped
**/
public void put( String name, Object obj )
{
int idx = indexOf( name );
if ( idx >= 0 )
objects.setElementAt( obj, idx );
else
{
//-- we may need some synchronization here
//-- if we are in a multithreaded environment
names.addElement( name );
objects.addElement( obj );
}
} //-- put
/**
* Removes and returns the Object located at the given index
*
* @param name the name of the Object to remove
* @return the object removed from the map.
**/
public Object remove( int index )
throws IndexOutOfBoundsException
{
Object obj = objects.elementAt( index );
objects.removeElementAt( index );
names.removeElementAt( index );
return obj;
} //-- remove
/**
* Removes and returns the Object associated with the given name
*
* @param name the name of the Object to remove
* @return the object removed from the map.
**/
public Object remove( String name )
{
Object obj = null;
int idx = indexOf( name );
if ( idx >= 0 )
{
obj = objects.elementAt( idx );
objects.removeElementAt( idx );
names.removeElementAt( idx );
}
return obj;
} //-- remove
/**
* Returns the number of Object associations currently in
* this named map
*
* @return the number of Object associations currently in
* this named map
**/
public int size()
{
return names.size();
} //-- size
} //-- JNamedMap JNaming.java 0000664 0000000 0000000 00000013235 11666547660 0037541 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999-2000 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JNaming.java 555 2006-01-29 21:38:08Z jvanzyl $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* A utility class used to validate identifiers
* and class names
* @author Keith Visco
* @version $Revision: 555 $ $Date: 2006-01-29 22:38:08 +0100 (dim. 29 janv. 2006) $
**/
class JNaming
{
private static final String[] keywords = {
"abstract",
"boolean",
"break",
"byte",
"case",
"catch",
"char",
"class",
"const",
"continue",
"default",
"do",
"double",
"else",
"extends",
"false",
"final",
"finally",
"float",
"for",
"goto",
"if",
"implements",
"import",
"instanceof",
"int",
"interface",
"long",
"native",
"new",
"null",
"package",
"private",
"protected",
"public",
"return",
"short",
"static",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"true",
"try",
"void",
"volatile",
"while"
}; //-- keywords
private JNaming()
{
super();
}
/**
* Returns true if the given String is a Java keyword which
* will cause a problem when used as a variable name
**/
public static boolean isKeyword( String name )
{
if ( name == null ) return false;
for ( int i = 0; i < keywords.length; i++ )
{
if ( keywords[i].equals( name ) ) return true;
}
return false;
} //-- isKeyword
/**
* Returns true if the given String matches the
* production of a valid Java identifier
*
* @param string, the String to check the production of
* @return true if the given String matches the
* production of a valid Java name, otherwise false
**/
public static boolean isValidJavaIdentifier( String string )
{
if ( ( string == null ) || ( string.length() == 0 ) )
return false;
char[] chars = string.toCharArray();
//-- make sure starting character is valid
if ( !Character.isJavaIdentifierStart( chars[0] ) )
return false;
for ( int i = 1; i < chars.length; i++ )
{
if ( !Character.isJavaIdentifierPart( chars[i] ) )
return false;
}
if ( isKeyword( string ) ) return false;
return true;
} //-- isValidJavaIdentifier
} //-- JNaming JParameter.java 0000664 0000000 0000000 00000014126 11666547660 0040250 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JParameter.java 1299 2009-07-24 16:22:01Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* Represents a parameter to a JMethod.
* @author Keith Visco
* @version $Revision: 1299 $ $Date: 2009-07-24 18:22:01 +0200 (ven. 24 juil. 2009) $
**/
public class JParameter
{
/**
* The type associated with this JParameter
**/
private JType type = null;
/**
* The name of this JParameter
**/
private String name = null;
private JAnnotations annotations = null;
/**
* Creates a new JParameter with the given type, and name
* @param type the type to associate with this JParameter
* @param the name of the JParameter
**/
public JParameter( JType type, String name )
throws IllegalArgumentException
{
super();
setType( type );
setName( name );
} //-- JParameter
/**
* Returns the name of the parameter
* @return the name of the parameter
**/
public String getName()
{
return this.name;
} //-- getName
/**
* Returns the parameter type
* @return the parameter type
**/
public JType getType()
{
return this.type;
} //-- getType
/**
* Sets the name of this parameter
* @param name the new name of the parameter
**/
public void setName( String name )
{
this.name = name;
} //-- setName
/**
* Sets the type of this parameter
* @param type the new type of this parameter
**/
public void setType( JType type )
throws IllegalArgumentException
{
if ( type == null )
{
String err = "A Parameter cannot have a null type.";
throw new IllegalArgumentException( err );
}
this.type = type;
} //-- setType
/**
* Returns the String representation of this JParameter. The
* String returns will consist of the String representation
* of the parameter type, followed by the name of the parameter
* @return the String representation of this JParameter
**/
public String toString()
{
StringBuffer sb = new StringBuffer();
if ( annotations != null )
{
sb.append( annotations.toString() );
sb.append( ' ' );
}
sb.append( this.type.toString() );
sb.append( ' ' );
sb.append( this.name );
return sb.toString();
} //-- toString
/**
* @return the annotations
*/
public JAnnotations getAnnotations()
{
return annotations;
}
/**
* @param annotation the annotation to append
*/
public void appendAnnotation( String annotation )
{
if ( annotations == null )
{
annotations = new JAnnotations();
}
annotations.appendAnnotation( annotation );
}
/**
* @param annotations the annotations to set
*/
public void setAnnotations( JAnnotations annotations )
{
this.annotations = annotations;
}
} //-- JParamater JSourceCode.java 0000664 0000000 0000000 00000023225 11666547660 0040363 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999-2001 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JSourceCode.java 1413 2010-02-13 21:23:01Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.modello.ModelloRuntimeException;
import java.util.Vector;
/**
* A class for holding in-memory Java source code.
*
* @author Keith Visco
* @version $Revision: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $
**/
public class JSourceCode
{
/**
* A list of JCodeStatements
**/
private Vector source = null;
/**
* The indent size
**/
private short indentSize = 4;
/**
* The current indent size
**/
private short currentIndent = indentSize;
/**
* Creates an empty JSourceCode
**/
public JSourceCode()
{
super();
source = new Vector();
} //-- JSourceCode
/**
* Creates a JSourceCode and adds the given String
* to it's contents
* @param sourceCode the source to add
**/
public JSourceCode( String sourceCode )
{
this();
this.source.addElement( new JCodeStatement( sourceCode, currentIndent ) );
} //-- JSourceCode
/**
* Adds the given statement to this JSourceCode. The statement
* will be added on a new line.
* @param statement the statement to add
**/
public void add( String statement )
{
JCodeStatement jcs = new JCodeStatement( statement, currentIndent );
source.addElement( jcs );
} //-- add
/**
* Adds the given statement to this JSourceCode. The statement
* will be added on a new line.
* @param statement the statement to add
* @param the indentSize is the size of the indentation to use
* when printing this JSourceCode
* @see #print
* @deprecated this method is not here any mode in castor codegen 1.3rc1
**/
public void add( String statement, short indentSize )
{
JCodeStatement jcs = new JCodeStatement( statement, indentSize );
source.addElement( jcs );
} //-- add
/**
* Adds the given statement to this JSourceCode. The statement
* will be added on a new line and added with increased indent.
* This is a convenience method for the sequence
*
* indent();
* add(statement);
* unindent();
*
* @param statement the statement to add
**/
public void addIndented( String statement )
{
indent();
JCodeStatement jcs = new JCodeStatement( statement, currentIndent );
source.addElement( jcs );
unindent();
} //-- add
/**
* Appends the given String to the last line in this
* JSourceCode
* @param segment the String to append
**/
public void append( String segment )
{
if ( source.isEmpty() )
add( segment );
else
{
JCodeStatement jcs = (JCodeStatement) source.lastElement();
jcs.append( segment );
}
} //-- append(String)
/**
* Clears all the code statements from this JSourceCode
**/
public void clear()
{
source.removeAllElements();
} //-- clear();
/**
* Copies the contents of this JSourceCode into the given JSourceCode
* @param jsc the JSourceCode to copy this JSourceCode into
**/
public void copyInto( JSourceCode jsc )
{
for ( int i = 0; i < source.size(); i++ )
{
jsc.addCodeStatement( (JCodeStatement) source.elementAt( i ) );
}
} //-- copyInto
/**
* Increases the current indent level by 1
**/
public void indent()
{
currentIndent += indentSize;
} //-- indent();
/**
* Returns true if this JSourceCode is empty (ie. no source).
* @return true if this JSourceCode is empty.
**/
public boolean isEmpty()
{
return source.isEmpty();
} //-- isEmpty
/**
* Prints this JSourceCode to the given JSourceWriter
* @param jsw the JSourceWriter to print to
**/
public void print( JSourceWriter jsw )
{
for ( int i = 0; i < source.size(); i++ )
jsw.writeln( source.elementAt( i ).toString() );
} //-- print
/**
* Decreases the indent level by 1
**/
public void unindent()
{
if ( currentIndent == 0 )
{
throw new ModelloRuntimeException( "Cannot unindent: current indent is 0." );
}
currentIndent -= indentSize;
} //-- unindent
/**
* Returns the String representation of this JSourceCode
* @return the String representation of this JSourceCode
**/
public String toString()
{
StringBuffer sb = new StringBuffer();
String lineSeparator = System.getProperty( "line.separator" );
for ( int i = 0; i < source.size(); i++ )
{
sb.append( source.elementAt( i ).toString() );
sb.append( lineSeparator );
}
return sb.toString();
} //-- toString
/**
* Adds the given JCodeStatement to this JSourceCode
* @param jcs the JCodeStatement to add
**/
private void addCodeStatement( JCodeStatement jcs )
{
short indent = (short) ( jcs.getIndent() + currentIndent - JCodeStatement.DEFAULT_INDENTSIZE );
source.addElement( new JCodeStatement( jcs.getStatement(), indent ) );
} //-- addCodeStatement(JCodeStatement)
} //-- JSourceCode
/**
* Represents a line of code, used by JSourceCode class
* @author Keith Visco
**/
class JCodeStatement
{
private StringBuffer value = null;
static public short DEFAULT_INDENTSIZE = 4;
private short indentSize = DEFAULT_INDENTSIZE;
JCodeStatement()
{
super();
value = new StringBuffer();
} //-- JCodeStatement
JCodeStatement( String statement )
{
this();
this.value.append( statement );
} //-- JCodeStatement
JCodeStatement( String statement, short indentSize )
{
this( statement );
this.indentSize = indentSize;
} //-- JCodeStatement
void append( String segment )
{
value.append( segment );
}
short getIndent()
{
return indentSize;
} //-- getIndent
String getStatement()
{
return value.toString();
} //-- getStatement
public String toString()
{
if ( value.length() == 0 )
{
return "";
}
StringBuffer sb = new StringBuffer( indentSize + value.length() );
for ( int i = 0; i < indentSize; i++ ) sb.append( ' ' );
sb.append( value.toString() );
return sb.toString();
}
} //-- JCodeStatement
JSourceWriter.java 0000664 0000000 0000000 00000036542 11666547660 0040773 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JSourceWriter.java 1292 2009-07-18 21:26:59Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.Writer;
/**
* The writer used by the modello classes
* @author Keith Visco
* @version $Revision: 1292 $ $Date: 2009-07-18 23:26:59 +0200 (sam. 18 juil. 2009) $
**/
public class JSourceWriter extends Writer
{
/**
* The default character to use for indentation
**/
public static final char DEFAULT_CHAR = ' ';
/**
* The default indentation size
**/
public static final short DEFAULT_SIZE = 4;
/**
* The line separator to use for the writeln methods
**/
private String lineSeparator = System.getProperty( "line.separator" );
/**
* Flag for indicating whether we need to add
* the whitespace to beginning of next write
* call
**/
private boolean addIndentation = true;
/**
* A flag indicating whether this JSourceWriter should perform
* autoflush at the end of a new line
**/
private boolean autoflush = false;
/**
* The tab (indentation) size
**/
private short tabSize = DEFAULT_SIZE;
/**
* The tab representation
**/
private char[] tab;
/**
* The character to use for indentation
**/
private char tabChar = DEFAULT_CHAR;
/**
* The current tab level
**/
private short tabLevel = 0;
/**
* The writer to send all output to
**/
private Writer out = null;
/**
* Creates a new JSourceWriter
* @param out the Writer to write the actual output to
**/
public JSourceWriter( Writer out )
{
this( out, DEFAULT_SIZE, DEFAULT_CHAR, false );
} //-- JSourceWriter
/**
* Creates a new JSourceWriter
* @param out the Writer to write the actual output to
* @param autoflush a boolean indicating whether or not to
* perform automatic flush at the end of a line
**/
public JSourceWriter( Writer out, boolean autoflush )
{
this( out, DEFAULT_SIZE, DEFAULT_CHAR, autoflush );
} //-- JSourceWriter
/**
* Creates a new JSourceWriter
* @param out the Writer to write the actual output to
* @param tabSize the size of each indentation
* @param autoflush a boolean indicating whether or not to
* perform automatic flush at the end of a line
**/
public JSourceWriter
( Writer out, short tabSize, boolean autoflush )
{
this( out, tabSize, DEFAULT_CHAR, autoflush );
} //-- JSourceWriter
/**
* Creates a new JSourceWriter
* @param out the Writer to write the actual output to
* @param tabSize the size of each indentation
* @param tabChar the character to use for indentation
* @param autoflush a boolean indicating whether or not to
* perform automatic flush at the end of a line
**/
public JSourceWriter
( Writer out, short tabSize, char tabChar, boolean autoflush )
{
this.out = out;
this.autoflush = autoflush;
this.tabChar = tabChar;
this.tabSize = tabSize;
createTab();
} //-- JSourceWriter
/**
* Returns the line separator being used by this JSourceWriter
* @return the line separator being used by this JSourceWriter
**/
public String getLineSeparator()
{
return lineSeparator;
} //-- getLineSeparator
/**
* Increases the indentation level by 1
**/
public void indent()
{
++tabLevel;
} //-- increaseIndent
/**
* Checks to see if the cursor is positioned on a new line
* @return true if the cursor is at the start of a new line, otherwise false
**/
public boolean isNewline()
{
//-- if we need to add indentation, we are on a new line
return addIndentation;
} //-- isNewline
/**
* Sets the line separator to use at the end of each line
* @param lineSeparator the String to use as a line
* separator.
*
* Typically a line separator will be one of the following:
*
* "\r\n" for MS Windows
* "\n" for UNIX
* "\r" for Macintosh
**/
public void setLineSeparator( String lineSeparator )
{
this.lineSeparator = lineSeparator;
} //-- setLineSeparator
/**
* Decreases the indentation level by 1
**/
public void unindent()
{
if ( tabLevel > 0 ) --tabLevel;
} //-- decreaseIndent
//----------------------------/
//- Additional write methods -/
//----------------------------/
public void write( float f )
{
write( String.valueOf( f ) );
} //-- write(float)
public void write( long l )
{
write( String.valueOf( l ) );
} //-- write(long)
public void write( double d )
{
write( String.valueOf( d ) );
} //-- write(double)
public void write( Object obj )
{
write( obj.toString() );
} //-- write(Object)
public void write( boolean b )
{
write( String.valueOf( b ) );
} //-- write(boolean)
//- writeln() methods
public void writeln()
{
synchronized ( lock )
{
linefeed();
addIndentation = true;
}
} //-- writeln
public void writeln( float f )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( String.valueOf( f ) );
}
catch ( java.io.IOException ioe )
{
}
;
linefeed();
addIndentation = true;
}
} //-- writeln(float)
public void writeln( long l )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( String.valueOf( l ) );
}
catch ( java.io.IOException ioe )
{
}
;
linefeed();
addIndentation = true;
}
} //-- writeln(long)
public void writeln( int i )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( String.valueOf( i ) );
}
catch ( java.io.IOException ioe )
{
}
;
linefeed();
addIndentation = true;
}
} //-- writeln(int)
public void writeln( double d )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( String.valueOf( d ) );
}
catch ( java.io.IOException ioe )
{
}
;
linefeed();
addIndentation = true;
}
} //-- writeln(double)
public void writeln( Object obj )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( obj.toString() );
}
catch ( java.io.IOException ioe )
{
}
;
linefeed();
addIndentation = true;
}
} //-- writeln(Object)
public void writeln( String string )
{
synchronized ( lock )
{
if ( string.length() > 0 )
{
ensureIndent();
try
{
out.write( string );
}
catch ( java.io.IOException ioe )
{
}
}
linefeed();
addIndentation = true;
}
} //-- writeln(String)
public void writeln( char[] chars )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( chars );
}
catch ( java.io.IOException ioe )
{
}
;
linefeed();
addIndentation = true;
}
} //-- writeln(char[])
public void writeln( boolean b )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( String.valueOf( b ) );
}
catch ( java.io.IOException ioe )
{
}
;
linefeed();
addIndentation = true;
}
} //-- writeln(boolean)
public void writeln( char c )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( c );
}
catch ( java.io.IOException ioe )
{
}
;
linefeed();
addIndentation = true;
}
} //-- writeln(char)
//-----------------------/
//- Methods from Writer -/
//-----------------------/
public void close()
{
try
{
out.close();
}
catch ( java.io.IOException ioe )
{
}
;
} //-- close
public void flush()
{
try
{
out.flush();
}
catch ( java.io.IOException ioe )
{
}
;
} //-- flush
public void write( String s, int off, int len )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( s, off, len );
}
catch ( java.io.IOException ioe )
{
}
;
if ( autoflush ) flush();
}
} //-- write
public void write( String s )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( s );
}
catch ( java.io.IOException ioe )
{
}
;
if ( autoflush ) flush();
}
} //-- write
public void write( char[] buf )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( buf );
}
catch ( java.io.IOException ioe )
{
}
;
if ( autoflush ) flush();
}
} //-- write
public void write( int c )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( c );
}
catch ( java.io.IOException ioe )
{
}
;
if ( autoflush ) flush();
}
} //-- write
public void write( char[] buf, int off, int len )
{
synchronized ( lock )
{
ensureIndent();
try
{
out.write( buf, off, len );
}
catch ( java.io.IOException ioe )
{
}
;
if ( autoflush ) flush();
}
} //-- write
//---------------------/
//- Protected Methods -/
//---------------------/
protected short getIndentLevel()
{
return tabLevel;
}
/**
* Returns the current indent size (getIndentLevel()*tabSize);
* @return the current indent size
**/
protected short getIndentSize()
{
return (short) ( tabLevel * tabSize );
} //-- getIndentSize
protected char getIndentChar()
{
return tabChar;
}
protected void writeIndent()
{
try
{
for ( int i = 0; i < tabLevel; i++ ) out.write( tab );
}
catch ( java.io.IOException ioe )
{
}
;
} //-- writeIndent
//-------------------/
//- Private Methods -/
//-------------------/
private void ensureIndent()
{
if ( addIndentation )
{
writeIndent();
addIndentation = false;
}
} //-- ensureIndent
/**
* writes the line separator character to the writer
**/
private void linefeed()
{
try
{
out.write( lineSeparator );
}
catch ( java.io.IOException ioe )
{
}
;
} //-- linefeed
/**
* Creates the tab from the tabSize and the tabChar
**/
private void createTab()
{
tab = new char[tabSize];
for ( int i = 0; i < tabSize; i++ )
{
tab[i] = tabChar;
}
} //-- createTab
} //-- JSourceWriter
JStructure.java 0000664 0000000 0000000 00000066221 11666547660 0040333 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001-2002 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JStructure.java 1413 2010-02-13 21:23:01Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.File;
import java.util.Enumeration;
import java.util.Vector;
import org.codehaus.plexus.util.WriterFactory;
/**
* This class represents the basic Java "structure" for a Java
* source file. This is the base class for JClass and JInterface.
*
* This is a useful utility when creating in memory source code.
* The code in this package was modelled after the Java Reflection API
* as much as possible to reduce the learning curve.
*
* @author Martin Skopp
* @author Keith Visco
* @version $Revision: 1413 $ $Date: 2010-02-13 22:23:01 +0100 (sam. 13 févr. 2010) $
*/
public abstract class JStructure extends JType
{
/**
* The Id for Source control systems
* I needed to separate this line to prevent CVS from
* expanding it here! ;-)
*/
static final String DEFAULT_HEADER
= "$" + "Id$";
/**
* The source control version for listed in the JavaDoc
* I needed to separate this line to prevent CVS from
* expanding it here! ;-)
*/
static final String version = "$" + "Revision$ $" + "Date$";
/**
* The source header
*/
private JComment header = null;
/**
* List of imported classes and packages
*/
private Vector imports = null;
/**
* The set of interfaces implemented/extended by this JStructure
*/
private Vector interfaces = null;
/**
* The Javadoc for this JStructure
*/
private JDocComment jdc = null;
/**
* The JModifiers for this JStructure, which allows us to
* change the resulting qualifiers
*/
private JModifiers modifiers = null;
/**
* The package to which this JStructure belongs
*/
private String packageName = null;
private JAnnotations annotations = null;
/**
* Creates a new JStructure with the given name.
*
* @param name the name of the JStructure.
* @throws java.lang.IllegalArgumentException when the given name
* is not a valid Class name.
*/
protected JStructure( String name )
throws IllegalArgumentException
{
super( name );
//-- verify name is a valid java class name
if ( !isValidClassName( name ) )
{
String lname = getLocalName();
String err = "'" + lname + "' is ";
if ( JNaming.isKeyword( lname ) )
err += "a reserved word and may not be used as "
+ " a class name.";
else
err += "not a valid Java identifier.";
throw new IllegalArgumentException( err );
}
this.packageName = getPackageFromClassName( name );
imports = new Vector();
interfaces = new Vector();
jdc = new JDocComment();
modifiers = new JModifiers();
//-- initialize default Java doc
jdc.addDescriptor( JDocDescriptor.createVersionDesc( version ) );
} //-- JStructure
/**
* Adds the given JField to this JStructure.
*
* This method is implemented by subclasses and
* should only accept the proper fields for the
* subclass otherwise an IllegalArgumentException
* will be thrown. For example a JInterface will
* only accept static fields.
*
* @param jField, the JField to add
* @exception java.lang.IllegalArgumentException when the given
* JField has a name of an existing JField
*/
public abstract void addField( JField jField )
throws IllegalArgumentException;
/**
* Adds the given JMember to this JStructure.
*
* This method is implemented by subclasses and
* should only accept the proper types for the
* subclass otherwise an IllegalArgumentException
* will be thrown.
*
* @param jMember the JMember to add to this JStructure.
* @throws java.lang.IllegalArgumentException when the given
* JMember has the same name of an existing JField
* or JMethod respectively.
*/
public abstract void addMember( JMember jMember )
throws IllegalArgumentException;
/**
* Adds the given import to this JStructure
*
* @param the className of the class to import.
*/
public void addImport( String className )
{
if ( className == null ) return;
if ( className.length() == 0 ) return;
//-- getPackageName
String pkgName = getPackageFromClassName( className );
if ( pkgName != null )
{
if ( pkgName.equals( this.packageName ) ) return;
//-- XXX: Fix needed for this...
//-- This may cause issues if the current package
//-- defines any classes that have the same name
//-- name as the java.lang package.
if ( "java.lang".equals( pkgName ) ) return;
//-- for readabilty keep import list sorted, and make sure
//-- we do not include more than one of the same import
for ( int i = 0; i < imports.size(); i++ )
{
String imp = (String) imports.elementAt( i );
if ( imp.equals( className ) ) return;
if ( imp.compareTo( className ) > 0 )
{
imports.insertElementAt( className, i );
return;
}
}
imports.addElement( className );
}
} //-- addImport
/**
* Adds the given interface to the list of interfaces this
* JStructure inherits method declarations from, and either
* implements (JClass) or extends (JInterface).
*
* @param interfaceName the name of the interface to "inherit"
* method declarations from.
*/
public void addInterface( String interfaceName )
{
if ( !interfaces.contains( interfaceName ) )
interfaces.addElement( interfaceName );
} //-- addInterface
/**
* Adds the given interface to the list of interfaces this
* JStructure inherits method declarations from, and either
* implements (JClass) or extends (JInterface).
*
* @param jInterface the JInterface to inherit from.
*/
public void addInterface( JInterface jInterface )
{
if ( jInterface == null ) return;
String interfaceName = jInterface.getName();
if ( !interfaces.contains( interfaceName ) )
{
interfaces.addElement( interfaceName );
}
} //-- addInterface
/**
* Adds the given JMethodSignature to this JClass
*
* @param jMethodSig the JMethodSignature to add.
* @throws java.lang.IllegalArgumentException when the given
* JMethodSignature conflicts with an existing
* method signature.
*/
/*
public void addMethod(JMethodSignature jMethodSig)
throws IllegalArgumentException
{
if (jMethodSig == null) {
String err = "The JMethodSignature cannot be null.";
throw new IllegalArgumentException(err);
}
//-- XXXX: check method name and signatures *add later*
//-- keep method list sorted for esthetics when printing
//-- START SORT :-)
boolean added = false;
short modifierVal = 0;
JModifiers modifiers = jMethodSig.getModifiers();
for (int i = 0; i < methods.size(); i++) {
JMethodSignature tmp = (JMethodSignature) methods.elementAt(i);
//-- first compare modifiers
if (tmp.getModifiers().isProtected()) {
if (!modifiers.isProtected()) {
methods.insertElementAt(jMethodSig, i);
added = true;
break;
}
}
//-- compare names
if (jMethodSig.getName().compareTo(tmp.getName()) < 0) {
methods.insertElementAt(jMethodSig, i);
added = true;
break;
}
}
//-- END SORT
if (!added) methods.addElement(jMethodSig);
//-- check parameter packages to make sure we have them
//-- in our import list
String[] pkgNames = jMethodSig.getParameterClassNames();
for (int i = 0; i < pkgNames.length; i++) {
addImport(pkgNames[i]);
}
//-- check return type to make sure it's included in the
//-- import list
JType jType = jMethodSig.getReturnType();
if (jType != null) {
while (jType.isArray())
jType = jType.getComponentType();
if (!jType.isPrimitive())
addImport(jType.getName());
}
//-- check exceptions
JClass[] exceptions = jMethodSig.getExceptions();
for (int i = 0; i < exceptions.length; i++) {
addImport(exceptions[i].getName());
}
} //-- addMethod
*/
/**
* Returns the field with the given name, or null if no field
* was found with the given name.
*
* @param name the name of the field to return.
* @return the field with the given name, or null if no field
* was found with the given name.
*/
public abstract JField getField( String name );
/**
* Returns an array of all the JFields of this JStructure
*
* @return an array of all the JFields of this JStructure
*/
public abstract JField[] getFields();
/**
* Returns the name of the file that this JStructure would be
* printed to, given a call to #print.
*
* @param destDir the destination directory. This may be null.
* @return the name of the file that this JInterface would be
* printed as, given a call to #print.
*/
public String getFilename( String destDir )
{
String filename = getLocalName() + ".java";
//-- Convert Java package to path string
String javaPackagePath = "";
if ( ( packageName != null ) && ( packageName.length() > 0 ) )
{
javaPackagePath = packageName.replace( '.', File.separatorChar );
}
//-- Create fully qualified path (including 'destDir') to file
File pathFile;
if ( destDir == null )
pathFile = new File( javaPackagePath );
else
pathFile = new File( destDir, javaPackagePath );
if ( !pathFile.exists() )
{
pathFile.mkdirs();
}
//-- Prefix filename with path
if ( pathFile.toString().length() > 0 )
filename = pathFile.toString() + File.separator + filename;
return filename;
} //-- getFilename
/**
* Returns the JComment header to display at the top of the source file
* for this JStructure, or null if no header was set.
*
* @return the JComment header or null if none exists.
*/
public JComment getHeader()
{
return this.header;
} //-- getHeader
/**
* Returns an Enumeration of imported package and
* class names for this JStructure.
*
* @return the Enumeration of imports. May be empty.
*/
public Enumeration getImports()
{
return imports.elements();
} //-- getImports
/**
* Returns an Enumeration of interface names that this
* JStructure inherits from.
*
* @return the Enumeration of interface names for this
* JStructure. May be empty.
*/
public Enumeration getInterfaces()
{
return interfaces.elements();
} //-- getInterfaces
/**
* Returns the Java Doc comment for this JStructure
*
* @return the JDocComment for this JStructure
*/
public JDocComment getJDocComment()
{
return jdc;
} //-- getJDocComment
/**
* Returns an array of all the JMethodSignatures of this JInterface.
*
* @return an array of all the JMethodSignatures of this JInterface.
*/
/*
public JMethodSignature[] getMethods() {
JMethodSignature[] marray = new JMethodSignature[methods.size()];
methods.copyInto(marray);
return marray;
} //-- getMethods
*/
/**
* Returns the JMethodSignature with the given name,
* and occuring at or after the given starting index.
*
* @param name the name of the JMethodSignature to return.
* @param startIndex the starting index to begin searching
* from.
* @return the JMethodSignature, or null if not found.
*/
/*
public JMethodSignature getMethod(String name, int startIndex) {
for (int i = startIndex; i < methods.size(); i++) {
JMethodSignature jMethod = (JMethodSignature)methods.elementAt(i);
if (jMethod.getName().equals(name)) return jMethod;
}
return null;
} //-- getMethod
*/
/**
* Returns the JMethodSignature at the given index.
*
* @param index the index of the JMethodSignature to return.
* @return the JMethodSignature at the given index.
*/
/*
public JMethodSignature getMethod(int index) {
return (JMethodSignature)methods.elementAt(index);
} //-- getMethod
*/
/**
* Returns the JModifiers which allows the qualifiers to be changed.
*
* @return the JModifiers for this JStructure.
*/
public JModifiers getModifiers()
{
return modifiers;
} //-- getModifiers
/**
* Returns the name of the package that this JStructure is a member
* of.
*
* @return the name of the package that this JStructure is a member
* of, or null if there is no current package name defined.
*/
public String getPackageName()
{
return this.packageName;
} //-- getPackageName
/**
* Returns the name of the interface.
*
* @param stripPackage a boolean that when true indicates that only
* the local name (no package) should be returned.
* @return the name of the class.
*/
public String getName( boolean stripPackage )
{
String name = super.getName();
if ( stripPackage )
{
int period = name.lastIndexOf( "." );
if ( period > 0 )
name = name.substring( period + 1 );
}
return name;
} //-- getName
/**
* Returns true if the given classname exists in the imports
* of this JStructure
*
* @param classname the class name to check for
* @return true if the given classname exists in the imports list
*/
public boolean hasImport( String classname )
{
return imports.contains( classname );
} //-- hasImport
public boolean removeImport( String className )
{
boolean result = false;
if ( className == null ) return result;
if ( className.length() == 0 ) return result;
result = imports.removeElement( className );
return result;
} //-- removeImport
public boolean isAbstract()
{
return modifiers.isAbstract();
}
public static boolean isValidClassName( String name )
{
if ( name == null ) return false;
//-- ignore package information, for now
int period = name.lastIndexOf( "." );
if ( period > 0 )
name = name.substring( period + 1 );
return JNaming.isValidJavaIdentifier( name );
} //-- isValidClassName
/**
* Prints the source code for this JStructure in the current
* working directory. Sub-directories will be created if necessary
* for the package.
*/
public void print()
{
print( (String) null, (String) null );
} //-- printSrouce
/**
* Prints the source code for this JStructure to the destination
* directory. Sub-directories will be created if necessary for the
* package.
*
* @param lineSeparator the line separator to use at the end of each line.
* If null, then the default line separator for the runtime platform will
* be used.
*/
public void print( String destDir, String lineSeparator )
{
// String name = getLocalName();
//-- open output file
String filename = getFilename( destDir );
File file = new File( filename );
JSourceWriter jsw = null;
try
{
jsw = new JSourceWriter( WriterFactory.newPlatformWriter( file ) );
}
catch ( java.io.IOException ioe )
{
System.out.println( "unable to create class file: " + filename );
return;
}
if ( lineSeparator == null )
{
lineSeparator = System.getProperty( "line.separator" );
}
jsw.setLineSeparator( lineSeparator );
print( jsw );
jsw.close();
} //-- print
/**
* Prints the source code for this JStructure to the given
* JSourceWriter.
*
* @param jsw the JSourceWriter to print to.
*/
public abstract void print( JSourceWriter jsw );
/**
* A utility method that prints the header to the given
* JSourceWriter
*
* @param jsw the JSourceWriter to print to.
*/
public void printHeader( JSourceWriter jsw )
{
if ( jsw == null )
{
throw new IllegalArgumentException( "argument 'jsw' should not be null." );
}
//-- write class header
JComment header = getHeader();
if ( header != null )
header.print( jsw );
else
{
jsw.writeln( "/*" );
jsw.writeln( " * " + DEFAULT_HEADER );
jsw.writeln( " */" );
}
jsw.writeln();
jsw.flush();
} //-- printHeader
/**
* A utility method that prints the imports to the given
* JSourceWriter
*
* @param jsw the JSourceWriter to print to.
*/
public void printImportDeclarations( JSourceWriter jsw )
{
if ( jsw == null )
{
throw new IllegalArgumentException( "argument 'jsw' should not be null." );
}
//-- print imports
if ( imports.size() > 0 )
{
jsw.writeln( " //---------------------------------/" );
jsw.writeln( " //- Imported classes and packages -/" );
jsw.writeln( "//---------------------------------/" );
jsw.writeln();
Enumeration e = imports.elements();
while ( e.hasMoreElements() )
{
jsw.write( "import " );
jsw.write( e.nextElement() );
jsw.writeln( ';' );
}
jsw.writeln();
jsw.flush();
}
} //-- printImportDeclarations
/**
* A utility method that prints the packageDeclaration to
* the given JSourceWriter
*
* @param jsw the JSourceWriter to print to.
*/
public void printPackageDeclaration( JSourceWriter jsw )
{
if ( jsw == null )
{
throw new IllegalArgumentException( "argument 'jsw' should not be null." );
}
//-- print package name
if ( ( packageName != null ) && ( packageName.length() > 0 ) )
{
jsw.write( "package " );
jsw.write( packageName );
jsw.writeln( ';' );
jsw.writeln();
}
jsw.flush();
} //-- printPackageDeclaration
/**
* Prints the source code for this JStructure to the given
* JSourceWriter.
*
* @param jsw the JSourceWriter to print to.
*
public abstract void print(JSourceWriter jsw);
StringBuffer buffer = new StringBuffer();
printHeader();
printPackageDeclaration();
printImportDeclarations();
//------------/
//- Java Doc -/
//------------/
jdc.print(jsw);
//-- print class information
//-- we need to add some JavaDoc API adding comments
buffer.setLength(0);
if (modifiers.isPrivate()) {
buffer.append("private ");
}
else if (modifiers.isPublic()) {
buffer.append("public ");
}
if (modifiers.isAbstract()) {
buffer.append("abstract ");
}
buffer.append("interface ");
buffer.append(getLocalName());
buffer.append(' ');
if (interfaces.size() > 0) {
boolean endl = false;
if (interfaces.size() > 1) {
jsw.writeln(buffer.toString());
buffer.setLength(0);
endl = true;
}
buffer.append("extends ");
for (int i = 0; i < interfaces.size(); i++) {
if (i > 0) buffer.append(", ");
buffer.append(interfaces.elementAt(i));
}
if (endl) {
jsw.writeln(buffer.toString());
buffer.setLength(0);
}
else buffer.append(' ');
}
buffer.append('{');
jsw.writeln(buffer.toString());
buffer.setLength(0);
jsw.writeln();
jsw.indent();
//-- print method signatures
if (methods.size() > 0) {
jsw.writeln();
jsw.writeln(" //-----------/");
jsw.writeln(" //- Methods -/");
jsw.writeln("//-----------/");
jsw.writeln();
}
for (int i = 0; i < methods.size(); i++) {
JMethodSignature signature = (JMethodSignature) methods.elementAt(i);
signature.print(jsw);
jsw.writeln(';');
}
jsw.unindent();
jsw.writeln('}');
jsw.flush();
jsw.close();
} //-- printSource
*/
/**
* Sets the header comment for this JStructure
*
* @param comment the comment to display at the top of the source file
* when printed
*/
public void setHeader( JComment comment )
{
this.header = comment;
} //-- setHeader
/**
* Allows changing the package name of this JStructure
*
* @param packageName the package name to use
* @deprecated removed in future version of javasource
*/
public void setPackageName( String packageName )
{
this.packageName = packageName;
changePackage( packageName );
} //-- setPackageName
//---------------------/
//- Protected Methods -/
//---------------------/
protected int getInterfaceCount()
{
return interfaces.size();
}
/**
* Prints the given source string to the JSourceWriter using the given prefix at
* the beginning of each new line.
*
* @param prefix the prefix for each new line.
* @param source the source code to print
* @param jsw the JSourceWriter to print to.
*/
protected static void printlnWithPrefix( String prefix, String source, JSourceWriter jsw )
{
jsw.write( prefix );
if ( source == null ) return;
char[] chars = source.toCharArray();
int lastIdx = 0;
for ( int i = 0; i < chars.length; i++ )
{
char ch = chars[i];
if ( ch == '\n' )
{
//-- free buffer
jsw.write( chars, lastIdx, ( i - lastIdx ) + 1 );
lastIdx = i + 1;
if ( i < chars.length )
{
jsw.write( prefix );
}
}
}
//-- free buffer
if ( lastIdx < chars.length )
{
jsw.write( chars, lastIdx, chars.length - lastIdx );
}
jsw.writeln();
} //-- printlnWithPrefix
/**
* Returns the package name from the given class name
*/
protected static String getPackageFromClassName( String className )
{
int idx = -1;
if ( ( idx = className.lastIndexOf( '.' ) ) > 0 )
{
return className.substring( 0, idx );
}
return null;
} //-- getPackageFromClassName
/**
* @return the annotations
*/
public JAnnotations getAnnotations()
{
return annotations;
}
/**
* @param annotation the annotation to append
*/
public void appendAnnotation( String annotation )
{
if ( annotations == null )
{
annotations = new JAnnotations();
}
annotations.appendAnnotation( annotation );
}
/**
* @param annotations the annotations to set
*/
public void setAnnotations( JAnnotations annotations )
{
this.annotations = annotations;
}
} //-- JStructure
JType.java 0000664 0000000 0000000 00000016335 11666547660 0037255 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource /**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Intalio, Inc. For written permission,
* please contact info@codehaus.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Intalio, Inc. Exolab is a registered
* trademark of Intalio, Inc.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.codehaus.org/).
*
* THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 1999 (C) Intalio, Inc. All Rights Reserved.
*
* $Id: JType.java 1041 2008-12-21 22:06:18Z hboutemy $
*/
package org.codehaus.modello.plugin.java.javasource;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* @author Keith Visco
* @version $Revision: 1041 $ $Date: 2008-12-21 23:06:18 +0100 (dim. 21 déc. 2008) $
**/
public class JType
{
public static final JType BOOLEAN = new JType( "boolean" );
public static final JType BYTE = new JType( "byte" );
public static final JType CHAR = new JType( "char" );
public static final JType DOUBLE = new JType( "double" );
public static final JType FLOAT = new JType( "float" );
public static final JType INT = new JType( "int" );
public static final JType LONG = new JType( "long" );
public static final JType SHORT = new JType( "short" );
private String name = null;
private boolean _isArray = false;
/**
* used for array types
**/
private JType _componentType = null;
/**
* Creates a new JType with the given name
* @param the name of the type
**/
public JType( String name )
{
super();
this.name = name;
} //-- JType
/**
* Creates a JType Object representing an array of the current
* JType.
* @return the new JType which is represents an array.
* @deprecated removed in javasource 1.3rc1, replaced by JArrayType
**/
public final JType createArray()
{
JType jType = new JType( getName() );
jType._isArray = true;
jType._componentType = this;
return jType;
} //-- createArray
/**
* If this JType is an array this method will returns the component type
* of the array, otherwise null will be returned.
* @return the component JType if this JType is an array, otherwise null.
**/
public JType getComponentType()
{
return _componentType;
} //-- getComponentType
public String getLocalName()
{
//-- use getName method in case it's been overloaded
String name = getName();
if ( name == null ) return null;
int idx = name.lastIndexOf( '.' );
if ( idx >= 0 )
{
name = name.substring( idx + 1 );
}
return name;
} //-- getLocalName
public String getName()
{
return this.name;
} //-- getName
/**
* Checks to see if this JType represents an array.
* @return true if this JType represents an array, otherwise false
**/
public final boolean isArray()
{
return _isArray;
}
/**
* Checks to see if this JType represents a primitive
* @return true if this JType represents a primitive, otherwise false
**/
public boolean isPrimitive()
{
return ( ( this == BOOLEAN ) ||
( this == BYTE ) ||
( this == CHAR ) ||
( this == DOUBLE ) ||
( this == FLOAT ) ||
( this == INT ) ||
( this == LONG ) ||
( this == SHORT ) );
} //-- isPrimitive
/**
* Returns the String representation of this JType, which is
* simply the name of this type.
* @return the String representation of this JType
**/
public String toString()
{
if ( _isArray )
return _componentType.toString() + "[]";
else
return this.name;
} //-- toString
//---------------------/
//- Protected methods -/
//---------------------/
/**
* Allows subtypes, such as JClass to alter the package to which
* this JType belongs
* @param newPackage the new package to which this JType belongs
*
* Note: The package name cannot be changed on a primitive type.
**/
protected void changePackage( String newPackage )
{
if ( this.name == null ) return;
if ( this.isPrimitive() ) return;
String localName = null;
int idx = name.lastIndexOf( '.' );
if ( idx >= 0 )
localName = this.name.substring( idx + 1 );
else
localName = this.name;
if ( ( newPackage == null ) || ( newPackage.length() == 0 ) )
this.name = localName;
else
this.name = newPackage + "." + localName;
} //-- changePackage
} //-- JType
0000775 0000000 0000000 00000000000 11666547660 0034765 5 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata JavaAssociationMetadata.java 0000664 0000000 0000000 00000006671 11666547660 0042361 0 ustar 00root root 0000000 0000000 modello1.4-1.4.1/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata package org.codehaus.modello.plugin.java.metadata;
/*
* Copyright (c) 2004, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.modello.metadata.AssociationMetadata;
import java.util.ArrayList;
import java.util.List;
/**
* @author Emmanuel Venisse
* @version $Id: JavaAssociationMetadata.java 1413 2010-02-13 21:23:01Z hboutemy $
*/
public class JavaAssociationMetadata
implements AssociationMetadata
{
public static final String ID = JavaAssociationMetadata.class.getName();
public static final String LAZY_INIT = "lazy";
public static final String CONSTRUCTOR_INIT = "constructor";
public static final String FIELD_INIT = "field";
public final static List INIT_TYPES;
static
{
INIT_TYPES = new ArrayList();
INIT_TYPES.add( LAZY_INIT );
INIT_TYPES.add( CONSTRUCTOR_INIT );
INIT_TYPES.add( FIELD_INIT );
}
public static final String CLONE_SHALLOW = "shallow";
public static final String CLONE_DEEP = "deep";
public final static List