Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improvement] Code refactoring #4

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 60 additions & 69 deletions src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java

Large diffs are not rendered by default.

36 changes: 17 additions & 19 deletions src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.doxia.siterenderer.RendererException;
import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -91,7 +89,7 @@ public class AntlrHtmlReport extends AbstractAntlrMojo implements MavenReport {
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
*/
@Override
public String getName(Locale locale) {
public String getName(final Locale locale) {
if (StringUtils.isEmpty(name)) {
return i18n.getString("antlr-report", locale, "report.name");
}
Expand All @@ -103,7 +101,7 @@ public String getName(Locale locale) {
* @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
*/
@Override
public String getDescription(Locale locale) {
public String getDescription(final Locale locale) {
if (StringUtils.isEmpty(description)) {
return i18n.getString("antlr-report", locale, "report.description");
}
Expand All @@ -115,7 +113,7 @@ public String getDescription(Locale locale) {
* @see org.codehaus.mojo.antlr.AbstractAntlrMojo#addArgs(java.util.List)
*/
@Override
protected void addArgs(List arguments) {
protected void addArgs(final List arguments) {
// ----------------------------------------------------------------------
// See http://www.antlr2.org/doc/options.html#Command%20Line%20Options
// ----------------------------------------------------------------------
Expand All @@ -127,16 +125,16 @@ protected void addArgs(List arguments) {
* @see org.apache.maven.reporting.MavenReport#generate(org.codehaus.doxia.sink.Sink, java.util.Locale)
*/
@Override
public void generate(Sink sink, Locale locale) throws MavenReportException {
public void generate(final Sink sink, final Locale locale) throws MavenReportException {
outputDirectory = getReportOutputDirectory();

try {
executeAntlr();
} catch (MojoExecutionException e) {
} catch (final MojoExecutionException e) {
throw new MavenReportException("Antlr execution failed: " + e.getMessage(), e);
}

AntlrRenderer r = new AntlrRenderer(sink, outputDirectory, i18n, Locale.ENGLISH);
final AntlrRenderer r = new AntlrRenderer(sink, outputDirectory, i18n, Locale.ENGLISH);
r.render();
}

Expand Down Expand Up @@ -188,7 +186,7 @@ public File getReportOutputDirectory() {
* @see org.apache.maven.reporting.MavenReport#setReportOutputDirectory(java.io.File)
*/
@Override
public void setReportOutputDirectory(File reportOutputDirectory) {
public void setReportOutputDirectory(final File reportOutputDirectory) {
if ((reportOutputDirectory != null) && (!reportOutputDirectory.getAbsolutePath().endsWith("antlr"))) {
this.reportOutputDirectory = new File(reportOutputDirectory, "antlr");
} else {
Expand All @@ -202,11 +200,11 @@ public void setReportOutputDirectory(File reportOutputDirectory) {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
SiteRendererSink sink = new SiteRendererSink(
final SiteRendererSink sink = new SiteRendererSink(
new org.apache.maven.doxia.siterenderer.RenderingContext(getReportOutputDirectory(), getOutputName() + ".html"));

generate(sink, Locale.getDefault());
} catch (MavenReportException e) {
} catch (final MavenReportException e) {
throw new MojoExecutionException("An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e);
}
}
Expand All @@ -215,13 +213,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* Renderer report
*/
private static class AntlrRenderer extends AbstractMavenReportRenderer {
private File outputDirectory;
private final File outputDirectory;

private I18N i18n;
private final I18N i18n;

private Locale locale;
private final Locale locale;

AntlrRenderer(Sink sink, File outputDirectory, I18N i18n, Locale locale) {
AntlrRenderer(final Sink sink, final File outputDirectory, final I18N i18n, final Locale locale) {
super(sink);

this.outputDirectory = outputDirectory;
Expand Down Expand Up @@ -253,14 +251,14 @@ public void renderBody() {
startSection(i18n.getString("antlr-report", locale, "report.grammars.title"));

try {
List htmlFiles = FileUtils.getFiles(outputDirectory, "**/*.html", "**/*index.html");
final List htmlFiles = FileUtils.getFiles(outputDirectory, "**/*.html", "**/*index.html");

if (htmlFiles.isEmpty()) {
sink.text(i18n.getString("antlr-report", locale, "report.grammars.noreport"));
} else {
sink.list();
for (Iterator it = htmlFiles.iterator(); it.hasNext();) {
File current = (File) it.next();
for (final Object htmlFile : htmlFiles) {
final File current = (File) htmlFile;

sink.listItem();
sink.link(PathUtils.toRelative(outputDirectory, current.getAbsolutePath()));
Expand All @@ -270,7 +268,7 @@ public void renderBody() {
}
sink.list_();
}
} catch (IOException e) {
} catch (final IOException e) {
throw new RuntimeException("IOException: " + e.getMessage(), e);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/mojo/antlr/AntlrPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void execute() throws MojoExecutionException {
/**
* @see org.codehaus.mojo.antlr.AbstractAntlrMojo#addArgs(java.util.List)
*/
protected void addArgs(List arguments) {
protected void addArgs(final List arguments) {
// nop
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/codehaus/mojo/antlr/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
* @author Steve Ebersole
*/
public interface Environment {
public Log getLog();
Log getLog();

public File getSourceDirectory();
File getSourceDirectory();

public File getOutputDirectory();
File getOutputDirectory();
}
10 changes: 5 additions & 5 deletions src/main/java/org/codehaus/mojo/antlr/metadata/Grammar.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Grammar {

private String exportVocab;

public Grammar(GrammarFile grammarFile) {
public Grammar(final GrammarFile grammarFile) {
this.grammarFile = grammarFile;
grammarFile.addGrammar(this);
}
Expand All @@ -52,31 +52,31 @@ public String getClassName() {
return className;
}

public void setClassName(String className) {
public void setClassName(final String className) {
this.className = className;
}

public String getSuperGrammarName() {
return superGrammarName;
}

public void setSuperGrammarName(String superGrammarName) {
public void setSuperGrammarName(final String superGrammarName) {
this.superGrammarName = superGrammarName;
}

public String getImportVocab() {
return importVocab;
}

public void setImportVocab(String importVocab) {
public void setImportVocab(final String importVocab) {
this.importVocab = importVocab;
}

public String getExportVocab() {
return exportVocab;
}

public void setExportVocab(String exportVocab) {
public void setExportVocab(final String exportVocab) {
this.exportVocab = exportVocab;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class GrammarFile {
private final String[] glibs;

private String packageName;
private List<Grammar> grammars = new ArrayList<>();
private final List<Grammar> grammars = new ArrayList<>();

public GrammarFile(String id, String fileName, String[] glibs) {
public GrammarFile(final String id, final String fileName, final String[] glibs) {
this.id = id;
this.fileName = fileName;
this.glibs = glibs;
Expand All @@ -58,11 +58,11 @@ public String getPackageName() {
return packageName;
}

void setPackageName(String packageName) {
void setPackageName(final String packageName) {
this.packageName = packageName;
}

void addGrammar(Grammar grammar) {
void addGrammar(final Grammar grammar) {
grammars.add(grammar);
}

Expand Down
Loading