From 6fcec3e16a3552a63435bf3796f47109698f8f6a Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Tue, 17 May 2022 01:13:37 +0200 Subject: [PATCH 1/2] Require Maven 3.2.5+ --- modello-maven-plugin/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modello-maven-plugin/pom.xml b/modello-maven-plugin/pom.xml index 0e3cf8bac..a29f0c755 100644 --- a/modello-maven-plugin/pom.xml +++ b/modello-maven-plugin/pom.xml @@ -22,7 +22,7 @@ 3.6.4 - 3.1.1 + 3.2.5 diff --git a/pom.xml b/pom.xml index fcba6369c..ed1493f85 100644 --- a/pom.xml +++ b/pom.xml @@ -422,7 +422,7 @@ ${java.version} - 3.0.5 + 3.2.5 From 392cc55489d7011dec9a0435dfb979c51ba2c4f9 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Tue, 17 May 2022 01:49:03 +0200 Subject: [PATCH 2/2] automatic code cleanup --- .../java/org/codehaus/modello/Modello.java | 4 +- .../codehaus/modello/core/io/ModelReader.java | 26 ++-- .../metadata/AbstractMetadataPlugin.java | 2 +- .../codehaus/modello/model/BaseElement.java | 6 +- .../org/codehaus/modello/model/Model.java | 4 +- .../codehaus/modello/model/ModelClass.java | 10 +- .../codehaus/modello/model/ModelDefault.java | 2 +- .../modello/model/ModelInterface.java | 4 +- .../org/codehaus/modello/model/ModelType.java | 14 +- .../org/codehaus/modello/model/Version.java | 7 +- .../plugin/AbstractModelloGenerator.java | 16 +- .../modello/plugin/AbstractPluginManager.java | 2 +- .../maven/AbstractModelloGeneratorMojo.java | 13 +- .../maven/ModelloConvertersMojoTest.java | 6 +- .../modello/maven/ModelloJavaMojoTest.java | 6 +- .../plugin/converters/ConverterGenerator.java | 39 ++--- .../plugin/dom4j/Dom4jReaderGenerator.java | 9 +- .../plugin/dom4j/Dom4jWriterGenerator.java | 14 +- .../plugin/dom4j/Dom4jGeneratorTest.java | 2 +- .../jackson/JacksonReaderGenerator.java | 8 +- .../jackson/JacksonWriterGenerator.java | 6 +- .../java/AbstractJavaModelloGenerator.java | 14 +- .../plugin/java/JavaModelloGenerator.java | 30 ++-- .../plugin/java/javasource/JAnnotations.java | 4 +- .../plugin/java/javasource/JClass.java | 43 +++--- .../plugin/java/javasource/JComment.java | 14 +- .../plugin/java/javasource/JCompUnit.java | 18 +-- .../plugin/java/javasource/JConstructor.java | 19 ++- .../plugin/java/javasource/JDocComment.java | 20 +-- .../java/javasource/JDocDescriptor.java | 2 +- .../plugin/java/javasource/JField.java | 21 ++- .../plugin/java/javasource/JInterface.java | 11 +- .../plugin/java/javasource/JMember.java | 14 +- .../plugin/java/javasource/JMethod.java | 16 +- .../java/javasource/JMethodSignature.java | 27 ++-- .../plugin/java/javasource/JNaming.java | 3 +- .../plugin/java/javasource/JParameter.java | 2 +- .../plugin/java/javasource/JSourceCode.java | 21 ++- .../plugin/java/javasource/JSourceWriter.java | 61 +++----- .../plugin/java/javasource/JStructure.java | 142 ++---------------- .../modello/plugin/java/javasource/JType.java | 4 +- .../metadata/JavaAssociationMetadata.java | 4 +- .../java/metadata/JavaClassMetadata.java | 2 +- .../modello/plugin/java/Permission.java | 4 +- .../codehaus/modello/plugin/java/Role.java | 16 +- .../java/javasource/JavaSourceTest.java | 4 +- .../plugin/jdom/JDOMWriterGenerator.java | 2 +- .../jsonschema/JsonSchemaGenerator.java | 5 +- .../plugin/sax/SaxWriterGenerator.java | 28 +--- .../modello/plugin/sax/SaxGeneratorTest.java | 2 +- .../snakeyaml/SnakeYamlReaderGenerator.java | 8 +- .../snakeyaml/SnakeYamlWriterGenerator.java | 6 +- .../plugin/stax/AbstractStaxGenerator.java | 2 +- .../modello/plugin/stax/GeneratorNode.java | 6 +- .../plugin/stax/StaxReaderGenerator.java | 22 +-- .../plugin/stax/StaxSerializerGenerator.java | 4 +- .../plugin/stax/StaxWriterGenerator.java | 38 ++--- .../xml/stax/StaxGeneratorPartsTest.java | 4 +- .../generator/xml/stax/StaxGeneratorTest.java | 4 +- .../stax/StaxGeneratorVersionInFieldTest.java | 4 +- .../StaxGeneratorVersionInNamespaceTest.java | 4 +- ...taxGeneratorVersionReaderDelegateTest.java | 2 - ...xGeneratorWrongVersionInNamespaceTest.java | 4 +- .../stax/StaxGeneratorWrongVersionTest.java | 4 +- .../modello/plugin/xdoc/XdocGenerator.java | 11 +- .../plugin/xdoc/XdocGeneratorTest.java | 20 ++- .../modello/plugins/xml/XmlModelHelpers.java | 8 +- .../plugins/xml/XmlModelloPluginTest.java | 2 +- .../plugin/xpp3/Xpp3ReaderGenerator.java | 11 +- .../plugin/xpp3/Xpp3WriterGenerator.java | 28 +--- .../generator/xml/xpp3/Xpp3GeneratorTest.java | 2 +- .../modello/plugin/xsd/XsdGenerator.java | 17 +-- .../modello/plugin/xsd/XsdGeneratorTest.java | 2 +- .../AbstractModelloJavaGeneratorTest.java | 21 ++- .../codehaus/modello/OrderedProperties.java | 2 +- 75 files changed, 347 insertions(+), 642 deletions(-) diff --git a/modello-core/src/main/java/org/codehaus/modello/Modello.java b/modello-core/src/main/java/org/codehaus/modello/Modello.java index 03a1927ba..0952eeeba 100644 --- a/modello-core/src/main/java/org/codehaus/modello/Modello.java +++ b/modello-core/src/main/java/org/codehaus/modello/Modello.java @@ -38,8 +38,6 @@ */ public class Modello { - private PlexusContainer container; - private ModelloCore core; public Modello() @@ -47,7 +45,7 @@ public Modello() { try { - container = new DefaultPlexusContainer(); + PlexusContainer container = new DefaultPlexusContainer(); core = (ModelloCore) container.lookup( ModelloCore.ROLE ); } diff --git a/modello-core/src/main/java/org/codehaus/modello/core/io/ModelReader.java b/modello-core/src/main/java/org/codehaus/modello/core/io/ModelReader.java index bafb3ab83..3deb25782 100644 --- a/modello-core/src/main/java/org/codehaus/modello/core/io/ModelReader.java +++ b/modello-core/src/main/java/org/codehaus/modello/core/io/ModelReader.java @@ -50,15 +50,15 @@ */ public class ModelReader { - private Map modelAttributes = new HashMap(); + private Map modelAttributes = new HashMap<>(); - private Map> classAttributes = new HashMap>(); + private Map> classAttributes = new HashMap<>(); - private Map> interfaceAttributes = new HashMap>(); + private Map> interfaceAttributes = new HashMap<>(); - private Map> fieldAttributes = new HashMap>(); + private Map> fieldAttributes = new HashMap<>(); - private Map> associationAttributes = new HashMap>(); + private Map> associationAttributes = new HashMap<>(); public Map getAttributesForModel() { @@ -102,11 +102,7 @@ public Model loadModel( Reader reader ) return model; } - catch ( IOException ex ) - { - throw new ModelloException( "Error parsing the model.", ex ); - } - catch ( XmlPullParserException ex ) + catch ( IOException | XmlPullParserException ex ) { throw new ModelloException( "Error parsing the model.", ex ); } @@ -343,7 +339,7 @@ private void parseFields( ModelClass modelClass, XmlPullParser parser ) Map fAttributes = getAttributes( parser ); - Map aAttributes = new HashMap(); + Map aAttributes = new HashMap<>(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { @@ -374,11 +370,11 @@ else if ( "typeValidator".equals( parser.getName() ) ) } else if ( "required".equals( parser.getName() ) ) { - modelField.setRequired( Boolean.valueOf( parser.nextText() ) ); + modelField.setRequired( Boolean.parseBoolean( parser.nextText() ) ); } else if ( "identifier".equals( parser.getName() ) ) { - modelField.setIdentifier( Boolean.valueOf( parser.nextText() ).booleanValue() ); + modelField.setIdentifier( Boolean.parseBoolean( parser.nextText() ) ); } else { @@ -553,7 +549,7 @@ else if ( "comment".equals( parser.getName() ) ) } else if ( "annotations".equals( parser.getName() ) ) { - List annotationsList = new ArrayList(); + List annotationsList = new ArrayList<>(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "annotation".equals( parser.getName() ) ) @@ -573,7 +569,7 @@ else if ( "annotations".equals( parser.getName() ) ) private Map getAttributes( XmlPullParser parser ) { - Map attributes = new HashMap(); + Map attributes = new HashMap<>(); for ( int i = 0; i < parser.getAttributeCount(); i++ ) { diff --git a/modello-core/src/main/java/org/codehaus/modello/metadata/AbstractMetadataPlugin.java b/modello-core/src/main/java/org/codehaus/modello/metadata/AbstractMetadataPlugin.java index 7bdf42bb6..c3bf1f052 100644 --- a/modello-core/src/main/java/org/codehaus/modello/metadata/AbstractMetadataPlugin.java +++ b/modello-core/src/main/java/org/codehaus/modello/metadata/AbstractMetadataPlugin.java @@ -43,7 +43,7 @@ protected boolean getBoolean( Map data, String key, boolean defa return defaultValue; } - return Boolean.valueOf( value ).booleanValue(); + return Boolean.parseBoolean( value ); } protected String getString( Map data, String key ) diff --git a/modello-core/src/main/java/org/codehaus/modello/model/BaseElement.java b/modello-core/src/main/java/org/codehaus/modello/model/BaseElement.java index d6b620748..5a688fb74 100644 --- a/modello-core/src/main/java/org/codehaus/modello/model/BaseElement.java +++ b/modello-core/src/main/java/org/codehaus/modello/model/BaseElement.java @@ -45,13 +45,13 @@ public abstract class BaseElement private String comment; - private List annotations = new ArrayList(); + private List annotations = new ArrayList<>(); private VersionRange versionRange = new VersionRange( "0.0.0+" ); private Version deprecatedVersion; - private transient Map metadata = new HashMap(); + private transient Map metadata = new HashMap<>(); private boolean nameRequired; @@ -190,7 +190,7 @@ protected boolean isEmpty( String string ) public boolean equals( Object other ) { - if ( other == null || !( other instanceof BaseElement ) ) + if ( !( other instanceof BaseElement ) ) { return false; } diff --git a/modello-core/src/main/java/org/codehaus/modello/model/Model.java b/modello-core/src/main/java/org/codehaus/modello/model/Model.java index 04ffea4d1..eec53674b 100644 --- a/modello-core/src/main/java/org/codehaus/modello/model/Model.java +++ b/modello-core/src/main/java/org/codehaus/modello/model/Model.java @@ -99,7 +99,7 @@ public String getRoot( Version version ) { metadata = (ModelClassMetadata) currentClass.getMetadata( ModelClassMetadata.ID ); } - catch ( Exception e ) + catch ( Exception ignored ) { } @@ -261,7 +261,7 @@ public List getDefaults() public ModelDefault getDefault( String key ) { - ModelDefault modelDefault = (ModelDefault) defaultMap.get( key ); + ModelDefault modelDefault = defaultMap.get( key ); if ( modelDefault == null ) { diff --git a/modello-core/src/main/java/org/codehaus/modello/model/ModelClass.java b/modello-core/src/main/java/org/codehaus/modello/model/ModelClass.java index 163c8be01..8d1a7fc49 100644 --- a/modello-core/src/main/java/org/codehaus/modello/model/ModelClass.java +++ b/modello-core/src/main/java/org/codehaus/modello/model/ModelClass.java @@ -46,7 +46,7 @@ public class ModelClass private List fields; - private transient Map> fieldMap = new HashMap>(); + private transient Map> fieldMap = new HashMap<>(); public ModelClass() { @@ -81,7 +81,7 @@ public List getInterfaces() { if ( interfaces == null ) { - interfaces = new ArrayList(); + interfaces = new ArrayList<>(); } return interfaces; @@ -108,7 +108,7 @@ public List getAllFields() { if ( fields == null ) { - fields = new ArrayList(); + fields = new ArrayList<>(); } return fields; @@ -126,7 +126,7 @@ public List getAllFields( boolean withInheritedField ) return getAllFields(); } - List fields = new ArrayList( getAllFields() ); + List fields = new ArrayList<>( getAllFields() ); ModelClass c = this; @@ -177,7 +177,7 @@ public void addField( ModelField modelField ) } else { - List fieldList = new ArrayList(); + List fieldList = new ArrayList<>(); fieldMap.put( modelField.getName(), fieldList ); } diff --git a/modello-core/src/main/java/org/codehaus/modello/model/ModelDefault.java b/modello-core/src/main/java/org/codehaus/modello/model/ModelDefault.java index 6272e6245..6046d31ee 100644 --- a/modello-core/src/main/java/org/codehaus/modello/model/ModelDefault.java +++ b/modello-core/src/main/java/org/codehaus/modello/model/ModelDefault.java @@ -124,7 +124,7 @@ public String getValue() public boolean getBoolean() { - return Boolean.valueOf( value ).booleanValue(); + return Boolean.parseBoolean( value ); } public void validateElement() diff --git a/modello-core/src/main/java/org/codehaus/modello/model/ModelInterface.java b/modello-core/src/main/java/org/codehaus/modello/model/ModelInterface.java index 34d3a6a60..967ac92a1 100644 --- a/modello-core/src/main/java/org/codehaus/modello/model/ModelInterface.java +++ b/modello-core/src/main/java/org/codehaus/modello/model/ModelInterface.java @@ -60,7 +60,7 @@ public String getSuperInterface() */ public List getAllFields() { - return new ArrayList(); + return new ArrayList<>(); } /** @@ -68,7 +68,7 @@ public List getAllFields() */ public List getAllFields( boolean withInheritedField ) { - return new ArrayList(); + return new ArrayList<>(); } public ModelField getField( String type, VersionRange versionRange ) diff --git a/modello-core/src/main/java/org/codehaus/modello/model/ModelType.java b/modello-core/src/main/java/org/codehaus/modello/model/ModelType.java index 6972e685b..bb5b84d9e 100644 --- a/modello-core/src/main/java/org/codehaus/modello/model/ModelType.java +++ b/modello-core/src/main/java/org/codehaus/modello/model/ModelType.java @@ -41,7 +41,7 @@ public abstract class ModelType private transient Model model; - private transient Map codeSegmentMap = new HashMap(); + private transient Map codeSegmentMap = new HashMap<>(); public ModelType() { @@ -106,7 +106,7 @@ public List getAllCodeSegments() { if ( codeSegments == null ) { - codeSegments = new ArrayList(); + codeSegments = new ArrayList<>(); } return codeSegments; @@ -121,7 +121,7 @@ public List getCodeSegments( VersionRange versionRange ) { List codeSegments = getAllCodeSegments(); - List codeSegmentsList = new ArrayList(); + List codeSegmentsList = new ArrayList<>(); if ( codeSegments != null ) { @@ -180,7 +180,7 @@ public void addCodeSegment( CodeSegment codeSegment ) */ public List getFields( Version version ) { - List fieldList = new ArrayList(); + List fieldList = new ArrayList<>(); for ( ModelField currentField : getAllFields() ) { @@ -195,9 +195,9 @@ public List getFields( Version version ) public List getAllFields( Version version, boolean withInheritedField ) { - List allFieldsList = new ArrayList(); + List allFieldsList = new ArrayList<>(); - List fieldList = new ArrayList(); + List fieldList = new ArrayList<>(); for ( ModelField currentField : getAllFields( withInheritedField ) ) { @@ -239,7 +239,7 @@ public ModelField getField( String type, Version version ) public List getIdentifierFields( Version version ) { - List identifierFields = new ArrayList(); + List identifierFields = new ArrayList<>(); for ( ModelField field : getFields( version ) ) { diff --git a/modello-core/src/main/java/org/codehaus/modello/model/Version.java b/modello-core/src/main/java/org/codehaus/modello/model/Version.java index 5def332c5..2b4a12f1d 100644 --- a/modello-core/src/main/java/org/codehaus/modello/model/Version.java +++ b/modello-core/src/main/java/org/codehaus/modello/model/Version.java @@ -218,12 +218,7 @@ else if ( ( this.greaterThan( range.getFromVersion() ) ) && ( this.lesserThan( r { return true; } - else if ( this.equals( range.getFromVersion() ) || this.equals( range.getToVersion() ) ) - { - return true; - } - - return false; + else return this.equals( range.getFromVersion() ) || this.equals( range.getToVersion() ); } // ---------------------------------------------------------------------- diff --git a/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractModelloGenerator.java b/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractModelloGenerator.java index ae9898964..28da2c413 100644 --- a/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractModelloGenerator.java +++ b/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractModelloGenerator.java @@ -81,7 +81,7 @@ protected void initialize( Model model, Properties parameters ) generatedVersion = new Version( version ); packageWithVersion = - Boolean.valueOf( getParameter( parameters, ModelloParameterConstants.PACKAGE_WITH_VERSION ) ); + Boolean.parseBoolean( getParameter( parameters, ModelloParameterConstants.PACKAGE_WITH_VERSION ) ); encoding = parameters.getProperty( ModelloParameterConstants.ENCODING ); } @@ -126,7 +126,7 @@ protected boolean isClassInModel( String fieldType, Model model ) { return model.getClass( fieldType, generatedVersion ) != null; } - catch ( Exception e ) + catch ( Exception ignored ) { } @@ -140,7 +140,7 @@ protected boolean isClassInModel( String fieldType, Model model ) */ protected List getFieldsForClass( ModelClass modelClass ) { - List fields = new ArrayList(); + List fields = new ArrayList<>(); while ( modelClass != null ) { @@ -183,10 +183,7 @@ protected String capitalise( String str ) return str; } - return new StringBuilder( str.length() ) - .append( Character.toTitleCase( str.charAt( 0 ) ) ) - .append( str.substring( 1 ) ) - .toString(); + return Character.toTitleCase( str.charAt( 0 ) ) + str.substring( 1 ); } public static String singular( String name ) @@ -223,10 +220,7 @@ public static String uncapitalise( String str ) return str; } - return new StringBuilder( str.length() ) - .append( Character.toLowerCase( str.charAt( 0 ) ) ) - .append( str.substring( 1 ) ) - .toString(); + return Character.toLowerCase( str.charAt( 0 ) ) + str.substring( 1 ); } // ---------------------------------------------------------------------- diff --git a/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractPluginManager.java b/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractPluginManager.java index 03b5a88c6..53784c9c1 100644 --- a/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractPluginManager.java +++ b/modello-core/src/main/java/org/codehaus/modello/plugin/AbstractPluginManager.java @@ -38,7 +38,7 @@ public abstract class AbstractPluginManager implements Initializable { /* injected by Plexus: see META-INF/plexus/components.xml */ - private Map plugins = new HashMap(); + private Map plugins = new HashMap<>(); public void initialize() { diff --git a/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/AbstractModelloGeneratorMojo.java b/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/AbstractModelloGeneratorMojo.java index bed178894..53ed80f1e 100644 --- a/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/AbstractModelloGeneratorMojo.java +++ b/modello-maven-plugin/src/main/java/org/codehaus/modello/maven/AbstractModelloGeneratorMojo.java @@ -95,7 +95,7 @@ public abstract class AbstractModelloGeneratorMojo * packageWithVersion setting. */ @Parameter - private List packagedVersions = new ArrayList(); + private List packagedVersions = new ArrayList<>(); /** * @since 1.0.1 @@ -258,16 +258,7 @@ private void doExecute( String modelStr, String outputDirectory, Properties para BuildContext.SEVERITY_ERROR, mojoExecutionException ); throw mojoExecutionException; } - catch ( ModelloException e ) - { - MojoExecutionException mojoExecutionException = - new MojoExecutionException( "Error generating: " + e.getMessage(), e ); - // TODO: Provide actual line/column numbers - buildContext.addMessage( modelFile, 1 /* line */, 1 /* column */, mojoExecutionException.getMessage(), - BuildContext.SEVERITY_ERROR, mojoExecutionException ); - throw mojoExecutionException; - } - catch ( ModelValidationException e ) + catch ( ModelloException | ModelValidationException e ) { MojoExecutionException mojoExecutionException = new MojoExecutionException( "Error generating: " + e.getMessage(), e ); diff --git a/modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloConvertersMojoTest.java b/modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloConvertersMojoTest.java index 4c08d8151..2a88cf1ae 100644 --- a/modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloConvertersMojoTest.java +++ b/modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloConvertersMojoTest.java @@ -41,7 +41,7 @@ public void testModelloConvertersMojo() { ModelloCore modelloCore = (ModelloCore) lookup( ModelloCore.ROLE ); - BuildContext buildContext = (BuildContext) lookup( BuildContext.class ); + BuildContext buildContext = lookup( BuildContext.class ); ModelloConvertersMojo mojo = new ModelloConvertersMojo(); @@ -55,7 +55,7 @@ public void testModelloConvertersMojo() mojo.setOutputDirectory( outputDirectory ); - String models[] = new String[1]; + String[] models = new String[1]; models[0] = getTestPath( "src/test/resources/java-model.mdo" ); mojo.setModels( models ); @@ -63,7 +63,7 @@ public void testModelloConvertersMojo() mojo.setPackageWithVersion( false ); - mojo.setPackagedVersions( Arrays.asList( new String[] { "0.9.0", "1.0.0" } ) ); + mojo.setPackagedVersions( Arrays.asList( "0.9.0", "1.0.0" ) ); mojo.setModelloCore( modelloCore ); diff --git a/modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloJavaMojoTest.java b/modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloJavaMojoTest.java index dc109e269..e57b9b06a 100644 --- a/modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloJavaMojoTest.java +++ b/modello-maven-plugin/src/test/java/org/codehaus/modello/maven/ModelloJavaMojoTest.java @@ -41,7 +41,7 @@ public void testModelloJavaMojo() { ModelloCore modelloCore = (ModelloCore) lookup( ModelloCore.ROLE ); - BuildContext buildContext = (BuildContext) lookup( BuildContext.class ); + BuildContext buildContext = lookup( BuildContext.class ); ModelloJavaMojo mojo = new ModelloJavaMojo(); @@ -55,7 +55,7 @@ public void testModelloJavaMojo() mojo.setOutputDirectory( outputDirectory ); - String models[] = new String[1]; + String[] models = new String[1]; models[0] = getTestPath( "src/test/resources/java-model.mdo" ); mojo.setModels( models ); @@ -63,7 +63,7 @@ public void testModelloJavaMojo() mojo.setPackageWithVersion( false ); - mojo.setPackagedVersions( Arrays.asList( new String[] { "0.9.0", "1.0.0" } ) ); + mojo.setPackagedVersions( Arrays.asList( "0.9.0", "1.0.0" ) ); mojo.setModelloCore( modelloCore ); diff --git a/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/converters/ConverterGenerator.java b/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/converters/ConverterGenerator.java index e3f86295f..155ddc352 100644 --- a/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/converters/ConverterGenerator.java +++ b/modello-plugins/modello-plugin-converters/src/main/java/org/codehaus/modello/plugin/converters/ConverterGenerator.java @@ -64,7 +64,7 @@ public void generate( Model model, Properties parameters ) String[] versions = parameters.getProperty( ModelloParameterConstants.ALL_VERSIONS ).split( "," ); - List allVersions = new ArrayList( versions.length ); + List allVersions = new ArrayList<>( versions.length ); for ( String version : versions ) { allVersions.add( new Version( version ) ); @@ -99,7 +99,7 @@ public void generate( Model model, Properties parameters ) } private void generateConverters( Version toVersion ) - throws ModelloException, IOException + throws IOException { Model objectModel = getModel(); @@ -279,9 +279,6 @@ private void generateConverters( Version toVersion ) sc.add( "value.set" + name + "( list );" ); - sc.unindent(); - - sc.add( "}" ); } else { @@ -326,10 +323,9 @@ private void generateConverters( Version toVersion ) sc.add( "value.set" + name + "( map );" ); - sc.unindent(); - - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); } else { @@ -353,26 +349,18 @@ private void generateConverters( Version toVersion ) sc.add( "return value;" ); } - JSourceWriter interfaceWriter = null; - JSourceWriter classWriter = null; - - try + try ( JSourceWriter interfaceWriter = + newJSourceWriter( packageName, conversionInterface.getName( true ) ); + JSourceWriter classWriter = + newJSourceWriter( packageName, basicConverterClass.getName( true ) ) ) { - interfaceWriter = newJSourceWriter( packageName, conversionInterface.getName( true ) ); - classWriter = newJSourceWriter( packageName, basicConverterClass.getName( true ) ); - conversionInterface.print( interfaceWriter ); basicConverterClass.print( classWriter ); } - finally - { - IOUtil.close( classWriter ); - IOUtil.close( interfaceWriter ); - } } private void generateConverterTool( List allVersions ) - throws ModelloException, IOException + throws IOException { Model objectModel = getModel(); String root = objectModel.getRoot( getGeneratedVersion() ); @@ -401,16 +389,11 @@ private void generateConverterTool( List allVersions ) } writeConvertMethod( converterClass, objectModel, basePackage, allVersions, null, rootClass ); - JSourceWriter classWriter = null; - try + try ( JSourceWriter classWriter = + newJSourceWriter( packageName, converterClass.getName( true ) ) ) { - classWriter = newJSourceWriter( packageName, converterClass.getName( true ) ); converterClass.print( new JSourceWriter( classWriter ) ); } - finally - { - IOUtil.close( classWriter ); - } } private static void writeConvertMethod( JClass converterClass, Model objectModel, String basePackage, diff --git a/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jReaderGenerator.java b/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jReaderGenerator.java index ec3947ab0..b6b2d0d77 100644 --- a/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jReaderGenerator.java +++ b/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jReaderGenerator.java @@ -567,14 +567,9 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, sc.unindent(); sc.add( "}" ); - sc.unindent(); - sc.add( "}" ); - } - else - { - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); } else { diff --git a/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jWriterGenerator.java b/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jWriterGenerator.java index 5349a2203..c2ed6d816 100644 --- a/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jWriterGenerator.java +++ b/modello-plugins/modello-plugin-dom4j/src/main/java/org/codehaus/modello/plugin/dom4j/Dom4jWriterGenerator.java @@ -376,11 +376,6 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, + singular( uncapitalise( field.getName() ) ) + " );" ); } - sc.unindent(); - sc.add( "}" ); - - sc.unindent(); - sc.add( "}" ); } else { @@ -419,12 +414,11 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, sc.add( "listElement.addElement( key ).setText( value );" ); } - sc.unindent(); - sc.add( "}" ); - - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); + sc.unindent(); + sc.add( "}" ); } } else diff --git a/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/Dom4jGeneratorTest.java b/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/Dom4jGeneratorTest.java index 5da68baf8..070eeda23 100644 --- a/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/Dom4jGeneratorTest.java +++ b/modello-plugins/modello-plugin-dom4j/src/test/java/org/codehaus/modello/plugin/dom4j/Dom4jGeneratorTest.java @@ -57,7 +57,7 @@ public void testDom4jGenerator() assertEquals( 27, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-plugins/modello-plugin-jackson/src/main/java/org/codehaus/modello/plugin/jackson/JacksonReaderGenerator.java b/modello-plugins/modello-plugin-jackson/src/main/java/org/codehaus/modello/plugin/jackson/JacksonReaderGenerator.java index 850c9b026..f63c443f9 100644 --- a/modello-plugins/modello-plugin-jackson/src/main/java/org/codehaus/modello/plugin/jackson/JacksonReaderGenerator.java +++ b/modello-plugins/modello-plugin-jackson/src/main/java/org/codehaus/modello/plugin/jackson/JacksonReaderGenerator.java @@ -594,8 +594,6 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, sc.unindent(); sc.add( "}" ); - sc.unindent(); - sc.add( "}" ); } else { @@ -719,9 +717,9 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, sc.add( "}" ); } - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); } } } @@ -731,7 +729,7 @@ private void writePrimitiveField( ModelField field, String type, String objectNa { XmlFieldMetadata xmlFieldMetadata = (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ); - String parserGetter = null; + String parserGetter; if ( "boolean".equals( type ) || "Boolean".equals( type ) ) { parserGetter = "parser.getBooleanValue()"; diff --git a/modello-plugins/modello-plugin-jackson/src/main/java/org/codehaus/modello/plugin/jackson/JacksonWriterGenerator.java b/modello-plugins/modello-plugin-jackson/src/main/java/org/codehaus/modello/plugin/jackson/JacksonWriterGenerator.java index fd54a629f..e51674c00 100644 --- a/modello-plugins/modello-plugin-jackson/src/main/java/org/codehaus/modello/plugin/jackson/JacksonWriterGenerator.java +++ b/modello-plugins/modello-plugin-jackson/src/main/java/org/codehaus/modello/plugin/jackson/JacksonWriterGenerator.java @@ -285,8 +285,6 @@ private void writeClass( ModelClass modelClass, JClass jClass ) sc.add( "generator.writeEndArray();" ); - sc.unindent(); - sc.add( "}" ); } else { @@ -368,9 +366,9 @@ private void writeClass( ModelClass modelClass, JClass jClass ) sc.add( "generator.writeEndObject();" ); } - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); } } else diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/AbstractJavaModelloGenerator.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/AbstractJavaModelloGenerator.java index c325fc7d4..de9e8608c 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/AbstractJavaModelloGenerator.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/AbstractJavaModelloGenerator.java @@ -24,9 +24,6 @@ import java.io.File; import java.io.IOException; -import java.io.Writer; -import java.nio.charset.Charset; -import java.nio.file.Path; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -48,7 +45,6 @@ import org.codehaus.modello.model.ModelInterface; import org.codehaus.modello.model.ModelType; import org.codehaus.modello.plugin.AbstractModelloGenerator; -import org.codehaus.modello.plugin.CachingWriter; import org.codehaus.modello.plugin.java.javasource.JClass; import org.codehaus.modello.plugin.java.javasource.JComment; import org.codehaus.modello.plugin.java.javasource.JInterface; @@ -89,7 +85,7 @@ protected void initialize( Model model, Properties parameters ) * @param packageName the package of the source file to create * @param className the class of the source file to create * @return a JSourceWriter with configured encoding - * @throws IOException + * @throws IOException if an error occurs */ protected JSourceWriter newJSourceWriter( String packageName, String className ) throws IOException @@ -339,7 +335,7 @@ else if ( "Date".equals( type ) && field.getDefaultValue() != null ) protected List getClasses( Model model ) { - List modelClasses = new ArrayList(); + List modelClasses = new ArrayList<>(); for ( ModelClass modelClass : model.getClasses( getGeneratedVersion() ) ) { @@ -370,11 +366,7 @@ protected boolean isTrackingSupport( ModelClass modelClass ) { return true; } - if ( StringUtils.isNotEmpty( modelClassMetadata.getSourceTracker() ) ) - { - return true; - } - return false; + return StringUtils.isNotEmpty( modelClassMetadata.getSourceTracker() ); } } diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java index ce23f2803..1c555459f 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/JavaModelloGenerator.java @@ -29,6 +29,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Objects; import java.util.Properties; import java.util.Set; @@ -68,9 +69,9 @@ public class JavaModelloGenerator extends AbstractJavaModelloGenerator { - private Collection immutableTypes = new HashSet( Arrays.asList( - new String[]{ "boolean", "Boolean", "byte", "Byte", "char", "Character", "short", "Short", "int", "Integer", - "long", "Long", "float", "Float", "double", "Double", "String" } ) ); + private final Collection immutableTypes = new HashSet<>( Arrays.asList( + "boolean", "Boolean", "byte", "Byte", "char", "Character", "short", "Short", "int", "Integer", + "long", "Long", "float", "Float", "double", "Double", "String" ) ); public void generate( Model model, Properties parameters ) throws ModelloException @@ -295,7 +296,7 @@ else if ( locationTrackerClass != null && modelClass != sourceTrackerClass && !s } private void generateInterface( ModelInterface modelInterface ) - throws ModelloException, IOException + throws IOException { Model objectModel = modelInterface.getModel(); @@ -686,7 +687,7 @@ else if ( isMap( modelField.getType() ) ) private String getCloneMode( ModelClass modelClass ) throws ModelloException { - String cloneMode = null; + String cloneMode; for ( ModelClass currentClass = modelClass; ; ) { @@ -745,7 +746,6 @@ else if ( !JavaAssociationMetadata.CLONE_MODES.contains( cloneModeAssoc ) ) } private String getCloneHook( ModelClass modelClass ) - throws ModelloException { JavaClassMetadata javaClassMetadata = (JavaClassMetadata) modelClass.getMetadata( JavaClassMetadata.ID ); @@ -753,7 +753,7 @@ private String getCloneHook( ModelClass modelClass ) } private String generateLocationTracker( Model objectModel, ModelClass locationClass ) - throws ModelloException, IOException + throws IOException { if ( locationClass == null ) { @@ -799,7 +799,6 @@ private String generateLocationTracker( Model objectModel, ModelClass locationCl } private void generateLocationTracking( JClass jClass, ModelClass modelClass, ModelClass locationClass ) - throws ModelloException { if ( locationClass == null ) { @@ -1670,14 +1669,14 @@ else if ( ModelDefault.MAP.equals( modelAssociation.getType() ) ) } } - if ( StringUtils.equals( javaAssociationMetadata.getInitializationMode(), - JavaAssociationMetadata.FIELD_INIT ) ) + if ( Objects.equals( javaAssociationMetadata.getInitializationMode(), + JavaAssociationMetadata.FIELD_INIT ) ) { jField.setInitString( defaultValue ); } - if ( StringUtils.equals( javaAssociationMetadata.getInitializationMode(), - JavaAssociationMetadata.CONSTRUCTOR_INIT ) ) + if ( Objects.equals( javaAssociationMetadata.getInitializationMode(), + JavaAssociationMetadata.CONSTRUCTOR_INIT ) ) { jConstructorSource.add( "this." + jField.getName() + " = " + defaultValue + ";" ); } @@ -1692,8 +1691,8 @@ else if ( ModelDefault.MAP.equals( modelAssociation.getType() ) ) JSourceCode sc = getter.getSourceCode(); - if ( StringUtils.equals( javaAssociationMetadata.getInitializationMode(), - JavaAssociationMetadata.LAZY_INIT ) ) + if ( Objects.equals( javaAssociationMetadata.getInitializationMode(), + JavaAssociationMetadata.LAZY_INIT ) ) { sc.add( "if ( this." + jField.getName() + " == null )" ); @@ -2244,7 +2243,7 @@ private void generateBuilder( ModelClass modelClass, JClass builderClass, JConst private void createInstanceAndSetProperties( ModelClass modelClass, JConstructor constructor, JSourceCode sc ) throws ModelloException { - final Set ctorArgs = new HashSet(); + final Set ctorArgs = new HashSet<>(); StringBuilder ctor = new StringBuilder( modelClass.getName() ) .append( " instance = new " ) @@ -2338,7 +2337,6 @@ private void createBuilderField( JClass jClass, ModelField modelField ) } private boolean createSetBuilderFieldToInstance( Set ctorArgs, ModelField modelField, JSourceCode sc ) - throws ModelloException { JavaFieldMetadata javaFieldMetadata = (JavaFieldMetadata) modelField.getMetadata( JavaFieldMetadata.ID ); diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JAnnotations.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JAnnotations.java index 224b07b7f..a9edd4a76 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JAnnotations.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JAnnotations.java @@ -10,7 +10,7 @@ public class JAnnotations public JAnnotations() { - this.annotations = new ArrayList(); + this.annotations = new ArrayList<>(); } public void appendAnnotation( String annotation ) @@ -45,7 +45,7 @@ public void print( JSourceWriter jsw ) { for ( String annotation : annotations ) { - jsw.writeln( annotation.toString() ); + jsw.writeln( annotation ); } } // -- print } diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JClass.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JClass.java index 3de933976..a81e83603 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JClass.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JClass.java @@ -97,21 +97,21 @@ public class JClass extends JStructure /** * The list of constructors for this JClass */ - private List _constructors = null; + private List _constructors; /** * The list of member variables (fields) of this JClass */ - private Map _fields = null; + private Map _fields; - private List _innerClasses = null; + private List _innerClasses; /** * The list of methods of this JClass */ - private List _methods = null; + private List _methods; /** * The superclass for this JClass @@ -134,10 +134,10 @@ public JClass( String name ) throws IllegalArgumentException { super( name ); - _constructors = new ArrayList(); + _constructors = new ArrayList<>(); _fields = new LinkedHashMap<>(); - _methods = new ArrayList(); - _innerClasses = new ArrayList(); + _methods = new ArrayList<>(); + _innerClasses = new ArrayList<>(); //-- initialize default Java doc getJDocComment().appendComment( "Class " + getLocalName() + "." ); @@ -219,7 +219,7 @@ else if ( jMember instanceof JMethod ) addMethod( (JMethod) jMember ); else { - String error = null; + String error; if ( jMember == null ) { error = "the argument 'jMember' must not be null."; @@ -277,7 +277,7 @@ public void addMethod( JMethod jMethod, boolean importReturnType ) for ( int i = 0; i < _methods.size(); i++ ) { - JMethod tmp = (JMethod) _methods.get( i ); + JMethod tmp = _methods.get( i ); //-- first compare modifiers if ( tmp.getModifiers().isPrivate() ) { @@ -392,7 +392,7 @@ public JClass createInnerClass( String localname ) */ public JConstructor getConstructor( int index ) { - return (JConstructor) _constructors.get( index ); + return _constructors.get( index ); } //-- getConstructor /** @@ -423,7 +423,7 @@ public JConstructor[] getConstructors() **/ public JField getField( String name ) { - return (JField) _fields.get( name ); + return _fields.get( name ); } //-- getField /** @@ -551,7 +551,7 @@ public void print( JSourceWriter jsw, boolean classOnly ) List removeImports = null; if ( _innerClasses.size() > 0 ) { - removeImports = new ArrayList(); + removeImports = new ArrayList<>(); for ( JClass iClass : _innerClasses ) { Enumeration e = iClass.getImports(); @@ -571,9 +571,9 @@ public void print( JSourceWriter jsw, boolean classOnly ) //-- remove imports from inner-classes, if necessary if ( removeImports != null ) { - for ( int i = 0; i < removeImports.size(); i++ ) + for ( String removeImport : removeImports ) { - removeImport( removeImports.get( i ) ); + removeImport( removeImport ); } } @@ -722,9 +722,8 @@ else if ( modifiers.isPublic() ) jsw.writeln( "//----------------/" ); jsw.writeln(); } - for ( int i = 0; i < _constructors.size(); i++ ) + for ( JConstructor jConstructor : _constructors ) { - JConstructor jConstructor = _constructors.get( i ); jConstructor.print( jsw ); jsw.writeln(); } @@ -739,9 +738,8 @@ else if ( modifiers.isPublic() ) jsw.writeln(); } - for ( int i = 0; i < _methods.size(); i++ ) + for ( JMethod jMethod : _methods ) { - JMethod jMethod = _methods.get( i ); jMethod.print( jsw ); jsw.writeln(); } @@ -755,9 +753,8 @@ else if ( modifiers.isPublic() ) jsw.writeln( "//-----------------/" ); jsw.writeln(); } - for ( int i = 0; i < _innerClasses.size(); i++ ) + for ( JClass jClass : _innerClasses ) { - JClass jClass = _innerClasses.get( i ); jClass.print( jsw, true ); jsw.writeln(); } @@ -773,7 +770,7 @@ else if ( modifiers.isPublic() ) jsw.flush(); } //-- printSource - private List sourceCodeEntries = new ArrayList(); + private List sourceCodeEntries = new ArrayList<>(); public void addSourceCode( String sourceCode ) { @@ -801,7 +798,7 @@ public JField removeField( String name ) { if ( name == null ) return null; - JField field = (JField) _fields.remove( name ); + JField field = _fields.remove( name ); //-- clean up imports //-- NOT YET IMPLEMENTED @@ -850,7 +847,7 @@ public void setSuperClass( String superClass ) _superClass = superClass; } //-- setSuperClass - final class JInnerClass extends JClass + static final class JInnerClass extends JClass { JInnerClass( String name ) { diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JComment.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JComment.java index 2e7072d7f..b48bf420b 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JComment.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JComment.java @@ -124,7 +124,7 @@ public class JComment /** * The main comment for this JDocComment **/ - private StringBuilder _comment = null; + private StringBuilder _comment; /** * The maximum number of characters per line @@ -172,7 +172,7 @@ public void print( JSourceWriter jsw ) if ( jsw == null ) return; //-- nothing to do - LineFormatter formatter = null; + LineFormatter formatter; //-- calculate comment length short currentIndent = jsw.getIndentSize(); @@ -198,7 +198,7 @@ public void print( JSourceWriter jsw ) //-- start comment - String prefix = null; + String prefix; String start = null; String end = null; @@ -271,7 +271,7 @@ public String toString() class LineFormatter { - String comment = null; + String comment; int maxLength = 65; int offset = 0; @@ -279,7 +279,7 @@ class LineFormatter String prefix = null; - private StringBuilder sb = null; + private StringBuilder sb; /** * Creates a LineFormatter for the given comment @@ -342,7 +342,7 @@ String nextLine() char ch = comment.charAt( index ); if ( isNewLine( ch ) ) { - sb.append( comment.substring( offset, index ) ); + sb.append( comment, offset, index ); offset = index + 1; return sb.toString(); } @@ -364,7 +364,7 @@ String nextLine() else index = breakable; } - sb.append( comment.substring( offset, index ) ); + sb.append( comment, offset, index ); offset = index + 1; return sb.toString(); } //-- getNextLine diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JCompUnit.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JCompUnit.java index 149ff859e..a5a82d351 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JCompUnit.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JCompUnit.java @@ -109,12 +109,12 @@ public class JCompUnit /** * The package for this JCompUnit **/ - private String packageName = null; + private String packageName; /** * The file to which this JCompUnit will be saved **/ - private String fileName = null; + private String fileName; /** * The set of top-level classes that live in this compilation unit. @@ -194,8 +194,8 @@ public JCompUnit( JInterface jInterface ) private void init() { - classes = new ArrayList(); - interfaces = new ArrayList(); + classes = new ArrayList<>(); + interfaces = new ArrayList<>(); } /** @@ -252,7 +252,7 @@ public void addInterface( JInterface jInterface ) public SortedSet getImports() { - SortedSet allImports = new TreeSet(); + SortedSet allImports = new TreeSet<>(); // add imports from classes for ( JClass jClass : classes ) @@ -287,7 +287,7 @@ public SortedSet getImports() public String getFilename( String destDir ) { - String filename = new String( fileName ); + String filename = fileName; //-- Convert Java package to path string String javaPackagePath = ""; @@ -309,7 +309,7 @@ public String getFilename( String destDir ) //-- Prefix filename with path if ( pathFile.toString().length() > 0 ) - filename = pathFile.toString() + File.separator + filename; + filename = pathFile + File.separator + filename; return filename; } //-- getFilename @@ -326,7 +326,7 @@ public String getPackageName() protected static String getPackageFromClassName( String className ) { - int idx = -1; + int idx; if ( ( idx = className.lastIndexOf( '.' ) ) > 0 ) { return className.substring( 0, idx ); @@ -369,7 +369,7 @@ public void print( String destDir, String lineSeparator ) String filename = getFilename( destDir ); File file = new File( filename ); - JSourceWriter jsw = null; + JSourceWriter jsw; try { jsw = new JSourceWriter( WriterFactory.newPlatformWriter( file ) ); diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JConstructor.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JConstructor.java index b58033eea..3128811e5 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JConstructor.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JConstructor.java @@ -83,19 +83,19 @@ public class JConstructor /** * The set of modifiers for this JMethod **/ - private JModifiers modifiers = null; + private JModifiers modifiers; /** * List of parameters for this Constructor **/ - private Map params = null; + private Map params; /** * The Class in this JMember has been declared **/ - private JClass declaringClass = null; + private JClass declaringClass; - private JSourceCode sourceCode = null; + private JSourceCode sourceCode; private JAnnotations annotations = null; @@ -127,12 +127,11 @@ public void addParameter( JParameter parameter ) //-- check current params if ( params.get( parameter.getName() ) != null ) { - StringBuilder err = new StringBuilder(); - err.append( "A parameter already exists for the constructor, " ); - err.append( this.declaringClass.getName() ); - err.append( ", with the name: " ); - err.append( parameter.getName() ); - throw new IllegalArgumentException( err.toString() ); + String err = "A parameter already exists for the constructor, " + + this.declaringClass.getName() + + ", with the name: " + + parameter.getName(); + throw new IllegalArgumentException( err ); } params.put( parameter.getName(), parameter ); diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocComment.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocComment.java index 52d9dd072..527b8a9be 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocComment.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocComment.java @@ -87,12 +87,12 @@ public class JDocComment /** * An ordered list of descriptors */ - private List _descriptors = null; + private List _descriptors; /** * The internal buffer for this JDocComment */ - private StringBuilder _comment = null; + private StringBuilder _comment; /** * Creates a new JavaDoc Comment @@ -100,7 +100,7 @@ public class JDocComment public JDocComment() { super(); - _descriptors = new ArrayList(); + _descriptors = new ArrayList<>(); _comment = new StringBuilder(); } //-- JDocComment @@ -230,10 +230,10 @@ public void print( JSourceWriter jsw ) jComment.appendComment( "\n" ); } - for ( int i = 0; i < _descriptors.size(); i++ ) + for ( JDocDescriptor descriptor : _descriptors ) { jComment.appendComment( "\n" ); - jComment.appendComment( _descriptors.get( i ).toString() ); + jComment.appendComment( descriptor.toString() ); } jComment.print( jsw ); } //-- print @@ -256,14 +256,8 @@ public void setComment( String comment ) */ public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append( "/**\n" ); - sb.append( " * " ); - - sb.append( " */\n" ); - - return sb.toString(); - } //-- toString + return "/**\n" + " * " + " */\n"; + } } //-- JDocComment diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocDescriptor.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocDescriptor.java index 161378546..1ae135c3c 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocDescriptor.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JDocDescriptor.java @@ -122,7 +122,7 @@ public class JDocDescriptor private String description = null; private String name = null; - private short type = -1; + private short type; /** * Creates a new JDocDescriptor diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JField.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JField.java index 0bfe24f9f..a3eff2ae6 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JField.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JField.java @@ -81,17 +81,17 @@ public class JField implements JMember /** * The set of modifiers for this JField **/ - private JModifiers modifiers = null; + private JModifiers modifiers; - private JType type = null; + private JType type; private String name = null; - private JDocComment comment = null; + private JDocComment comment; private String initString = null; - private JAnnotations annotations = null; + private JAnnotations annotations; /** * The Class in this JField has been declared @@ -236,13 +236,12 @@ protected void setDeclaringClass( JClass declaringClass ) public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append( modifiers.toString() ); - sb.append( ' ' ); - sb.append( type ); - sb.append( ' ' ); - sb.append( name ); - return sb.toString(); + String sb = modifiers.toString() + + ' ' + + type + + ' ' + + name; + return sb; } //-- toString /** diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JInterface.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JInterface.java index 28b70693d..b3fbdd305 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JInterface.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JInterface.java @@ -95,7 +95,7 @@ public final class JInterface extends JStructure /** * The list of methods of this JInterface */ - private List methods = null; + private List methods; /** @@ -109,7 +109,7 @@ public JInterface( String name ) throws IllegalArgumentException { super( name ); - methods = new ArrayList(); + methods = new ArrayList<>(); //-- initialize default Java doc getJDocComment().appendComment( "Interface " + getLocalName() + "." ); @@ -193,8 +193,7 @@ public void addMember( JMember jMember ) } else { - throw new IllegalArgumentException( "invalid member for JInterface: " + - jMember.toString() ); + throw new IllegalArgumentException( "invalid member for JInterface: " + jMember ); } } //-- addMember @@ -278,7 +277,7 @@ public void addMethod( JMethodSignature jMethodSig ) public JField getField( String name ) { if ( fields == null ) return null; - return (JField) fields.get( name ); + return fields.get( name ); } //-- getField /** @@ -499,7 +498,7 @@ else if ( modifiers.isPublic() ) jsw.close(); } //-- printSource - private List sourceCodeEntries = new ArrayList(); + private List sourceCodeEntries = new ArrayList<>(); public void addSourceCode( String sourceCode ) { diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMember.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMember.java index e53075a9a..81a85e694 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMember.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMember.java @@ -78,25 +78,25 @@ interface JMember { - /** - * Returns the class in which this JMember has been declared - * @return the class in which this JMember has been declared - **/ + /* + 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(); + JModifiers getModifiers(); /** * Returns the name of this JMember * @return the name of this JMember **/ - public String getName(); + String getName(); - public JAnnotations getAnnotations(); + JAnnotations getAnnotations(); } //-- JMember diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethod.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethod.java index e1ac27142..e4154905a 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethod.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethod.java @@ -86,24 +86,24 @@ public class JMethod implements JMember /** * The set of classes that contain this JMethod. **/ - private List _classes = null; + private List _classes; /** * The JavaDoc comment for this JMethod. This * will overwrite the JavaDoc for the * JMethodSignature. **/ - private JDocComment jdc = null; + private JDocComment jdc; /** * The source code for this method **/ - private JSourceCode source = null; + private JSourceCode source; /** * The signature for this method. **/ - private JMethodSignature _signature = null; + private JMethodSignature _signature; /** * The annotation(s) for this method. @@ -151,7 +151,7 @@ public JMethod( final String name, final JType returnType, final String returnDo throw new IllegalArgumentException( err ); } - _classes = new ArrayList( 1 ); + _classes = new ArrayList<>( 1 ); this.source = new JSourceCode(); _signature = new JMethodSignature( name, returnType ); this.jdc = _signature.getJDocComment(); @@ -205,9 +205,9 @@ 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 + /* + 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; diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethodSignature.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethodSignature.java index 853d7a306..9d4f4779f 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethodSignature.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JMethodSignature.java @@ -90,34 +90,34 @@ public final class JMethodSignature /** * The set of modifiers for this JMethod **/ - private JModifiers modifiers = null; + private JModifiers modifiers; /** * The return type of this Method **/ - private JType returnType = null; + private JType returnType; /** * The name of this method **/ - private String name = null; + private String name; /** * The list of parameters of this JMethodSignature in declared * order **/ - private Map params = null; + private Map params; /** * The JavaDoc comment for this method signature. **/ - private JDocComment jdc = null; + private JDocComment jdc; /** * The exceptions that this method throws **/ - private List exceptions = null; + private List exceptions; /** * Creates a new method with the given name and return type. @@ -140,7 +140,7 @@ public JMethodSignature( String name, JType returnType ) this.name = name; this.modifiers = new JModifiers(); this.params = new LinkedHashMap<>( 3 ); - this.exceptions = new ArrayList( 1 ); + this.exceptions = new ArrayList<>( 1 ); } //-- JMethodSignature /** @@ -186,12 +186,11 @@ public void addParameter( JParameter parameter ) //-- check current params if ( params.get( pName ) != null ) { - StringBuilder err = new StringBuilder(); - 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() ); + String err = "A parameter already exists for this method, " + + name + + ", with the name: " + + pName; + throw new IllegalArgumentException( err ); } @@ -431,7 +430,7 @@ public String toString() protected String[] getParameterClassNames() { - List names = new ArrayList( params.size() ); + List names = new ArrayList<>( params.size() ); for ( JParameter param : params.values() ) { diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JNaming.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JNaming.java index a42d4c51a..b74a09d6a 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JNaming.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JNaming.java @@ -177,8 +177,7 @@ public static boolean isValidJavaIdentifier( String string ) if ( !Character.isJavaIdentifierPart( chars[i] ) ) return false; } - if ( isKeyword( string ) ) return false; - return true; + return !isKeyword( string ); } //-- isValidJavaIdentifier } //-- JNaming \ No newline at end of file diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JParameter.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JParameter.java index b2f2aa20c..9c274d2b1 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JParameter.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JParameter.java @@ -153,7 +153,7 @@ public String toString() StringBuilder sb = new StringBuilder(); if ( annotations != null ) { - sb.append( annotations.toString() ); + sb.append( annotations ); sb.append( ' ' ); } sb.append( this.type.toString() ); diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceCode.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceCode.java index d96d59d9f..671e0a446 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceCode.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceCode.java @@ -85,7 +85,7 @@ public class JSourceCode /** * A list of JCodeStatements **/ - private List source = null; + private List source; /** * The indent size @@ -103,7 +103,7 @@ public class JSourceCode public JSourceCode() { super(); - source = new ArrayList(); + source = new ArrayList<>(); } //-- JSourceCode /** @@ -174,7 +174,7 @@ public void append( String segment ) add( segment ); else { - JCodeStatement jcs = (JCodeStatement) source.get( source.size() - 1 ); + JCodeStatement jcs = source.get( source.size() - 1 ); jcs.append( segment ); } } //-- append(String) @@ -193,9 +193,9 @@ public void clear() **/ public void copyInto( JSourceCode jsc ) { - for ( int i = 0; i < source.size(); i++ ) + for ( JCodeStatement jCodeStatement : source ) { - jsc.addCodeStatement( source.get( i ) ); + jsc.addCodeStatement( jCodeStatement ); } } //-- copyInto @@ -222,8 +222,7 @@ public boolean isEmpty() **/ public void print( JSourceWriter jsw ) { - for ( int i = 0; i < source.size(); i++ ) - jsw.writeln( source.get( i ).toString() ); + for ( JCodeStatement jCodeStatement : source ) jsw.writeln( jCodeStatement.toString() ); } //-- print /** @@ -247,9 +246,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); String lineSeparator = System.getProperty( "line.separator" ); - for ( int i = 0; i < source.size(); i++ ) + for ( JCodeStatement jCodeStatement : source ) { - sb.append( source.get( i ).toString() ); + sb.append( jCodeStatement.toString() ); sb.append( lineSeparator ); } return sb.toString(); @@ -274,7 +273,7 @@ private void addCodeStatement( JCodeStatement jcs ) class JCodeStatement { - private StringBuilder value = null; + private StringBuilder value; static public short DEFAULT_INDENTSIZE = 4; private short indentSize = DEFAULT_INDENTSIZE; @@ -321,7 +320,7 @@ public String toString() StringBuilder sb = new StringBuilder( indentSize + value.length() ); for ( int i = 0; i < indentSize; i++ ) sb.append( ' ' ); - sb.append( value.toString() ); + sb.append( value ); return sb.toString(); } } //-- JCodeStatement diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceWriter.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceWriter.java index f16c59c26..c59ea3cbc 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceWriter.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JSourceWriter.java @@ -103,12 +103,12 @@ public class JSourceWriter extends Writer * A flag indicating whether this JSourceWriter should perform * autoflush at the end of a new line **/ - private boolean autoflush = false; + private boolean autoflush; /** * The tab (indentation) size **/ - private short tabSize = DEFAULT_SIZE; + private short tabSize; /** * The tab representation @@ -118,7 +118,7 @@ public class JSourceWriter extends Writer /** * The character to use for indentation **/ - private char tabChar = DEFAULT_CHAR; + private char tabChar; /** * The current tab level @@ -128,7 +128,7 @@ public class JSourceWriter extends Writer /** * The writer to send all output to **/ - private Writer out = null; + private Writer out; /** @@ -286,10 +286,9 @@ public void writeln( float f ) { out.write( String.valueOf( f ) ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; linefeed(); addIndentation = true; } @@ -304,10 +303,9 @@ public void writeln( long l ) { out.write( String.valueOf( l ) ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; linefeed(); addIndentation = true; } @@ -322,10 +320,9 @@ public void writeln( int i ) { out.write( String.valueOf( i ) ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; linefeed(); addIndentation = true; } @@ -340,10 +337,9 @@ public void writeln( double d ) { out.write( String.valueOf( d ) ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; linefeed(); addIndentation = true; } @@ -359,10 +355,9 @@ public void writeln( Object obj ) { out.write( obj.toString() ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; linefeed(); addIndentation = true; } @@ -379,7 +374,7 @@ public void writeln( String string ) { out.write( string ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } } @@ -398,10 +393,9 @@ public void writeln( char[] chars ) { out.write( chars ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; linefeed(); addIndentation = true; } @@ -416,10 +410,9 @@ public void writeln( boolean b ) { out.write( String.valueOf( b ) ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; linefeed(); addIndentation = true; } @@ -434,10 +427,9 @@ public void writeln( char c ) { out.write( c ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; linefeed(); addIndentation = true; } @@ -454,10 +446,9 @@ public void close() { out.close(); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; } //-- close @@ -467,10 +458,9 @@ public void flush() { out.flush(); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; } //-- flush @@ -483,10 +473,9 @@ public void write( String s, int off, int len ) { out.write( s, off, len ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; if ( autoflush ) flush(); } } //-- write @@ -501,10 +490,9 @@ public void write( String s ) { out.write( s ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; if ( autoflush ) flush(); } } //-- write @@ -518,10 +506,9 @@ public void write( char[] buf ) { out.write( buf ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; if ( autoflush ) flush(); } @@ -537,10 +524,9 @@ public void write( int c ) { out.write( c ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; if ( autoflush ) flush(); } } //-- write @@ -555,10 +541,9 @@ public void write( char[] buf, int off, int len ) { out.write( buf, off, len ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; if ( autoflush ) flush(); } } //-- write @@ -593,10 +578,9 @@ protected void writeIndent() { for ( int i = 0; i < tabLevel; i++ ) out.write( tab ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; } //-- writeIndent @@ -623,10 +607,9 @@ private void linefeed() { out.write( lineSeparator ); } - catch ( java.io.IOException ioe ) + catch ( java.io.IOException ignored ) { } - ; } //-- linefeed /** diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JStructure.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JStructure.java index 5230d2b9a..14ccfe208 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JStructure.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JStructure.java @@ -113,23 +113,23 @@ public abstract class JStructure extends JType /** * List of imported classes and packages */ - private List imports = null; + private List imports; /** * The set of interfaces implemented/extended by this JStructure */ - private List interfaces = null; + private List interfaces; /** * The Javadoc for this JStructure */ - private JDocComment jdc = null; + private JDocComment jdc; /** * The JModifiers for this JStructure, which allows us to * change the resulting qualifiers */ - private JModifiers modifiers = null; + private JModifiers modifiers; /** * The package to which this JStructure belongs @@ -164,8 +164,8 @@ protected JStructure( String name ) throw new IllegalArgumentException( err ); } this.packageName = getPackageFromClassName( name ); - imports = new ArrayList(); - interfaces = new ArrayList(); + imports = new ArrayList<>(); + interfaces = new ArrayList<>(); jdc = new JDocComment(); modifiers = new JModifiers(); //-- initialize default Java doc @@ -278,14 +278,6 @@ public void addInterface( JInterface jInterface ) - /** - * 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 @@ -396,7 +388,7 @@ public String getFilename( String destDir ) //-- Prefix filename with path if ( pathFile.toString().length() > 0 ) - filename = pathFile.toString() + File.separator + filename; + filename = pathFile + File.separator + filename; return filename; } //-- getFilename @@ -445,12 +437,7 @@ 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); @@ -458,16 +445,7 @@ public JMethodSignature[] getMethods() { } //-- 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); @@ -477,12 +455,6 @@ public JMethodSignature getMethod(String name, int startIndex) { } //-- 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); @@ -579,7 +551,7 @@ public static boolean isValidClassName( String name ) */ public void print() { - print( (String) null, (String) null ); + print( null, null ); } //-- printSrouce /** @@ -601,7 +573,7 @@ public void print( String destDir, String lineSeparator ) String filename = getFilename( destDir ); File file = new File( filename ); - JSourceWriter jsw = null; + JSourceWriter jsw; try { jsw = new JSourceWriter( WriterFactory.newPlatformWriter( file ) ); @@ -714,96 +686,6 @@ public void printPackageDeclaration( JSourceWriter jsw ) 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); - - - StringBuilder buffer = new StringBuilder(); - - - 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 * @@ -871,7 +753,7 @@ protected static void printlnWithPrefix( String prefix, String source, JSourceWr */ protected static String getPackageFromClassName( String className ) { - int idx = -1; + int idx; if ( ( idx = className.lastIndexOf( '.' ) ) > 0 ) { return className.substring( 0, idx ); diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JType.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JType.java index 587c6e598..38fb5f3d0 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JType.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/javasource/JType.java @@ -84,7 +84,7 @@ public class JType public static final JType LONG = new JType( "long" ); public static final JType SHORT = new JType( "short" ); - private String name = null; + private String name; private boolean _isArray = false; @@ -204,7 +204,7 @@ protected void changePackage( String newPackage ) if ( this.name == null ) return; if ( this.isPrimitive() ) return; - String localName = null; + String localName; int idx = name.lastIndexOf( '.' ); if ( idx >= 0 ) localName = this.name.substring( idx + 1 ); diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.java index 9e081ef60..517225531 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaAssociationMetadata.java @@ -43,7 +43,7 @@ public class JavaAssociationMetadata static { - INIT_TYPES = new ArrayList(); + INIT_TYPES = new ArrayList<>(); INIT_TYPES.add( LAZY_INIT ); INIT_TYPES.add( CONSTRUCTOR_INIT ); INIT_TYPES.add( FIELD_INIT ); @@ -56,7 +56,7 @@ public class JavaAssociationMetadata static { - CLONE_MODES = new ArrayList(); + CLONE_MODES = new ArrayList<>(); CLONE_MODES.add( CLONE_SHALLOW ); CLONE_MODES.add( CLONE_DEEP ); } diff --git a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.java b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.java index 63b7c7e2d..3373d139b 100644 --- a/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.java +++ b/modello-plugins/modello-plugin-java/src/main/java/org/codehaus/modello/plugin/java/metadata/JavaClassMetadata.java @@ -43,7 +43,7 @@ public class JavaClassMetadata static { - CLONE_MODES = new ArrayList(); + CLONE_MODES = new ArrayList<>(); CLONE_MODES.add( CLONE_NONE ); CLONE_MODES.add( CLONE_SHALLOW ); CLONE_MODES.add( CLONE_DEEP ); diff --git a/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Permission.java b/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Permission.java index 934c6b7cd..ea76d837a 100644 --- a/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Permission.java +++ b/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Permission.java @@ -23,7 +23,7 @@ */ public interface Permission { - public String getName(); + String getName(); - public void setName( String name ); + void setName( String name ); } diff --git a/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Role.java b/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Role.java index 8a3da1881..b2e8db238 100644 --- a/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Role.java +++ b/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/Role.java @@ -25,19 +25,19 @@ */ public interface Role { - public String getName(); + String getName(); - public void setName(String name); + void setName(String name); - public void setRoles(List roles); + void setRoles(List roles); - public List getRoles(); + List getRoles(); - public void addRole(Role role); + void addRole(Role role); - public void removeRole(Role role); + void removeRole(Role role); - public void setPermission(Permission permission); + void setPermission(Permission permission); - public Permission getPermission(); + Permission getPermission(); } diff --git a/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javasource/JavaSourceTest.java b/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javasource/JavaSourceTest.java index b86280ea5..3cd554956 100644 --- a/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javasource/JavaSourceTest.java +++ b/modello-plugins/modello-plugin-java/src/test/java/org/codehaus/modello/plugin/java/javasource/JavaSourceTest.java @@ -32,7 +32,7 @@ private void checkJClass() testClass.addMember( new JField( JType.INT, "x" ) ); JClass jcString = new JClass( "String" ); - JField field = null; + JField field; field = new JField( JType.INT, "_z" ); field.appendAnnotation( "@Deprecated" ); field.getModifiers().setStatic( true ); @@ -111,7 +111,7 @@ private void checkJCompUnit() testClass.addImport( "java.util.Vector" ); testClass.addMember( new JField( JType.INT, "x" ) ); - JField field = null; + JField field; field = new JField( JType.INT, "_z" ); field.getModifiers().setStatic( true ); testClass.addField( field ); diff --git a/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/JDOMWriterGenerator.java b/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/JDOMWriterGenerator.java index 03b9cc231..32e59e2af 100644 --- a/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/JDOMWriterGenerator.java +++ b/modello-plugins/modello-plugin-jdom/src/main/java/org/codehaus/modello/plugin/jdom/JDOMWriterGenerator.java @@ -477,7 +477,7 @@ private JMethod[] generateDomMethods() private void writeAllClasses( Model objectModel, JClass jClass, ModelClass rootClass ) throws ModelloException { - List alwaysExistingElements = new ArrayList(); + List alwaysExistingElements = new ArrayList<>(); alwaysExistingElements.add( rootClass ); for ( ModelClass clazz : getClasses( objectModel ) ) diff --git a/modello-plugins/modello-plugin-jsonschema/src/main/java/org/codehaus/modello/plugin/jsonschema/JsonSchemaGenerator.java b/modello-plugins/modello-plugin-jsonschema/src/main/java/org/codehaus/modello/plugin/jsonschema/JsonSchemaGenerator.java index 8fe9e63a0..107a76e64 100644 --- a/modello-plugins/modello-plugin-jsonschema/src/main/java/org/codehaus/modello/plugin/jsonschema/JsonSchemaGenerator.java +++ b/modello-plugins/modello-plugin-jsonschema/src/main/java/org/codehaus/modello/plugin/jsonschema/JsonSchemaGenerator.java @@ -40,7 +40,6 @@ import org.codehaus.modello.plugins.xml.metadata.XmlAssociationMetadata; import org.codehaus.plexus.util.StringUtils; -import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator.Feature; @@ -70,7 +69,7 @@ public void generate( Model model, Properties parameters ) } private void generateJsonSchema( Properties parameters ) - throws IOException, ModelloException + throws IOException { Model objectModel = getModel(); @@ -158,7 +157,7 @@ private void writeClassDocumentation( JsonGenerator generator, ModelClass modelC generator.writeObjectFieldStart( "properties" ); - List required = new LinkedList(); + List required = new LinkedList<>(); ModelClass reference = modelClass; // traverse the whole modelClass hierarchy to create the nested Builder instance diff --git a/modello-plugins/modello-plugin-sax/src/main/java/org/codehaus/modello/plugin/sax/SaxWriterGenerator.java b/modello-plugins/modello-plugin-sax/src/main/java/org/codehaus/modello/plugin/sax/SaxWriterGenerator.java index e6c0d14fc..045954631 100644 --- a/modello-plugins/modello-plugin-sax/src/main/java/org/codehaus/modello/plugin/sax/SaxWriterGenerator.java +++ b/modello-plugins/modello-plugin-sax/src/main/java/org/codehaus/modello/plugin/sax/SaxWriterGenerator.java @@ -464,16 +464,6 @@ private void writeClass( ModelClass modelClass, JClass jClass ) sc.add( "contentHandler.endElement( NAMESPACE, \"" + valuesTagName + "\", \"" + valuesTagName + "\" );" ); } - sc.unindent(); - sc.add( "}" ); - - if ( wrappedItems ) - { - sc.add( "contentHandler.endElement( NAMESPACE, \"" + fieldTagName + "\", \"" + fieldTagName + "\" );" ); - } - - sc.unindent(); - sc.add( "}" ); } else { @@ -533,17 +523,15 @@ private void writeClass( ModelClass modelClass, JClass jClass ) } } - sc.unindent(); - sc.add( "}" ); - - if ( wrappedItems ) - { - sc.add( "contentHandler.endElement( NAMESPACE, \"" + fieldTagName + "\", \"" + fieldTagName + "\" );" ); - } - - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); + if ( wrappedItems ) + { + sc.add( "contentHandler.endElement( NAMESPACE, \"" + fieldTagName + "\", \"" + fieldTagName + "\" );" ); + } + sc.unindent(); + sc.add( "}" ); } } else diff --git a/modello-plugins/modello-plugin-sax/src/test/java/org/codehaus/modello/plugin/sax/SaxGeneratorTest.java b/modello-plugins/modello-plugin-sax/src/test/java/org/codehaus/modello/plugin/sax/SaxGeneratorTest.java index e0fa8b107..c3d3bcaab 100644 --- a/modello-plugins/modello-plugin-sax/src/test/java/org/codehaus/modello/plugin/sax/SaxGeneratorTest.java +++ b/modello-plugins/modello-plugin-sax/src/test/java/org/codehaus/modello/plugin/sax/SaxGeneratorTest.java @@ -56,7 +56,7 @@ public void testXpp3Generator() assertEquals( 28, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlReaderGenerator.java b/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlReaderGenerator.java index e0f29dc7e..23e4ce3c6 100644 --- a/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlReaderGenerator.java +++ b/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlReaderGenerator.java @@ -403,7 +403,7 @@ private void writeClassParser( ModelClass modelClass, JClass jClass, boolean roo writeNewSetLocation( "\"\"", uncapClassName, null, sc ); } - ModelField contentField = null; + ModelField contentField; List modelFields = getFieldsForXml( modelClass, getGeneratedVersion() ); @@ -653,8 +653,6 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, "add", sc, false ); } - sc.unindent(); - sc.add( "}" ); } else { @@ -779,9 +777,9 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, sc.add( "parser.getEvent();" ); - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); } } } diff --git a/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlWriterGenerator.java b/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlWriterGenerator.java index dca1cb783..3e4a0c464 100644 --- a/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlWriterGenerator.java +++ b/modello-plugins/modello-plugin-snakeyaml/src/main/java/org/codehaus/modello/plugin/snakeyaml/SnakeYamlWriterGenerator.java @@ -346,8 +346,6 @@ private void writeClass( ModelClass modelClass, JClass jClass ) sc.add( "generator.emit( new SequenceEndEvent( null, null ) );" ); - sc.unindent(); - sc.add( "}" ); } else { @@ -436,9 +434,9 @@ private void writeClass( ModelClass modelClass, JClass jClass ) sc.add( "generator.emit( new MappingEndEvent( null, null ) );" ); } - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); } } else diff --git a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/AbstractStaxGenerator.java b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/AbstractStaxGenerator.java index 14cc7a736..c1e945a33 100644 --- a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/AbstractStaxGenerator.java +++ b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/AbstractStaxGenerator.java @@ -88,7 +88,7 @@ protected boolean isAssociationPartToClass( ModelClass modelClass ) { if ( parts == null ) { - parts = new HashSet(); + parts = new HashSet<>(); for ( ModelClass clazz : modelClass.getModel().getClasses( getGeneratedVersion() ) ) { for ( ModelField modelField : clazz.getFields( getGeneratedVersion() ) ) diff --git a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/GeneratorNode.java b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/GeneratorNode.java index a736ecf6a..0ed3fb679 100644 --- a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/GeneratorNode.java +++ b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/GeneratorNode.java @@ -36,13 +36,13 @@ class GeneratorNode private boolean referencableChildren; - private List children = new LinkedList(); + private List children = new LinkedList<>(); private ModelAssociation association; private boolean referencable; - private Map nodesWithReferencableChildren = new HashMap(); + private Map nodesWithReferencableChildren = new HashMap<>(); private List chain; @@ -60,7 +60,7 @@ private GeneratorNode( String to, GeneratorNode parent, ModelAssociation associa { this.to = to; this.association = association; - this.chain = parent != null ? new ArrayList( parent.getChain() ) : new ArrayList(); + this.chain = parent != null ? new ArrayList<>( parent.getChain() ) : new ArrayList<>(); this.chain.add( to ); } diff --git a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java index ab6ba2395..52a6744b7 100644 --- a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java +++ b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxReaderGenerator.java @@ -93,7 +93,7 @@ public void generate( Model model, Properties parameters ) * with public RootClass read( ... ) methods. * * @throws ModelloException - * @throws IOException + * @throws IOException if an error occurs while writing the source code. */ private void generateStaxReader() throws ModelloException, IOException @@ -668,7 +668,7 @@ private static void writeNamespaceVersionGetMethod( String namespace, JClass jCl * * @param objectModel the model * @param jClass the generated class source file - * @throws ModelloException + * @throws ModelloException if an error occurs * @see {@link #writeClassParser(ModelClass, JClass, boolean)} */ private void writeAllClassesParser( Model objectModel, JClass jClass ) @@ -803,7 +803,7 @@ private void writeClassParser( ModelClass modelClass, JClass jClass, boolean roo if ( identifierFields.size() == 1 ) { - ModelField field = (ModelField) identifierFields.get( 0 ); + ModelField field = identifierFields.get( 0 ); String v = uncapClassName + ".get" + capitalise( field.getName() ) + "()"; v = getValue( field.getType(), v, (XmlFieldMetadata) field.getMetadata( XmlFieldMetadata.ID ) ); @@ -975,12 +975,10 @@ private static String getInstanceFieldName( String to ) * Add code to parse fields of a model class that are XML attributes. * * @param modelClass the model class - * @param uncapClassName + * @param uncapClassName the uncapitalised name of the class * @param sc the source code to add to - * @throws ModelloException */ private void writeAttributes( ModelClass modelClass, String uncapClassName, JSourceCode sc ) - throws ModelloException { for ( ModelField field : modelClass.getAllFields( getGeneratedVersion(), true ) ) { @@ -1004,7 +1002,7 @@ private void writeAttributes( ModelClass modelClass, String uncapClassName, JSou * @param objectName the object name in the source * @param rootElement is the enclosing model class the root class (for model version field handling) * @param jClass the generated class source file - * @throws ModelloException + * @throws ModelloException if an error occurs */ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, boolean addElse, JSourceCode sc, String objectName, boolean rootElement, JClass jClass ) @@ -1208,15 +1206,9 @@ private void processField( ModelField field, XmlFieldMetadata xmlFieldMetadata, sc.unindent(); sc.add( "}" ); - sc.unindent(); - sc.add( "}" ); - } - else - { - - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); } else { diff --git a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxSerializerGenerator.java b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxSerializerGenerator.java index 9001b0688..83f1d52d5 100644 --- a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxSerializerGenerator.java +++ b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxSerializerGenerator.java @@ -64,7 +64,7 @@ public void generate( Model model, Properties parameters ) } private void generateStaxSerializer() - throws ModelloException, IOException + throws IOException { Model objectModel = getModel(); @@ -327,7 +327,7 @@ private void addField( JClass jClass, String fieldType, String fieldName, String private void add( JClass jClass, String name, String before, String after, JParameter... params ) { - List names = new ArrayList(); + List names = new ArrayList<>(); JMethod jMethod = new JMethod( "write" + name ); jMethod.addException( new JClass( "XMLStreamException" ) ); diff --git a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxWriterGenerator.java b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxWriterGenerator.java index 8d7ccb6cc..cf2b4e64e 100644 --- a/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxWriterGenerator.java +++ b/modello-plugins/modello-plugin-stax/src/main/java/org/codehaus/modello/plugin/stax/StaxWriterGenerator.java @@ -451,16 +451,6 @@ private void writeClass( ModelClass modelClass, JClass jClass ) sc.add( "serializer.writeEndElement();" ); } - sc.unindent(); - sc.add( "}" ); - - if ( wrappedItems ) - { - sc.add( "serializer.writeEndElement();" ); - } - - sc.unindent(); - sc.add( "}" ); } else { @@ -503,17 +493,15 @@ private void writeClass( ModelClass modelClass, JClass jClass ) sc.add( "serializer.writeEndElement();" ); } - sc.unindent(); - sc.add( "}" ); - - if ( wrappedItems ) - { - sc.add( "serializer.writeEndElement();" ); - } - - sc.unindent(); - sc.add( "}" ); } + sc.unindent(); + sc.add( "}" ); + if ( wrappedItems ) + { + sc.add( "serializer.writeEndElement();" ); + } + sc.unindent(); + sc.add( "}" ); } } else @@ -621,9 +609,7 @@ private void createWriteDomMethod( JClass jClass ) sc.indent(); sc.add( "String attributeName = attributeNames[i];" ); sc.add( "serializer.writeAttribute( attributeName, dom.getAttribute( attributeName ) );" ); - sc.unindent(); - - sc.add( "}" ); + } else { @@ -634,10 +620,10 @@ private void createWriteDomMethod( JClass jClass ) sc.indent(); sc.add( "org.w3c.dom.Node attribute = attributes.item( i );" ); sc.add( "serializer.writeAttribute( attribute.getNodeName(), attribute.getNodeValue() );" ); - sc.unindent(); - - sc.add( "}" ); + } + sc.unindent(); + sc.add( "}" ); // child nodes & text if ( domAsXpp3 ) diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorPartsTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorPartsTest.java index 73c9bc1d2..9d4f572d8 100644 --- a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorPartsTest.java +++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorPartsTest.java @@ -25,7 +25,6 @@ import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.List; @@ -35,7 +34,6 @@ public class StaxGeneratorPartsTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorPartsTest() - throws ComponentLookupException { super( "stax-parts" ); } @@ -49,7 +47,7 @@ public void testStaxReaderParts() assertEquals( 12, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorTest.java index 3f3c44e22..6b37d2591 100644 --- a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorTest.java +++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorTest.java @@ -27,7 +27,6 @@ import org.codehaus.modello.model.ModelField; import org.codehaus.modello.model.Version; import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.List; @@ -39,7 +38,6 @@ public class StaxGeneratorTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorTest() - throws ComponentLookupException { super( "stax" ); } @@ -53,7 +51,7 @@ public void testStaxGenerator() assertEquals( 27, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInFieldTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInFieldTest.java index 1d51ed922..1a6080095 100644 --- a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInFieldTest.java +++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInFieldTest.java @@ -3,7 +3,6 @@ import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.List; @@ -15,7 +14,6 @@ public class StaxGeneratorVersionInFieldTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionInFieldTest() - throws ComponentLookupException { super( "stax-version-in-field" ); } @@ -29,7 +27,7 @@ public void testStaxReaderVersionInField() assertEquals( 1, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInNamespaceTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInNamespaceTest.java index aa813a944..ebdb5933d 100644 --- a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInNamespaceTest.java +++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionInNamespaceTest.java @@ -3,7 +3,6 @@ import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.List; @@ -15,7 +14,6 @@ public class StaxGeneratorVersionInNamespaceTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionInNamespaceTest() - throws ComponentLookupException { super( "stax-version-in-namespace" ); } @@ -29,7 +27,7 @@ public void testStaxReaderVersionInField() assertEquals( 1, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionReaderDelegateTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionReaderDelegateTest.java index 6fba27ad8..3cbec46ad 100644 --- a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionReaderDelegateTest.java +++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorVersionReaderDelegateTest.java @@ -23,7 +23,6 @@ */ import org.codehaus.modello.model.Model; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; /** */ @@ -31,7 +30,6 @@ public class StaxGeneratorVersionReaderDelegateTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorVersionReaderDelegateTest() - throws ComponentLookupException { super( "stax-version-reader-delegate" ); } diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionInNamespaceTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionInNamespaceTest.java index 6fc6b9d26..d6beb8daa 100644 --- a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionInNamespaceTest.java +++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionInNamespaceTest.java @@ -3,7 +3,6 @@ import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.List; @@ -15,7 +14,6 @@ public class StaxGeneratorWrongVersionInNamespaceTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorWrongVersionInNamespaceTest() - throws ComponentLookupException { super( "stax-wrong-version-in-namespace" ); } @@ -29,7 +27,7 @@ public void testStaxReaderVersionInField() assertEquals( 1, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionTest.java b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionTest.java index b97151196..c79912b65 100644 --- a/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionTest.java +++ b/modello-plugins/modello-plugin-stax/src/test/java/org/codehaus/modello/generator/xml/stax/StaxGeneratorWrongVersionTest.java @@ -3,7 +3,6 @@ import org.codehaus.modello.model.Model; import org.codehaus.modello.model.ModelClass; import org.codehaus.modello.model.Version; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import java.util.List; @@ -15,7 +14,6 @@ public class StaxGeneratorWrongVersionTest extends AbstractStaxGeneratorTestCase { public StaxGeneratorWrongVersionTest() - throws ComponentLookupException { super( "stax-wrong-version" ); } @@ -29,7 +27,7 @@ public void testStaxReaderVersionInField() assertEquals( 1, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java b/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java index ad3bc2d12..53e371e4c 100644 --- a/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java +++ b/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java @@ -494,7 +494,7 @@ else if ( ModelDefault.PROPERTIES.equals( f.getType() ) ) */ private String getModelXmlDescriptor( ModelClass rootModelClass ) { - return getElementXmlDescriptor( rootModelClass, null, new Stack() ); + return getElementXmlDescriptor( rootModelClass, null, new Stack<>() ); } /** @@ -504,7 +504,7 @@ private String getModelXmlDescriptor( ModelClass rootModelClass ) * @param association the association we are coming from (can be null) * @param stack the stack of elements that have been traversed to come to the current one * @return the String representing the tree model - * @throws ModelloRuntimeException + * @throws ModelloRuntimeException if the model is not well formed */ private String getElementXmlDescriptor( ModelClass modelClass, ModelAssociation association, Stack stack ) throws ModelloRuntimeException @@ -533,10 +533,11 @@ private String getElementXmlDescriptor( ModelClass modelClass, ModelAssociation { String schemaLocation = xmlModelMetadata.getSchemaLocation( getGeneratedVersion() ); - sb.append( " xmlns=\"" + targetNamespace + "\"" ); + sb.append( " xmlns=\"" ).append( targetNamespace ).append( "\"" ); sb.append( " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" ); - sb.append( " xsi:schemaLocation=\"" + targetNamespace ); - sb.append( " " + schemaLocation + "\"" ); + sb.append( " xsi:schemaLocation=\"" ).append( targetNamespace ); + sb.append( " " ).append( schemaLocation ) + .append( "\"" ); addNewline = true; } diff --git a/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java b/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java index a662c9c6f..49b6d99c4 100644 --- a/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java +++ b/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java @@ -43,8 +43,6 @@ import org.xmlunit.builder.Input; import org.xmlunit.diff.Diff; -import junit.framework.Assert; - /** * @author Trygve Laugstøl */ @@ -98,7 +96,7 @@ private void checkMavenXdocGenerator() assertEquals( 26, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); @@ -149,7 +147,7 @@ public void checkFeaturesXdocGenerator() String content = FileUtils.fileRead( new File( getOutputDirectory(), "features.xml" ), "UTF-8" ); - assertTrue( "Transient fields were erroneously documented", !content.contains( "transientString" ) ); + assertFalse( "Transient fields were erroneously documented", content.contains( "transientString" ) ); } public void checkSettingsXdocGenerator() @@ -167,38 +165,38 @@ public void checkSettingsXdocGenerator() String content = FileUtils.fileRead( new File( getOutputDirectory(), "settings.xml" ), "UTF-8" ); - assertTrue( "Properties field was erroneously documented", !content.contains("<properties/>") ); + assertFalse( "Properties field was erroneously documented", content.contains( "<properties/>" ) ); } /** * Checks internal links in the xdoc content: for every 'a href="#xxx"' link, a 'a name="xxx"' must exist (or there * is a problem in the generated content). * - * @param xdoc - * @throws Exception + * @param filename the filename to check + * @throws Exception if something goes wrong */ private void checkInternalLinks( String filename ) throws Exception { String content = FileUtils.fileRead( new File( getOutputDirectory(), filename ), "UTF-8" ); - Set hrefs = new HashSet(); + Set hrefs = new HashSet<>(); Pattern p = Pattern.compile( "( initialCapacity ) ); + writeComplexTypeDescriptor( w, objectModel, root, new HashSet<>( initialCapacity ) ); w.endElement(); } - finally - { - writer.close(); - } } private static void writeClassDocumentation( XMLWriter w, ModelClass modelClass ) @@ -213,7 +208,7 @@ private void writeComplexTypeDescriptor( XMLWriter w, Model objectModel, ModelCl writeClassDocumentation( w, modelClass ); - Set toWrite = new HashSet(); + Set toWrite = new HashSet<>(); if ( fields.size() > 0 ) { diff --git a/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/XsdGeneratorTest.java b/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/XsdGeneratorTest.java index 8215f1905..cf761bfb2 100644 --- a/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/XsdGeneratorTest.java +++ b/modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/XsdGeneratorTest.java @@ -56,7 +56,7 @@ public void testXsdGenerator() assertEquals( 26, classesList.size() ); - ModelClass clazz = (ModelClass) classesList.get( 0 ); + ModelClass clazz = classesList.get( 0 ); assertEquals( "Model", clazz.getName() ); diff --git a/modello-test/src/main/java/org/codehaus/modello/AbstractModelloJavaGeneratorTest.java b/modello-test/src/main/java/org/codehaus/modello/AbstractModelloJavaGeneratorTest.java index d498c6f8c..7afb26f2b 100755 --- a/modello-test/src/main/java/org/codehaus/modello/AbstractModelloJavaGeneratorTest.java +++ b/modello-test/src/main/java/org/codehaus/modello/AbstractModelloJavaGeneratorTest.java @@ -28,7 +28,6 @@ import org.codehaus.plexus.compiler.CompilerException; import org.codehaus.plexus.compiler.CompilerMessage; import org.codehaus.plexus.compiler.CompilerResult; -import org.codehaus.plexus.compiler.javac.JavacCompiler; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.FileUtils; @@ -57,11 +56,11 @@ public abstract class AbstractModelloJavaGeneratorTest extends AbstractModelloGeneratorTest { - private List dependencies = new ArrayList(); + private List dependencies = new ArrayList<>(); - private List urls = new ArrayList(); + private List urls = new ArrayList<>(); - private List classPathElements = new ArrayList(); + private List classPathElements = new ArrayList<>(); protected AbstractModelloJavaGeneratorTest( String name ) { @@ -192,14 +191,14 @@ else if ( runtimeSource <= 11 ) } else { - javaSource = Integer.toString( Math.max( minJavaSource, 7) );; + javaSource = Integer.toString( Math.max( minJavaSource, 7) ); } compileGeneratedSources( verifierId, javaSource ); } private void compileGeneratedSources( String verifierId, String javaSource ) - throws IOException, CompilerException + throws CompilerException { File generatedSources = getOutputDirectory(); File destinationDirectory = getOutputClasses(); @@ -214,7 +213,7 @@ private void compileGeneratedSources( String verifierId, String javaSource ) for ( int i = 0; i < dependencies.size(); i++ ) { - classPathElements[i + 2] = ( (File) dependencies.get( i ) ).getAbsolutePath(); + classPathElements[i + 2] = dependencies.get( i ).getAbsolutePath(); } File verifierDirectory = getTestFile( "src/test/verifiers/" + verifierId ); @@ -249,7 +248,7 @@ private void compileGeneratedSources( String verifierId, String javaSource ) CompilerResult result = compiler.performCompile( configuration ); - List errors = new ArrayList( 0 ); + List errors = new ArrayList<>( 0 ); for ( CompilerMessage compilerMessage : result.getCompilerMessages() ) { if ( compilerMessage.isError() ) @@ -275,7 +274,7 @@ protected void verifyCompiledGeneratedSources( String verifierClassName ) addClassPathFile( getTestFile( "target/test-classes" ) ); ClassLoader oldCCL = Thread.currentThread().getContextClassLoader(); - URLClassLoader classLoader = URLClassLoader.newInstance( urls.toArray( new URL[urls.size()] ), null ); + URLClassLoader classLoader = URLClassLoader.newInstance( urls.toArray( new URL[0] ), null ); Thread.currentThread().setContextClassLoader( classLoader ); @@ -283,11 +282,11 @@ protected void verifyCompiledGeneratedSources( String verifierClassName ) { Class clazz = classLoader.loadClass( verifierClassName ); - Method verify = clazz.getMethod( "verify", new Class[0] ); + Method verify = clazz.getMethod( "verify" ); try { - verify.invoke( clazz.getDeclaredConstructor().newInstance(), new Object[0] ); + verify.invoke( clazz.getDeclaredConstructor().newInstance() ); } catch ( InvocationTargetException ex ) { diff --git a/modello-test/src/main/java/org/codehaus/modello/OrderedProperties.java b/modello-test/src/main/java/org/codehaus/modello/OrderedProperties.java index 4aea5e291..03e004d1a 100644 --- a/modello-test/src/main/java/org/codehaus/modello/OrderedProperties.java +++ b/modello-test/src/main/java/org/codehaus/modello/OrderedProperties.java @@ -39,6 +39,6 @@ public class OrderedProperties public Set keySet() { - return new TreeSet( super.keySet() ); + return new TreeSet<>( super.keySet() ); } }