Skip to content

Commit

Permalink
Merge pull request #3 from zbynek/code-style
Browse files Browse the repository at this point in the history
Improve code style of generated stream classes
  • Loading branch information
kaikalur authored Sep 17, 2023
2 parents 0942ada + 1677363 commit aed1a05
Show file tree
Hide file tree
Showing 25 changed files with 1,598 additions and 1,487 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ jobs:
distribution: 'adopt'
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Run integration tests
run: mvn install
13 changes: 13 additions & 0 deletions examples/Gwt/checkstyle-suppress.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress checks="MultipleVariableDeclarations" files="." />
<suppress checks="AbbreviationAsWordInName" files="." />
<suppress checks="MemberName" files="." />
<suppress checks="MethodName" files="." />

<suppress checks="Indentation" files=".*Gwt.*TokenManager.java"/>
<suppress checks="Indentation" files=".*Gwt.*Parser.java"/>
</suppressions>
25 changes: 25 additions & 0 deletions examples/Gwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<violationSeverity>warning</violationSeverity>
<sourceDirectories>target/generated-sources/java</sourceDirectories>
<suppressionsLocation>checkstyle-suppress.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>generate-sources</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<name>JavaCC examples Java Simple</name>
Expand Down
10 changes: 7 additions & 3 deletions examples/Gwt/src/main/javacc/GwtSimpleParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import java.io.PrintStream;
public class GwtSimpleParser {

/** Main entry point. */
public static void main(String args[]) throws ParseException, IOException {
public static void main(String[] args) throws ParseException, IOException {
PrintStream output = System.out;
PrintStream error = System.err;
PrintStream prevOutput = null;
Expand All @@ -76,8 +76,12 @@ public class GwtSimpleParser {
} catch (Exception e) {
error.println(e.getMessage());
} finally {
if (prevOutput != null) System.setOut(prevOutput);
if (prevError != null) System.setErr(prevError);
if (prevOutput != null) {
System.setOut(prevOutput);
}
if (prevError != null) {
System.setErr(prevError);
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions examples/Gwt/src/main/javacc/GwtUnicodeParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import java.io.PrintStream;
public class GwtUnicodeParser {

/** Main entry point. */
public static void main(String args[]) throws ParseException, IOException {
public static void main(String[] args) throws ParseException, IOException {
PrintStream output = System.out;
PrintStream error = System.err;
PrintStream prevOutput = null;
Expand All @@ -76,8 +76,12 @@ public class GwtUnicodeParser {
} catch (Exception e) {
error.println(e.getMessage());
} finally {
if (prevOutput != null) System.setOut(prevOutput);
if (prevError != null) System.setErr(prevError);
if (prevOutput != null) {
System.setOut(prevOutput);
}
if (prevError != null) {
System.setErr(prevError);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions examples/JavaCC/checkstyle-suppress.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress checks="MultipleVariableDeclarations" files="." />
<suppress checks="AbbreviationAsWordInName" files="." />
<suppress checks="MemberName" files="." />
<suppress checks="MethodName" files="." />

<suppress checks="Indentation|LineLength" files=".*JavaCC.*TokenManager.java"/>
<suppress checks="Indentation|MissingJavadocMethod|LineLength" files=".*JavaCC.*Parser.java"/>
</suppressions>
25 changes: 25 additions & 0 deletions examples/JavaCC/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<violationSeverity>warning</violationSeverity>
<sourceDirectories>target/generated-sources/java</sourceDirectories>
<suppressionsLocation>checkstyle-suppress.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>generate-sources</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
87 changes: 47 additions & 40 deletions examples/JavaCC/src/main/javacc/JavaCC.jj
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ options {

PARSER_BEGIN(JavaCCParser)

/**
* Parser for JavaCC grammar.
*/
public class JavaCCParser {

public static void main(String args[]) {
public static void main(String[] args) {
JavaCCParser parser;
if (args.length == 0) {
System.out.println("JavaCC Parser: Reading from standard input . . .");
Expand Down Expand Up @@ -69,21 +72,21 @@ public class JavaCCParser {
* Returns true if the next token is not in the FOLLOW list of "expansion".
* It is used to decide when the end of an "expansion" has been reached.
*/
static private boolean notTailOfExpansionUnit() {
private static boolean notTailOfExpansionUnit() {
Token t;
t = getToken(1);
if (t.kind == BIT_OR || t.kind == COMMA || t.kind == RPAREN || t.kind == RBRACE || t.kind == RBRACKET) return false;
return true;
return !(t.kind == BIT_OR || t.kind == COMMA || t.kind == RPAREN
|| t.kind == RBRACE || t.kind == RBRACKET);
}

}

PARSER_END(JavaCCParser)


/**********************************************
* THE JAVACC TOKEN SPECIFICATION STARTS HERE *
**********************************************/
/*--------------------------------------------
* THE JAVACC TOKEN SPECIFICATION STARTS HERE
*-------------------------------------------*/

/* JAVACC RESERVED WORDS: These are the only tokens in JavaCC but not in Java */

Expand Down Expand Up @@ -350,9 +353,9 @@ TOKEN :
| < BIT_OR: "|" >
| < XOR: "^" >
| < REM: "%" >
// | < LSHIFT: "<<" >
// | < RSIGNEDSHIFT: ">>" >
// | < RUNSIGNEDSHIFT: ">>>" >
// | < LSHIFT: "<<" >
// | < RSIGNEDSHIFT: ">>" >
// | < RUNSIGNEDSHIFT: ">>>" >
| < PLUSASSIGN: "+=" >
| < MINUSASSIGN: "-=" >
| < STARASSIGN: "*=" >
Expand All @@ -361,15 +364,15 @@ TOKEN :
| < ORASSIGN: "|=" >
| < XORASSIGN: "^=" >
| < REMASSIGN: "%=" >
// | < LSHIFTASSIGN: "<<=" >
// | < RSIGNEDSHIFTASSIGN: ">>=" >
// | < RUNSIGNEDSHIFTASSIGN: ">>>=" >
// | < LSHIFTASSIGN: "<<=" >
// | < RSIGNEDSHIFTASSIGN: ">>=" >
// | < RUNSIGNEDSHIFTASSIGN: ">>>=" >
}


/************************************************
* THE JAVACC GRAMMAR SPECIFICATION STARTS HERE *
************************************************/
/*-----------------------------------------------
* THE JAVACC GRAMMAR SPECIFICATION STARTS HERE
*----------------------------------------------*/

void javacc_input() :
{}
Expand Down Expand Up @@ -503,9 +506,9 @@ void expansion() :
}

void local_lookahead() :
{
boolean commaAtEnd = false, emptyLA = true;
}
{
boolean commaAtEnd = false, emptyLA = true;
}
{
[
/*
Expand All @@ -516,27 +519,28 @@ void local_lookahead() :
*/
LOOKAHEAD(1)
IntegerLiteral()
{
emptyLA = false;
}
{
emptyLA = false;
}
]
[ LOOKAHEAD(0, { !emptyLA && (getToken(1).kind != RPAREN) } )
","
{
commaAtEnd = true;
}
{
commaAtEnd = true;
}
]
[ LOOKAHEAD(0, { getToken(1).kind != RPAREN && getToken(1).kind != LBRACE } )
expansion_choices()
{
emptyLA = false; commaAtEnd = false;
}
{
emptyLA = false;
commaAtEnd = false;
}
]
[ LOOKAHEAD(0, { !emptyLA && !commaAtEnd && (getToken(1).kind != RPAREN) } )
","
{
commaAtEnd = true;
}
{
commaAtEnd = true;
}
]
[ LOOKAHEAD(0, { emptyLA || commaAtEnd } )
"{" Expression() "}"
Expand Down Expand Up @@ -628,9 +632,9 @@ void identifier() :
}


/**********************************************
* THE JJTREE PRODUCTIONS START HERE *
**********************************************/
/*-----------------------------------
* THE JJTREE PRODUCTIONS START HERE
*-----------------------------------*/

void node_descriptor() :
{}
Expand All @@ -653,19 +657,22 @@ void node_descriptor_expression()
if (tok.kind == 0) {
throw new ParseException();
}
if (tok.kind == LPAREN) nesting++;
if (tok.kind == RPAREN) {
if (tok.kind == LPAREN) {
nesting++;
} else if (tok.kind == RPAREN) {
nesting--;
if (nesting == 0) break;
if (nesting == 0) {
break;
}
}
tok = getNextToken();
}
}


/**********************************************
* THE JAVA GRAMMAR SPECIFICATION STARTS HERE *
**********************************************/
/*--------------------------------------------
* THE JAVA GRAMMAR SPECIFICATION STARTS HERE
*--------------------------------------------*/

/*
* The Java grammar is modified to use sequences of tokens
Expand Down
13 changes: 13 additions & 0 deletions java.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/bugs/bug001/target/generated-sources/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/bugs/bug002/target/generated-sources/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples/Gwt/target/generated-sources/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples/JavaCC/target/generated-sources/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples/Lookahead/target/generated-sources/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples/Transformer/target/generated-sources/java" isTestSource="false" />
</content>
</component>
</module>
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.6.0</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/javacc/java/JavaCodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ JavaCodeBuilder addImportName(String importName) {

@Override
protected final void build() {
StringBuffer buffer = new StringBuffer();
StringBuffer buffer = new StringBuffer("\n");

if (packageName.length() > 0) {
buffer.append("package ").append(packageName).append(";\n\n");
Expand Down
Loading

0 comments on commit aed1a05

Please sign in to comment.