tmysik commented on code in PR #9113:
URL: https://github.com/apache/netbeans/pull/9113#discussion_r2868909792
##########
php/php.editor/src/org/netbeans/modules/php/editor/indent/IndentationCounter.java:
##########
@@ -343,6 +343,13 @@ && isFirstCommaAfterDoubleArrow(startExpression,
caretOffset, ts)) {
newIndent = Utilities.getRowIndent(doc,
startExpression) + continuationSize;
break;
}
+ } else if (ts.token().id() == PHPTokenId.PHP_OPERATOR
&& TokenUtilities.textEquals("|>", ts.token().text())) { // NOI18N
Review Comment:
Just curious - don't we use constants for these PHP operators?
##########
php/php.editor/tools/ASTPHP5Scanner.flex:
##########
@@ -880,6 +880,7 @@
NOWDOC_CHARS=({NEWLINE}*(([^a-zA-Z_\x7f-\xff\n\r][^\n\r]*)|({LABEL}[^a-zA-Z0-9_\
return createSymbol(ASTPHP5Symbols.T_SR_EQUAL);
}
+
Review Comment:
Extra empty line.
##########
php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/CompositionExpression.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.parser.astnodes;
+
+/**
+ * Represents a function composition expression
+ * chaining multiple callables from left to right
+ * It's marked by the pipe operator "|>"
+ * @see https://wiki.php.net/rfc/pipe-operator-v3
+ * <pre>
+ * $a |> strtoupper(...)
+ * $a |> trim(...)
+ * </pre>
+ *
+ */
+public class CompositionExpression extends Expression {
+
+ /**
+ * Operator type used for the composition expression
+ * possible rfc with using "+" for composition
+ * https://wiki.php.net/rfc/function-composition
+ */
+ public enum OperatorType {
+ PIPE("|>"); // NOI18N
+
+ private final String operatorSign;
+
+ private OperatorType(final String operatorSign) {
+ this.operatorSign = operatorSign;
+ }
+
+ @Override
+ public String toString() {
+ return operatorSign;
+ }
+ }
+
+ private Expression left;
+ private CompositionExpression.OperatorType operator;
+ private Expression right;
+
+ public CompositionExpression(int start, int end, Expression left,
CompositionExpression.OperatorType operator, Expression right) {
+ super(start, end);
+
+ if (right == null || left == null) {
+ throw new IllegalArgumentException();
Review Comment:
Please, add an exact error indicating what is wrong.
##########
php/php.api.phpmodule/src/org/netbeans/modules/php/api/PhpVersion.java:
##########
@@ -115,6 +116,11 @@ public enum PhpVersion {
* @since 2.100
*/
PHP_84(Bundle.PhpVersion_PHP_84()),
+ /**
+ * PHP 8.4.
Review Comment:
```suggestion
* PHP 8.5.
```
##########
php/php.editor/src/org/netbeans/modules/php/editor/parser/astnodes/visitors/DefaultVisitor.java:
##########
@@ -295,6 +302,7 @@ public void visit(ConditionalExpression node) {
scan(node.getIfFalse());
}
+
Review Comment:
Extra empty line added.
##########
php/php.api.phpmodule/src/org/netbeans/modules/php/api/PhpVersion.java:
##########
@@ -41,6 +41,7 @@
"PhpVersion.PHP_82=PHP 8.2",
"PhpVersion.PHP_83=PHP 8.3",
"PhpVersion.PHP_84=PHP 8.4",
+ "PhpVersion.PHP_85=PHP 8.5",
Review Comment:
An API class is changed -> we need to increase the version of this API
module.
##########
php/php.editor/src/org/netbeans/modules/php/editor/verification/PHP85UnhandledError.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.verification;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import org.netbeans.modules.csl.api.Error;
+import org.netbeans.modules.csl.api.OffsetRange;
+import org.netbeans.modules.csl.spi.support.CancelSupport;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.editor.CodeUtils;
+import org.netbeans.modules.php.editor.parser.PHPParseResult;
+import org.netbeans.modules.php.editor.parser.astnodes.ASTNode;
+import org.netbeans.modules.php.editor.parser.astnodes.CompositionExpression;
+import org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor;
+import org.openide.filesystems.FileObject;
+import org.openide.util.NbBundle;
+
+/**
+ * Unhandled Error for PHP 8.5
+ *
+ * @see <a href="https://wiki.php.net/rfc#php_85">PHP 8.5 RFC</a>
+ */
+public final class PHP85UnhandledError extends UnhandledErrorRule {
+
+ @NbBundle.Messages("PHP85UnhandledError.displayName=Language feature not
compatible with PHP version indicated in project settings")
+ @Override
+ public String getDisplayName() {
+ return Bundle.PHP85UnhandledError_displayName();
+ }
+
+ @Override
+ public void invoke(PHPRuleContext context, List<Error> errors) {
+ PHPParseResult phpParseResult = (PHPParseResult) context.parserResult;
+ if (phpParseResult.getProgram() == null) {
+ return;
+ }
+ FileObject fileObject =
phpParseResult.getSnapshot().getSource().getFileObject();
+ if (fileObject != null
+ && appliesTo(fileObject)) {
+ if (CancelSupport.getDefault().isCancelled()) {
+ return;
+ }
+ CheckVisitor checkVisitor = new CheckVisitor(fileObject);
+ phpParseResult.getProgram().accept(checkVisitor);
+ if (CancelSupport.getDefault().isCancelled()) {
+ return;
+ }
+ errors.addAll(checkVisitor.getErrors());
+ }
+ }
+
+ private static boolean appliesTo(FileObject fileObject) {
+ return CodeUtils.isPhpVersionLessThan(fileObject, PhpVersion.PHP_85);
+ }
+
+ //~ Inner classes
+ private static final class CheckVisitor extends DefaultVisitor {
+
+ private final List<VerificationError> errors = new ArrayList<>();
+ private final FileObject fileObject;
+
+ public CheckVisitor(FileObject fileObject) {
+ this.fileObject = fileObject;
+ }
+
+ public Collection<VerificationError> getErrors() {
+ return Collections.unmodifiableCollection(errors);
+ }
+
+ @Override
+ public void visit(CompositionExpression node) {
+ if (CancelSupport.getDefault().isCancelled()) {
+ return;
+ }
+
+ //composition expression are available since PHP 8.5
+ createError(node);
+ }
+
+
+ private void createError(ASTNode node) {
+ createError(node.getStartOffset(), node.getEndOffset());
+ }
+
+ private void createError(OffsetRange offsetRange) {
+ errors.add(new PHP85VersionError(fileObject,
offsetRange.getStart(), offsetRange.getEnd()));
+ }
+
+ private void createError(int startOffset, int endOffset) {
+ errors.add(new PHP85VersionError(fileObject, startOffset,
endOffset));
+ }
+ }
+
+ private static final class PHP85VersionError extends VerificationError {
+
+ private static final String KEY = "Php.Version.85"; // NOI18N
+
+ private PHP85VersionError(FileObject fileObject, int startOffset, int
endOffset) {
+ super(fileObject, startOffset, endOffset);
+ }
+
+ @NbBundle.Messages("PHP85VersionError.displayName=Language feature not
compatible with PHP version indicated in project settings")
+ @Override
+ public String getDisplayName() {
+ return Bundle.PHP85VersionError_displayName();
+ }
+
+ @NbBundle.Messages("PHP85VersionError.description=Detected language
features not compatible with PHP version indicated in project settings")
+ @Override
+ public String getDescription() {
+ return Bundle.PHP83VersionError_description();
Review Comment:
```suggestion
return Bundle.PHP85VersionError_description();
```
##########
php/php.editor/src/org/netbeans/modules/php/editor/verification/PHP84UnhandledError.java:
##########
@@ -183,7 +183,7 @@ private PHP84VersionError(FileObject fileObject, int
startOffset, int endOffset)
@NbBundle.Messages("PHP84VersionError.displayName=Language feature not
compatible with PHP version indicated in project settings")
@Override
public String getDisplayName() {
- return Bundle.PHP83VersionError_displayName();
+ return Bundle.PHP84VersionError_displayName();
Review Comment:
Thanks for catching this.
##########
php/php.editor/src/org/netbeans/modules/php/editor/parser/PHP5ErrorHandlerImpl.java:
##########
@@ -397,6 +397,8 @@ public static String getTokenTextForm(int token) {
case ASTPHP5Symbols.T_YIELD : text = "yield"; break; //NOI18N
case ASTPHP5Symbols.T_YIELD_FROM : text = "yield from"; break;
//NOI18N
case ASTPHP5Symbols.T_READONLY : text = "readonly"; break;
//NOI18N PHP 8.1
+ //skiping T_PIPE = "|>" PHP 8.5 as it doesn't bring much to
the expected tokens error message
Review Comment:
I don't understand exactly why we are skipping the pipe here. Can you
explain/provide an example?
##########
php/php.api.phpmodule/src/org/netbeans/modules/php/api/PhpVersion.java:
##########
@@ -41,6 +41,7 @@
"PhpVersion.PHP_82=PHP 8.2",
"PhpVersion.PHP_83=PHP 8.3",
"PhpVersion.PHP_84=PHP 8.4",
+ "PhpVersion.PHP_85=PHP 8.5",
Review Comment:
(And this new version muist be used by other modules.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists