Skip to content

Commit

Permalink
jflex: add %no_suppress_warnings directive
Browse files Browse the repository at this point in the history
By default JFlex emits @SuppressWarnings("fallthrough") at the class
level. This directive removes that annotation and leaves it up to the
user to define their own.

Fixes #762
  • Loading branch information
lsf37 committed Jan 6, 2023
1 parent 8c44333 commit f44691e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions jflex/src/main/java/jflex/core/AbstractLexScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public enum CharSetSize {
boolean standalone;
boolean debugOption;
boolean eofclose;
boolean noSuppressWarnings;

String isImplementing;
String isExtending;
Expand Down Expand Up @@ -395,6 +396,10 @@ public int bufferSize() {
return bufferSize;
}

public boolean noSuppressWarnings() {
return noSuppressWarnings;
}

/**
* Returns the current line number.
*
Expand Down
7 changes: 4 additions & 3 deletions jflex/src/main/java/jflex/generator/Emitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ private void emitUserCode() {
}

private void emitClassName() {
// TODO(#222) Actually fix the fall-through violations
println("// See https://github.com/jflex-de/jflex/issues/222");
println("@SuppressWarnings(\"FallThrough\")");
if (!scanner.noSuppressWarnings()) {
// TODO(#222) Actually fix the fall-through violations
println("@SuppressWarnings(\"fallthrough\")");
}
if (scanner.isPublic()) print("public ");

if (scanner.isAbstract()) print("abstract ");
Expand Down
2 changes: 2 additions & 0 deletions jflex/src/main/jflex/LexScan.flex
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ DottedVersion = [1-9][0-9]*(\.[0-9]+){0,2}
"%warn" {WSP}+ {WarningIdent} {WSP}* { OptionUtils.enableWarning(yytext().substring(6).trim()); }
"%warn" {WSP}+ {NNL}* { throw new ScannerException(file, ErrorMessages.NOT_A_WARNING_ID, yyline); }

"%no_suppress_warnings" {WSP}* { noSuppressWarnings = true; }

{Ident} { return symbol(IDENT, yytext()); }
"="{WSP}* { yybegin(REGEXP);
return symbol(EQUALS);
Expand Down

0 comments on commit f44691e

Please sign in to comment.