This is an automated email from the ASF dual-hosted git repository. tmysik 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 1dda0b0ab4 Fix the highlighting for private constants of Enum new fdbf8b4b03 Merge pull request #5720 from junichi11/php-enum-private-const-highlighting 1dda0b0ab4 is described below commit 1dda0b0ab47a371c36911d5b583b56a9302fb35a Author: Junichi Yamamoto <junich...@apache.org> AuthorDate: Sun Mar 26 09:45:45 2023 +0900 Fix the highlighting for private constants of Enum --- .../modules/php/editor/csl/SemanticAnalysis.java | 7 +++ .../semantic/enumerationsWithPrivateConst.php | 71 ++++++++++++++++++++++ .../enumerationsWithPrivateConst.php.semantic | 71 ++++++++++++++++++++++ .../php/editor/csl/SemanticAnalyzerTest.java | 4 ++ 4 files changed, 153 insertions(+) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java b/php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java index a1aa52130c..ff246f1337 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/csl/SemanticAnalysis.java @@ -663,6 +663,7 @@ public class SemanticAnalysis extends SemanticAnalyzer { if (node.getBody() != null) { node.getBody().accept(this); scanMethodBodies(); + addColoringForUnusedPrivateConstants(); } needToScan.remove(typeInfo); removeFromPath(); @@ -819,6 +820,12 @@ public class SemanticAnalysis extends SemanticAnalyzer { if (!isPrivate || parentNode instanceof TraitDeclaration) { addColoringForNode(identifier, coloring); } else { + // NOTE: private constants, methods, and fields may be used in traits + // currently, we don't check traits (if there is no performance problem, should check them if possible) + // an enum is handled as a "final" class in PHP + // so, virtually, "protected" is "private" + // however, as written above, it may be used in traits + // don't add protected items of Enum to unused items privateUnusedConstants.put(new UnusedIdentifier(identifier.getName(), typeInfo), new ASTNodeColoring(identifier, coloring)); } } diff --git a/php/php.editor/test/unit/data/testfiles/semantic/enumerationsWithPrivateConst.php b/php/php.editor/test/unit/data/testfiles/semantic/enumerationsWithPrivateConst.php new file mode 100644 index 0000000000..db2a3cbe54 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/semantic/enumerationsWithPrivateConst.php @@ -0,0 +1,71 @@ +<?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. + */ + +enum UsedPrivateConst1 { + + public const PUBLIC_CONST = 'public const'; + private const PRIVATE_CONST = 'private const'; + protected const PROTECTED_CONST = 'protected const'; + + case Case1; + + private function test(): void { + self::PRIVATE_CONST; + } + +} + +enum UsedPrivateConst2 { + + public const PUBLIC_CONST = 'public const'; + private const PRIVATE_CONST = 'private const'; + protected const PROTECTED_CONST = 'protected const'; + + case Case1; + + private function test(): void { + static::PRIVATE_CONST; + } + +} + +enum UsedPrivateConst3 { + + public const PUBLIC_CONST = 'public const'; + private const PRIVATE_CONST = 'private const'; + protected const PROTECTED_CONST = 'protected const'; + + case Case1; + + private function test(): void { + UsedPrivateConst3::PRIVATE_CONST; + } + +} + +enum UnusedPrivateConst { + + public const PUBLIC_CONST = 'public const'; + private const PRIVATE_CONST = 'private const'; + protected const PROTECTED_CONST = 'protected const'; + + case Case1; + +} diff --git a/php/php.editor/test/unit/data/testfiles/semantic/enumerationsWithPrivateConst.php.semantic b/php/php.editor/test/unit/data/testfiles/semantic/enumerationsWithPrivateConst.php.semantic new file mode 100644 index 0000000000..bdc266a968 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/semantic/enumerationsWithPrivateConst.php.semantic @@ -0,0 +1,71 @@ +<?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. + */ + +enum |>CLASS:UsedPrivateConst1<| { + + public const |>FIELD,STATIC:PUBLIC_CONST<| = 'public const'; + private const |>FIELD,STATIC:PRIVATE_CONST<| = 'private const'; + protected const |>FIELD,STATIC:PROTECTED_CONST<| = 'protected const'; + + case |>FIELD,STATIC:Case1<|; + + private function |>METHOD,UNUSED:test<|(): void { + self::|>FIELD,STATIC:PRIVATE_CONST<|; + } + +} + +enum |>CLASS:UsedPrivateConst2<| { + + public const |>FIELD,STATIC:PUBLIC_CONST<| = 'public const'; + private const |>FIELD,STATIC:PRIVATE_CONST<| = 'private const'; + protected const |>FIELD,STATIC:PROTECTED_CONST<| = 'protected const'; + + case |>FIELD,STATIC:Case1<|; + + private function |>METHOD,UNUSED:test<|(): void { + static::|>FIELD,STATIC:PRIVATE_CONST<|; + } + +} + +enum |>CLASS:UsedPrivateConst3<| { + + public const |>FIELD,STATIC:PUBLIC_CONST<| = 'public const'; + private const |>FIELD,STATIC:PRIVATE_CONST<| = 'private const'; + protected const |>FIELD,STATIC:PROTECTED_CONST<| = 'protected const'; + + case |>FIELD,STATIC:Case1<|; + + private function |>METHOD,UNUSED:test<|(): void { + UsedPrivateConst3::|>FIELD,STATIC:PRIVATE_CONST<|; + } + +} + +enum |>CLASS:UnusedPrivateConst<| { + + public const |>FIELD,STATIC:PUBLIC_CONST<| = 'public const'; + private const |>FIELD,STATIC,UNUSED:PRIVATE_CONST<| = 'private const'; + protected const |>FIELD,STATIC:PROTECTED_CONST<| = 'protected const'; + + case |>FIELD,STATIC:Case1<|; + +} diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/SemanticAnalyzerTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/SemanticAnalyzerTest.java index f7c50a0cc9..4fbc1df869 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/SemanticAnalyzerTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/csl/SemanticAnalyzerTest.java @@ -214,6 +214,10 @@ public class SemanticAnalyzerTest extends SemanticAnalysisTestBase { checkSemantic("testfiles/semantic/enumerations.php"); } + public void testEnumerationsWithPrivateConst() throws Exception { + checkSemantic("testfiles/semantic/enumerationsWithPrivateConst.php"); + } + public void testConstantsInTraits() throws Exception { checkSemantic("testfiles/semantic/constantsInTraits.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