From f76ac0aa8970f8837955e1e8f43026f5199b23fa Mon Sep 17 00:00:00 2001 From: Maikel Steneker Date: Fri, 10 May 2019 16:27:37 +0200 Subject: [PATCH 1/3] Added unit test for question mark (?) token in Matlab tokenizer. --- .../net/sourceforge/pmd/cpd/MatlabTokenizerTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java b/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java index 50fdb1832e..6f10aa814d 100644 --- a/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java +++ b/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java @@ -54,4 +54,14 @@ public class MatlabTokenizerTest extends AbstractTokenizerTest { TokenEntry.getEOF(); assertEquals(2, tokens.size()); // 2 tokens: "end" + EOF } + + @Test + public void testQuestionMark() throws IOException { + SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader("classdef Class1" + PMD.EOL + + "properties (SetAccess = ?Class2)")); + Tokens tokens = new Tokens(); + tokenizer.tokenize(sourceCode, tokens); + TokenEntry.getEOF(); + assertEquals(10, tokens.size()); + } } From 4ec25840bb33ef1ae3362617eca6d90416260000 Mon Sep 17 00:00:00 2001 From: Maikel Steneker Date: Fri, 10 May 2019 16:28:08 +0200 Subject: [PATCH 2/3] Added support for question mark (?) token in Matlab tokenizer. --- pmd-matlab/etc/grammar/matlab.jj | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd-matlab/etc/grammar/matlab.jj b/pmd-matlab/etc/grammar/matlab.jj index 6f61dd0d42..0e1029a203 100644 --- a/pmd-matlab/etc/grammar/matlab.jj +++ b/pmd-matlab/etc/grammar/matlab.jj @@ -65,6 +65,7 @@ SPECIAL_TOKEN: | < AT: "@" > : DEFAULT | < DOT: "." > : TRANSPOSE | < COMMA: "," > : DEFAULT +| < QUESTIONMARK: "?" > : DEFAULT } TOKEN : /* OPERATORS AND ASSIGNMENTS */ From 1f02f5ff7f4a5172bbb28677b6bded7fc3a42b4c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 12 May 2019 16:12:07 +0200 Subject: [PATCH 3/3] Update release notes, refs #1821 --- docs/pages/release_notes.md | 12 ++++++++++++ .../net/sourceforge/pmd/cpd/MatlabTokenizerTest.java | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 0c717925c2..2d8a1811bf 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -29,6 +29,17 @@ Being based on a proper Antlr grammar, CPD can: This PMD release ships a new version of the pmd-designer. For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designer/blob/6.14.0/CHANGELOG.md). +#### Enhanced Matlab support + +Thanks to the contribution from [Maikel Steneker](https://github.com/maikelsteneker) CPD for Matlab can +now parse matlab programs which use the question mark operator to specify access to +class members: + +``` +lassdef Class1 +properties (SetAccess = ?Class2) +``` + ### Modified Rules * The Java rule {% rule "java/errorprone/AssignmentToNonFinalStatic" %} (`java-errorprone`) will now report on each @@ -73,6 +84,7 @@ No changes. * [#1781](https://github.com/pmd/pmd/pull/1781): \[java] Location change in AssignmentToNonFinalStatic - [Maikel Steneker](https://github.com/maikelsteneker) * [#1789](https://github.com/pmd/pmd/pull/1789): \[cpd] \[core] Use current classloader instead of Thread's classloader - [Andreas Schmid](https://github.com/aaschmid) * [#1791](https://github.com/pmd/pmd/pull/1791): \[dart] \[cpd] Dart escaped string - [Maikel Steneker](https://github.com/maikelsteneker) +* [#1821](https://github.com/pmd/pmd/pull/1821): \[matlab] \[cpd] Matlab question mark token - [Maikel Steneker](https://github.com/maikelsteneker) {% endtocmaker %} diff --git a/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java b/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java index 6f10aa814d..ae041a3e1c 100644 --- a/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java +++ b/pmd-matlab/src/test/java/net/sourceforge/pmd/cpd/MatlabTokenizerTest.java @@ -61,7 +61,6 @@ public class MatlabTokenizerTest extends AbstractTokenizerTest { + "properties (SetAccess = ?Class2)")); Tokens tokens = new Tokens(); tokenizer.tokenize(sourceCode, tokens); - TokenEntry.getEOF(); assertEquals(10, tokens.size()); } }