From 8e06d0bc81dd130c8010cd1b6b7abae30c3c6b1a Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Thu, 15 Jun 2023 11:08:04 +0800 Subject: [PATCH] build: config spotless plugin and reformat code --- build.gradle | 2 ++ input/JavaScriptBaseLexer.java | 47 ++++++++++++-------------- input/JavaScriptBaseParser.java | 27 +++++++-------- src/main/entry/AntlrGenLexerTool.java | 5 +-- src/main/entry/AntlrGenParserTool.java | 3 +- src/main/entry/AntlrTest.java | 8 ++--- src/main/entry/AntlrTool.java | 11 +++--- 7 files changed, 51 insertions(+), 52 deletions(-) diff --git a/build.gradle b/build.gradle index 80bed72..a571d07 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ plugins { id 'java-library' } +apply from: '../spotless.gradle' + sourceSets { main { java { diff --git a/input/JavaScriptBaseLexer.java b/input/JavaScriptBaseLexer.java index ffb38cb..e576c8e 100644 --- a/input/JavaScriptBaseLexer.java +++ b/input/JavaScriptBaseLexer.java @@ -1,23 +1,23 @@ package org.bdware.sc.parser; + import org.antlr.v4.runtime.*; import java.util.Stack; -public abstract class JavaScriptBaseLexer extends Lexer -{ + +public abstract class JavaScriptBaseLexer extends Lexer { /** - * Stores values of nested modes. By default mode is strict or - * defined externally (useStrictDefault) + * Stores values of nested modes. By default mode is strict or defined externally + * (useStrictDefault) */ private Stack scopeStrictModes = new Stack(); private Token lastToken = null; /** - * Default value of strict mode - * Can be defined externally by setUseStrictDefault + * Default value of strict mode Can be defined externally by setUseStrictDefault */ private boolean useStrictDefault = false; /** - * Current value of strict mode - * Can be defined during parsing, see StringFunctions.js and StringGlobal.js samples + * Current value of strict mode Can be defined during parsing, see StringFunctions.js and + * StringGlobal.js samples */ private boolean useStrictCurrent = false; @@ -39,10 +39,9 @@ public abstract class JavaScriptBaseLexer extends Lexer } /** - * Return the next token from the character stream and records this last - * token in case it resides on the default channel. This recorded token - * is used to determine when the lexer could possibly match a regex - * literal. Also changes scopeStrictModes stack if tokenize special + * Return the next token from the character stream and records this last token in case it + * resides on the default channel. This recorded token is used to determine when the lexer could + * possibly match a regex literal. Also changes scopeStrictModes stack if tokenize special * string 'use strict'; * * @return the next token from the character stream. @@ -59,24 +58,20 @@ public abstract class JavaScriptBaseLexer extends Lexer return next; } - protected void ProcessOpenBrace() - { - useStrictCurrent = scopeStrictModes.size() > 0 && scopeStrictModes.peek() ? true : useStrictDefault; + protected void ProcessOpenBrace() { + useStrictCurrent = + scopeStrictModes.size() > 0 && scopeStrictModes.peek() ? true : useStrictDefault; scopeStrictModes.push(useStrictCurrent); } - protected void ProcessCloseBrace() - { + protected void ProcessCloseBrace() { useStrictCurrent = scopeStrictModes.size() > 0 ? scopeStrictModes.pop() : useStrictDefault; } - protected void ProcessStringLiteral() - { - if (lastToken == null || lastToken.getType() == JavaScriptLexer.OpenBrace) - { + protected void ProcessStringLiteral() { + if (lastToken == null || lastToken.getType() == JavaScriptLexer.OpenBrace) { String text = getText(); - if (text.equals("\"use strict\"") || text.equals("'use strict'")) - { + if (text.equals("\"use strict\"") || text.equals("'use strict'")) { if (scopeStrictModes.size() > 0) scopeStrictModes.pop(); useStrictCurrent = true; @@ -89,13 +84,13 @@ public abstract class JavaScriptBaseLexer extends Lexer * Returns {@code true} if the lexer can match a regex literal. */ protected boolean IsRegexPossible() { - + if (this.lastToken == null) { // No token has been produced yet: at the start of the input, // no division is possible, so a regex literal _is_ possible. return true; } - + switch (this.lastToken.getType()) { case JavaScriptLexer.Identifier: case JavaScriptLexer.NullLiteral: @@ -116,4 +111,4 @@ public abstract class JavaScriptBaseLexer extends Lexer return true; } } -} \ No newline at end of file +} diff --git a/input/JavaScriptBaseParser.java b/input/JavaScriptBaseParser.java index 2c41620..4956e83 100644 --- a/input/JavaScriptBaseParser.java +++ b/input/JavaScriptBaseParser.java @@ -3,8 +3,8 @@ package org.bdware.sc.parser; import org.antlr.v4.runtime.*; /** - * All parser methods that used in grammar (p, prev, notLineTerminator, etc.) - * should start with lower case char similar to parser rules. + * All parser methods that used in grammar (p, prev, notLineTerminator, etc.) should start with + * lower case char similar to parser rules. */ public abstract class JavaScriptBaseParser extends Parser { public JavaScriptBaseParser(TokenStream input) { @@ -53,12 +53,12 @@ public abstract class JavaScriptBaseParser extends Parser { } /** - * Returns {@code true} iff on the current index of the parser's token stream a - * token of the given {@code type} exists on the {@code HIDDEN} channel. + * Returns {@code true} iff on the current index of the parser's token stream a token of the + * given {@code type} exists on the {@code HIDDEN} channel. * * @param type the type of the token on the {@code HIDDEN} channel to check. - * @return {@code true} iff on the current index of the parser's token stream a - * token of the given {@code type} exists on the {@code HIDDEN} channel. + * @return {@code true} iff on the current index of the parser's token stream a token of the + * given {@code type} exists on the {@code HIDDEN} channel. */ private boolean here(final int type) { @@ -72,14 +72,13 @@ public abstract class JavaScriptBaseParser extends Parser { } /** - * Returns {@code true} iff on the current index of the parser's token stream a - * token exists on the {@code HIDDEN} channel which either is a line terminator, - * or is a multi line comment that contains a line terminator. + * Returns {@code true} iff on the current index of the parser's token stream a token exists on + * the {@code HIDDEN} channel which either is a line terminator, or is a multi line comment that + * contains a line terminator. * - * @return {@code true} iff on the current index of the parser's token stream a - * token exists on the {@code HIDDEN} channel which either is a line - * terminator, or is a multi line comment that contains a line - * terminator. + * @return {@code true} iff on the current index of the parser's token stream a token exists on + * the {@code HIDDEN} channel which either is a line terminator, or is a multi line + * comment that contains a line terminator. */ protected boolean lineTerminatorAhead() { @@ -111,4 +110,4 @@ public abstract class JavaScriptBaseParser extends Parser { return (type == YJSParser.MultiLineComment && (text.contains("\r") || text.contains("\n"))) || (type == YJSParser.LineTerminator); } -} \ No newline at end of file +} diff --git a/src/main/entry/AntlrGenLexerTool.java b/src/main/entry/AntlrGenLexerTool.java index f5645ca..cb23e6a 100644 --- a/src/main/entry/AntlrGenLexerTool.java +++ b/src/main/entry/AntlrGenLexerTool.java @@ -8,6 +8,7 @@ public class AntlrGenLexerTool { public static void main(String[] args) throws IOException { processLexer(); } + private static void processLexer() { String g5 = "JavaScriptLexer.g4"; String pkg = "org.bdware.sc.parser"; @@ -16,8 +17,8 @@ public class AntlrGenLexerTool { out.delete(); try { Files.copy(from.toPath(), out.toPath()); - Tool.main(new String[]{g5, "-package", pkg, "-o", "./common/src/main/gen/" + - pkg.replaceAll("\\.", "/"), "-visitor"}); + Tool.main(new String[] {g5, "-package", pkg, "-o", + "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"}); new File(g5).delete(); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/entry/AntlrGenParserTool.java b/src/main/entry/AntlrGenParserTool.java index 5cd3751..f20cf58 100644 --- a/src/main/entry/AntlrGenParserTool.java +++ b/src/main/entry/AntlrGenParserTool.java @@ -28,6 +28,7 @@ public class AntlrGenParserTool { } catch (Exception e) { e.printStackTrace(); } - Tool.main(new String[]{g4, "-package", pkg, "-o", "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"}); + Tool.main(new String[] {g4, "-package", pkg, "-o", + "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"}); } } diff --git a/src/main/entry/AntlrTest.java b/src/main/entry/AntlrTest.java index 754d7a0..17408d9 100644 --- a/src/main/entry/AntlrTest.java +++ b/src/main/entry/AntlrTest.java @@ -1,8 +1,8 @@ import org.antlr.v4.gui.TestRig; public class AntlrTest { - @SuppressWarnings("deprecation") - public static void main(String[] args) throws Exception { - TestRig.main(new String[] {}); - } + @SuppressWarnings("deprecation") + public static void main(String[] args) throws Exception { + TestRig.main(new String[] {}); + } } diff --git a/src/main/entry/AntlrTool.java b/src/main/entry/AntlrTool.java index c3bff16..afb8c63 100644 --- a/src/main/entry/AntlrTool.java +++ b/src/main/entry/AntlrTool.java @@ -31,9 +31,10 @@ public class AntlrTool { e.printStackTrace(); } // Tool.main(new String[] {}); - Tool.main(new String[]{g4, "-package", pkg, "-o", "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"}); - // Tool.main(new String[] { g5, "-package", pkg, "-o", "./gen/" + - // pkg.replaceAll("\\.", "/"), "-visitor" }); + Tool.main(new String[] {g4, "-package", pkg, "-o", + "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"}); + // Tool.main(new String[] { g5, "-package", pkg, "-o", "./gen/" + + // pkg.replaceAll("\\.", "/"), "-visitor" }); System.out.println("DeleteFiles!"); out.delete(); @@ -48,8 +49,8 @@ public class AntlrTool { out.delete(); try { Files.copy(from.toPath(), out.toPath()); - Tool.main(new String[]{g5, "-package", pkg, "-o", "./common/src/main/gen/" + - pkg.replaceAll("\\.", "/"), "-visitor"}); + Tool.main(new String[] {g5, "-package", pkg, "-o", + "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"}); new File(g5).delete(); } catch (Exception e) { e.printStackTrace();