This is an automated email from the ASF dual-hosted git repository. junichi11 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 e8bf72eec6 Fix incorrect AbstractClassInstantiationHintError #6119 new 3a61869b00 Merge pull request #6171 from junichi11/php-gh-6119-incorrect-abstract-instantiation-hint e8bf72eec6 is described below commit e8bf72eec654d4fb46d3eca1a255ab3b2ece4c28 Author: Junichi Yamamoto <junich...@apache.org> AuthorDate: Mon Jul 10 00:09:29 2023 +0900 Fix incorrect AbstractClassInstantiationHintError #6119 - https://github.com/apache/netbeans/issues/6119 - Check whether the class name has `$` - Add unit tests --- .../org/netbeans/modules/php/editor/CodeUtils.java | 9 +++++ .../AbstractClassInstantiationHintError.java | 12 ++++-- .../AbstractClassInstantiationHint/gh6119.php | 23 +++++++++++ .../gh6119.php.testGH6119.hints | 1 + .../testAbstractClassInstantiationHint.php | 0 ...nt.php.testAbstractClassInstantiationHint.hints | 0 .../testAbstractClassInstantiationHint_02.php | 0 ...php.testAbstractClassInstantiationHint_02.hints | 0 .../AbstractClassInstantiationHintErrorTest.java | 47 ++++++++++++++++++++++ .../modules/php/editor/verification/HintsTest.java | 8 ---- 10 files changed, 89 insertions(+), 11 deletions(-) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/CodeUtils.java b/php/php.editor/src/org/netbeans/modules/php/editor/CodeUtils.java index fcc307ef31..d87712a333 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/CodeUtils.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/CodeUtils.java @@ -690,6 +690,15 @@ public final class CodeUtils { return "__construct".equals(extractMethodName(node)); //NOI18N } + public static boolean isDollaredName(ClassName className) { + Expression name = className.getName(); + if (name instanceof Variable) { + Variable variable = (Variable) name; + return variable.isDollared(); + } + return false; + } + /** * Finds common namespace prefixes for the given <b>sorted</b> namespaces. * <p> diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/AbstractClassInstantiationHintError.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/AbstractClassInstantiationHintError.java index f1d3dcc389..375807bed5 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/AbstractClassInstantiationHintError.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/AbstractClassInstantiationHintError.java @@ -19,11 +19,13 @@ package org.netbeans.modules.php.editor.verification; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Set; import org.netbeans.modules.csl.api.Hint; import org.netbeans.modules.csl.api.OffsetRange; import org.netbeans.modules.csl.spi.support.CancelSupport; +import org.netbeans.modules.php.editor.CodeUtils; import org.netbeans.modules.php.editor.api.ElementQuery.Index; import org.netbeans.modules.php.editor.api.NameKind; import org.netbeans.modules.php.editor.api.QualifiedName; @@ -79,7 +81,7 @@ public class AbstractClassInstantiationHintError extends HintErrorRule { } public List<Hint> getHints() { - return hints; + return Collections.unmodifiableList(hints); } @Override @@ -88,7 +90,12 @@ public class AbstractClassInstantiationHintError extends HintErrorRule { "AbstractClassInstantiationDesc=Abstract class {0} can not be instantiated" }) public void visit(ClassInstanceCreation node) { - if (CancelSupport.getDefault().isCancelled()) { + if (CancelSupport.getDefault().isCancelled() + || CodeUtils.isDollaredName(node.getClassName())) { + // GH-6119 + // e.g. + // abstract class AbstractClass {} + // $a = new $abstractClass(); return; } ASTNodeInfo<ClassInstanceCreation> info = ASTNodeInfo.create(node); @@ -110,7 +117,6 @@ public class AbstractClassInstantiationHintError extends HintErrorRule { } } } - } @Override diff --git a/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/gh6119.php b/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/gh6119.php new file mode 100644 index 0000000000..105ae28aa9 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/gh6119.php @@ -0,0 +1,23 @@ +<?php +/* + * 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. + */ + +abstract class AbstractClass {} + +$abstractClass = new $abstractClass(); diff --git a/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/gh6119.php.testGH6119.hints b/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/gh6119.php.testGH6119.hints new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/gh6119.php.testGH6119.hints @@ -0,0 +1 @@ + diff --git a/php/php.editor/test/unit/data/testfiles/verification/testAbstractClassInstantiationHint.php b/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/testAbstractClassInstantiationHint.php similarity index 100% rename from php/php.editor/test/unit/data/testfiles/verification/testAbstractClassInstantiationHint.php rename to php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/testAbstractClassInstantiationHint.php diff --git a/php/php.editor/test/unit/data/testfiles/verification/testAbstractClassInstantiationHint.php.testAbstractClassInstantiationHint.hints b/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/testAbstractClassInstantiationHint.php.testAbstractClassInstantiationHint.hints similarity index 100% rename from php/php.editor/test/unit/data/testfiles/verification/testAbstractClassInstantiationHint.php.testAbstractClassInstantiationHint.hints rename to php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/testAbstractClassInstantiationHint.php.testAbstractClassInstantiationHint.hints diff --git a/php/php.editor/test/unit/data/testfiles/verification/testAbstractClassInstantiationHint_02.php b/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/testAbstractClassInstantiationHint_02.php similarity index 100% rename from php/php.editor/test/unit/data/testfiles/verification/testAbstractClassInstantiationHint_02.php rename to php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/testAbstractClassInstantiationHint_02.php diff --git a/php/php.editor/test/unit/data/testfiles/verification/testAbstractClassInstantiationHint_02.php.testAbstractClassInstantiationHint_02.hints b/php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/testAbstractClassInstantiationHint_02.php.testAbstractClassInstantiationHint_02.hints similarity index 100% rename from php/php.editor/test/unit/data/testfiles/verification/testAbstractClassInstantiationHint_02.php.testAbstractClassInstantiationHint_02.hints rename to php/php.editor/test/unit/data/testfiles/verification/AbstractClassInstantiationHint/testAbstractClassInstantiationHint_02.php.testAbstractClassInstantiationHint_02.hints diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/AbstractClassInstantiationHintErrorTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/AbstractClassInstantiationHintErrorTest.java new file mode 100644 index 0000000000..ece8ba50e1 --- /dev/null +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/AbstractClassInstantiationHintErrorTest.java @@ -0,0 +1,47 @@ +/* + * 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.php.editor.verification; + +public class AbstractClassInstantiationHintErrorTest extends PHPHintsTestBase { + + public AbstractClassInstantiationHintErrorTest(String testName) { + super(testName); + } + + @Override + protected String getTestDirectory() { + return TEST_DIRECTORY + "AbstractClassInstantiationHint/"; + } + + public void testAbstractClassInstantiationHint() throws Exception { + checkHints("testAbstractClassInstantiationHint.php"); + } + + public void testAbstractClassInstantiationHint_02() throws Exception { + checkHints("testAbstractClassInstantiationHint_02.php"); + } + + public void testGH6119() throws Exception { + checkHints("gh6119.php"); + } + + private void checkHints(String fileName) throws Exception { + checkHints(new AbstractClassInstantiationHintError(), fileName); + } +} diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/HintsTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/HintsTest.java index 063fab1c2c..3c5cf9c617 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/HintsTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/HintsTest.java @@ -43,14 +43,6 @@ public class HintsTest extends PHPHintsTestBase { return inputFile; } - public void testAbstractClassInstantiationHint() throws Exception { - checkHints(new AbstractClassInstantiationHintError(), "testAbstractClassInstantiationHint.php"); - } - - public void testAbstractClassInstantiationHint_02() throws Exception { - checkHints(new AbstractClassInstantiationHintError(), "testAbstractClassInstantiationHint_02.php"); - } - public void testAmbiguousComparisonHint() throws Exception { checkHints(new AmbiguousComparisonHint(), "testAmbiguousComparisonHint.php"); } --------------------------------------------------------------------- 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