Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ $(eval $(call make-shared-test-rule,java-package-info,java,Java,test-grammars/ja
$(eval $(call make-shared-test-rule,java-multiple-types,java,Java,test-grammars/java/test-multiple-types.java))
$(eval $(call make-shared-test-rule,java-enum-javadoc,java,Java,test-grammars/java/test-enum-javadoc.java))
$(eval $(call make-shared-test-rule,java-generic-void,java,Java,test-grammars/java/test-generic-void.java))
$(eval $(call make-shared-test-rule,java-volatile-strictfp,java,Java,test-grammars/java/test-volatile-strictfp.java))
$(eval $(call make-shared-test-rule,java-empty-enum,java,Java,test-grammars/java/test-empty-enum.java))
$(eval $(call make-shared-test-rule,java-for-update-list,java,Java,test-grammars/java/test-for-update-list.java))

# JavaDoc comment tests (blank line + {@link Class#method()} regression tests)
$(eval $(call make-shared-test-rule,java-javadoc-blank-link,java,Java,test-grammars/java/javadoc/test-blank-then-link.java))
Expand All @@ -223,7 +226,7 @@ accept-lex-java: test-out/java-main
ACCEPT=1 ./test-java-lexical.sh

# Run all Java tests
test-all-java: test-java test-java-simple test-java-minimal test-java-field test-java-field-public test-java-package test-java-string test-java-complex test-java-full test-java-generics test-java-enum test-java-annotations test-java-empty-method test-java-simple-return test-java-return-field test-java-very-simple test-java-parameter-only test-java-field-this test-java-simple-assignment test-java-compound-assignment test-java-set-value test-java-implements test-java-nested-if test-java-anon-class test-java-array-init test-java-default-method test-java-annotation-array test-java-package-info test-java-multiple-types test-java-enum-javadoc test-java-generic-void test-java-javadoc-blank-link test-java-javadoc-minimal-hash test-java-javadoc-minimal-fail test-java-javadoc-link-tag test-java-javadoc-just-hash
test-all-java: test-java test-java-simple test-java-minimal test-java-field test-java-field-public test-java-package test-java-string test-java-complex test-java-full test-java-generics test-java-enum test-java-annotations test-java-empty-method test-java-simple-return test-java-return-field test-java-very-simple test-java-parameter-only test-java-field-this test-java-simple-assignment test-java-compound-assignment test-java-set-value test-java-implements test-java-nested-if test-java-anon-class test-java-array-init test-java-default-method test-java-annotation-array test-java-package-info test-java-multiple-types test-java-enum-javadoc test-java-generic-void test-java-volatile-strictfp test-java-empty-enum test-java-for-update-list test-java-javadoc-blank-link test-java-javadoc-minimal-hash test-java-javadoc-minimal-fail test-java-javadoc-link-tag test-java-javadoc-just-hash
@echo ""
@echo "=== All Java tests completed successfully! ==="

Expand Down
31 changes: 29 additions & 2 deletions test-grammars/java.pg
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ grammar 'Java';
# tokens, shared nonterminals, or '{' never following a complete
# expression). Only the family-6 item moved: the empty unit's first
# nullable is now OptDocComment instead of the retired (Package)? option.
# The issues 139/140/141 batch - 'volatile' and 'strictfp' modifiers, the
# optional enum constant list, and the comma-separated for-update list -
# likewise adds ZERO conflicts; see the notes at Modifier, EnumDeclaration
# and ForUpdateList.
# ============================================================================

Java = CompilationUnit ;
Expand Down Expand Up @@ -247,10 +251,16 @@ EnumConstant = OptDocComment AnnotationList id ('(' Arglist ')')? ('{' FieldDecl

EnumConstantList = EnumConstant (',' EnumConstant)* (',')? ;

# The constant list is optional (JLS 8.9: EnumBody allows an empty body and
# a declarations-only body 'enum F { ; void m() { } }'). The empty-list
# epsilon-reduce fires only on ';' and '}', disjoint from the constant
# starters (doccomment, '@', id). One tolerated JLS deviation: a bare-comma
# body '{ , }' stays a parse error, because the trailing comma lives inside
# EnumConstantList.
EnumDeclaration =
'enum' id
ImplementsList?
'{' EnumConstantList (';' FieldDeclarationList)? '}' ;
'{' EnumConstantList? (';' FieldDeclarationList)? '}' ;

# NOTE: MemberDeclaration unifies MethodDeclaration, VariableDeclaration, and ConstructorDeclaration
# to eliminate ambiguity. All three can start with an identifier:
Expand Down Expand Up @@ -480,10 +490,21 @@ DoStatement =
WhileStatement =
'while' '(' Expression ')' Statement ;

# The update slot is a comma-separated list (JLS 14.14.1: ForUpdate is a
# StatementExpressionList), spelled as its own optional rule so return and
# the condition slot keep plain OptExpression. Conflict-free: the only token
# after a complete update expression here is ')', so the ',' continuation is
# a fresh shift (argument lists live behind their own '(' in different
# states). The init slot deliberately stays a single expression - it sits in
# the delicate Type-vs-Expression region (see VariableDeclaration NOTEs).
# That the listed expressions are *statement* expressions is a semantic
# check (javac's job), per the grammar's tolerance policy.
ForUpdateList = Expression ( ',' Expression )* ;

ForStatement =
'for' '(' ( VariableDeclaration | ( Expression ';' ) | ';' )
OptExpression ';'
OptExpression
ForUpdateList?
')' Statement
| 'for' '(' ForEachHeader ')' Statement ;

Expand Down Expand Up @@ -934,6 +955,12 @@ Modifier =
| 'abstract'
| 'threadsafe'
| 'transient'
# 'volatile' (JLS 8.3.1.4) and 'strictfp' (JLS 8.1.1.3): reserved words, so
# promoting them from id costs nothing, and like every other modifier they
# only ever extend a ModifierList - no state parsing one has a competing
# action on these tokens (same argument as 'default' below).
| 'volatile'
| 'strictfp'
| 'default' ;

# The tail of a dotted name, hoisted into a NAMED rule so that CompoundName
Expand Down
20 changes: 20 additions & 0 deletions test-grammars/java/test-empty-enum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package test;

enum EmptyEnum { }

// declarations-only body (JLS 8.9: both the constant list and the
// declarations tail are independently optional)
enum NoConstants {
;
static int helper() { return 1; }
}

// regression guard: the existing forms keep parsing
enum WithConstants {
ONE, TWO,
}

enum ConstantsAndMembers {
A, B;
int m() { return 0; }
}
28 changes: 28 additions & 0 deletions test-grammars/java/test-for-update-list.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package test;

class ForUpdateList {
void twoUpdates(int n) {
for (int i = 0; i < n; i++, n--) {
}
}

void mixedUpdates(int[] a) {
int pos = 0;
long time = 0;
for (int i = 0; i < a.length; i++, pos++, time += 1000) {
a[pos] = a[i];
}
}

// regression guards: single update and empty update keep parsing
void singleUpdate(int n) {
for (int i = 0; i < n; i++) {
}
}

void emptyUpdate(int n) {
for (int i = 0; i < n;) {
i++;
}
}
}
22 changes: 22 additions & 0 deletions test-grammars/java/test-volatile-strictfp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package test;

class VolatileFields {
volatile int counter;
private volatile boolean initialized;
static volatile Object ref;

volatile int get() { return counter; }
}

strictfp class StrictClass {
double d = 0.1;

strictfp double sum(double a, double b) {
return a + b;
}
}

interface WithStrictfp {
// modifiers combine freely on one list
static strictfp double half(double x) { return x / 2.0; }
}
9 changes: 1 addition & 8 deletions test-suites/commons-lang-parser-blacklist-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
# references (TimeUnit[]::new)
# - lambdas with typed or modified parameter lists, under casts, and in a
# conditional's false branch
# - comma-separated statement-expression lists in a for-update (i++, t += 1)
# - the 'volatile' modifier
# - type annotations in a generic return type (<T> @Nonnull T m())
# - an empty enum body (enum E { })
#
# Total: 18 files blacklisted, 249 files passing
# Total: 14 files blacklisted, 253 files passing
# As grammar support is added, remove files from this list

org/apache/commons/lang3/AnnotationUtilsTest.java
Expand All @@ -18,12 +15,8 @@ org/apache/commons/lang3/ClassUtilsTest.java
org/apache/commons/lang3/EnumUtilsTest.java
org/apache/commons/lang3/ObjectUtilsTest.java
org/apache/commons/lang3/StringUtilsTest.java
org/apache/commons/lang3/builder/JsonToStringStyleTest.java
org/apache/commons/lang3/concurrent/BackgroundInitializerSupplierTest.java
org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java
org/apache/commons/lang3/concurrent/MultiBackgroundInitializerSupplierTest.java
org/apache/commons/lang3/concurrent/MultiBackgroundInitializerTest.java
org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java
org/apache/commons/lang3/function/MethodFixtures.java
org/apache/commons/lang3/function/Objects.java
org/apache/commons/lang3/reflect/ConstructorUtilsTest.java
Expand Down
11 changes: 2 additions & 9 deletions test-suites/commons-lang-parser-blacklist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@
# lambdas directly under a cast ((Predicate<T>) t -> ...), and lambdas in
# a conditional's false branch (cond ? x : (a, b) -> ...)
# - array class literals (String[].class) and array-constructor method
# references (boolean[]::new)
# - comma-separated statement-expression lists in a for-update (i++, pos++)
# - the 'volatile' modifier
# references (boolean[]::new, char[]::new)
#
# Total: 27 files blacklisted, 232 files passing
# Total: 22 files blacklisted, 237 files passing
# As grammar support is added, remove files from this list

org/apache/commons/lang3/AppendableJoiner.java
org/apache/commons/lang3/ArrayUtils.java
org/apache/commons/lang3/CharSequenceUtils.java
org/apache/commons/lang3/StringUtils.java
org/apache/commons/lang3/ThreadUtils.java
org/apache/commons/lang3/builder/DiffBuilder.java
org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
org/apache/commons/lang3/builder/ToStringBuilder.java
org/apache/commons/lang3/concurrent/LazyInitializer.java
org/apache/commons/lang3/function/BooleanConsumer.java
org/apache/commons/lang3/function/ByteConsumer.java
org/apache/commons/lang3/function/FailableBiFunction.java
Expand All @@ -36,5 +30,4 @@ org/apache/commons/lang3/function/FailableLongUnaryOperator.java
org/apache/commons/lang3/function/TriFunction.java
org/apache/commons/lang3/reflect/TypeUtils.java
org/apache/commons/lang3/text/StrBuilder.java
org/apache/commons/lang3/text/StrMatcher.java
org/apache/commons/lang3/text/StrSubstitutor.java
Loading
Loading