Skip to content

Commit

Permalink
Merge pull request #4888 from junichi11/php82-allow-nul-and-false-and…
Browse files Browse the repository at this point in the history
…-true-as-stand-alone-types

PHP 8.2 Support: Allow `null`, `false`, and `true` as stand-alone types
  • Loading branch information
tmysik authored Oct 30, 2022
2 parents 9445a56 + 4760216 commit ebb361e
Show file tree
Hide file tree
Showing 251 changed files with 1,024 additions and 56 deletions.
2 changes: 1 addition & 1 deletion php/php.api.phpmodule/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.php.api.phpmodule
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/api/phpmodule/resources/Bundle.properties
OpenIDE-Module-Specification-Version: 2.86
OpenIDE-Module-Specification-Version: 2.87
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"PhpVersion.PHP_74=PHP 7.4",
"PhpVersion.PHP_80=PHP 8.0",
"PhpVersion.PHP_81=PHP 8.1",
"PhpVersion.PHP_82=PHP 8.2",
})
public enum PhpVersion {

Expand Down Expand Up @@ -96,7 +97,13 @@ public enum PhpVersion {
* PHP 8.1.
* @since 2.80
*/
PHP_81(Bundle.PhpVersion_PHP_81());
PHP_81(Bundle.PhpVersion_PHP_81()),
/**
* PHP 8.2.
* @since 2.87
*/
PHP_82(Bundle.PhpVersion_PHP_82()),
;

private final String displayName;
private final boolean namespaces;
Expand Down Expand Up @@ -220,6 +227,17 @@ public boolean hasNeverType() {
return this.compareTo(PhpVersion.PHP_81) >= 0;
}

/**
* Check whether this version supports the null, false, and true types.
*
* @return {@code true} if this version supports null, false, and true
* types, {@code false} otherwise
* @since 2.87
*/
public boolean hasNullAndFalseAndTrueTypes() {
return this.compareTo(PhpVersion.PHP_82) >= 0;
}

/**
* Check whether this is supported version yet by PHP official.
*
Expand Down Expand Up @@ -254,6 +272,7 @@ private enum Period {
PHP_74(LocalDate.of(2019, 11, 28), LocalDate.of(2021, 11, 28), LocalDate.of(2022, 11, 28)),
PHP_80(LocalDate.of(2020, 11, 26), LocalDate.of(2022, 11, 26), LocalDate.of(2023, 11, 26)),
PHP_81(LocalDate.of(2021, 11, 25), LocalDate.of(2023, 11, 25), LocalDate.of(2024, 11, 25)),
PHP_82(LocalDate.of(2022, 11, 24), LocalDate.of(2024, 11, 24), LocalDate.of(2025, 11, 24)),
;

private final LocalDate initialRelease;
Expand Down
2 changes: 1 addition & 1 deletion php/php.editor/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ build.compiler=extJavac
nbjavac.ignore.missing.enclosing=**/CUP$ASTPHP5Parser$actions.class
javac.compilerargs=-J-Xmx512m
nbm.needs.restart=true
spec.version.base=2.19.0
spec.version.base=2.20.0
release.external/predefined_vars-1.0.zip=docs/predefined_vars.zip
sigtest.gen.fail.on.error=false

Expand Down
2 changes: 1 addition & 1 deletion php/php.editor/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>2.83</specification-version>
<specification-version>2.87</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@ private static boolean isType(Token<PHPTokenId> token) {
|| id == PHPTokenId.PHP_STATIC
|| id == PHPTokenId.PHP_NULL
|| id == PHPTokenId.PHP_FALSE
|| id == PHPTokenId.PHP_TRUE
|| id == PHPTokenId.PHP_ARRAY
|| id == PHPTokenId.PHP_ITERABLE
|| id == PHPTokenId.PHP_CALLABLE;
Expand Down Expand Up @@ -1285,8 +1286,12 @@ private static List<? extends Token<PHPTokenId>> getPreceedingLineTokens(Token<P
break;
}
Token<PHPTokenId> cToken = tokenSequence.token();
if (cToken.id() == PHPTokenId.WHITESPACE
&& TokenUtilities.indexOf(cToken.text(), '\n') != -1) { // NOI18N
if ((cToken.id() == PHPTokenId.WHITESPACE
&& TokenUtilities.indexOf(cToken.text(), '\n') != -1) // NOI18N
|| cToken.id() == PHPTokenId.PHP_LINE_COMMENT) {
// e.g.
// public bool $bool = true; // line comment
// public tru^e $true = true;
break;
}
tokens.addLast(cToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private static enum UseType {
PHPTokenId.WHITESPACE, PHPTokenId.PHP_STRING, PHPTokenId.PHP_NS_SEPARATOR,
PHPTokenId.PHP_TYPE_BOOL, PHPTokenId.PHP_TYPE_FLOAT, PHPTokenId.PHP_TYPE_INT, PHPTokenId.PHP_TYPE_STRING, PHPTokenId.PHP_TYPE_VOID,
PHPTokenId.PHP_TYPE_OBJECT, PHPTokenId.PHP_TYPE_MIXED, PHPTokenId.PHP_SELF, PHPTokenId.PHP_PARENT, PHPTokenId.PHP_STATIC,
PHPTokenId.PHP_NULL, PHPTokenId.PHP_FALSE, PHPTokenId.PHP_ARRAY, PHPTokenId.PHP_ITERABLE, PHPTokenId.PHP_CALLABLE,
PHPTokenId.PHP_NULL, PHPTokenId.PHP_FALSE, PHPTokenId.PHP_TRUE, PHPTokenId.PHP_ARRAY, PHPTokenId.PHP_ITERABLE, PHPTokenId.PHP_CALLABLE,
PHPTokenId.PHPDOC_COMMENT_START, PHPTokenId.PHPDOC_COMMENT, PHPTokenId.PHPDOC_COMMENT_END,
PHPTokenId.PHP_COMMENT_START, PHPTokenId.PHP_COMMENT, PHPTokenId.PHP_COMMENT_END
);
Expand Down Expand Up @@ -319,7 +319,6 @@ public CodeCompletionResult complete(CodeCompletionContext completionContext) {
if (CancelSupport.getDefault().isCancelled()) {
return CodeCompletionResult.NONE;
}

CompletionContext context = CompletionContextFinder.findCompletionContext(info, caretOffset);
LOGGER.log(Level.FINE, "CC context: {0}", context);

Expand Down Expand Up @@ -534,7 +533,7 @@ public CodeCompletionResult complete(CodeCompletionContext completionContext) {
typesForTypeName.addAll(Type.getSpecialTypesForType());
}
if (isNullableType(info, caretOffset)) {
typesForTypeName.remove(Type.FALSE);
// ?false, ?true is OK since PHP 8.2
typesForTypeName.remove(Type.NULL);
}
if (isUnionType(info, caretOffset)) {
Expand All @@ -555,7 +554,7 @@ public CodeCompletionResult complete(CodeCompletionContext completionContext) {
typesForReturnTypeName.add(Type.STATIC);
}
if (isNullableType(info, caretOffset)) {
typesForReturnTypeName.remove(Type.FALSE);
// ?false, ?true is OK since PHP 8.2
typesForReturnTypeName.remove(Type.NULL);
typesForReturnTypeName.remove(Type.VOID);
typesForReturnTypeName.remove(Type.NEVER);
Expand Down Expand Up @@ -1154,7 +1153,7 @@ private void autoCompleteKeywordsInPHPDoc(final PHPCompletionResult completionRe
String prefix = doc.getText(start, 1);
if (CodeUtils.NULLABLE_TYPE_PREFIX.equals(prefix)) {
List<String> keywords = new ArrayList<>(Type.getTypesForEditor());
keywords.remove(Type.FALSE);
// ?false, ?true is OK since PHP 8.2
keywords.remove(Type.NULL);
autoCompleteKeywords(completionResult, request, keywords);
} else {
Expand Down Expand Up @@ -1301,7 +1300,7 @@ private void autoCompleteFieldType(ParserResult info, int caretOffset, final PHP
}
}
if (isNullableType) {
keywords.remove(Type.FALSE);
// ?false, ?true is OK since PHP 8.2
keywords.remove(Type.NULL);
}
if (isUnionType(info, caretOffset)) {
Expand Down Expand Up @@ -1350,6 +1349,7 @@ private boolean completeFieldTypes(TokenSequence<PHPTokenId> tokenSequence, int
PHPTokenId.PHP_ITERABLE,
PHPTokenId.PHP_SELF,
PHPTokenId.PHP_PARENT,
PHPTokenId.PHP_TRUE,
PHPTokenId.PHP_FALSE,
PHPTokenId.PHP_NULL,
PHPTokenId.PHP_STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ private Type() {
public static final String STATIC = "static"; //NOI18N NETBEANS-4443 PHP 8.0
public static final String NEVER = "never"; //NOI18N NETBEANS-5599 PHP 8.1

private static final List<String> TYPES_FOR_EDITOR = Arrays.asList(ARRAY, CALLABLE, ITERABLE, BOOL, FLOAT, INT, STRING, OBJECT, NULL, FALSE, MIXED);
private static final List<String> TYPES_FOR_RETURN_TYPE = Arrays.asList(ARRAY, CALLABLE, ITERABLE, BOOL, FLOAT, INT, STRING, VOID, OBJECT, NULL, FALSE, MIXED, NEVER);
private static final List<String> TYPES_FOR_FIELD_TYPE = Arrays.asList(ARRAY, ITERABLE, BOOL, FLOAT, INT, STRING, OBJECT, SELF, PARENT, NULL, FALSE, MIXED); // PHP 7.4 Typed Properties 2.0
private static final List<String> TYPES_FOR_EDITOR = Arrays.asList(ARRAY, CALLABLE, ITERABLE, BOOL, FLOAT, INT, STRING, OBJECT, NULL, FALSE, MIXED, TRUE);
private static final List<String> TYPES_FOR_RETURN_TYPE = Arrays.asList(ARRAY, CALLABLE, ITERABLE, BOOL, FLOAT, INT, STRING, VOID, OBJECT, NULL, FALSE, MIXED, NEVER, TRUE);
private static final List<String> TYPES_FOR_FIELD_TYPE = Arrays.asList(ARRAY, ITERABLE, BOOL, FLOAT, INT, STRING, OBJECT, SELF, PARENT, NULL, FALSE, MIXED, TRUE); // PHP 7.4 Typed Properties 2.0
private static final List<String> SPECIAL_TYPES_FOR_TYPE = Arrays.asList(SELF, PARENT);
private static final List<String> TYPES_FOR_PHP_DOC = Arrays.asList(STRING, INTEGER, INT, BOOLEAN, BOOL, FLOAT, DOUBLE, OBJECT, MIXED, ARRAY,
RESOURCE, VOID, NULL, CALLBACK, CALLABLE, ITERABLE, FALSE, TRUE, SELF);
Expand All @@ -107,7 +107,8 @@ public static boolean isPrimitive(String typeName) {
|| NUMBER.equals(typeName) || CALLBACK.equals(typeName) || RESOURCE.equals(typeName)
|| DOUBLE.equals(typeName) || STRING.equals(typeName) || NULL.equals(typeName)
|| VOID.equals(typeName) || CALLABLE.equals(typeName) || ITERABLE.equals(typeName)
|| FALSE.equals(typeName) || STATIC.equals(typeName) || NEVER.equals(typeName)) {
|| FALSE.equals(typeName) || STATIC.equals(typeName) || NEVER.equals(typeName)
|| TRUE.equals(typeName)) {
retval = true;
}
return retval;
Expand Down
Loading

0 comments on commit ebb361e

Please sign in to comment.