From 45edb6ebad170edcfd6863e664819082f3c05d95 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2024 21:14:07 +0200 Subject: [PATCH 1/8] Add final's --- .../mojo/antlr/AbstractAntlrMojo.java | 80 +++++++++---------- .../codehaus/mojo/antlr/AntlrHtmlReport.java | 34 ++++---- .../org/codehaus/mojo/antlr/AntlrPlugin.java | 2 +- .../codehaus/mojo/antlr/metadata/Grammar.java | 10 +-- .../mojo/antlr/metadata/GrammarFile.java | 8 +- .../antlr/metadata/MetadataExtracter.java | 77 +++++++++--------- .../codehaus/mojo/antlr/metadata/XRef.java | 20 ++--- .../codehaus/mojo/antlr/options/Grammar.java | 12 +-- .../mojo/antlr/plan/GenerationPlan.java | 8 +- .../antlr/plan/GenerationPlanBuilder.java | 20 ++--- .../org/codehaus/mojo/antlr/proxy/Helper.java | 8 +- .../org/codehaus/mojo/antlr/proxy/Tool.java | 4 +- 12 files changed, 141 insertions(+), 142 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java index cd964888..10f2f852 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java +++ b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java @@ -205,11 +205,11 @@ protected void executeAntlr() throws MojoExecutionException { validateParameters(); - Artifact antlrArtifact = locateAntlrArtifact(); - MetadataExtracter metadataExtracter = new MetadataExtracter(this, new Helper(antlrArtifact)); - XRef metadata = metadataExtracter.processMetadata(getGrammars()); + final Artifact antlrArtifact = locateAntlrArtifact(); + final MetadataExtracter metadataExtracter = new MetadataExtracter(this, new Helper(antlrArtifact)); + final XRef metadata = metadataExtracter.processMetadata(getGrammars()); - Iterator generationPlans = new GenerationPlanBuilder(this).buildGenerationPlans(metadata).iterator(); + final Iterator generationPlans = new GenerationPlanBuilder(this).buildGenerationPlans(metadata).iterator(); while (generationPlans.hasNext()) { final GenerationPlan plan = (GenerationPlan) generationPlans.next(); if (!plan.isOutOfDate()) { @@ -230,7 +230,7 @@ protected void executeAntlr() throws MojoExecutionException { protected final Artifact locateAntlrArtifact() throws NoAntlrDependencyDefinedException { Artifact antlrArtifact = null; if (project.getCompileArtifacts() != null) { - Iterator projectArtifacts = project.getCompileArtifacts().iterator(); + final Iterator projectArtifacts = project.getCompileArtifacts().iterator(); while (projectArtifacts.hasNext()) { final Artifact artifact = (Artifact) projectArtifacts.next(); if ("antlr".equals(artifact.getGroupId()) @@ -248,7 +248,7 @@ protected final Artifact locateAntlrArtifact() throws NoAntlrDependencyDefinedEx return antlrArtifact; } - protected void performGeneration(GenerationPlan plan, Artifact antlrArtifact) throws MojoExecutionException { + protected void performGeneration(final GenerationPlan plan, final Artifact antlrArtifact) throws MojoExecutionException { if (!plan.getGenerationDirectory().getParentFile().exists()) { plan.getGenerationDirectory().getParentFile().mkdirs(); } @@ -258,7 +258,7 @@ protected void performGeneration(GenerationPlan plan, Artifact antlrArtifact) th // Note: grammar file should be last // ---------------------------------------------------------------------- - List arguments = new LinkedList<>(); + final List arguments = new LinkedList<>(); addArgIf(arguments, debug, "-debug"); addArgIf(arguments, diagnostic, "-diagnostic"); addArgIf(arguments, trace, "-trace"); @@ -273,8 +273,8 @@ protected void performGeneration(GenerationPlan plan, Artifact antlrArtifact) th if (plan.getCollectedSuperGrammarIds().size() > 0) { arguments.add("-glib"); - StringBuffer buffer = new StringBuffer(); - Iterator ids = plan.getCollectedSuperGrammarIds().iterator(); + final StringBuffer buffer = new StringBuffer(); + final Iterator ids = plan.getCollectedSuperGrammarIds().iterator(); while (ids.hasNext()) { buffer.append(new File(sourceDirectory, (String) ids.next())); if (ids.hasNext()) { @@ -286,20 +286,20 @@ protected void performGeneration(GenerationPlan plan, Artifact antlrArtifact) th arguments.add(plan.getSource().getPath()); - String[] args = (String[]) arguments.toArray(new String[arguments.size()]); + final String[] args = (String[]) arguments.toArray(new String[arguments.size()]); if (plan.getImportVocabTokenTypesDirectory() != null && !plan.getImportVocabTokenTypesDirectory().equals(plan.getGenerationDirectory())) { // We need to spawn a new process to properly set up PWD - CommandLine commandLine = new CommandLine("java"); + final CommandLine commandLine = new CommandLine("java"); commandLine.addArgument("-classpath", false); commandLine.addArgument(generateClasspathForProcessSpawning(antlrArtifact), true); commandLine.addArgument("antlr.Tool", false); commandLine.addArguments(args, true); - DefaultExecutor executor = new DefaultExecutor(); + final DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(plan.getImportVocabTokenTypesDirectory()); try { executor.execute(commandLine); - } catch (IOException e) { + } catch (final IOException e) { getLog().warn("Error spawning process to execute antlr tool : " + e.getMessage()); } @@ -320,15 +320,15 @@ protected void performGeneration(GenerationPlan plan, Artifact antlrArtifact) th System.setProperty("user.dir", plan.getImportVocabTokenTypesDirectory().getPath()); } - PrintStream oldErr = System.err; + final PrintStream oldErr = System.err; - OutputStream errOS = new StringOutputStream(); - PrintStream err = new PrintStream(errOS); + final OutputStream errOS = new StringOutputStream(); + final PrintStream err = new PrintStream(errOS); System.setErr(err); try { executeAntlrInIsolatedClassLoader((String[]) arguments.toArray(new String[0]), antlrArtifact); - } catch (RuntimeException e) { + } catch (final RuntimeException e) { if (e.getMessage().contains("ANTLR Panic")) { // ANTLR-12 // Now basically every ANTLR version could set different message, how to handle in generic way? @@ -349,29 +349,29 @@ protected void performGeneration(GenerationPlan plan, Artifact antlrArtifact) th } } - private String generateClasspathForProcessSpawning(Artifact antlrArtifact) { + private String generateClasspathForProcessSpawning(final Artifact antlrArtifact) { // todo : is maven by itself enough for the generation??? return antlrArtifact.getFile().getPath(); } - private void executeAntlrInIsolatedClassLoader(String[] args, Artifact antlrArtifact) throws MojoExecutionException { - try (URLClassLoader classLoader = new URLClassLoader(new URL[] { antlrArtifact.getFile().toURI().toURL() }, getSystemClassLoader())) { + private void executeAntlrInIsolatedClassLoader(final String[] args, final Artifact antlrArtifact) throws MojoExecutionException { + try (final URLClassLoader classLoader = new URLClassLoader(new URL[] { antlrArtifact.getFile().toURI().toURL() }, getSystemClassLoader())) { classLoader.loadClass("antlr.Tool") .getMethod("main", new Class[] { String[].class }) .invoke(null, new Object[] { args }); - } catch (MalformedURLException e) { + } catch (final MalformedURLException e) { throw new MojoExecutionException("Unable to resolve antlr:antlr artifact url", e); - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { throw new MojoExecutionException("could not locate antlr.Tool class"); - } catch (NoSuchMethodException e) { + } catch (final NoSuchMethodException e) { throw new MojoExecutionException("error locating antlt.Tool#main", e); - } catch (InvocationTargetException e) { + } catch (final InvocationTargetException e) { throw new MojoExecutionException("error perforing antlt.Tool#main", e.getTargetException()); - } catch (IllegalAccessException e) { + } catch (final IllegalAccessException e) { throw new MojoExecutionException("error perforing antlt.Tool#main", e); - } catch (IOException e1) { + } catch (final IOException e1) { e1.printStackTrace(); } } @@ -390,7 +390,7 @@ private void executeAntlrInIsolatedClassLoader(String[] args, Artifact antlrArti * @param b * @param value */ - protected static void addArgIf(List arguments, boolean b, String value) { + protected static void addArgIf(final List arguments, final boolean b, final String value) { if (b) { arguments.add(value); } @@ -402,19 +402,19 @@ protected static void addArgIf(List arguments, boolean b, String value) * @return generated file * @throws IOException */ - private File getGeneratedFile(String grammar, File outputDir) throws IOException { + private File getGeneratedFile(final String grammar, final File outputDir) throws IOException { String generatedFileName = null; String packageName = ""; - BufferedReader in = new BufferedReader(new FileReader(grammar)); + final BufferedReader in = new BufferedReader(new FileReader(grammar)); String line; while ((line = in.readLine()) != null) { line = line.trim(); - int extendsIndex = line.indexOf(" extends "); + final int extendsIndex = line.indexOf(" extends "); if (line.startsWith("class ") && extendsIndex > -1) { generatedFileName = line.substring(6, extendsIndex).trim(); @@ -453,7 +453,7 @@ private File getGeneratedFile(String grammar, File outputDir) throws IOException */ private void validateParameters() throws MojoExecutionException { if ((isEmpty(grammars)) && ((grammarDefs == null) || (grammarDefs.length == 0))) { - StringBuffer msg = new StringBuffer(); + final StringBuffer msg = new StringBuffer(); msg.append("Antlr plugin parameters are invalid/missing.").append('\n'); msg.append("Inside the definition for plugin 'antlr-maven-plugin' specify the following:").append('\n'); msg.append('\n'); @@ -476,14 +476,14 @@ private void validateParameters() throws MojoExecutionException { * @return an array of grammar from grammars and grammarDefs variables */ private org.codehaus.mojo.antlr.options.Grammar[] getGrammars() { - List grammarList = new ArrayList<>(); - Set grammarSet = new HashSet<>(); + final List grammarList = new ArrayList<>(); + final Set grammarSet = new HashSet<>(); if (StringUtils.isNotEmpty(grammars)) { - StringTokenizer st = new StringTokenizer(grammars, ", "); + final StringTokenizer st = new StringTokenizer(grammars, ", "); while (st.hasMoreTokens()) { - String currentGrammar = st.nextToken().trim(); + final String currentGrammar = st.nextToken().trim(); if (StringUtils.isNotEmpty(currentGrammar)) { // Check if some pattern has been used @@ -494,9 +494,9 @@ private org.codehaus.mojo.antlr.options.Grammar[] getGrammars() { .replaceAll("\\?", "."); // Filter the source directory - String[] dir = sourceDirectory.list(new FilenameFilter() { + final String[] dir = sourceDirectory.list(new FilenameFilter() { @Override - public boolean accept(File dir, String s) { + public boolean accept(final File dir, final String s) { return Pattern.matches(transformedGrammar, s); } }); @@ -505,7 +505,7 @@ public boolean accept(File dir, String s) { for (int i = 0; i < dir.length; i++) { // Just add fles which are not in the set of files already seen. if (!grammarSet.contains(dir[i])) { - org.codehaus.mojo.antlr.options.Grammar grammar = new org.codehaus.mojo.antlr.options.Grammar(); + final org.codehaus.mojo.antlr.options.Grammar grammar = new org.codehaus.mojo.antlr.options.Grammar(); grammar.setName(dir[i]); grammarList.add(grammar); @@ -514,7 +514,7 @@ public boolean accept(File dir, String s) { } } else { if (!grammarSet.contains(currentGrammar)) { - org.codehaus.mojo.antlr.options.Grammar grammar = new org.codehaus.mojo.antlr.options.Grammar(); + final org.codehaus.mojo.antlr.options.Grammar grammar = new org.codehaus.mojo.antlr.options.Grammar(); grammar.setName(currentGrammar); grammarList.add(grammar); @@ -532,7 +532,7 @@ public boolean accept(File dir, String s) { } public static class NoAntlrDependencyDefinedException extends MojoExecutionException { - public NoAntlrDependencyDefinedException(String s) { + public NoAntlrDependencyDefinedException(final String s) { super(s); } } diff --git a/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java b/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java index a27e7ca7..32c25493 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java +++ b/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java @@ -91,7 +91,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"); } @@ -103,7 +103,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"); } @@ -115,7 +115,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 // ---------------------------------------------------------------------- @@ -127,16 +127,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(); } @@ -188,7 +188,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 { @@ -202,11 +202,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); } } @@ -215,13 +215,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; @@ -253,14 +253,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 Iterator it = htmlFiles.iterator(); it.hasNext();) { + final File current = (File) it.next(); sink.listItem(); sink.link(PathUtils.toRelative(outputDirectory, current.getAbsolutePath())); @@ -270,7 +270,7 @@ public void renderBody() { } sink.list_(); } - } catch (IOException e) { + } catch (final IOException e) { throw new RuntimeException("IOException: " + e.getMessage(), e); } diff --git a/src/main/java/org/codehaus/mojo/antlr/AntlrPlugin.java b/src/main/java/org/codehaus/mojo/antlr/AntlrPlugin.java index 77fb69b2..4802b3f4 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AntlrPlugin.java +++ b/src/main/java/org/codehaus/mojo/antlr/AntlrPlugin.java @@ -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 } } diff --git a/src/main/java/org/codehaus/mojo/antlr/metadata/Grammar.java b/src/main/java/org/codehaus/mojo/antlr/metadata/Grammar.java index 521bc574..6571c82e 100644 --- a/src/main/java/org/codehaus/mojo/antlr/metadata/Grammar.java +++ b/src/main/java/org/codehaus/mojo/antlr/metadata/Grammar.java @@ -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); } @@ -52,7 +52,7 @@ public String getClassName() { return className; } - public void setClassName(String className) { + public void setClassName(final String className) { this.className = className; } @@ -60,7 +60,7 @@ public String getSuperGrammarName() { return superGrammarName; } - public void setSuperGrammarName(String superGrammarName) { + public void setSuperGrammarName(final String superGrammarName) { this.superGrammarName = superGrammarName; } @@ -68,7 +68,7 @@ public String getImportVocab() { return importVocab; } - public void setImportVocab(String importVocab) { + public void setImportVocab(final String importVocab) { this.importVocab = importVocab; } @@ -76,7 +76,7 @@ public String getExportVocab() { return exportVocab; } - public void setExportVocab(String exportVocab) { + public void setExportVocab(final String exportVocab) { this.exportVocab = exportVocab; } diff --git a/src/main/java/org/codehaus/mojo/antlr/metadata/GrammarFile.java b/src/main/java/org/codehaus/mojo/antlr/metadata/GrammarFile.java index 02effe68..fd70adbc 100644 --- a/src/main/java/org/codehaus/mojo/antlr/metadata/GrammarFile.java +++ b/src/main/java/org/codehaus/mojo/antlr/metadata/GrammarFile.java @@ -34,9 +34,9 @@ public class GrammarFile { private final String[] glibs; private String packageName; - private List grammars = new ArrayList<>(); + private final List 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; @@ -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); } diff --git a/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java b/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java index 6f8eaa23..95e0821d 100644 --- a/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java +++ b/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java @@ -31,49 +31,49 @@ public class MetadataExtracter { private final Environment environment; private final Class antlrHierarchyClass; - public MetadataExtracter(Environment environment, Helper helper) throws MojoExecutionException { + public MetadataExtracter(final Environment environment, final Helper helper) throws MojoExecutionException { this.environment = environment; this.helper = helper; this.antlrHierarchyClass = helper.getAntlrHierarchyClass(); } - public XRef processMetadata(org.codehaus.mojo.antlr.options.Grammar[] grammars) throws MojoExecutionException { - Object hierarchy; - Method readGrammarFileMethod; - Method getFileMethod; + public XRef processMetadata(final org.codehaus.mojo.antlr.options.Grammar[] grammars) throws MojoExecutionException { + final Object hierarchy; + final Method readGrammarFileMethod; + final Method getFileMethod; try { - Object antlrTool = helper.getAntlrToolClass().getDeclaredConstructor().newInstance(); + final Object antlrTool = helper.getAntlrToolClass().getDeclaredConstructor().newInstance(); hierarchy = antlrHierarchyClass.getConstructor(new Class[] { helper.getAntlrToolClass() }) .newInstance(new Object[] { antlrTool }); readGrammarFileMethod = antlrHierarchyClass.getMethod("readGrammarFile", Helper.STRING_ARG_SIGNATURE); getFileMethod = antlrHierarchyClass.getMethod("getFile", Helper.STRING_ARG_SIGNATURE); - } catch (Throwable t) { + } catch (final Throwable t) { throw new MojoExecutionException("Unable to instantiate Antlr preprocessor tool", causeToUse(t)); } - List files = new ArrayList<>(); + final List files = new ArrayList<>(); for (int i = 0; i < grammars.length; i++) { - String grammarName = grammars[i].getName().trim(); + final String grammarName = grammars[i].getName().trim(); if (isEmpty(grammarName)) { environment.getLog().info("Empty grammar in the configuration; skipping."); continue; } - File grammar = new File(environment.getSourceDirectory(), grammarName); + final File grammar = new File(environment.getSourceDirectory(), grammarName); if (!grammar.exists()) { throw new MojoExecutionException("The grammar '" + grammar.getAbsolutePath() + "' doesnt exist."); } - String grammarFilePath = grammar.getPath(); - GrammarFile grammarFile = new GrammarFile( + final String grammarFilePath = grammar.getPath(); + final GrammarFile grammarFile = new GrammarFile( grammarName, grammarFilePath, isNotEmpty(grammars[i].getGlib()) ? split(grammars[i].getGlib(), ":,") : new String[0]); // :( antlr.preprocessor.GrammarFile's only access to package is through a protected field :( - try (BufferedReader in = new BufferedReader(new FileReader(grammar))) { + try (final BufferedReader in = new BufferedReader(new FileReader(grammar))) { String line; while ((line = in.readLine()) != null) { @@ -84,7 +84,7 @@ public XRef processMetadata(org.codehaus.mojo.antlr.options.Grammar[] grammars) } } } - catch (IOException e) { + catch (final IOException e) { e.printStackTrace(); } @@ -92,19 +92,19 @@ public XRef processMetadata(org.codehaus.mojo.antlr.options.Grammar[] grammars) try { readGrammarFileMethod.invoke(hierarchy, new Object[] { grammarFilePath }); - } catch (Throwable t) { + } catch (final Throwable t) { throw new MojoExecutionException("Unable to use Antlr preprocessor to read grammar file", causeToUse(t)); } } - XRef xref = new XRef(hierarchy); - for (GrammarFile gf : files) { - String grammarFilePath = gf.getFileName(); + final XRef xref = new XRef(hierarchy); + for (final GrammarFile gf : files) { + final String grammarFilePath = gf.getFileName(); try { - Object antlrGrammarFileDef = getFileMethod.invoke(hierarchy, new Object[] { grammarFilePath }); + final Object antlrGrammarFileDef = getFileMethod.invoke(hierarchy, new Object[] { grammarFilePath }); intrepretMetadata(gf, antlrGrammarFileDef); xref.addGrammarFile(gf); - } catch (Throwable t) { + } catch (final Throwable t) { throw new MojoExecutionException("Unable to build grammar metadata", causeToUse(t)); } } @@ -112,50 +112,49 @@ public XRef processMetadata(org.codehaus.mojo.antlr.options.Grammar[] grammars) return xref; } - private void intrepretMetadata(GrammarFile grammarFile, Object antlrGrammarFileDef) throws MojoExecutionException { + private void intrepretMetadata(final GrammarFile grammarFile, final Object antlrGrammarFileDef) throws MojoExecutionException { try { - Object grammarsVector = helper.getAntlrGrammarFileClass() + final Object grammarsVector = helper.getAntlrGrammarFileClass() .getMethod("getGrammars", NO_ARG_SIGNATURE) .invoke(antlrGrammarFileDef, NO_ARGS); - @SuppressWarnings("unchecked") - Enumeration grammars = (Enumeration) + @SuppressWarnings("unchecked") final Enumeration grammars = (Enumeration) helper.getAntlrIndexedVectorClass() .getMethod("elements", NO_ARG_SIGNATURE) .invoke(grammarsVector, NO_ARGS); while (grammars.hasMoreElements()) { - Grammar grammar = new Grammar(grammarFile); + final Grammar grammar = new Grammar(grammarFile); intrepret(grammar, grammars.nextElement()); } - } catch (Throwable t) { + } catch (final Throwable t) { throw new MojoExecutionException("Error attempting to access grammars within grammar file", t); } } - private void intrepret(Grammar grammar, Object antlrGrammarDef) throws MojoExecutionException { + private void intrepret(final Grammar grammar, final Object antlrGrammarDef) throws MojoExecutionException { try { - Method getNameMethod = helper.getAntlrGrammarClass().getDeclaredMethod("getName", NO_ARG_SIGNATURE); + final Method getNameMethod = helper.getAntlrGrammarClass().getDeclaredMethod("getName", NO_ARG_SIGNATURE); getNameMethod.setAccessible(true); - String name = (String) getNameMethod.invoke(antlrGrammarDef, NO_ARGS); + final String name = (String) getNameMethod.invoke(antlrGrammarDef, NO_ARGS); grammar.setClassName(name); - Method getSuperGrammarNameMethod = helper.getAntlrGrammarClass().getMethod("getSuperGrammarName", NO_ARG_SIGNATURE); + final Method getSuperGrammarNameMethod = helper.getAntlrGrammarClass().getMethod("getSuperGrammarName", NO_ARG_SIGNATURE); getSuperGrammarNameMethod.setAccessible(true); - String superGrammarName = (String) getSuperGrammarNameMethod.invoke(antlrGrammarDef, NO_ARGS); + final String superGrammarName = (String) getSuperGrammarNameMethod.invoke(antlrGrammarDef, NO_ARGS); grammar.setSuperGrammarName(superGrammarName); - Method getOptionsMethod = helper.getAntlrGrammarClass().getMethod("getOptions", NO_ARG_SIGNATURE); + final Method getOptionsMethod = helper.getAntlrGrammarClass().getMethod("getOptions", NO_ARG_SIGNATURE); getOptionsMethod.setAccessible(true); - Object options = getOptionsMethod.invoke(antlrGrammarDef, NO_ARGS); + final Object options = getOptionsMethod.invoke(antlrGrammarDef, NO_ARGS); - Method getElementMethod = helper.getAntlrIndexedVectorClass().getMethod("getElement", new Class[] { Object.class }); + final Method getElementMethod = helper.getAntlrIndexedVectorClass().getMethod("getElement", new Class[] { Object.class }); getElementMethod.setAccessible(true); - Method getRHSMethod = helper.getAntlrOptionClass().getMethod("getRHS", NO_ARG_SIGNATURE); + final Method getRHSMethod = helper.getAntlrOptionClass().getMethod("getRHS", NO_ARG_SIGNATURE); getRHSMethod.setAccessible(true); - Object importVocabOption = getElementMethod.invoke(options, new Object[] { "importVocab" }); + final Object importVocabOption = getElementMethod.invoke(options, new Object[] { "importVocab" }); if (importVocabOption != null) { String importVocab = (String) getRHSMethod.invoke(importVocabOption, NO_ARGS); if (importVocab != null) { @@ -167,7 +166,7 @@ private void intrepret(Grammar grammar, Object antlrGrammarDef) throws MojoExecu } } - Object exportVocabOption = getElementMethod.invoke(options, new Object[] { "exportVocab" }); + final Object exportVocabOption = getElementMethod.invoke(options, new Object[] { "exportVocab" }); if (exportVocabOption != null) { String exportVocab = (String) getRHSMethod.invoke(exportVocabOption, NO_ARGS); if (exportVocab != null) { @@ -178,12 +177,12 @@ private void intrepret(Grammar grammar, Object antlrGrammarDef) throws MojoExecu } grammar.setExportVocab(exportVocab); } - } catch (Throwable t) { + } catch (final Throwable t) { throw new MojoExecutionException("Error accessing Antlr grammar metadata", t); } } - private Throwable causeToUse(Throwable throwable) { + private Throwable causeToUse(final Throwable throwable) { if (throwable instanceof InvocationTargetException) { return ((InvocationTargetException) throwable).getTargetException(); } diff --git a/src/main/java/org/codehaus/mojo/antlr/metadata/XRef.java b/src/main/java/org/codehaus/mojo/antlr/metadata/XRef.java index 7effb2e4..cae2f287 100644 --- a/src/main/java/org/codehaus/mojo/antlr/metadata/XRef.java +++ b/src/main/java/org/codehaus/mojo/antlr/metadata/XRef.java @@ -32,11 +32,11 @@ public class XRef { private final Object antlrHierarchy; - private LinkedHashMap filesById = new LinkedHashMap<>(); - private Map filesByExportVocab = new HashMap<>(); - private Map filesByClassName = new HashMap<>(); + private final LinkedHashMap filesById = new LinkedHashMap<>(); + private final Map filesByExportVocab = new HashMap<>(); + private final Map filesByClassName = new HashMap<>(); - public XRef(Object antlrHierarchy) { + public XRef(final Object antlrHierarchy) { this.antlrHierarchy = antlrHierarchy; } @@ -44,13 +44,13 @@ public Object getAntlrHierarchy() { return antlrHierarchy; } - void addGrammarFile(GrammarFile grammarFile) { + void addGrammarFile(final GrammarFile grammarFile) { filesById.put(grammarFile.getId(), grammarFile); - for (Grammar grammar : grammarFile.getGrammars()) { + for (final Grammar grammar : grammarFile.getGrammars()) { filesByClassName.put(grammar.getClassName(), grammarFile); if (grammar.getExportVocab() != null) { - GrammarFile old = filesByExportVocab.put(grammar.getExportVocab(), grammarFile); + final GrammarFile old = filesByExportVocab.put(grammar.getExportVocab(), grammarFile); if (old != null && old != grammarFile) { System.out.println("[WARNING] : multiple grammars defined the same exportVocab : " + grammar.getExportVocab()); } @@ -62,15 +62,15 @@ public Iterator iterateGrammarFiles() { return filesById.values().iterator(); } - public GrammarFile getGrammarFileById(String id) { + public GrammarFile getGrammarFileById(final String id) { return (GrammarFile) filesById.get(id); } - public GrammarFile getGrammarFileByClassName(String className) { + public GrammarFile getGrammarFileByClassName(final String className) { return (GrammarFile) filesByClassName.get(className); } - public GrammarFile getGrammarFileByExportVocab(String exportVocab) { + public GrammarFile getGrammarFileByExportVocab(final String exportVocab) { return (GrammarFile) filesByExportVocab.get(exportVocab); } } diff --git a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java index 13896f8e..e276c2b0 100644 --- a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java +++ b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java @@ -46,7 +46,7 @@ public String getGlib() { * * @param glib */ - public void setGlib(String glib) { + public void setGlib(final String glib) { this.glib = glib; } @@ -62,7 +62,7 @@ public String getName() { * * @param name */ - public void setName(String name) { + public void setName(final String name) { this.name = name; } @@ -71,7 +71,7 @@ public void setName(String name) { * * @param other */ - public boolean equals(Object other) { + public boolean equals(final Object other) { if (this == other) { return true; } @@ -80,7 +80,7 @@ public boolean equals(Object other) { return false; } - Grammar that = (Grammar) other; + final Grammar that = (Grammar) other; boolean result = true; result = result && (getName() == null ? that.getName() == null : getName().equals(that.getName())); result = result && (getGlib() == null ? that.getGlib() == null : getGlib().equals(that.getGlib())); @@ -102,7 +102,7 @@ public int hashCode() { * Method toString */ public java.lang.String toString() { - StringBuffer buf = new StringBuffer(); + final StringBuffer buf = new StringBuffer(); buf.append("name = '"); buf.append(getName() + "'"); buf.append("\n"); @@ -113,7 +113,7 @@ public java.lang.String toString() { private String modelEncoding = "UTF-8"; - public void setModelEncoding(String modelEncoding) { + public void setModelEncoding(final String modelEncoding) { this.modelEncoding = modelEncoding; } diff --git a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java index 067d415b..c3957192 100644 --- a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java +++ b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java @@ -35,9 +35,9 @@ public class GenerationPlan { private File importVocabTokenTypesDirectory; private boolean outOfDate; - private LinkedHashSet collectedSuperGrammarIds = new LinkedHashSet<>(); + private final LinkedHashSet collectedSuperGrammarIds = new LinkedHashSet<>(); - GenerationPlan(String id, File source, File generationDirectory, String[] glibIds) { + GenerationPlan(final String id, final File source, final File generationDirectory, final String[] glibIds) { this.id = id; this.source = source; this.generationDirectory = generationDirectory; @@ -60,7 +60,7 @@ public File getGenerationDirectory() { return generationDirectory; } - void addSuperGrammarId(String id) { + void addSuperGrammarId(final String id) { collectedSuperGrammarIds.add(id); } @@ -72,7 +72,7 @@ public File getImportVocabTokenTypesDirectory() { return importVocabTokenTypesDirectory; } - void setImportVocabTokenTypesDirectory(File importVocabTokenTypesDirectory) { + void setImportVocabTokenTypesDirectory(final File importVocabTokenTypesDirectory) { this.importVocabTokenTypesDirectory = importVocabTokenTypesDirectory; } diff --git a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java index 4831b0e1..53915443 100644 --- a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java +++ b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java @@ -43,14 +43,14 @@ public class GenerationPlanBuilder { private XRef metadataXRef; - public GenerationPlanBuilder(Environment environment) { + public GenerationPlanBuilder(final Environment environment) { this.environment = environment; } public synchronized List buildGenerationPlans(XRef metadataXRef) { this.metadataXRef = metadataXRef; - Iterator grammarFiles = metadataXRef.iterateGrammarFiles(); + final Iterator grammarFiles = metadataXRef.iterateGrammarFiles(); while (grammarFiles.hasNext()) { final GrammarFile grammarFile = (GrammarFile) grammarFiles.next(); // NOTE : loacteOrBuildGenerationPlan populates the generationPlans map @@ -61,7 +61,7 @@ public synchronized List buildGenerationPlans(XRef metadataXRef) { return new ArrayList(generationPlans.values()); } - private GenerationPlan loacteOrBuildGenerationPlan(GrammarFile grammarFile) { + private GenerationPlan loacteOrBuildGenerationPlan(final GrammarFile grammarFile) { GenerationPlan generationPlan = (GenerationPlan) generationPlans.get(grammarFile.getId()); if (generationPlan == null) { generationPlan = buildGenerationPlan(grammarFile); @@ -69,14 +69,14 @@ private GenerationPlan loacteOrBuildGenerationPlan(GrammarFile grammarFile) { return generationPlan; } - private GenerationPlan buildGenerationPlan(GrammarFile grammarFile) { - File generationDirectory = StringUtils.isEmpty(grammarFile.getPackageName()) ? environment.getOutputDirectory() + private GenerationPlan buildGenerationPlan(final GrammarFile grammarFile) { + final File generationDirectory = StringUtils.isEmpty(grammarFile.getPackageName()) ? environment.getOutputDirectory() : new File(environment.getOutputDirectory(), grammarFile.getPackageName().replace('.', File.separatorChar)); - GenerationPlan generationPlan = new GenerationPlan(grammarFile.getId(), new File(grammarFile.getFileName()), generationDirectory, + final GenerationPlan generationPlan = new GenerationPlan(grammarFile.getId(), new File(grammarFile.getFileName()), generationDirectory, grammarFile.getGlibs()); - File leastRecentGrammarOutput = locateLeastRecentlyModifiedOutputFile(generationDirectory); + final File leastRecentGrammarOutput = locateLeastRecentlyModifiedOutputFile(generationDirectory); // see if the grammar is out-of-date by way super-grammars from user defined glib options for (int i = 0; i < grammarFile.getGlibs().length; i++) { @@ -89,7 +89,7 @@ private GenerationPlan buildGenerationPlan(GrammarFile grammarFile) { } } - Iterator grammars = grammarFile.getGrammars().iterator(); + final Iterator grammars = grammarFile.getGrammars().iterator(); while (grammars.hasNext()) { final Grammar grammar = (Grammar) grammars.next(); final File generatedParserFile = new File(environment.getOutputDirectory(), grammar.determineGeneratedParserPath()); @@ -138,12 +138,12 @@ private GenerationPlan buildGenerationPlan(GrammarFile grammarFile) { return generationPlan; } - private static File locateLeastRecentlyModifiedOutputFile(File directory) { + private static File locateLeastRecentlyModifiedOutputFile(final File directory) { if (!directory.exists()) { return null; } - File[] contents = directory.listFiles(); + final File[] contents = directory.listFiles(); if (contents.length == 0) { return null; } diff --git a/src/main/java/org/codehaus/mojo/antlr/proxy/Helper.java b/src/main/java/org/codehaus/mojo/antlr/proxy/Helper.java index 0cec8396..2dd85090 100644 --- a/src/main/java/org/codehaus/mojo/antlr/proxy/Helper.java +++ b/src/main/java/org/codehaus/mojo/antlr/proxy/Helper.java @@ -48,10 +48,10 @@ public class Helper { private final Class antlrOptionClass; private final Class antlrIndexedVectorClass; - public Helper(Artifact antlrArtifact) throws MojoExecutionException { + public Helper(final Artifact antlrArtifact) throws MojoExecutionException { try { this.antlrClassLoader = new URLClassLoader(new URL[] { antlrArtifact.getFile().toURL() }, ClassLoader.getSystemClassLoader()); - } catch (MalformedURLException e) { + } catch (final MalformedURLException e) { throw new MojoExecutionException("Unable to resolve antlr:antlr artifact url", e); } @@ -64,10 +64,10 @@ public Helper(Artifact antlrArtifact) throws MojoExecutionException { antlrIndexedVectorClass = loadAntlrClass("antlr.collections.impl.IndexedVector"); } - private Class loadAntlrClass(String className) throws MojoExecutionException { + private Class loadAntlrClass(final String className) throws MojoExecutionException { try { return antlrClassLoader.loadClass(className); - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { throw new MojoExecutionException("could not load Antlr class :" + className, e); } } diff --git a/src/main/java/org/codehaus/mojo/antlr/proxy/Tool.java b/src/main/java/org/codehaus/mojo/antlr/proxy/Tool.java index 89ca859c..178814c0 100644 --- a/src/main/java/org/codehaus/mojo/antlr/proxy/Tool.java +++ b/src/main/java/org/codehaus/mojo/antlr/proxy/Tool.java @@ -32,10 +32,10 @@ public class Tool { private final Object antlrTool; - public Tool(Environment environment, Helper helper) throws MojoExecutionException { + public Tool(final Environment environment, final Helper helper) throws MojoExecutionException { try { antlrTool = helper.getAntlrToolClass().newInstance(); - } catch (Throwable t) { + } catch (final Throwable t) { throw new MojoExecutionException("Unable to instantiate antlr.Tool", t); } this.environment = environment; From 8dc03af96db5ce1147361eaed026c97f656413be Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2024 21:14:40 +0200 Subject: [PATCH 2/8] Codestyle improvements --- .../java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java | 2 +- src/main/java/org/codehaus/mojo/antlr/Environment.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java index 10f2f852..ce26ca2e 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java +++ b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java @@ -345,7 +345,7 @@ protected void performGeneration(final GenerationPlan plan, final Artifact antlr } System.setErr(oldErr); - System.err.println(errOS.toString()); + System.err.println(errOS); } } diff --git a/src/main/java/org/codehaus/mojo/antlr/Environment.java b/src/main/java/org/codehaus/mojo/antlr/Environment.java index 4e027533..d2035234 100644 --- a/src/main/java/org/codehaus/mojo/antlr/Environment.java +++ b/src/main/java/org/codehaus/mojo/antlr/Environment.java @@ -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(); } From b21e14c16856a3abdf796fa598f00f90ee5171a7 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2024 21:15:17 +0200 Subject: [PATCH 3/8] Unused import --- src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java b/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java index 32c25493..f293688c 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java +++ b/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java @@ -26,7 +26,6 @@ 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; From 9c9bd2ef3fa904954930d26e40fac89643fe3f29 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2024 21:16:10 +0200 Subject: [PATCH 4/8] Java5 improvements --- .../mojo/antlr/AbstractAntlrMojo.java | 20 +++++++++---------- .../codehaus/mojo/antlr/AntlrHtmlReport.java | 4 ++-- .../antlr/metadata/MetadataExtracter.java | 15 +++++++------- .../codehaus/mojo/antlr/options/Grammar.java | 2 +- .../mojo/antlr/plan/GenerationPlan.java | 4 ++-- .../antlr/plan/GenerationPlanBuilder.java | 6 ++---- 6 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java index ce26ca2e..06eb1b08 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java +++ b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java @@ -209,9 +209,8 @@ protected void executeAntlr() throws MojoExecutionException { final MetadataExtracter metadataExtracter = new MetadataExtracter(this, new Helper(antlrArtifact)); final XRef metadata = metadataExtracter.processMetadata(getGrammars()); - final Iterator generationPlans = new GenerationPlanBuilder(this).buildGenerationPlans(metadata).iterator(); - while (generationPlans.hasNext()) { - final GenerationPlan plan = (GenerationPlan) generationPlans.next(); + for (Object o : new GenerationPlanBuilder(this).buildGenerationPlans(metadata)) { + final GenerationPlan plan = (GenerationPlan) o; if (!plan.isOutOfDate()) { getLog().info("grammar [" + plan.getId() + "] was up-to-date; skipping"); continue; @@ -230,9 +229,8 @@ protected void executeAntlr() throws MojoExecutionException { protected final Artifact locateAntlrArtifact() throws NoAntlrDependencyDefinedException { Artifact antlrArtifact = null; if (project.getCompileArtifacts() != null) { - final Iterator projectArtifacts = project.getCompileArtifacts().iterator(); - while (projectArtifacts.hasNext()) { - final Artifact artifact = (Artifact) projectArtifacts.next(); + for (Object o : project.getCompileArtifacts()) { + final Artifact artifact = (Artifact) o; if ("antlr".equals(artifact.getGroupId()) && ("antlr".equals(artifact.getArtifactId()) || "antlr-all".equals(artifact.getArtifactId()))) { antlrArtifact = artifact; @@ -273,7 +271,7 @@ protected void performGeneration(final GenerationPlan plan, final Artifact antlr if (plan.getCollectedSuperGrammarIds().size() > 0) { arguments.add("-glib"); - final StringBuffer buffer = new StringBuffer(); + final StringBuilder buffer = new StringBuilder(); final Iterator ids = plan.getCollectedSuperGrammarIds().iterator(); while (ids.hasNext()) { buffer.append(new File(sourceDirectory, (String) ids.next())); @@ -453,7 +451,7 @@ private File getGeneratedFile(final String grammar, final File outputDir) throws */ private void validateParameters() throws MojoExecutionException { if ((isEmpty(grammars)) && ((grammarDefs == null) || (grammarDefs.length == 0))) { - final StringBuffer msg = new StringBuffer(); + final StringBuilder msg = new StringBuilder(); msg.append("Antlr plugin parameters are invalid/missing.").append('\n'); msg.append("Inside the definition for plugin 'antlr-maven-plugin' specify the following:").append('\n'); msg.append('\n'); @@ -502,11 +500,11 @@ public boolean accept(final File dir, final String s) { }); if ((dir != null) && (dir.length != 0)) { - for (int i = 0; i < dir.length; i++) { + for (String s : dir) { // Just add fles which are not in the set of files already seen. - if (!grammarSet.contains(dir[i])) { + if (!grammarSet.contains(s)) { final org.codehaus.mojo.antlr.options.Grammar grammar = new org.codehaus.mojo.antlr.options.Grammar(); - grammar.setName(dir[i]); + grammar.setName(s); grammarList.add(grammar); } diff --git a/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java b/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java index f293688c..adf8f34f 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java +++ b/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java @@ -258,8 +258,8 @@ public void renderBody() { sink.text(i18n.getString("antlr-report", locale, "report.grammars.noreport")); } else { sink.list(); - for (final Iterator it = htmlFiles.iterator(); it.hasNext();) { - final File current = (File) it.next(); + for (Object htmlFile : htmlFiles) { + final File current = (File) htmlFile; sink.listItem(); sink.link(PathUtils.toRelative(outputDirectory, current.getAbsolutePath())); diff --git a/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java b/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java index 95e0821d..e3499765 100644 --- a/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java +++ b/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java @@ -53,8 +53,8 @@ public XRef processMetadata(final org.codehaus.mojo.antlr.options.Grammar[] gram } final List files = new ArrayList<>(); - for (int i = 0; i < grammars.length; i++) { - final String grammarName = grammars[i].getName().trim(); + for (org.codehaus.mojo.antlr.options.Grammar value : grammars) { + final String grammarName = value.getName().trim(); if (isEmpty(grammarName)) { environment.getLog().info("Empty grammar in the configuration; skipping."); continue; @@ -68,13 +68,13 @@ public XRef processMetadata(final org.codehaus.mojo.antlr.options.Grammar[] gram final String grammarFilePath = grammar.getPath(); final GrammarFile grammarFile = new GrammarFile( - grammarName, + grammarName, grammarFilePath, - isNotEmpty(grammars[i].getGlib()) ? split(grammars[i].getGlib(), ":,") : new String[0]); + isNotEmpty(value.getGlib()) ? split(value.getGlib(), ":,") : new String[0]); // :( antlr.preprocessor.GrammarFile's only access to package is through a protected field :( try (final BufferedReader in = new BufferedReader(new FileReader(grammar))) { - + String line; while ((line = in.readLine()) != null) { line = line.trim(); @@ -83,15 +83,14 @@ public XRef processMetadata(final org.codehaus.mojo.antlr.options.Grammar[] gram break; } } - } - catch (final IOException e) { + } catch (final IOException e) { e.printStackTrace(); } files.add(grammarFile); try { - readGrammarFileMethod.invoke(hierarchy, new Object[] { grammarFilePath }); + readGrammarFileMethod.invoke(hierarchy, new Object[]{grammarFilePath}); } catch (final Throwable t) { throw new MojoExecutionException("Unable to use Antlr preprocessor to read grammar file", causeToUse(t)); } diff --git a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java index e276c2b0..6d1b28e9 100644 --- a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java +++ b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java @@ -102,7 +102,7 @@ public int hashCode() { * Method toString */ public java.lang.String toString() { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); buf.append("name = '"); buf.append(getName() + "'"); buf.append("\n"); diff --git a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java index c3957192..06c2d904 100644 --- a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java +++ b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java @@ -42,8 +42,8 @@ public class GenerationPlan { this.source = source; this.generationDirectory = generationDirectory; if (glibIds != null) { - for (int i = 0; i < glibIds.length; i++) { - addSuperGrammarId(glibIds[i]); + for (String glibId : glibIds) { + addSuperGrammarId(glibId); } } } diff --git a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java index 53915443..6b433fe4 100644 --- a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java +++ b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java @@ -50,7 +50,7 @@ public GenerationPlanBuilder(final Environment environment) { public synchronized List buildGenerationPlans(XRef metadataXRef) { this.metadataXRef = metadataXRef; - final Iterator grammarFiles = metadataXRef.iterateGrammarFiles(); + final Iterator grammarFiles = metadataXRef.iterateGrammarFiles(); while (grammarFiles.hasNext()) { final GrammarFile grammarFile = (GrammarFile) grammarFiles.next(); // NOTE : loacteOrBuildGenerationPlan populates the generationPlans map @@ -89,9 +89,7 @@ private GenerationPlan buildGenerationPlan(final GrammarFile grammarFile) { } } - final Iterator grammars = grammarFile.getGrammars().iterator(); - while (grammars.hasNext()) { - final Grammar grammar = (Grammar) grammars.next(); + for (Grammar grammar : grammarFile.getGrammars()) { final File generatedParserFile = new File(environment.getOutputDirectory(), grammar.determineGeneratedParserPath()); if (!generatedParserFile.exists()) { From e440c9824f7bb966f9f7fa198eab5ac8d3154227 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2024 21:16:39 +0200 Subject: [PATCH 5/8] Replace with lambda --- .../java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java index 06eb1b08..43dbcb91 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java +++ b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java @@ -492,12 +492,7 @@ private org.codehaus.mojo.antlr.options.Grammar[] getGrammars() { .replaceAll("\\?", "."); // Filter the source directory - final String[] dir = sourceDirectory.list(new FilenameFilter() { - @Override - public boolean accept(final File dir, final String s) { - return Pattern.matches(transformedGrammar, s); - } - }); + final String[] dir = sourceDirectory.list((dir1, s) -> Pattern.matches(transformedGrammar, s)); if ((dir != null) && (dir.length != 0)) { for (String s : dir) { From e7967b95acf2ae2220f69779b455fac12a109c5b Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2024 21:17:14 +0200 Subject: [PATCH 6/8] Intellij performance suggestions --- src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java | 4 ++-- src/main/java/org/codehaus/mojo/antlr/options/Grammar.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java index 43dbcb91..ff3d42b2 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java +++ b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java @@ -284,7 +284,7 @@ protected void performGeneration(final GenerationPlan plan, final Artifact antlr arguments.add(plan.getSource().getPath()); - final String[] args = (String[]) arguments.toArray(new String[arguments.size()]); + final String[] args = (String[]) arguments.toArray(new String[0]); if (plan.getImportVocabTokenTypesDirectory() != null && !plan.getImportVocabTokenTypesDirectory().equals(plan.getGenerationDirectory())) { // We need to spawn a new process to properly set up PWD @@ -431,7 +431,7 @@ private File getGeneratedFile(final String grammar, final File outputDir) throws File genFile = null; - if ("".equals(packageName)) { + if (packageName.isEmpty()) { genFile = new File(outputDir, generatedFileName + ".java"); } else { String packagePath = packageName.replace('.', File.separatorChar); diff --git a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java index 6d1b28e9..b0c3ff62 100644 --- a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java +++ b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java @@ -104,10 +104,10 @@ public int hashCode() { public java.lang.String toString() { final StringBuilder buf = new StringBuilder(); buf.append("name = '"); - buf.append(getName() + "'"); + buf.append(getName()).append("'"); buf.append("\n"); buf.append("glib = '"); - buf.append(getGlib() + "'"); + buf.append(getGlib()).append("'"); return buf.toString(); } // -- java.lang.String toString() From 452aa1bc304dac0e76cf13c2bb166d597e3e155e Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2024 21:18:32 +0200 Subject: [PATCH 7/8] Verbose or redundant code constructs --- .../mojo/antlr/AbstractAntlrMojo.java | 31 +++++++++---------- .../antlr/metadata/MetadataExtracter.java | 12 +++---- .../codehaus/mojo/antlr/metadata/XRef.java | 6 ++-- .../codehaus/mojo/antlr/options/Grammar.java | 13 ++++---- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java index ff3d42b2..b01a4671 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java +++ b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java @@ -274,7 +274,7 @@ protected void performGeneration(final GenerationPlan plan, final Artifact antlr final StringBuilder buffer = new StringBuilder(); final Iterator ids = plan.getCollectedSuperGrammarIds().iterator(); while (ids.hasNext()) { - buffer.append(new File(sourceDirectory, (String) ids.next())); + buffer.append(new File(sourceDirectory, ids.next())); if (ids.hasNext()) { buffer.append(';'); } @@ -284,7 +284,7 @@ protected void performGeneration(final GenerationPlan plan, final Artifact antlr arguments.add(plan.getSource().getPath()); - final String[] args = (String[]) arguments.toArray(new String[0]); + final String[] args = arguments.toArray(new String[0]); if (plan.getImportVocabTokenTypesDirectory() != null && !plan.getImportVocabTokenTypesDirectory().equals(plan.getGenerationDirectory())) { // We need to spawn a new process to properly set up PWD @@ -325,7 +325,7 @@ protected void performGeneration(final GenerationPlan plan, final Artifact antlr System.setErr(err); try { - executeAntlrInIsolatedClassLoader((String[]) arguments.toArray(new String[0]), antlrArtifact); + executeAntlrInIsolatedClassLoader(arguments.toArray(new String[0]), antlrArtifact); } catch (final RuntimeException e) { if (e.getMessage().contains("ANTLR Panic")) { // ANTLR-12 @@ -356,7 +356,7 @@ private void executeAntlrInIsolatedClassLoader(final String[] args, final Artifa try (final URLClassLoader classLoader = new URLClassLoader(new URL[] { antlrArtifact.getFile().toURI().toURL() }, getSystemClassLoader())) { classLoader.loadClass("antlr.Tool") - .getMethod("main", new Class[] { String[].class }) + .getMethod("main", String[].class) .invoke(null, new Object[] { args }); } catch (final MalformedURLException e) { @@ -451,17 +451,16 @@ private File getGeneratedFile(final String grammar, final File outputDir) throws */ private void validateParameters() throws MojoExecutionException { if ((isEmpty(grammars)) && ((grammarDefs == null) || (grammarDefs.length == 0))) { - final StringBuilder msg = new StringBuilder(); - msg.append("Antlr plugin parameters are invalid/missing.").append('\n'); - msg.append("Inside the definition for plugin 'antlr-maven-plugin' specify the following:").append('\n'); - msg.append('\n'); - msg.append("").append('\n'); - msg.append(" VALUE").append('\n'); - msg.append("- OR - ").append('\n'); - msg.append(" VALUE").append('\n'); - msg.append("").append('\n'); - - throw new MojoExecutionException(msg.toString()); + String msg = "Antlr plugin parameters are invalid/missing." + '\n' + + "Inside the definition for plugin 'antlr-maven-plugin' specify the following:" + '\n' + + '\n' + + "" + '\n' + + " VALUE" + '\n' + + "- OR - " + '\n' + + " VALUE" + '\n' + + "" + '\n'; + + throw new MojoExecutionException(msg); } } @@ -521,7 +520,7 @@ private org.codehaus.mojo.antlr.options.Grammar[] getGrammars() { grammarList.addAll(asList(grammarDefs)); } - return (org.codehaus.mojo.antlr.options.Grammar[]) grammarList.toArray(new org.codehaus.mojo.antlr.options.Grammar[0]); + return grammarList.toArray(new org.codehaus.mojo.antlr.options.Grammar[0]); } public static class NoAntlrDependencyDefinedException extends MojoExecutionException { diff --git a/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java b/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java index e3499765..34f8e1d7 100644 --- a/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java +++ b/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java @@ -44,7 +44,7 @@ public XRef processMetadata(final org.codehaus.mojo.antlr.options.Grammar[] gram try { final Object antlrTool = helper.getAntlrToolClass().getDeclaredConstructor().newInstance(); hierarchy = antlrHierarchyClass.getConstructor(new Class[] { helper.getAntlrToolClass() }) - .newInstance(new Object[] { antlrTool }); + .newInstance(antlrTool); readGrammarFileMethod = antlrHierarchyClass.getMethod("readGrammarFile", Helper.STRING_ARG_SIGNATURE); getFileMethod = antlrHierarchyClass.getMethod("getFile", Helper.STRING_ARG_SIGNATURE); @@ -90,7 +90,7 @@ public XRef processMetadata(final org.codehaus.mojo.antlr.options.Grammar[] gram files.add(grammarFile); try { - readGrammarFileMethod.invoke(hierarchy, new Object[]{grammarFilePath}); + readGrammarFileMethod.invoke(hierarchy, grammarFilePath); } catch (final Throwable t) { throw new MojoExecutionException("Unable to use Antlr preprocessor to read grammar file", causeToUse(t)); } @@ -100,7 +100,7 @@ public XRef processMetadata(final org.codehaus.mojo.antlr.options.Grammar[] gram for (final GrammarFile gf : files) { final String grammarFilePath = gf.getFileName(); try { - final Object antlrGrammarFileDef = getFileMethod.invoke(hierarchy, new Object[] { grammarFilePath }); + final Object antlrGrammarFileDef = getFileMethod.invoke(hierarchy, grammarFilePath); intrepretMetadata(gf, antlrGrammarFileDef); xref.addGrammarFile(gf); } catch (final Throwable t) { @@ -147,13 +147,13 @@ private void intrepret(final Grammar grammar, final Object antlrGrammarDef) thro getOptionsMethod.setAccessible(true); final Object options = getOptionsMethod.invoke(antlrGrammarDef, NO_ARGS); - final Method getElementMethod = helper.getAntlrIndexedVectorClass().getMethod("getElement", new Class[] { Object.class }); + final Method getElementMethod = helper.getAntlrIndexedVectorClass().getMethod("getElement", Object.class); getElementMethod.setAccessible(true); final Method getRHSMethod = helper.getAntlrOptionClass().getMethod("getRHS", NO_ARG_SIGNATURE); getRHSMethod.setAccessible(true); - final Object importVocabOption = getElementMethod.invoke(options, new Object[] { "importVocab" }); + final Object importVocabOption = getElementMethod.invoke(options, "importVocab"); if (importVocabOption != null) { String importVocab = (String) getRHSMethod.invoke(importVocabOption, NO_ARGS); if (importVocab != null) { @@ -165,7 +165,7 @@ private void intrepret(final Grammar grammar, final Object antlrGrammarDef) thro } } - final Object exportVocabOption = getElementMethod.invoke(options, new Object[] { "exportVocab" }); + final Object exportVocabOption = getElementMethod.invoke(options, "exportVocab"); if (exportVocabOption != null) { String exportVocab = (String) getRHSMethod.invoke(exportVocabOption, NO_ARGS); if (exportVocab != null) { diff --git a/src/main/java/org/codehaus/mojo/antlr/metadata/XRef.java b/src/main/java/org/codehaus/mojo/antlr/metadata/XRef.java index cae2f287..8a7d204b 100644 --- a/src/main/java/org/codehaus/mojo/antlr/metadata/XRef.java +++ b/src/main/java/org/codehaus/mojo/antlr/metadata/XRef.java @@ -63,14 +63,14 @@ public Iterator iterateGrammarFiles() { } public GrammarFile getGrammarFileById(final String id) { - return (GrammarFile) filesById.get(id); + return filesById.get(id); } public GrammarFile getGrammarFileByClassName(final String className) { - return (GrammarFile) filesByClassName.get(className); + return filesByClassName.get(className); } public GrammarFile getGrammarFileByExportVocab(final String exportVocab) { - return (GrammarFile) filesByExportVocab.get(exportVocab); + return filesByExportVocab.get(exportVocab); } } diff --git a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java index b0c3ff62..50d11f53 100644 --- a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java +++ b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java @@ -102,13 +102,12 @@ public int hashCode() { * Method toString */ public java.lang.String toString() { - final StringBuilder buf = new StringBuilder(); - buf.append("name = '"); - buf.append(getName()).append("'"); - buf.append("\n"); - buf.append("glib = '"); - buf.append(getGlib()).append("'"); - return buf.toString(); + String buf = "name = '" + + getName() + "'" + + "\n" + + "glib = '" + + getGlib() + "'"; + return buf; } // -- java.lang.String toString() private String modelEncoding = "UTF-8"; From 918203a934dccc6a96c6d011753212d9220a3352 Mon Sep 17 00:00:00 2001 From: Dannes Wessels Date: Sun, 4 Aug 2024 21:21:39 +0200 Subject: [PATCH 8/8] Some remaining changes --- .../org/codehaus/mojo/antlr/AbstractAntlrMojo.java | 11 +++++------ .../java/org/codehaus/mojo/antlr/AntlrHtmlReport.java | 3 +-- .../mojo/antlr/metadata/MetadataExtracter.java | 2 +- .../java/org/codehaus/mojo/antlr/options/Grammar.java | 2 +- .../org/codehaus/mojo/antlr/plan/GenerationPlan.java | 2 +- .../mojo/antlr/plan/GenerationPlanBuilder.java | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java index b01a4671..301ea829 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java +++ b/src/main/java/org/codehaus/mojo/antlr/AbstractAntlrMojo.java @@ -26,7 +26,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; -import java.io.FilenameFilter; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; @@ -209,7 +208,7 @@ protected void executeAntlr() throws MojoExecutionException { final MetadataExtracter metadataExtracter = new MetadataExtracter(this, new Helper(antlrArtifact)); final XRef metadata = metadataExtracter.processMetadata(getGrammars()); - for (Object o : new GenerationPlanBuilder(this).buildGenerationPlans(metadata)) { + for (final Object o : new GenerationPlanBuilder(this).buildGenerationPlans(metadata)) { final GenerationPlan plan = (GenerationPlan) o; if (!plan.isOutOfDate()) { getLog().info("grammar [" + plan.getId() + "] was up-to-date; skipping"); @@ -229,7 +228,7 @@ protected void executeAntlr() throws MojoExecutionException { protected final Artifact locateAntlrArtifact() throws NoAntlrDependencyDefinedException { Artifact antlrArtifact = null; if (project.getCompileArtifacts() != null) { - for (Object o : project.getCompileArtifacts()) { + for (final Object o : project.getCompileArtifacts()) { final Artifact artifact = (Artifact) o; if ("antlr".equals(artifact.getGroupId()) && ("antlr".equals(artifact.getArtifactId()) || "antlr-all".equals(artifact.getArtifactId()))) { @@ -269,7 +268,7 @@ protected void performGeneration(final GenerationPlan plan, final Artifact antlr arguments.add("-o"); arguments.add(plan.getGenerationDirectory().getPath()); - if (plan.getCollectedSuperGrammarIds().size() > 0) { + if (!plan.getCollectedSuperGrammarIds().isEmpty()) { arguments.add("-glib"); final StringBuilder buffer = new StringBuilder(); final Iterator ids = plan.getCollectedSuperGrammarIds().iterator(); @@ -451,7 +450,7 @@ private File getGeneratedFile(final String grammar, final File outputDir) throws */ private void validateParameters() throws MojoExecutionException { if ((isEmpty(grammars)) && ((grammarDefs == null) || (grammarDefs.length == 0))) { - String msg = "Antlr plugin parameters are invalid/missing." + '\n' + + final String msg = "Antlr plugin parameters are invalid/missing." + '\n' + "Inside the definition for plugin 'antlr-maven-plugin' specify the following:" + '\n' + '\n' + "" + '\n' + @@ -494,7 +493,7 @@ private org.codehaus.mojo.antlr.options.Grammar[] getGrammars() { final String[] dir = sourceDirectory.list((dir1, s) -> Pattern.matches(transformedGrammar, s)); if ((dir != null) && (dir.length != 0)) { - for (String s : dir) { + for (final String s : dir) { // Just add fles which are not in the set of files already seen. if (!grammarSet.contains(s)) { final org.codehaus.mojo.antlr.options.Grammar grammar = new org.codehaus.mojo.antlr.options.Grammar(); diff --git a/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java b/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java index adf8f34f..f618c2b6 100644 --- a/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java +++ b/src/main/java/org/codehaus/mojo/antlr/AntlrHtmlReport.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; -import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -258,7 +257,7 @@ public void renderBody() { sink.text(i18n.getString("antlr-report", locale, "report.grammars.noreport")); } else { sink.list(); - for (Object htmlFile : htmlFiles) { + for (final Object htmlFile : htmlFiles) { final File current = (File) htmlFile; sink.listItem(); diff --git a/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java b/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java index 34f8e1d7..fce34071 100644 --- a/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java +++ b/src/main/java/org/codehaus/mojo/antlr/metadata/MetadataExtracter.java @@ -53,7 +53,7 @@ public XRef processMetadata(final org.codehaus.mojo.antlr.options.Grammar[] gram } final List files = new ArrayList<>(); - for (org.codehaus.mojo.antlr.options.Grammar value : grammars) { + for (final org.codehaus.mojo.antlr.options.Grammar value : grammars) { final String grammarName = value.getName().trim(); if (isEmpty(grammarName)) { environment.getLog().info("Empty grammar in the configuration; skipping."); diff --git a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java index 50d11f53..7d330c1f 100644 --- a/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java +++ b/src/main/java/org/codehaus/mojo/antlr/options/Grammar.java @@ -102,7 +102,7 @@ public int hashCode() { * Method toString */ public java.lang.String toString() { - String buf = "name = '" + + final String buf = "name = '" + getName() + "'" + "\n" + "glib = '" + diff --git a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java index 06c2d904..e44d0eb4 100644 --- a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java +++ b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlan.java @@ -42,7 +42,7 @@ public class GenerationPlan { this.source = source; this.generationDirectory = generationDirectory; if (glibIds != null) { - for (String glibId : glibIds) { + for (final String glibId : glibIds) { addSuperGrammarId(glibId); } } diff --git a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java index 6b433fe4..065aca39 100644 --- a/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java +++ b/src/main/java/org/codehaus/mojo/antlr/plan/GenerationPlanBuilder.java @@ -89,7 +89,7 @@ private GenerationPlan buildGenerationPlan(final GrammarFile grammarFile) { } } - for (Grammar grammar : grammarFile.getGrammars()) { + for (final Grammar grammar : grammarFile.getGrammars()) { final File generatedParserFile = new File(environment.getOutputDirectory(), grammar.determineGeneratedParserPath()); if (!generatedParserFile.exists()) {