Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.4 Support: Property hooks #8227

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion php/php.editor/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ javac.release=17
javac.compilerargs=-Xlint -Xlint:-serial
nbjavac.ignore.missing.enclosing=**/CUP$ASTPHP5Parser$actions.class
nbm.needs.restart=true
spec.version.base=2.45.0
spec.version.base=2.46.0
release.external/predefined_vars-1.0.zip=docs/predefined_vars.zip
sigtest.gen.fail.on.error=false

Expand Down
9 changes: 9 additions & 0 deletions php/php.editor/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.libs.json_simple</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>0.40</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.csl.api</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,31 @@ public enum PhpElementKind {
VARIABLE, CONSTANT, FUNCTION,
NAMESPACE_DECLARATION, USE_STATEMENT, GROUP_USE_STATEMENT, CONSTRUCTOR,
TRAIT, TRAIT_CONFLICT_RESOLUTION, TRAIT_METHOD_ALIAS, EMPTY,
ENUM, ENUM_CASE;
ENUM, ENUM_CASE,
PROPERTY_HOOK,
;

public final ElementKind getElementKind() {
ElementKind result;
switch (this) {
case CLASS:
result = ElementKind.CLASS;
break;
case TYPE_CONSTANT:
result = ElementKind.CONSTANT;
break;
case CONSTANT:
result = ElementKind.CONSTANT;
break;
case FIELD:
result = ElementKind.FIELD;
break;
case FUNCTION:
result = ElementKind.METHOD;
break;
case IFACE:
result = ElementKind.INTERFACE;
break;
case METHOD:
result = ElementKind.METHOD;
break;
case VARIABLE:
result = ElementKind.VARIABLE;
break;
case NAMESPACE_DECLARATION:
result = ElementKind.PACKAGE;
break;
case ENUM_CASE:
result = ElementKind.CONSTANT;
break;
default:
result = ElementKind.OTHER;
}
return result;
return switch (this) {
case CLASS ->
ElementKind.CLASS;
case TYPE_CONSTANT, CONSTANT, ENUM_CASE ->
ElementKind.CONSTANT;
case FIELD ->
ElementKind.FIELD;
case FUNCTION, METHOD ->
ElementKind.METHOD;
case IFACE ->
ElementKind.INTERFACE;
case VARIABLE ->
ElementKind.VARIABLE;
case NAMESPACE_DECLARATION ->
ElementKind.PACKAGE;
case CONSTRUCTOR, EMPTY, ENUM, GROUP_USE_STATEMENT,
INCLUDE, INDEX, PROGRAM, PROPERTY_HOOK,
TRAIT, TRAIT_CONFLICT_RESOLUTION,
TRAIT_METHOD_ALIAS, USE_ALIAS, USE_STATEMENT ->
ElementKind.OTHER;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ private PhpModifiers(int... bitmask) {
for (int mode : bitmask) {
this.mod |= mode;
}
if (!Modifier.isPrivate(mod) && !Modifier.isProtected(mod) && !Modifier.isImplicitPublic(mod)) {
mod |= Modifier.PUBLIC;
if (!Modifier.isPrivate(mod) && !Modifier.isProtected(mod) && !Modifier.isPublic(mod)) {
mod |= Modifier.IMPLICIT_PUBLIC;
}
Comment on lines 132 to 137
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMPLICIT_PUBLIC is better if mod is 0 because the public modifier doesn't exist.

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,56 @@
* specific language governing permissions and limitations
* under the License.
*/

package org.netbeans.modules.php.editor.api.elements;

import java.util.List;
import org.netbeans.modules.php.editor.api.PhpElementKind;

/**
* @author Radek Matous
*/
public interface FieldElement extends TypedInstanceElement, TypeMemberElement {

PhpElementKind KIND = PhpElementKind.FIELD;

String getName(boolean dollared);

boolean isAnnotation();

boolean isUnionType();

boolean isIntersectionType();

String getDeclaredType();

/**
* Check whether this element is a hooked property(field).
*
* @param field
* @return {@code true} it's hooked property, {@code false} otherwise
* @since 2.46.0
*/
public static boolean isHooked(FieldElement field) {
return (field instanceof HookedFieldElement)
&& ((HookedFieldElement) field).isHooked();
}

public interface HookedFieldElement extends FieldElement {

/**
* Check whether this element is a hooked property.
*
* @return {@code true} it's hooked property, {@code false} otherwise
* @since 2.46.0
*/
boolean isHooked();

/**
* Get property hooks.
*
* @return property hooks
* @since 2.46.0
*/
List<? extends PropertyHookElement> getPropertyHooks();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.
*/
package org.netbeans.modules.php.editor.api.elements;

import java.util.List;
import org.netbeans.modules.csl.api.OffsetRange;

/**
* Property hook element.
*
* @see @since 2.46.0
*/
public interface PropertyHookElement extends PhpElement {

/**
* Check whether a property hook is reference.
*
* e.g. {@code &get{}}
*
* @return {@code true} if it's reference, {@code false} otherwise
* @since 2.46.0
*/
boolean isReference();

/**
* Check whether a property hook has a body(`{}` part).
*
* Interface property and abstract properties don't have a body. (e.g.
* {@code get; set;})
*
* @return {@code true} if it has a body, {@code false} otherwise
* @since 2.46.0
*/
boolean hasBody();

/**
* Check whether a property hook has attributes. (e.g.
* {@code #[Attr] get{}})
*
* @return {@code true} if a property hook has attributes, {@code false}
* otherwise
* @since 2.46.0
*/
boolean isAttributed();

/**
* Get parameters of a property hook.
*
* e.g. {@code set(#[Attr] string $value){}}
*
* @return parameters
* @since 2.46.0
*/
List<? extends ParameterElement> getParameters();

/**
* Get the offset range.
*
* @return the offset range
* @since 2.46.0
*/
OffsetRange getOffsetRange();
// TODO add List<? extends AttributeElemnt> getAttributes();
}
Loading