You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ju...@apache.org on 2023/02/21 00:10:13 UTC
[netbeans] branch master updated: Fixed detection of duplicate types
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 064e9e3b84 Fixed detection of duplicate types
new c12e495692 Merge pull request #5534 from KacerCZ/fix-duplicate-type-hint
064e9e3b84 is described below
commit 064e9e3b84667fe7faae8c0ee5b68abbabd3dc5c
Author: Tomas Prochazka <ka...@razdva.cz>
AuthorDate: Sun Feb 19 15:21:38 2023 +0100
Fixed detection of duplicate types
Goes through all types and does not return on first error.
Partial fix for #5072
---
.../verification/UnusableTypesHintError.java | 3 -
.../testDuplicateTypes_01.php | 99 ++++++++++++++++++
...plicateTypes_01.php.testDuplicateTypes_01.hints | 114 +++++++++++++++++++++
.../verification/UnusableTypesHintErrorTest.java | 4 +
4 files changed, 217 insertions(+), 3 deletions(-)
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusableTypesHintError.java b/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusableTypesHintError.java
index b777a168d6..227b7efe82 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusableTypesHintError.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/verification/UnusableTypesHintError.java
@@ -430,18 +430,15 @@ public class UnusableTypesHintError extends HintErrorRule {
}
if (checkedTypes.contains(name)) {
createDuplicateTypeError(type, typeName);
- return;
} else if (checkedTypes.contains(Type.BOOL)) {
// bool|false bool|true
if (Type.FALSE.equals(name) || Type.TRUE.equals(name)) {
createDuplicateTypeError(type, typeName);
- return;
}
} else if (checkedTypes.contains(Type.FALSE) || checkedTypes.contains(Type.TRUE)) {
// false|bool true|bool
if (Type.BOOL.equals(name)) {
createDuplicateTypeError(type, typeName);
- return;
}
}
checkedTypes.add(name);
diff --git a/php/php.editor/test/unit/data/testfiles/verification/UnusableTypesHintError/testDuplicateTypes_01.php b/php/php.editor/test/unit/data/testfiles/verification/UnusableTypesHintError/testDuplicateTypes_01.php
new file mode 100644
index 0000000000..74eb42c6b6
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/verification/UnusableTypesHintError/testDuplicateTypes_01.php
@@ -0,0 +1,99 @@
+<?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.
+ */
+
+class DuplicateTypes {
+
+ private First|First $union;
+ private First&First $intersection;
+ private First|Second|First|Second $twoUnions;
+ private First&Second&First&Second $twoIntersections;
+
+ private bool|true|bool $unionBoolAndTrue;
+ private bool|false|bool $unionBoolAndFalse;
+
+ private bool|true|First|First $unionAfterBoolAndTrue;
+ private bool|false|First|First $unionAfterBoolAndFalse;
+ private true|bool|First|First $unionAfterTrueAndBool;
+ private false|bool|First|First $unionAfterFalseAndBool;
+
+ public function returnUnion(): First|First {
+ }
+
+ public function returnIntersection(): First&First {
+ }
+
+ public function returnTwoUnions(): First|Second|First|Second {
+ }
+
+ public function returnTwoIntersections(): First&Second&First&Second {
+ }
+
+ public function returnUnionBoolAndTrue(): bool|true|bool {
+ }
+
+ public function returnUnionBoolAndFalse(): bool|false|bool {
+ }
+
+ public function returnUnionAfterBoolAndTrue(): bool|true|First|First {
+ }
+
+ public function returnUnionAfterBoolAndFalse(): bool|false|First|First {
+ }
+
+ public function returnUnionAfterTrueAndBool(): true|bool|First|First {
+ }
+
+ public function returnUnionAfterFalseAndBool(): false|bool|First|First {
+ }
+
+ public function parameterUnion(First|First $union) {
+ }
+
+ public function parameterIntersection(First&First $intersection) {
+ }
+
+ public function parameterTwoUnions(First|Second|First|Second $twoUnions) {
+ }
+
+ public function parameterTwoIntersections(First&Second&First&Second $twoIntersections) {
+ }
+
+ public function parameterUnionBoolAndTrue(bool|true|bool $union) {
+ }
+
+ public function parameterUnionBoolAndFalse(bool|false|bool $union) {
+ }
+
+ public function parameterUnionAfterBoolAndTrue(bool|true|First|First $union) {
+ }
+
+ public function parameterUnionAfterBoolAndFalse(bool|false|First|First $union) {
+ }
+
+ public function parameterUnionAfterTrueAndBool(true|bool|First|First $union) {
+ }
+
+ public function parameterUnionAfterFalseAndBool(false|bool|First|First $union) {
+ }
+}
+
+class First {}
+
+class Second {}
diff --git a/php/php.editor/test/unit/data/testfiles/verification/UnusableTypesHintError/testDuplicateTypes_01.php.testDuplicateTypes_01.hints b/php/php.editor/test/unit/data/testfiles/verification/UnusableTypesHintError/testDuplicateTypes_01.php.testDuplicateTypes_01.hints
new file mode 100644
index 0000000000..7956ae6927
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/verification/UnusableTypesHintError/testDuplicateTypes_01.php.testDuplicateTypes_01.hints
@@ -0,0 +1,114 @@
+ private First|First $union;
+ -----
+HINT:Type "First" is duplicated.
+ private First&First $intersection;
+ -----
+HINT:Type "First" is duplicated.
+ private First|Second|First|Second $twoUnions;
+ ------
+HINT:Type "First" is duplicated.
+HINT:Type "Second" is duplicated.
+ private First&Second&First&Second $twoIntersections;
+ ------
+HINT:Type "First" is duplicated.
+HINT:Type "Second" is duplicated.
+ private bool|true|bool $unionBoolAndTrue;
+ ----
+HINT:Type "bool" is duplicated.
+HINT:Type "true" is duplicated.
+ private bool|false|bool $unionBoolAndFalse;
+ ----
+HINT:Type "bool" is duplicated.
+HINT:Type "false" is duplicated.
+ private bool|true|First|First $unionAfterBoolAndTrue;
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "true" is duplicated.
+ private bool|false|First|First $unionAfterBoolAndFalse;
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "false" is duplicated.
+ private true|bool|First|First $unionAfterTrueAndBool;
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "bool" is duplicated.
+ private false|bool|First|First $unionAfterFalseAndBool;
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "bool" is duplicated.
+ public function returnUnion(): First|First {
+ -----
+HINT:Type "First" is duplicated.
+ public function returnIntersection(): First&First {
+ -----
+HINT:Type "First" is duplicated.
+ public function returnTwoUnions(): First|Second|First|Second {
+ ------
+HINT:Type "First" is duplicated.
+HINT:Type "Second" is duplicated.
+ public function returnTwoIntersections(): First&Second&First&Second {
+ ------
+HINT:Type "First" is duplicated.
+HINT:Type "Second" is duplicated.
+ public function returnUnionBoolAndTrue(): bool|true|bool {
+ ----
+HINT:Type "bool" is duplicated.
+HINT:Type "true" is duplicated.
+ public function returnUnionBoolAndFalse(): bool|false|bool {
+ ----
+HINT:Type "bool" is duplicated.
+HINT:Type "false" is duplicated.
+ public function returnUnionAfterBoolAndTrue(): bool|true|First|First {
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "true" is duplicated.
+ public function returnUnionAfterBoolAndFalse(): bool|false|First|First {
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "false" is duplicated.
+ public function returnUnionAfterTrueAndBool(): true|bool|First|First {
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "bool" is duplicated.
+ public function returnUnionAfterFalseAndBool(): false|bool|First|First {
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "bool" is duplicated.
+ public function parameterUnion(First|First $union) {
+ -----
+HINT:Type "First" is duplicated.
+ public function parameterIntersection(First&First $intersection) {
+ -----
+HINT:Type "First" is duplicated.
+ public function parameterTwoUnions(First|Second|First|Second $twoUnions) {
+ ------
+HINT:Type "First" is duplicated.
+HINT:Type "Second" is duplicated.
+ public function parameterTwoIntersections(First&Second&First&Second $twoIntersections) {
+ ------
+HINT:Type "First" is duplicated.
+HINT:Type "Second" is duplicated.
+ public function parameterUnionBoolAndTrue(bool|true|bool $union) {
+ ----
+HINT:Type "bool" is duplicated.
+HINT:Type "true" is duplicated.
+ public function parameterUnionBoolAndFalse(bool|false|bool $union) {
+ ----
+HINT:Type "bool" is duplicated.
+HINT:Type "false" is duplicated.
+ public function parameterUnionAfterBoolAndTrue(bool|true|First|First $union) {
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "true" is duplicated.
+ public function parameterUnionAfterBoolAndFalse(bool|false|First|First $union) {
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "false" is duplicated.
+ public function parameterUnionAfterTrueAndBool(true|bool|First|First $union) {
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "bool" is duplicated.
+ public function parameterUnionAfterFalseAndBool(false|bool|First|First $union) {
+ -----
+HINT:Type "First" is duplicated.
+HINT:Type "bool" is duplicated.
diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusableTypesHintErrorTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusableTypesHintErrorTest.java
index 9b7a7d3d98..81b375a6e2 100644
--- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusableTypesHintErrorTest.java
+++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/UnusableTypesHintErrorTest.java
@@ -71,6 +71,10 @@ public class UnusableTypesHintErrorTest extends PHPHintsTestBase {
checkHints(new UnusableTypesHintError(), "testDnfTypes_01.php");
}
+ public void testDuplicateTypes_01() throws Exception {
+ checkHints(new UnusableTypesHintError(), "testDuplicateTypes_01.php");
+ }
+
@Override
protected String getTestDirectory() {
return TEST_DIRECTORY + "UnusableTypesHintError/";
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists