Skip to content

Commit 05703f8

Browse files
committed
PHP 8.4 Support: Property hooks (Part 2)
- apache#8035 - https://wiki.php.net/rfc#php_84 - https://wiki.php.net/rfc/property-hooks - Fix the indexer and the model - Use JSON format as a signature for property hooks - Current format is semicolon separated but it's hard to add hooks to a field signature without JSON format - Use the "JSON simple". If we use "Jackson", problems(timeout, java.lang.NoClassDefFoundError) occurs in CI for Windows ```json [ { "name":"set", "start":3651, "end":3690, "mod":1, "isRef":false, "isAttr":false, "hasBody":true, "paramSig":"$value::0::1:1:0:0:0:0::" } ] ``` - Add interface methods - `FieldElemnt.isHooked()` - `FieldElement.HookedFieldElemnt.isHooked()` - `FieldElement.HookedFieldElemnt.getPropertyHooks()` - `IndexScope.PHP84IndexScope.findFields()` - `TypeScope.FieldDeclarable.getDeclaredFields()` - `TypeScope.FieldDeclarable.getInheritedFields()` - `PropertyHookScope.isReference()` - `PropertyHookScope.hasBody()` - `PropertyHookScope.isAttributed()` - `PropertyHookScope.getParameterNames()` - `PropertyHookScope.getParameters()` - `PropertyHookScope.getOffsetRange()` - `PropertyHookElement.isReference()` - `PropertyHookElement.hasBody()` - `PropertyHookElement.isAttributed()` - `PropertyHookElement.getParameters()` - `PropertyHookElement.getOffsetRange()` - Add/Fix unit tests for the index and the model Log: ``` FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: getSignatureFromScopes() took: 0 ms INFO [org.netbeans.ui.indexing]: Indexing finished, indexing took 14 ms. FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 1 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms FINE [org.netbeans.modules.php.editor.model.impl.PropertyHookSignatureItem]: fromSignature() took: 0 ms ```
1 parent 5e2fad5 commit 05703f8

File tree

54 files changed

+4058
-385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4058
-385
lines changed

php/php.editor/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ javac.release=17
1818
javac.compilerargs=-Xlint -Xlint:-serial
1919
nbjavac.ignore.missing.enclosing=**/CUP$ASTPHP5Parser$actions.class
2020
nbm.needs.restart=true
21-
spec.version.base=2.45.0
21+
spec.version.base=2.46.0
2222
release.external/predefined_vars-1.0.zip=docs/predefined_vars.zip
2323
sigtest.gen.fail.on.error=false
2424

php/php.editor/nbproject/project.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@
7878
<specification-version>1.0</specification-version>
7979
</run-dependency>
8080
</dependency>
81+
<dependency>
82+
<code-name-base>org.netbeans.libs.json_simple</code-name-base>
83+
<build-prerequisite/>
84+
<compile-dependency/>
85+
<run-dependency>
86+
<release-version>1</release-version>
87+
<specification-version>0.40</specification-version>
88+
</run-dependency>
89+
</dependency>
8190
<dependency>
8291
<code-name-base>org.netbeans.modules.csl.api</code-name-base>
8392
<build-prerequisite/>

php/php.editor/src/org/netbeans/modules/php/editor/api/PhpElementKind.java

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,31 @@ public enum PhpElementKind {
2828
VARIABLE, CONSTANT, FUNCTION,
2929
NAMESPACE_DECLARATION, USE_STATEMENT, GROUP_USE_STATEMENT, CONSTRUCTOR,
3030
TRAIT, TRAIT_CONFLICT_RESOLUTION, TRAIT_METHOD_ALIAS, EMPTY,
31-
ENUM, ENUM_CASE;
31+
ENUM, ENUM_CASE,
32+
PROPERTY_HOOK,
33+
;
3234

3335
public final ElementKind getElementKind() {
34-
ElementKind result;
35-
switch (this) {
36-
case CLASS:
37-
result = ElementKind.CLASS;
38-
break;
39-
case TYPE_CONSTANT:
40-
result = ElementKind.CONSTANT;
41-
break;
42-
case CONSTANT:
43-
result = ElementKind.CONSTANT;
44-
break;
45-
case FIELD:
46-
result = ElementKind.FIELD;
47-
break;
48-
case FUNCTION:
49-
result = ElementKind.METHOD;
50-
break;
51-
case IFACE:
52-
result = ElementKind.INTERFACE;
53-
break;
54-
case METHOD:
55-
result = ElementKind.METHOD;
56-
break;
57-
case VARIABLE:
58-
result = ElementKind.VARIABLE;
59-
break;
60-
case NAMESPACE_DECLARATION:
61-
result = ElementKind.PACKAGE;
62-
break;
63-
case ENUM_CASE:
64-
result = ElementKind.CONSTANT;
65-
break;
66-
default:
67-
result = ElementKind.OTHER;
68-
}
69-
return result;
36+
return switch (this) {
37+
case CLASS ->
38+
ElementKind.CLASS;
39+
case TYPE_CONSTANT, CONSTANT, ENUM_CASE ->
40+
ElementKind.CONSTANT;
41+
case FIELD ->
42+
ElementKind.FIELD;
43+
case FUNCTION, METHOD ->
44+
ElementKind.METHOD;
45+
case IFACE ->
46+
ElementKind.INTERFACE;
47+
case VARIABLE ->
48+
ElementKind.VARIABLE;
49+
case NAMESPACE_DECLARATION ->
50+
ElementKind.PACKAGE;
51+
case CONSTRUCTOR, EMPTY, ENUM, GROUP_USE_STATEMENT,
52+
INCLUDE, INDEX, PROGRAM, PROPERTY_HOOK,
53+
TRAIT, TRAIT_CONFLICT_RESOLUTION,
54+
TRAIT_METHOD_ALIAS, USE_ALIAS, USE_STATEMENT ->
55+
ElementKind.OTHER;
56+
};
7057
}
7158
}

php/php.editor/src/org/netbeans/modules/php/editor/api/elements/FieldElement.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,56 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package org.netbeans.modules.php.editor.api.elements;
2120

21+
import java.util.List;
2222
import org.netbeans.modules.php.editor.api.PhpElementKind;
2323

2424
/**
2525
* @author Radek Matous
2626
*/
2727
public interface FieldElement extends TypedInstanceElement, TypeMemberElement {
28+
2829
PhpElementKind KIND = PhpElementKind.FIELD;
30+
2931
String getName(boolean dollared);
32+
3033
boolean isAnnotation();
34+
3135
boolean isUnionType();
36+
3237
boolean isIntersectionType();
38+
3339
String getDeclaredType();
40+
41+
/**
42+
* Check whether this element is a hooked property(field).
43+
*
44+
* @param field
45+
* @return {@code true} it's hooked property, {@code false} otherwise
46+
* @since 2.46.0
47+
*/
48+
public static boolean isHooked(FieldElement field) {
49+
return (field instanceof HookedFieldElement)
50+
&& ((HookedFieldElement) field).isHooked();
51+
}
52+
53+
public interface HookedFieldElement extends FieldElement {
54+
55+
/**
56+
* Check whether this element is a hooked property.
57+
*
58+
* @return {@code true} it's hooked property, {@code false} otherwise
59+
* @since 2.46.0
60+
*/
61+
boolean isHooked();
62+
63+
/**
64+
* Get property hooks.
65+
*
66+
* @return property hooks
67+
* @since 2.46.0
68+
*/
69+
List<? extends PropertyHookElement> getPropertyHooks();
70+
}
3471
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.api.elements;
20+
21+
import java.util.List;
22+
import org.netbeans.modules.csl.api.OffsetRange;
23+
24+
/**
25+
* Property hook element.
26+
*
27+
* @see @since 2.46.0
28+
*/
29+
public interface PropertyHookElement extends PhpElement {
30+
31+
/**
32+
* Check whether a property hook is reference.
33+
*
34+
* e.g. {@code &get{}}
35+
*
36+
* @return {@code true} if it's reference, {@code false} otherwise
37+
* @since 2.46.0
38+
*/
39+
boolean isReference();
40+
41+
/**
42+
* Check whether a property hook has a body(`{}` part).
43+
*
44+
* Interface property and abstract properties don't have a body. (e.g.
45+
* {@code get; set;})
46+
*
47+
* @return {@code true} if it has a body, {@code false} otherwise
48+
* @since 2.46.0
49+
*/
50+
boolean hasBody();
51+
52+
/**
53+
* Check whether a property hook has attributes. (e.g.
54+
* {@code #[Attr] get{}})
55+
*
56+
* @return {@code true} if a property hook has attributes, {@code false}
57+
* otherwise
58+
* @since 2.46.0
59+
*/
60+
boolean isAttributed();
61+
62+
/**
63+
* Get parameters of a property hook.
64+
*
65+
* e.g. {@code set(#[Attr] string $value){}}
66+
*
67+
* @return parameters
68+
* @since 2.46.0
69+
*/
70+
List<? extends ParameterElement> getParameters();
71+
72+
/**
73+
* Get the offset range.
74+
*
75+
* @return the offset range
76+
* @since 2.46.0
77+
*/
78+
OffsetRange getOffsetRange();
79+
// TODO add List<? extends AttributeElemnt> getAttributes();
80+
}

0 commit comments

Comments
 (0)