52 Commits

Author SHA1 Message Date
5de405d23f [java] Fix scoping inconsistencies
- Reduce LocalScope creations. Method parameters and method locals have
the same visibility / reachability, so they should be in the same scope.
 - Fix the grammar `assert` lookahead. There is no need to use `(`
 - Fix illegal test code (shadowing of parameters is illegal)
 - Update Scope tests to deal with changes
 - Fixes #1051
2018-05-06 20:42:33 -03:00
32af9cabf2 [java] Update valid identifiers
- Newer Java versions have allowed for a lot more tokens in identifiers
2018-02-18 04:44:27 -03:00
22596e5176 Add ghost production for TypeAnnotation to cleanup the grammar
Type annotations can be nearly everywhere since Java 8, which makes the grammar
really hard to read when the check for correct jdk version is repeated all over
the place.
2018-02-16 23:53:37 +01:00
f9df6ed01e [java] Fix grammar for <> in Java 1.8
- Fixes #888
 - Allow the contents of an anonymous class to use diamong notation, but
the anonymous class itself can't use it
2018-01-29 14:10:40 -03:00
109f458dbf Fixes #793 [java] Parser error with private method in nested classes in interfaces
*   Remember old state to allow nesting
*   Fix ASTMethodDeclaration.isInterfaceMember
*   Extended tests
2017-12-22 12:03:20 +01:00
64b862eef9 Fixes #793 [java] Parser error with private method in nested classes in interfaces 2017-12-20 22:42:34 +01:00
05927af574 [java] Properly resolve array types
- Honor dimensions of arrays
 - Resolve types for allocations as well as declarations of arrays
2017-10-26 22:31:29 -03:00
c00400ef77 Fix try with final resource 2017-10-18 08:50:06 -03:00
6590a358e6 Support concise try-with-resources with java9 2017-09-23 00:15:08 +02:00
f30eb4b5ff Use semantic lookahead for the module productions
The new keyword are only "restricted keywords" and can still be used
as identifiers.
2017-09-22 23:43:43 +02:00
1020bf73db Enhance grammar to parse Java 9 module-info.java 2017-09-22 21:35:24 +02:00
672f9216dd Simplify grammar: TypeArguments is not used here, it's resolved
as a child by ClassOrInterfaceType already
2017-09-22 15:32:24 +02:00
77222904de Check for diamond operator for anonymous classes 2017-09-22 15:32:19 +02:00
722b2b1657 Allow nested private methods 2017-09-22 13:33:08 +02:00
cfa4b5b85c Add Java9 Language Module, Update grammar
* Java8 mode now rejects private methods in interfaces
* Java9 mode now rejects "_" as identifier
2017-09-22 12:19:38 +02:00
0822218574 Simplify expressions 2017-06-01 11:56:48 -03:00
2460402ea8 test case & adapted grammar for annotated generic return type
public static <T> @Nullable T getNullableEnum() {
		return null;
	}
2017-06-01 15:00:20 +02:00
b8d435235f fixed/removed unneeded change
@@ -1488,7 +1488,7 @@ void MethodDeclaration(int modifiers) :
 {jjtThis.setModifiers(modifiers);}
 {
   [ TypeParameters() ]
-  ResultType() MethodDeclarator() [ "throws" NameList() ]
+  [(Annotation() {checkForBadTypeAnnotations();})+] ResultType()
MethodDeclarator() [ "throws" NameList() ]
2017-06-01 10:13:29 +02:00
a4754e9fc9 I hear voices ... and they tell me to like multi dimensional arrays
private static void testMultiDimArrayWithAnnotations() {
		// ever used a 2D-Array in java??
		Object x = new Object @NonNull[2] @Nullable[1] @NonNull[3];
	}
2017-05-30 15:15:44 +02:00
7997297e0b test case for
public void createNonNullArray() {
		return new MetaColumn @NonNull [value];
	}
2017-05-30 14:13:38 +02:00
b5474cdcf8 test case and fix for
public static <T extends @NonNull Enum<T>> getEnum() {
		return null;
	}
2017-05-30 14:05:29 +02:00
0660c7298a + simplified 2017-05-30 12:31:03 +02:00
d314a2c301 test case for
private byte @Nullable [] getBytes(){
		return null;
	}
2017-05-30 12:20:26 +02:00
7a4766e8a6 [java] Parsing Problem with Annotation for Array Member Types #417 2017-05-30 10:52:09 +02:00
68ab7048cb *[java]* Java 8 parsing problem with annotations for wildcards #414 2017-05-29 18:20:12 +02:00
4e72eef495 [java] Parser Error for empty statements
Fixes #378
2017-05-20 21:28:39 +02:00
aaf9419344 Merge branch 'issue-309' 2017-03-27 21:21:38 +02:00
abe2e8561c Fixes #309: [java] Parse error on method reference 2017-03-27 21:07:28 +02:00
5cd0f2e928 Merge branch 'issue-257' 2017-02-20 16:13:37 +01:00
8f22e69560 Ugly workaround that don't need to change AST 2017-02-20 16:00:39 +01:00
907972f0ca [java] Improve grammar for CastExpression
- Provide a definite fix for casts. This allowed to remove a bunch of hacks.
 - I had to change the grammar a bit... `(int)` is now a cast with a
    PrimitiveType as child, not a Type with a nested PrimitiveType. This is due
    to JavaCC completely ignoring whatever you place in the LOOKAHEAD in favor
    of just looking the follow-up expression completely.
 - Removing the hacks raised an issue with expression orders, caused also by JavaCC's
    disregard to LOOKAHEAD contents
2017-02-20 16:00:39 +01:00
0ef09b2c0a Merge branch 'issue-208'
Closes #211 (rebased onto pmd/5.4.x)
2017-01-27 20:11:49 +01:00
c53e1790e1 [java] Allow more than 1 annotation in local classes
- This fixes #208
2017-01-27 20:00:08 +01:00
bbc9abd4e2 Merge branch 'issue-206'
Closes #210 (rebased onto pmd/5.4.x)
2017-01-27 19:50:50 +01:00
455b1c4ded Fix grammar for annotation members
- The lookahead (3 tokens) was too small, and without reaching the opening
    parenthesis assumed it was parsing a method and not a field.
 - Using a larger lookahead solves the issue.
 - Fixes #206
2017-01-27 19:38:48 +01:00
5c1a0a7abe Merge branch 'issue-207'
Closes #209 (rebased onto pmd/5.4.x)
2017-01-27 19:26:56 +01:00
33fd84d521 [java] Support generics in method references
- Fixes #207
 - Extend the Java grammar to support generics in
    method references: `Type::<Generic>method`
2017-01-27 19:10:42 +01:00
e280151987 pmd-cpp/pmd-java: checkstyle fixes 2016-12-16 15:48:53 +01:00
2158a792ff Merge branch 'simplify-variable-declarator-id-parsing' of https://github.com/Monits/pmd into pr-118
# Conflicts:
#	pmd-java/etc/grammar/Java.jjt
2016-10-30 18:51:44 +01:00
10e4cc7290 Merge branch 'faster-parse' of https://github.com/Monits/pmd into pr-115
# Conflicts:
#	pmd-java/etc/grammar/Java.jjt
2016-10-30 18:12:54 +01:00
283dc00a43 Replace syntactic lookahead with semantic one
- They are the same, but JavaCC seems to handle this one better.
2016-10-16 14:01:26 +02:00
567be45b8c Simplify VariableDeclaratorId parsing
- Don't look for arrays where there can be none
2016-10-14 10:06:29 -03:00
478ed3463c Simplify lambda pursing even further
- Remove a redundant case
 - Restrict grammar according to spec with a simpler scenario
2016-10-14 09:24:06 -03:00
a046b8f93d Simplify lambda parsing
- Handle less scenarios
 - Have scenarios be defined more broadly (ie: allow more than 3 params)
 - This improves parsing performance by roughly ~10%
2016-10-13 14:53:51 -03:00
0d20fe7e1c Fixes #1484 UnusedLocalVariable - false positive - parenthesis 2016-05-21 11:37:10 +02:00
81378fe8ed Fixes #1470 Error with type-bound lambda 2016-04-30 19:14:46 +02:00
e6f5380719 fixes #1455 PMD doesn't handle Java 8 explicit receiver parameters
Those parameters are correctly parsed now and can be found
with "//FormalParameter[@ExplicitReceiverParameter='true']"
2016-01-25 10:29:00 +01:00
1e0b8cfa21 Merge branch 'pmd/5.3.x' of https://github.com/amitbitcse/pmd into pr-72 2015-10-10 17:22:59 +02:00
a7a84766bd #1429 Java - Parse Error: Cast in return expression 2015-10-10 16:08:38 +02:00
1d190605e5 Added capability in Java and JSP parser for tracking tokens. It is often useful to keep track of each node's first and last token so that input can be easily reproduced again. Ref - https://javacc.java.net/doc/JJTree.html 2015-10-06 11:04:22 +05:30