From 4a4a2ce69842cfa447fb99f34b6f51c3beda9db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Fri, 29 Mar 2024 21:02:12 +0100 Subject: [PATCH] JS: Improve completion for property chain (obj.prop1.prop2) with embedded comments and new lines --- .../editor/CompletionContextFinder.java | 16 ++- .../testfiles/completion/gh5919/gh5919_0.js | 20 +++ .../gh5919_0.js.testGH5919_0_1.completion | 6 + .../testfiles/completion/gh5919/gh5919_1.js | 23 ++++ .../gh5919_1.js.testGH5919_1_1.completion | 5 + .../gh5919_1.js.testGH5919_1_2.completion | 5 + .../gh5919_1.js.testGH5919_1_3.completion | 6 + .../gh5919_1.js.testGH5919_1_4.completion | 5 + .../gh5919_1.js.testGH5919_1_5.completion | 6 + .../gh5919_1.js.testGH5919_1_6.completion | 5 + .../gh5919_1.js.testGH5919_1_7.completion | 5 + .../testfiles/completion/gh5919/gh5919_2.js | 23 ++++ .../gh5919_2.js.testGH5919_2_1.completion | 5 + .../gh5919_2.js.testGH5919_2_2.completion | 5 + .../gh5919_2.js.testGH5919_2_3.completion | 6 + .../gh5919_2.js.testGH5919_2_4.completion | 5 + .../gh5919_2.js.testGH5919_2_5.completion | 6 + .../gh5919_2.js.testGH5919_2_6.completion | 5 + .../gh5919_2.js.testGH5919_2_7.completion | 5 + .../testfiles/completion/gh5919/gh5919_3.js | 23 ++++ .../gh5919_3.js.testGH5919_3_1.completion | 5 + .../gh5919_3.js.testGH5919_3_2.completion | 5 + .../gh5919_3.js.testGH5919_3_3.completion | 5 + .../gh5919_3.js.testGH5919_3_4.completion | 6 + .../gh5919_3.js.testGH5919_3_5.completion | 5 + .../gh5919_3.js.testGH5919_3_6.completion | 6 + .../gh5919_3.js.testGH5919_3_7.completion | 5 + .../gh5919_3.js.testGH5919_3_8.completion | 5 + .../gh5919_3.js.testGH5919_3_9.completion | 5 + .../import-meta-resolve-multiline.js | 24 ++++ .../import-meta-resolve-multiline.js.ast.xml | 54 ++++++++ .../editor/JsCodeCompletionIssueGH5919.java | 122 ++++++++++++++++++ .../javascript2/editor/parser/AstTest.java | 4 + .../javascript2/model/api/ModelUtils.java | 6 +- .../src/com/oracle/js/parser/Parser.java | 2 + .../src/com/oracle/js/parser/ManualTest.java | 2 +- 36 files changed, 439 insertions(+), 7 deletions(-) create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_0.js create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_0.js.testGH5919_0_1.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_1.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_2.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_3.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_4.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_5.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_6.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_7.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_1.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_2.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_3.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_4.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_5.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_6.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_7.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_1.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_2.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_3.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_4.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_5.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_6.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_7.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_8.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_9.completion create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js create mode 100644 webcommon/javascript2.editor/test/unit/data/testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js.ast.xml create mode 100644 webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsCodeCompletionIssueGH5919.java diff --git a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/CompletionContextFinder.java b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/CompletionContextFinder.java index 7c7bf7bf0e31..3be694da949b 100644 --- a/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/CompletionContextFinder.java +++ b/webcommon/javascript2.editor/src/org/netbeans/modules/javascript2/editor/CompletionContextFinder.java @@ -318,6 +318,12 @@ private static boolean acceptTokenChain(TokenSequence tokenSequence, Object[] to int orgTokenSequencePos = tokenSequence.offset(); boolean accept = true; boolean moreTokens = movePrevious ? tokenSequence.movePrevious() : true; + while((tokenSequence.token().id() == JsTokenId.BLOCK_COMMENT || tokenSequence.token().id() == JsTokenId.LINE_COMMENT)) { + moreTokens = tokenSequence.movePrevious(); + if(! moreTokens) { + break; + } + } for (int i = tokenIdChain.length - 1; i >= 0; i --){ Object tokenID = tokenIdChain[i]; @@ -328,8 +334,14 @@ private static boolean acceptTokenChain(TokenSequence tokenSequence, Object[] to } if (tokenID instanceof JsTokenId) { - if (tokenSequence.token().id() == tokenID){ + if (tokenSequence.token().id() == tokenID) { moreTokens = tokenSequence.movePrevious(); + while ((tokenSequence.token().id() == JsTokenId.BLOCK_COMMENT || tokenSequence.token().id() == JsTokenId.LINE_COMMENT)) { + moreTokens = tokenSequence.movePrevious(); + if (!moreTokens) { + break; + } + } } else { // NO MATCH accept = false; @@ -342,7 +354,7 @@ private static boolean acceptTokenChain(TokenSequence tokenSequence, Object[] to tokenSequence.move(orgTokenSequencePos); tokenSequence.moveNext(); - return accept; + return accept; } private static void balanceBracketBack(TokenSequence ts) { diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_0.js b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_0.js new file mode 100644 index 000000000000..f4201efc5c74 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_0.js @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +impo \ No newline at end of file diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_0.js.testGH5919_0_1.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_0.js.testGH5919_0_1.completion new file mode 100644 index 000000000000..02659bb845ca --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_0.js.testGH5919_0_1.completion @@ -0,0 +1,6 @@ +Code completion result for source line: +impo| +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS import [PUBLIC] metaproperties.js +KEYWORD import ECMAScript 6 - 2015 diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js new file mode 100644 index 000000000000..2da06095351b --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import.meta.url; +function dummy() { + new.target; +} \ No newline at end of file diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_1.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_1.completion new file mode 100644 index 000000000000..5461f34f3f79 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_1.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import.|meta.url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS meta [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_2.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_2.completion new file mode 100644 index 000000000000..841c8c7e8067 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_2.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import.me|ta.url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS meta [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_3.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_3.completion new file mode 100644 index 000000000000..adfc6366cf28 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_3.completion @@ -0,0 +1,6 @@ +Code completion result for source line: +import.meta.|url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD resolve(moduleName: String): S [PUBLIC] metaproperties.js +FIELD url: null|String [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_4.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_4.completion new file mode 100644 index 000000000000..0f0e0ac2ccbc --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_4.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import.meta.ur|l; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +FIELD url: null|String [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_5.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_5.completion new file mode 100644 index 000000000000..95d81416ae2e --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_5.completion @@ -0,0 +1,6 @@ +Code completion result for source line: +ne|w.target; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS new [PUBLIC] metaproperties.js +KEYWORD new null diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_6.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_6.completion new file mode 100644 index 000000000000..2f4fbb46ab16 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_6.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +new.|target; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD target(): undefined [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_7.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_7.completion new file mode 100644 index 000000000000..d51311d9c20c --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_1.js.testGH5919_1_7.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +new.targ|et; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD target(): undefined [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js new file mode 100644 index 000000000000..fef0984da861 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import/*dummy*/.meta.url; +function dummy() { + new/*dummy*/.target; +} \ No newline at end of file diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_1.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_1.completion new file mode 100644 index 000000000000..6294b9fd7d25 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_1.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import/*dummy*/.|meta.url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS meta [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_2.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_2.completion new file mode 100644 index 000000000000..6452d8b8602a --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_2.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import/*dummy*/.me|ta.url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS meta [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_3.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_3.completion new file mode 100644 index 000000000000..d27ffed84199 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_3.completion @@ -0,0 +1,6 @@ +Code completion result for source line: +import/*dummy*/.meta.|url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD resolve(moduleName: String): S [PUBLIC] metaproperties.js +FIELD url: null|String [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_4.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_4.completion new file mode 100644 index 000000000000..16761120705c --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_4.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import/*dummy*/.meta.ur|l; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +FIELD url: null|String [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_5.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_5.completion new file mode 100644 index 000000000000..89f829bb96bd --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_5.completion @@ -0,0 +1,6 @@ +Code completion result for source line: +ne|w/*dummy*/.target; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS new [PUBLIC] metaproperties.js +KEYWORD new null diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_6.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_6.completion new file mode 100644 index 000000000000..2d06b121a972 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_6.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +new/*dummy*/.|target; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD target(): undefined [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_7.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_7.completion new file mode 100644 index 000000000000..b3d8f6755eb7 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_2.js.testGH5919_2_7.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +new/*dummy*/.targ|et; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD target(): undefined [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js new file mode 100644 index 000000000000..e225b32f4473 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import/*dummy*/./*dummy*/meta.url; +function dummy() { + new/*dummy*/./*dummy*/target; +} \ No newline at end of file diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_1.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_1.completion new file mode 100644 index 000000000000..1824e76f33cd --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_1.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import/*dummy*/.|/*dummy*/meta.url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS meta [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_2.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_2.completion new file mode 100644 index 000000000000..19e707533909 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_2.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import/*dummy*/./*dummy*/|meta.url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS meta [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_3.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_3.completion new file mode 100644 index 000000000000..4934bde9b982 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_3.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import/*dummy*/./*dummy*/me|ta.url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS meta [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_4.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_4.completion new file mode 100644 index 000000000000..68816a59bf92 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_4.completion @@ -0,0 +1,6 @@ +Code completion result for source line: +import/*dummy*/./*dummy*/meta.|url; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD resolve(moduleName: String): S [PUBLIC] metaproperties.js +FIELD url: null|String [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_5.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_5.completion new file mode 100644 index 000000000000..e52a69851fd6 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_5.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +import/*dummy*/./*dummy*/meta.ur|l; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +FIELD url: null|String [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_6.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_6.completion new file mode 100644 index 000000000000..39bf2e19a694 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_6.completion @@ -0,0 +1,6 @@ +Code completion result for source line: +ne|w/*dummy*/./*dummy*/target; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +CLASS new [PUBLIC] metaproperties.js +KEYWORD new null diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_7.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_7.completion new file mode 100644 index 000000000000..1f9a5122ff16 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_7.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +new/*dummy*/.|/*dummy*/target; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD target(): undefined [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_8.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_8.completion new file mode 100644 index 000000000000..1d58d42139ec --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_8.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +new/*dummy*/./*dummy*/|target; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD target(): undefined [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_9.completion b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_9.completion new file mode 100644 index 000000000000..e31db3c4cbff --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/completion/gh5919/gh5919_3.js.testGH5919_3_9.completion @@ -0,0 +1,5 @@ +Code completion result for source line: +new/*dummy*/./*dummy*/targ|et; +(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) +------------------------------------ +METHOD target(): undefined [PUBLIC] metaproperties.js diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js b/webcommon/javascript2.editor/test/unit/data/testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js new file mode 100644 index 000000000000..3d8285f18bd0 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import( + import + .meta + .resolve("demo") +); diff --git a/webcommon/javascript2.editor/test/unit/data/testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js.ast.xml b/webcommon/javascript2.editor/test/unit/data/testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js.ast.xml new file mode 100644 index 000000000000..8df8e6add79f --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/data/testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js.ast.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + import + + + + + + + import + + + + + diff --git a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsCodeCompletionIssueGH5919.java b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsCodeCompletionIssueGH5919.java new file mode 100644 index 000000000000..f7cf819dc9b9 --- /dev/null +++ b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/JsCodeCompletionIssueGH5919.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.javascript2.editor; + +public class JsCodeCompletionIssueGH5919 extends JsCodeCompletionBase { + + public JsCodeCompletionIssueGH5919(String testName) { + super(testName); + } + + public void testGH5919_0_1() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_0.js", "impo^", false); + } + + public void testGH5919_1_1() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_1.js", "import.^", false); + } + + public void testGH5919_1_2() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_1.js", "import.me^", false); + } + + public void testGH5919_1_3() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_1.js", "import.meta.^", false); + } + + public void testGH5919_1_4() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_1.js", "import.meta.ur^", false); + } + + public void testGH5919_1_5() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_1.js", " ne^w.target;", false); + } + + public void testGH5919_1_6() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_1.js", " new.^target;", false); + } + + public void testGH5919_1_7() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_1.js", " new.targ^et;", false); + } + + public void testGH5919_2_1() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_2.js", "import/*dummy*/.^", false); + } + + public void testGH5919_2_2() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_2.js", "import/*dummy*/.me^", false); + } + + public void testGH5919_2_3() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_2.js", "import/*dummy*/.meta.^", false); + } + + public void testGH5919_2_4() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_2.js", "import/*dummy*/.meta.ur^", false); + } + + public void testGH5919_2_5() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_2.js", " ne^w/*dummy*/.target;", false); + } + + public void testGH5919_2_6() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_2.js", " new/*dummy*/.^target;", false); + } + + public void testGH5919_2_7() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_2.js", " new/*dummy*/.targ^et;", false); + } + + public void testGH5919_3_1() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", "import/*dummy*/.^/*dummy*/", false); + } + + public void testGH5919_3_2() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", "import/*dummy*/./*dummy*/^", false); + } + + public void testGH5919_3_3() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", "import/*dummy*/./*dummy*/me^", false); + } + + public void testGH5919_3_4() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", "import/*dummy*/./*dummy*/meta.^", false); + } + + public void testGH5919_3_5() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", "import/*dummy*/./*dummy*/meta.ur^", false); + } + + public void testGH5919_3_6() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", " ne^w/*dummy*/./*dummy*/target;", false); + } + + public void testGH5919_3_7() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", " new/*dummy*/.^/*dummy*/target;", false); + } + + public void testGH5919_3_8() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", " new/*dummy*/./*dummy*/^target;", false); + } + + public void testGH5919_3_9() throws Exception { + checkCompletion("testfiles/completion/gh5919/gh5919_3.js", " new/*dummy*/./*dummy*/targ^et;", false); + } +} diff --git a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/parser/AstTest.java b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/parser/AstTest.java index 43c4ea6393d0..d432449c0b5a 100644 --- a/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/parser/AstTest.java +++ b/webcommon/javascript2.editor/test/unit/src/org/netbeans/modules/javascript2/editor/parser/AstTest.java @@ -3115,6 +3115,10 @@ public void testImportMetaResolveComment() throws Exception { checkAstResult("testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-comment.js"); } + public void testImportMetaResolveMultiline() throws Exception { + checkAstResult("testfiles/ecmascript6/parser/ES6/meta-property/import-meta-resolve-multiline.js"); + } + private void checkAstResult(String relFilePath) throws Exception { FileObject testFO = getTestFile(relFilePath); if (testFO == null) { diff --git a/webcommon/javascript2.model/src/org/netbeans/modules/javascript2/model/api/ModelUtils.java b/webcommon/javascript2.model/src/org/netbeans/modules/javascript2/model/api/ModelUtils.java index 1fe780449ed5..7d7a16a676c8 100644 --- a/webcommon/javascript2.model/src/org/netbeans/modules/javascript2/model/api/ModelUtils.java +++ b/webcommon/javascript2.model/src/org/netbeans/modules/javascript2/model/api/ModelUtils.java @@ -1769,8 +1769,6 @@ public static List resolveExpressionChain(Snapshot snapshot, int offset, while (token.id() != JsTokenId.OPERATOR_SEMICOLON && token.id() != JsTokenId.BRACKET_RIGHT_CURLY && token.id() != JsTokenId.BRACKET_LEFT_CURLY && token.id() != JsTokenId.BRACKET_LEFT_PAREN - && token.id() != JsTokenId.BLOCK_COMMENT - && token.id() != JsTokenId.LINE_COMMENT && token.id() != JsTokenId.OPERATOR_ASSIGNMENT && token.id() != JsTokenId.OPERATOR_PLUS) { @@ -1791,7 +1789,7 @@ public static List resolveExpressionChain(Snapshot snapshot, int offset, } } } - if (token.id() != JsTokenId.EOL) { + if (token.id() != JsTokenId.WHITESPACE && token.id() != JsTokenId.EOL && token.id() != JsTokenId.BLOCK_COMMENT && token.id() != JsTokenId.LINE_COMMENT) { if (token.id() != JsTokenId.OPERATOR_DOT && token.id() != JsTokenId.OPERATOR_OPTIONAL_ACCESS) { if (token.id() == JsTokenId.BRACKET_RIGHT_PAREN) { parenBalancer++; @@ -1847,7 +1845,7 @@ public static List resolveExpressionChain(Snapshot snapshot, int offset, wasLastDot = true; } } else { - if (!wasLastDot && ts.movePrevious()) { + if (token.id() != JsTokenId.BLOCK_COMMENT && token.id() != JsTokenId.LINE_COMMENT && !wasLastDot && ts.movePrevious()) { // check whether it's continuatino of previous line token = LexUtilities.findPrevious(ts, Arrays.asList(JsTokenId.WHITESPACE, JsTokenId.BLOCK_COMMENT, JsTokenId.LINE_COMMENT)); if (token.id() != JsTokenId.OPERATOR_DOT && token.id() != JsTokenId.OPERATOR_OPTIONAL_ACCESS) { diff --git a/webcommon/libs.nashorn/src/com/oracle/js/parser/Parser.java b/webcommon/libs.nashorn/src/com/oracle/js/parser/Parser.java index ae69bb90dcfc..1cafdada28bc 100644 --- a/webcommon/libs.nashorn/src/com/oracle/js/parser/Parser.java +++ b/webcommon/libs.nashorn/src/com/oracle/js/parser/Parser.java @@ -3807,6 +3807,7 @@ private boolean lookaheadMetaProperty() { TokenType t = T(k + lookAheadPos); switch (t) { case COMMENT: + case EOL: continue; default: if(t != PERIOD) { @@ -3821,6 +3822,7 @@ private boolean lookaheadMetaProperty() { TokenType t = T(k + lookAheadPos); switch (t) { case COMMENT: + case EOL: continue; default: return t == IDENT && "meta".equals(getValue(getToken(k + lookAheadPos))); diff --git a/webcommon/libs.nashorn/test/unit/src/com/oracle/js/parser/ManualTest.java b/webcommon/libs.nashorn/test/unit/src/com/oracle/js/parser/ManualTest.java index ce96b0af17b0..07c514b84da3 100644 --- a/webcommon/libs.nashorn/test/unit/src/com/oracle/js/parser/ManualTest.java +++ b/webcommon/libs.nashorn/test/unit/src/com/oracle/js/parser/ManualTest.java @@ -41,7 +41,7 @@ public static void main(String[] args) { // Source source = Source.sourceFor("dummy.js", "function a() {}; async function b() {}; class x { y(){} async z(){} }"); // Source source = Source.sourceFor("dummy.js", "const a = {/* Test */ /* Test */ /* Test */}{ a = 3 }
"); // Source source = Source.sourceFor("dummy.js", "function dummy() {console.log(new.target);}"); - Source source = Source.sourceFor("dummy.js", "console.log(import.meta.url);"); + Source source = Source.sourceFor("dummy.js", "function demo() {console.log(import\n\n.meta.url)}"); ScriptEnvironment.Builder builder = ScriptEnvironment.builder(); Parser parser = new Parser( builder.emptyStatements(true).ecmacriptEdition(13).jsx(true).dumpOnError(new PrintWriter(System.err)).build(),