This is an automated email from the ASF dual-hosted git repository. matthiasblaesing pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new a41856a756 Don't generate hint for missing semicolon in generated constructor node new df48f84e41 Merge pull request #4232 from matthiasblaesing/gh-4214 a41856a756 is described below commit a41856a75601a4565852a022fccf4bd237c1fea5 Author: Matthias Bläsing <mblaes...@doppel-helix.eu> AuthorDate: Thu Jun 16 21:36:02 2022 +0200 Don't generate hint for missing semicolon in generated constructor node For this construct: class A { } class B extends A { } the graaljs parser generates the default constructor: constructor(...args) { super(...args); } This irritates the semicolon hint, as the token for the semicolon can't be found and thus the hint is generated. Closes: #4214 --- .../javascript2/editor/hints/JsConventionRule.java | 26 ++++++++++++++++++++++ .../hints/semicolonWarningGeneratedConstructor.js | 8 +++++++ ....testSemicolonWarningGeneratedConstructor.hints | 0 .../hints/semicolonWarningRealConstructor.js | 13 +++++++++++ ...or.js.testSemicolonWarningRealConstructor.hints | 3 +++ .../editor/hint/JsConventionHintTest.java | 10 ++++++++- 6 files changed, 59 insertions(+), 1 deletion(-) diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/hints/JsConventionRule.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/hints/JsConventionRule.java index 06105fad4e..54b25af55a 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/hints/JsConventionRule.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/hints/JsConventionRule.java @@ -31,11 +31,14 @@ import com.oracle.js.parser.ir.ReturnNode; import com.oracle.js.parser.ir.ThrowNode; import com.oracle.js.parser.ir.VarNode; import com.oracle.js.parser.ir.WhileNode; + import static com.oracle.js.parser.TokenType.EQ; import static com.oracle.js.parser.TokenType.NE; + import com.oracle.js.parser.ir.ClassNode; import com.oracle.js.parser.ir.ExpressionStatement; import com.oracle.js.parser.ir.IdentNode; +import com.oracle.js.parser.ir.PropertyNode; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -594,5 +597,28 @@ public class JsConventionRule extends JsAstRule { checkCondition(binaryNode); return super.enterBinaryNode(binaryNode); } + + @Override + public boolean enterPropertyNode(PropertyNode propertyNode) { + ClassNode enclosingClass = classDefinitionHierarchie.isEmpty() ? null : classDefinitionHierarchie.get(classDefinitionHierarchie.size() - 1); + if(enclosingClass != null && propertyNode.getToken() == enclosingClass.getToken()) { + return false; + } + return super.enterPropertyNode(propertyNode); + } + + private List<ClassNode> classDefinitionHierarchie = new ArrayList<>(); + + @Override + public boolean enterClassNode(ClassNode classNode) { + classDefinitionHierarchie.add(classNode); + return super.enterClassNode(classNode); + } + + @Override + public Node leaveClassNode(ClassNode classNode) { + classDefinitionHierarchie.remove(classDefinitionHierarchie.size() - 1); + return super.leaveClassNode(classNode); + } } } diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningGeneratedConstructor.js b/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningGeneratedConstructor.js new file mode 100644 index 0000000000..e3979f1b61 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningGeneratedConstructor.js @@ -0,0 +1,8 @@ +class A { +} + +/** + * This class definition should not generate a "missing semicolon" hint + */ +class B extends A { +} diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningGeneratedConstructor.js.testSemicolonWarningGeneratedConstructor.hints b/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningGeneratedConstructor.js.testSemicolonWarningGeneratedConstructor.hints new file mode 100644 index 0000000000..e69de29bb2 diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningRealConstructor.js b/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningRealConstructor.js new file mode 100644 index 0000000000..1b003cf989 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningRealConstructor.js @@ -0,0 +1,13 @@ +class A { +} + +/** + * This class definition should generate a "missing semicolon" hint, as the + * explicit constructor really has not semicolon + */ +class B extends A { + constructor() { + super() + } +} + diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningRealConstructor.js.testSemicolonWarningRealConstructor.hints b/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningRealConstructor.js.testSemicolonWarningRealConstructor.hints new file mode 100644 index 0000000000..8c1001fd68 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/hints/semicolonWarningRealConstructor.js.testSemicolonWarningRealConstructor.hints @@ -0,0 +1,3 @@ + super() + - +HINT:Expected semicolon ; after ")". diff --git a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/hint/JsConventionHintTest.java b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/hint/JsConventionHintTest.java index 56160c91e7..436cf691ef 100644 --- a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/hint/JsConventionHintTest.java +++ b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/hint/JsConventionHintTest.java @@ -211,5 +211,13 @@ public class JsConventionHintTest extends HintTestBase { public void testIssue269659_04() throws Exception { checkHints(this, createDuplicatePropertyHint(), "testfiles/hints/issue269659_04.js", null); - } + } + + public void testSemicolonWarningGeneratedConstructor() throws Exception { + checkHints(this, createSemicolonHint(), "testfiles/hints/semicolonWarningGeneratedConstructor.js", null); + } + + public void testSemicolonWarningRealConstructor() throws Exception { + checkHints(this, createSemicolonHint(), "testfiles/hints/semicolonWarningRealConstructor.js", null); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists