Skip to content

Commit

Permalink
Merge pull request apache#1400 from apache/php7.4
Browse files Browse the repository at this point in the history
[NETBEANS-1696] PHP 7.4 Support
  • Loading branch information
tmysik authored Jul 25, 2019
2 parents f1603f0 + d644beb commit c068c0b
Show file tree
Hide file tree
Showing 780 changed files with 77,119 additions and 50,410 deletions.
15 changes: 15 additions & 0 deletions php/php.editor/src/org/netbeans/modules/php/editor/CodeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,21 @@ public static String extractVariableName(Variable var) {
return variableName;
}

@CheckForNull
public static String extractFormalParameterName(FormalParameter param) {
Expression expression = param.getParameterName();
if (expression instanceof Reference) {
expression = ((Reference) expression).getExpression();
}
if (expression instanceof Variadic) {
expression = ((Variadic) expression).getExpression();
}
if (expression instanceof Variable) {
Variable variable = (Variable) expression;
return extractVariableName(variable);
}
return null;
}

public static String extractVariableType(Assignment assignment) {
Expression rightSideExpression = assignment.getRightHandSide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,55 +52,57 @@ public final class PredefinedSymbols {

public static final List<String> SERVER_ENTRY_CONSTANTS =
Collections.unmodifiableList(Arrays.asList(new String[]{
"PHP_SELF",
"GATEWAY_INTERFACE",
"SERVER_ADDR",
"SERVER_NAME",
"SERVER_SOFTWARE",
"SERVER_PROTOCOL",
"REQUEST_METHOD",
"QUERY_STRING",
"DOCUMENT_ROOT",
"HTTP_ACCEPT",
"HTTP_ACCEPT_CHARSET",
"HTTP_ACCEPT_ENCODING",
"HTTP_ACCEPT_LANGUAGE",
"HTTP_CONNECTION",
"HTTP_HOST",
"HTTP_REFERER",
"HTTP_USER_AGENT",
"HTTPS",
"REMOTE_ADDR",
"REMOTE_HOST",
"REMOTE_PORT",
"SCRIPT_FILENAME",
"SERVER_ADMIN",
"SERVER_PORT",
"SERVER_SIGNATURE",
"PATH_TRANSLATED",
"SCRIPT_NAME",
"REQUEST_URI",
"PHP_AUTH_DIGEST",
"PHP_AUTH_USER",
"PHP_AUTH_PW",
"AUTH_TYPE"
"PHP_SELF", // NOI18N
"GATEWAY_INTERFACE", // NOI18N
"SERVER_ADDR", // NOI18N
"SERVER_NAME", // NOI18N
"SERVER_SOFTWARE", // NOI18N
"SERVER_PROTOCOL", // NOI18N
"REQUEST_METHOD", // NOI18N
"QUERY_STRING", // NOI18N
"DOCUMENT_ROOT", // NOI18N
"HTTP_ACCEPT", // NOI18N
"HTTP_ACCEPT_CHARSET", // NOI18N
"HTTP_ACCEPT_ENCODING", // NOI18N
"HTTP_ACCEPT_LANGUAGE", // NOI18N
"HTTP_CONNECTION", // NOI18N
"HTTP_HOST", // NOI18N
"HTTP_REFERER", // NOI18N
"HTTP_USER_AGENT", // NOI18N
"HTTPS", // NOI18N
"REMOTE_ADDR", // NOI18N
"REMOTE_HOST", // NOI18N
"REMOTE_PORT", // NOI18N
"SCRIPT_FILENAME", // NOI18N
"SERVER_ADMIN", // NOI18N
"SERVER_PORT", // NOI18N
"SERVER_SIGNATURE", // NOI18N
"PATH_TRANSLATED", // NOI18N
"SCRIPT_NAME", // NOI18N
"REQUEST_URI", // NOI18N
"PHP_AUTH_DIGEST", // NOI18N
"PHP_AUTH_USER", // NOI18N
"PHP_AUTH_PW", // NOI18N
"AUTH_TYPE" // NOI18N
}));


public static final Set<String> MAGIC_METHODS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(new String[]{
"__callStatic",
"__set_state",
"__call",
"__clone",
"__construct",
"__destruct",
"__get",
"__set",
"__isset",
"__unset",
"__sleep",
"__wakeup",
"__toString"
"__callStatic", // NOI18N
"__set_state", // NOI18N
"__call", // NOI18N
"__clone", // NOI18N
"__construct", // NOI18N
"__destruct", // NOI18N
"__get", // NOI18N
"__set", // NOI18N
"__isset", // NOI18N
"__unset", // NOI18N
"__sleep", // NOI18N
"__wakeup", // NOI18N
"__toString", // NOI18N
"__serialize", // NOI18N PHP 7.4
"__unserialize", // NOI18N PHP 7.4
})));

public static enum VariableKind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
public interface FieldElement extends TypedInstanceElement, TypeMemberElement {
PhpElementKind KIND = PhpElementKind.FIELD;
String getName(boolean dollared);
boolean isAnnotation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.api.lexer.TokenUtilities;
import org.netbeans.modules.csl.spi.ParserResult;
import org.netbeans.modules.php.editor.NavUtils;
import org.netbeans.modules.php.editor.lexer.LexUtilities;
import org.netbeans.modules.php.editor.lexer.PHPTokenId;
import org.netbeans.modules.php.editor.NavUtils;
import org.netbeans.modules.php.editor.parser.PHPParseResult;
import org.netbeans.modules.php.editor.parser.api.Utils;
import org.netbeans.modules.php.editor.parser.astnodes.ASTError;
Expand All @@ -58,6 +58,7 @@ final class CompletionContextFinder {
private static final String GROUP_USE_STATEMENT_TOKENS = "GROUP_USE_STATEMENT_TOKENS"; //NOI18N
private static final String MULTI_CATCH_EXCEPTION_TOKENS = "MULTI_CATCH_EXCEPTION_TOKENS"; //NOI18N
private static final String COMBINED_USE_STATEMENT_TOKENS = "COMBINED_USE_STATEMENT_TOKENS"; //NOI18N
private static final String CONST_STATEMENT_TOKENS = "CONST_STATEMENT_TOKENS"; //NOI18N
private static final String TYPE_KEYWORD = "TYPE_KEYWORD"; //NOI18N
private static final PHPTokenId[] COMMENT_TOKENS = new PHPTokenId[]{
PHPTokenId.PHP_COMMENT_START, PHPTokenId.PHP_COMMENT, PHPTokenId.PHP_LINE_COMMENT, PHPTokenId.PHP_COMMENT_END};
Expand Down Expand Up @@ -153,6 +154,16 @@ final class CompletionContextFinder {
new Object[]{PHPTokenId.PHP_FUNCTION},
new Object[]{PHPTokenId.PHP_FUNCTION, PHPTokenId.WHITESPACE},
new Object[]{PHPTokenId.PHP_FUNCTION, PHPTokenId.WHITESPACE, PHPTokenId.PHP_STRING});
private static final List<Object[]> FIELD_TYPE_TOKENCHAINS = Arrays.asList(
new Object[]{PHPTokenId.PHP_PRIVATE, PHPTokenId.WHITESPACE, NAMESPACE_FALSE_TOKEN},
new Object[]{PHPTokenId.PHP_PROTECTED, PHPTokenId.WHITESPACE, NAMESPACE_FALSE_TOKEN},
new Object[]{PHPTokenId.PHP_PUBLIC, PHPTokenId.WHITESPACE, NAMESPACE_FALSE_TOKEN},
new Object[]{PHPTokenId.PHP_STATIC, PHPTokenId.WHITESPACE, NAMESPACE_FALSE_TOKEN},
new Object[]{PHPTokenId.PHP_VAR, PHPTokenId.WHITESPACE, NAMESPACE_FALSE_TOKEN},
new Object[]{PHPTokenId.PHP_TOKEN}, // ? (nullable)
new Object[]{PHPTokenId.PHP_TOKEN, PHPTokenId.PHP_STRING},
new Object[]{PHPTokenId.PHP_TOKEN, NAMESPACE_FALSE_TOKEN}
);
private static final List<Object[]> CLASS_CONTEXT_KEYWORDS_TOKENCHAINS = Arrays.asList(
new Object[]{PHPTokenId.PHP_PRIVATE},
new Object[]{PHPTokenId.PHP_PRIVATE, PHPTokenId.WHITESPACE},
Expand Down Expand Up @@ -185,14 +196,18 @@ final class CompletionContextFinder {
new Object[]{PHPTokenId.PHP_SEMICOLON},
new Object[]{PHPTokenId.PHP_SEMICOLON, PHPTokenId.WHITESPACE},
new Object[]{PHPTokenId.PHP_SEMICOLON, PHPTokenId.WHITESPACE, PHPTokenId.PHP_STRING});
private static final List<Object[]> CONST_TOKENCHAINS = Arrays.asList(
new Object[]{PHPTokenId.PHP_CONST, PHPTokenId.WHITESPACE, PHPTokenId.PHP_STRING, PHPTokenId.WHITESPACE, CONST_STATEMENT_TOKENS},
new Object[]{PHPTokenId.PHP_CONST, PHPTokenId.WHITESPACE, PHPTokenId.PHP_STRING, CONST_STATEMENT_TOKENS}
);
private static final List<Object[]> SERVER_ARRAY_TOKENCHAINS = Collections.singletonList(
new Object[]{PHPTokenId.PHP_VARIABLE, PHPTokenId.PHP_TOKEN});
private static final List<String> SERVER_ARRAY_TOKENTEXTS =
Arrays.asList(new String[]{"$_SERVER", "["}); //NOI18N

public static enum CompletionContext {

EXPRESSION, HTML, CLASS_NAME, INTERFACE_NAME, TYPE_NAME, RETURN_TYPE_NAME, STRING,
EXPRESSION, GLOBAL_CONST_EXPRESSION, CLASS_CONST_EXPRESSION, HTML, CLASS_NAME, INTERFACE_NAME, TYPE_NAME, RETURN_TYPE_NAME, FIELD_TYPE_NAME, STRING,
CLASS_MEMBER, STATIC_CLASS_MEMBER, PHPDOC, INHERITANCE, EXTENDS, IMPLEMENTS, METHOD_NAME,
CLASS_CONTEXT_KEYWORDS, SERVER_ENTRY_CONSTANTS, NONE, NEW_CLASS, GLOBAL, NAMESPACE_KEYWORD,
GROUP_USE_KEYWORD, GROUP_USE_CONST_KEYWORD, GROUP_USE_FUNCTION_KEYWORD,
Expand Down Expand Up @@ -301,6 +316,11 @@ static CompletionContext findCompletionContext(ParserResult info, int caretOffse
CompletionContext paramContext = getParamaterContext(token, caretOffset, tokenSequence);
if (paramContext != null) {
return paramContext;
} else if (acceptTokenChains(tokenSequence, FIELD_TYPE_TOKENCHAINS, moveNextSucces)) {
// \Namespace\ClassName, ?, ?ClassName, ?\Namespace\ClassName etc.
return CompletionContext.FIELD_TYPE_NAME;
} else if (acceptTokenChains(tokenSequence, CONST_TOKENCHAINS, moveNextSucces)) {
return CompletionContext.CLASS_CONST_EXPRESSION;
} else if (acceptTokenChains(tokenSequence, CLASS_CONTEXT_KEYWORDS_TOKENCHAINS, moveNextSucces)) {
return CompletionContext.CLASS_CONTEXT_KEYWORDS;
}
Expand Down Expand Up @@ -352,6 +372,9 @@ && acceptTokenChainTexts(tokenSequence, SERVER_ARRAY_TOKENTEXTS)) {
&& TokenUtilities.textEquals("<?", tokenSequence.token().text()) && (tokenSequence.offset() + 2) == caretOffset) { // NOI18N
return CompletionContext.OPEN_TAG;
}
if (acceptTokenChains(tokenSequence, CONST_TOKENCHAINS, moveNextSucces)) {
return CompletionContext.GLOBAL_CONST_EXPRESSION;
}
return CompletionContext.EXPRESSION;
}

Expand Down Expand Up @@ -488,6 +511,11 @@ private static boolean acceptTokenChain(TokenSequence tokenSequence, Object[] to
accept = false;
break;
}
} else if (tokenID == CONST_STATEMENT_TOKENS) {
if (!consumeUntilConstEqual(tokenSequence)) {
accept = false;
break;
}
} else {
assert false : "Unsupported token type: " + tokenID.getClass().getName();
}
Expand Down Expand Up @@ -649,6 +677,24 @@ private static boolean consumeUntilTypeKeyword(TokenSequence tokenSequence) {
return result;
}

private static boolean consumeUntilConstEqual(TokenSequence tokenSequence) {
boolean hasEqual = false;
do {
if (tokenSequence.token().id() == PHPTokenId.PHP_SEMICOLON
|| tokenSequence.token().id() == PHPTokenId.PHP_CURLY_OPEN
|| tokenSequence.token().id() == PHPTokenId.PHP_CURLY_CLOSE) {
break;
}
if (isEqualSign(tokenSequence.token())) {
hasEqual = true;
tokenSequence.movePrevious();
break;
}
} while (tokenSequence.movePrevious());

return hasEqual;
}

private static Token[] getLeftPreceedingTokens(TokenSequence tokenSequence) {
Token[] preceedingTokens = getPreceedingTokens(tokenSequence);
if (preceedingTokens.length == 0) {
Expand Down Expand Up @@ -893,7 +939,8 @@ private static boolean isNamespaceSeparator(Token<PHPTokenId> token) {
}

private static boolean isFunctionDeclaration(Token<PHPTokenId> token) {
return token.id().equals(PHPTokenId.PHP_FUNCTION); //NOI18N
return token.id().equals(PHPTokenId.PHP_FUNCTION)
|| token.id().equals(PHPTokenId.PHP_FN);
}

private static boolean isVariable(Token<PHPTokenId> token) {
Expand Down
Loading

0 comments on commit c068c0b

Please sign in to comment.