Skip to content

Commit

Permalink
Fixed PMD warnings and added Javadocs. Refactored XML data type parsi…
Browse files Browse the repository at this point in the history
…ng implementation classes.
  • Loading branch information
david-waltermire committed Nov 1, 2024
1 parent a706005 commit 3d5216c
Show file tree
Hide file tree
Showing 35 changed files with 95 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public void execute() throws MojoExecutionException {
// }
}

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private void performGeneration() throws MojoExecutionException {
File outputDir = getOutputDirectory();
if (getLog().isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void execute() throws MojoExecutionException {
}
}

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private void performGeneration() throws MojoExecutionException {
File outputDir = getOutputDirectory();
if (getLog().isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ protected OpenOption[] getWriteOpenOptions() {
return OPEN_OPTIONS_TRUNCATE;
}

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private DynamicContainer generateScenario(
@NonNull TestScenario scenario,
@NonNull URI collectionUri,
Expand Down Expand Up @@ -346,7 +347,7 @@ private DynamicContainer generateScenario(
try {
schemaPath = ObjectUtils.requireNonNull(lazySchema.get());
} catch (Exception ex) {
throw new JUnitException( // NOPMD - cause is relevant, exception is not
throw new JUnitException(
"failed to generate schema", ex);
}
validateWithSchema(ObjectUtils.requireNonNull(supplier.get()), schemaPath);
Expand Down Expand Up @@ -416,13 +417,14 @@ protected Path convertContent(
LOGGER.atInfo().log("Converting content '{}' to {} as '{}'", resource, toFormat, convertedContetPath);
}

@SuppressWarnings("rawtypes") ISerializer serializer
ISerializer<?> serializer
= context.newSerializer(toFormat, ObjectUtils.asType(object.getClass()));
serializer.serialize(ObjectUtils.asType(object), convertedContetPath, getWriteOpenOptions());

return convertedContetPath;
}

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private DynamicTest generateValidationCase(
@NonNull ContentCaseType contentCase,
@NonNull IBindingContext bindingContext,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static Stream<? extends INamedModelInstanceAbsolute> explodeChoice(@NonN

@NonNull
protected List<IGroupableModelInstanceJsonProperty<?>> getGroupableModelInstances() {
return groupableModelInstances.get();
return ObjectUtils.notNull(groupableModelInstances.get());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ protected void generateBody(
}

// generate flag properties
for (IFlagInstance flag : flags) {
flags.forEach(flag -> {
assert flag != null;
new FlagInstanceJsonProperty(flag)
.generateProperty(properties, state); // NOPMD unavoidable instantiation
}
new FlagInstanceJsonProperty(flag).generateProperty(properties, state);
});

// generate value property
if (jsonValueKeyFlag == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;
package gov.nist.secauto.metaschema.schemagen.xml;

import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.schemagen.datatype.AbstractDatatypeManager;
import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeProvider;
import gov.nist.secauto.metaschema.schemagen.xml.impl.IDatatypeProvider;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlCoreDatatypeProvider;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlMarkupLineDatatypeProvider;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlMarkupMultilineDatatypeProvider;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlProseCompositDatatypeProvider;

import org.codehaus.stax2.XMLStreamWriter2;

Expand All @@ -21,6 +25,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import nl.talsmasoftware.lazy4j.Lazy;

/**
* Support for managing Module data type implementations aligned with the XML
* schema format for use in schema generation.
*/
public class XmlDatatypeManager
extends AbstractDatatypeManager {
public static final String NS_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import gov.nist.secauto.metaschema.schemagen.AbstractSchemaGenerator;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationException;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationFeature;
import gov.nist.secauto.metaschema.schemagen.xml.datatype.XmlDatatypeManager;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlGenerationState;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.IXmlType;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.IXmlType;

import org.codehaus.stax2.XMLOutputFactory2;
import org.codehaus.stax2.XMLStreamWriter2;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import gov.nist.secauto.metaschema.core.util.CollectionUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;

import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeContent;
import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeProvider;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import org.codehaus.stax2.XMLStreamWriter2;
import org.eclipse.jdt.annotation.Owning;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeContent;

import org.eclipse.jdt.annotation.Owning;
import org.jdom2.Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SPDX-FileCopyrightText: none
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.impl;

import java.util.List;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import edu.umd.cs.findbugs.annotations.NonNull;

public interface IDatatypeContent {
/**
* Get the name of the data type.
*
* @return the name
*/
@NonNull
String getTypeName();

/**
* Get the data type names this type depends on.
*
* @return the names
*/
@NonNull
List<String> getDependencies();

/**
* Write the data type to the XML stream.
*
* @param writer
* the XML stream
* @throws XMLStreamException
* if an error occurred while writing to the XML stream
*/
void write(@NonNull XMLStreamWriter writer) throws XMLStreamException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import org.codehaus.stax2.XMLStreamWriter2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.schemagen.datatype.AbstractDatatypeContent;

import org.jdom2.Element;
import org.jdom2.output.Format;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import org.jdom2.Document;
import org.jdom2.Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeContent;

import org.jdom2.Attribute;
import org.jdom2.Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import gov.nist.secauto.metaschema.schemagen.AbstractGenerationState;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationException;
import gov.nist.secauto.metaschema.schemagen.SchemaGenerationFeature;
import gov.nist.secauto.metaschema.schemagen.xml.datatype.XmlDatatypeManager;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.IXmlComplexType;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.IXmlSimpleType;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.IXmlType;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlComplexTypeAssemblyDefinition;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlComplexTypeFieldDefinition;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlSimpleTypeDataTypeReference;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlSimpleTypeDataTypeRestriction;
import gov.nist.secauto.metaschema.schemagen.xml.schematype.XmlSimpleTypeUnion;
import gov.nist.secauto.metaschema.schemagen.xml.XmlDatatypeManager;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.IXmlComplexType;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.IXmlSimpleType;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.IXmlType;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlComplexTypeAssemblyDefinition;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlComplexTypeFieldDefinition;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlSimpleTypeDataTypeReference;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlSimpleTypeDataTypeRestriction;
import gov.nist.secauto.metaschema.schemagen.xml.impl.schematype.XmlSimpleTypeUnion;

import org.codehaus.stax2.XMLStreamWriter2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

public class XmlMarkupLineDatatypeProvider
extends AbstractXmlMarkupDatatypeProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

public class XmlMarkupMultilineDatatypeProvider
extends AbstractXmlMarkupDatatypeProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import gov.nist.secauto.metaschema.core.model.IModule;
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeContent;

import org.jdom2.Element;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.datatype;

import gov.nist.secauto.metaschema.schemagen.datatype.CompositeDatatypeProvider;
import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeContent;
import gov.nist.secauto.metaschema.schemagen.datatype.IDatatypeProvider;
package gov.nist.secauto.metaschema.schemagen.xml.impl;

import org.codehaus.stax2.XMLStreamWriter2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.schematype;
package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;

import gov.nist.secauto.metaschema.core.model.IFlagInstance;
import gov.nist.secauto.metaschema.core.model.IModelDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.schematype;
package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;

import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
import gov.nist.secauto.metaschema.core.model.IValuedDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.schematype;
package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;

import javax.xml.namespace.QName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.schematype;
package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;

import gov.nist.secauto.metaschema.core.model.IDefinition;
import gov.nist.secauto.metaschema.schemagen.ModuleIndex.DefinitionEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.schemagen.xml.schematype;
package gov.nist.secauto.metaschema.schemagen.xml.impl.schematype;

import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
import gov.nist.secauto.metaschema.schemagen.xml.impl.XmlGenerationState;
Expand Down
Loading

0 comments on commit 3d5216c

Please sign in to comment.