Skip to content

Commit 264c6aa

Browse files
authored
Merge pull request #1649 from adamwojs/exclude_non_public_consts
Excluded non-public consts from !php/const autocompletion
2 parents 5d6fd5d + c02b30e commit 264c6aa

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/util/completion/PhpConstGotoCompletionProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void getLookupElements(@NotNull GotoCompletionProviderLookupArguments arg
5555
if (phpClass != null) {
5656
// reset the prefix matcher, starting after ::
5757
resultSet = resultSet.withPrefixMatcher(prefix.substring(prefix.indexOf(SCOPE_OPERATOR) + 2));
58-
resultSet.addAllElements(PhpVariantsUtil.getLookupItems(phpClass.getFields().stream().filter(Field::isConstant).collect(Collectors.toList()), false, null));
58+
resultSet.addAllElements(PhpVariantsUtil.getLookupItems(phpClass.getFields().stream().filter(f -> f.isConstant() && f.getModifier().isPublic()).collect(Collectors.toList()), false, null));
5959
}
6060
return;
6161
}
@@ -102,7 +102,7 @@ private void addAllClasses(Collection<LookupElement> elements, Collection<PhpCla
102102
private void addAllClassConstants(Collection<LookupElement> elements, Collection<PhpClass> classes) {
103103
for (PhpClass phpClass : classes) {
104104
// All class constants
105-
List<Field> fields = Arrays.stream(phpClass.getOwnFields()).filter(Field::isConstant).collect(Collectors.toList());
105+
List<Field> fields = Arrays.stream(phpClass.getOwnFields()).filter(f -> f.isConstant() && f.getModifier().isPublic()).collect(Collectors.toList());
106106
for (PhpNamedElement field : fields) {
107107
// Foo::BAR
108108
String lookupString = phpClass.getName() + SCOPE_OPERATOR + field.getName();

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/completion/yaml/YamlGotoCompletionRegistrarTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ public void testThatPhpConstAreCompletedAndNavigable() {
123123
"BAZ"
124124
);
125125

126+
assertCompletionNotContains(
127+
YAMLFileType.YML,
128+
"services:\n" +
129+
" foo:\n" +
130+
" class: Foo\\Foobar\n" +
131+
" arguments: \n" +
132+
" - !php/const Foo\\Bar::<caret>\n",
133+
"PROTECTED_CONST", "PRIVATE_CONST"
134+
);
135+
126136
assertCompletionIsEmpty(
127137
YAMLFileType.YML,
128138
"services:\n" +

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/completion/yaml/fixtures/YamlGotoCompletionRegistrar.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
class Bar
66
{
77
public const BAZ = 'baz';
8+
private const PRIVATE_CONST = 'private';
9+
protected const PROTECTED_CONST = 'protected';
810

911
public function create() {}
1012
}

0 commit comments

Comments
 (0)