You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ne...@apache.org on 2023/01/23 16:43:22 UTC
[netbeans] branch delivery updated: Fixed detection of magic methods
This is an automated email from the ASF dual-hosted git repository.
neilcsmith pushed a commit to branch delivery
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/delivery by this push:
new 55a2b6af0e5 Fixed detection of magic methods
new 5acab1abe61 Merge pull request #5344 from KacerCZ/php-magic-method-fix
55a2b6af0e5 is described below
commit 55a2b6af0e58c3227dfd87aeb094b1b38927289e
Author: Tomas Prochazka <ka...@razdva.cz>
AuthorDate: Sun Jan 22 17:28:57 2023 +0100
Fixed detection of magic methods
In PHP method names are case insensitive.
Method isMagic() did not work for methods __callStatic, __toString and __debugInfo.
Method isConstructor() should compare whole string even though this is already guarded by isMagic().
---
.../php/editor/model/impl/MethodScopeImpl.java | 30 ++++++++++++++--------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/MethodScopeImpl.java b/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/MethodScopeImpl.java
index ffb28d497f6..ee642fabee9 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/MethodScopeImpl.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/MethodScopeImpl.java
@@ -19,6 +19,7 @@
package org.netbeans.modules.php.editor.model.impl;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.netbeans.modules.parsing.spi.indexing.support.IndexDocument;
@@ -50,11 +51,20 @@ import org.netbeans.modules.php.editor.parser.astnodes.Variable;
* @author Radek Matous
*/
final class MethodScopeImpl extends FunctionScopeImpl implements MethodScope, VariableNameFactory, LazyBuild {
+
+ private static final Set<String> MAGIC_METHODS = new HashSet<>();
+
private final String classNormName;
private boolean scanned;
private MethodDeclaration originalNode;
private ModelVisitor visitor;
+ static {
+ for (String methodName : PredefinedSymbols.MAGIC_METHODS) {
+ MAGIC_METHODS.add(methodName.toLowerCase());
+ }
+ }
+
//new contructors
MethodScopeImpl(Scope inScope, String returnType, MethodDeclarationInfo nodeInfo, ModelVisitor visitor, boolean isDeprecated) {
super(inScope, nodeInfo, returnType, isDeprecated);
@@ -141,7 +151,7 @@ final class MethodScopeImpl extends FunctionScopeImpl implements MethodScope, Va
@Override
public boolean isMagic() {
- return PredefinedSymbols.MAGIC_METHODS.contains(getName().toLowerCase());
+ return MAGIC_METHODS.contains(getName().toLowerCase());
}
@Override
@@ -151,7 +161,7 @@ final class MethodScopeImpl extends FunctionScopeImpl implements MethodScope, Va
@Override
public boolean isConstructor() {
- return isMagic() ? getName().contains("__construct") : false; //NOI18N
+ return isMagic() ? getName().equalsIgnoreCase("__construct") : false; //NOI18N
}
@Override
@@ -177,16 +187,16 @@ final class MethodScopeImpl extends FunctionScopeImpl implements MethodScope, Va
sb.append(", "); //NOI18N
}
final ParameterElement param = parameterList.get(i);
- if (param.hasDeclaredType()) {
- Set<TypeResolver> types = param.getTypes();
- if (types.size() == 1) {
- for (TypeResolver typeResolver : types) {
- if (typeResolver.isResolved()) {
- sb.append(typeResolver.getTypeName(false)).append(' '); //NOI18N
- }
+ if (param.hasDeclaredType()) {
+ Set<TypeResolver> types = param.getTypes();
+ if (types.size() == 1) {
+ for (TypeResolver typeResolver : types) {
+ if (typeResolver.isResolved()) {
+ sb.append(typeResolver.getTypeName(false)).append(' '); //NOI18N
}
}
}
+ }
sb.append(param.getName());
if (!param.isMandatory()) {
@@ -285,7 +295,7 @@ final class MethodScopeImpl extends FunctionScopeImpl implements MethodScope, Va
@Override
public void scan() {
if (!scanned && visitor != null) {
- scanned = true;
+ scanned = true;
visitor.scanNoLazy(originalNode, this);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists