Skip to content

Commit 625ebde

Browse files
committed
[GH-8286] Fix Go to Declaration for an enum method using an FQ name
-Accessing a Constant of an Enum/Class now uses FQ name if possible Example: ```php namespace test; enum TestA{ case X; public function get(string $param): string{ return ''; } } namespace test2; enum TestB{ case X; public function get(): string{ return ''; } } \test\TestA::X->get('xxx'); // go to declaration and mark occurences do not work ```
1 parent f198805 commit 625ebde

File tree

7 files changed

+169
-1
lines changed

7 files changed

+169
-1
lines changed

php/php.editor/src/org/netbeans/modules/php/editor/model/impl/VariousUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,13 @@ private static String extractVariableTypeFromVariableBase(VariableBase varBase,
12671267
} else if (varBase instanceof StaticConstantAccess) {
12681268
StaticConstantAccess constantAccess = (StaticConstantAccess) varBase;
12691269
if (!constantAccess.isDynamicName()) {
1270-
String clsName = CodeUtils.extractUnqualifiedName(constantAccess.getDispatcher());
1270+
Expression dispatcher = constantAccess.getDispatcher();
1271+
String clsName = null;
1272+
if (dispatcher instanceof NamespaceName) {
1273+
clsName = CodeUtils.extractQualifiedName(dispatcher);
1274+
} else {
1275+
clsName = CodeUtils.extractUnqualifiedName(dispatcher);
1276+
}
12711277
String constName = CodeUtils.extractQualifiedName(constantAccess.getConstant());
12721278
if (constName != null) {
12731279
if (clsName != null) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
namespace test;
23+
24+
enum TestA{
25+
26+
case X;
27+
28+
public function get(string $param): string{//01
29+
return '';
30+
}
31+
}
32+
33+
namespace test2;
34+
35+
enum TestB{
36+
37+
case X;
38+
39+
public function get(string $param): string{//02
40+
return '';
41+
}
42+
}
43+
44+
\test\TestA::X->get();
45+
\test2\TestB::X->get();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
namespace test;
23+
24+
enum TestA{
25+
26+
case X;
27+
28+
public function get(string $param): string{
29+
return '';
30+
}
31+
}
32+
33+
namespace test2;
34+
35+
enum TestB{
36+
37+
case X;
38+
39+
public function get(): string{
40+
return '';
41+
}
42+
}
43+
44+
\test\TestA::X->get();
45+
\test2\TestB::X->get();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public function |>MARK_OCCURRENCES:get<|(string $param): string{
2+
\test\TestA::X->|>MARK_OCCURRENCES:ge^t<|();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public function |>MARK_OCCURRENCES:get<|(): string{
2+
\test2\TestB::X->|>MARK_OCCURRENCES:ge^t<|();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.php.editor.csl;
20+
21+
public class GotoDeclarationGH8286Test extends GotoDeclarationTestBase {
22+
23+
public GotoDeclarationGH8286Test(String testName) {
24+
super(testName);
25+
}
26+
27+
public void testIssueGH8286_01() throws Exception {
28+
checkDeclaration(getTestPath(), "\\test\\TestA::X->ge^t();", "public function ^get(string $param): string{//01");
29+
}
30+
31+
public void testIssueGH8286_02() throws Exception {
32+
checkDeclaration(getTestPath(), "\\test2\\TestB::X->ge^t();", "public function ^get(string $param): string{//02");
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.php.editor.csl;
20+
21+
public class OccurrencesFinderImplGH8286Test extends OccurrencesFinderImplTestBase {
22+
23+
public OccurrencesFinderImplGH8286Test(String testName) {
24+
super(testName);
25+
}
26+
27+
public void testIssueGH8286_01() throws Exception {
28+
checkOccurrences(getTestPath(), "\\test\\TestA::X->ge^t();", true);
29+
}
30+
31+
public void testIssueGH8286_02() throws Exception {
32+
checkOccurrences(getTestPath(), "\\test2\\TestB::X->ge^t();", true);
33+
}
34+
}

0 commit comments

Comments
 (0)