Skip to content

Commit

Permalink
Add clang-format to the XML extension project
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Jan 5, 2024
1 parent 37bc91a commit fd7fe62
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
18 changes: 17 additions & 1 deletion compiler/extensions/xml/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ zserio_xml.install_dir - Directory where to install Zserio Doc Extension
zserio_core.jar_file - Zserio core jar file used for classpath.
Default is "${zserio_extensions.build_dir}/../core/${ant.java.version}/jar/
zserio_core.jar".
clang_format.exe_file - Clang-format executable file. If not set, clang-format is not run.
spotbugs.home_dir - Location of the spotbugs tool. If not set, spotbugs is not run.
-->
Expand Down Expand Up @@ -149,7 +150,22 @@ spotbugs.home_dir - Location of the spotbugs tool. If not set, spotb
</copy>
</target>

<target name="spotbugs" depends="install" if="spotbugs.home_dir">
<target name="clang_format" depends="install" if="clang_format.exe_file">
<echo>
Command hints to reformat source using clang-format tool:
git clang-format
clang-format --style=file -i [SOURCE]
</echo>
<apply executable="${clang_format.exe_file}" failonerror="true">
<arg value="--style=file"/>
<arg value="--dry-run"/>
<arg value="--Werror"/>
<srcfile/>
<fileset dir="${zserio_xml.src_dir}" includes="**/*.java"/>
</apply>
</target>

<target name="spotbugs" depends="clang_format" if="spotbugs.home_dir">
<mkdir dir="${zserio_xml.spotbugs.out_dir}"/>
<taskdef classpath="${spotbugs.home_dir}/lib/spotbugs-ant.jar"
resource="edu/umd/cs/findbugs/anttask/tasks.properties"/>
Expand Down
27 changes: 13 additions & 14 deletions compiler/extensions/xml/src/zserio/extension/xml/XmlAstWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -31,11 +30,18 @@
import zserio.ast.CompatibilityVersion;
import zserio.ast.Constant;
import zserio.ast.DocComment;
import zserio.ast.DocCommentClassic;
import zserio.ast.DocCommentMarkdown;
import zserio.ast.DocElement;
import zserio.ast.DocLine;
import zserio.ast.DocLineElement;
import zserio.ast.DocMultiline;
import zserio.ast.DocParagraph;
import zserio.ast.DocTagDeprecated;
import zserio.ast.DocTagParam;
import zserio.ast.DocTagSee;
import zserio.ast.DocTagTodo;
import zserio.ast.DocText;
import zserio.ast.DynamicBitFieldType;
import zserio.ast.EnumItem;
import zserio.ast.EnumType;
Expand All @@ -47,15 +53,15 @@
import zserio.ast.Function;
import zserio.ast.Import;
import zserio.ast.InstantiateType;
import zserio.ast.Package;
import zserio.ast.PackageSymbol;
import zserio.ast.Parameter;
import zserio.ast.PubsubMessage;
import zserio.ast.PubsubType;
import zserio.ast.Root;
import zserio.ast.Rule;
import zserio.ast.RuleGroup;
import zserio.ast.ScopeSymbol;
import zserio.ast.Package;
import zserio.ast.PackageSymbol;
import zserio.ast.ServiceMethod;
import zserio.ast.ServiceType;
import zserio.ast.SqlConstraint;
Expand All @@ -73,13 +79,6 @@
import zserio.ast.UnionType;
import zserio.ast.VarIntegerType;
import zserio.ast.ZserioAstVisitor;
import zserio.ast.DocCommentClassic;
import zserio.ast.DocCommentMarkdown;
import zserio.ast.DocParagraph;
import zserio.ast.DocTagParam;
import zserio.ast.DocTagSee;
import zserio.ast.DocTagTodo;
import zserio.ast.DocText;
import zserio.ast.ZserioTemplatableType;
import zserio.ast.ZserioType;
import zserio.extension.common.ZserioExtensionException;
Expand Down Expand Up @@ -168,8 +167,8 @@ public void visitCompatibilityVersion(CompatibilityVersion compatibilityVersion)
public void visitImport(Import unitImport)
{
final Element xmlElement = xmlDoc.createElement("IMPORT");
xmlElement.setAttribute("importedPackageName",
unitImport.getImportedPackage().getPackageName().toString());
xmlElement.setAttribute(
"importedPackageName", unitImport.getImportedPackage().getPackageName().toString());

final PackageSymbol importedSymbol = unitImport.getImportedSymbol();
if (importedSymbol != null)
Expand Down Expand Up @@ -439,8 +438,8 @@ public void visitTypeReference(TypeReference typeReference)
final Element xmlElement = xmlDoc.createElement("TYPE_REFERENCE");
if (!typeReference.getReferencedPackageName().isEmpty())
{
xmlElement.setAttribute("referencedPackageName",
typeReference.getReferencedPackageName().toString());
xmlElement.setAttribute(
"referencedPackageName", typeReference.getReferencedPackageName().toString());
}
xmlElement.setAttribute("referencedTypeName", typeReference.getReferencedTypeName());
visitAstNode(typeReference, xmlElement);
Expand Down

0 comments on commit fd7fe62

Please sign in to comment.