-
Notifications
You must be signed in to change notification settings - Fork 933
PHP: Support variadic marked variables in PHPDoc #9487
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
Open
matthiasblaesing
wants to merge
2
commits into
apache:master
Choose a base branch
from
matthiasblaesing:php_varargs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,9 +204,13 @@ private PHPDocTag createTag(int start, int end, AnnotationParsedLine type, Strin | |
| if (types.isEmpty()) { | ||
| List<PHPDocTypeNode> docTypes = findTypes(description, start, originalComment, originalCommentStart, type); | ||
| if (PHP_DOC_VAR_TYPE_TAGS.contains(type)) { | ||
| String variable = getVaribleName(description); | ||
| String variable = getVariableName(description); | ||
| PHPDocNode varibaleNode = null; | ||
| if (variable != null) { | ||
| // Strip variadic prefix from variable | ||
| if (variable.startsWith("...")) { | ||
| variable = variable.substring(3); | ||
| } | ||
| int startOfVariable = findStartOfDocNode(originalComment, originalCommentStart, variable, start); | ||
| if (startOfVariable != -1) { | ||
| varibaleNode = new PHPDocNode(startOfVariable, startOfVariable + variable.length(), variable); | ||
|
|
@@ -298,7 +302,7 @@ private List<String> getTypes(String description, AnnotationParsedLine tagType) | |
| tokens = Arrays.copyOfRange(tokens, 1, tokens.length); | ||
| } | ||
| ArrayList<String> types = new ArrayList<>(); | ||
| if (tokens.length > 0 && (isReturnTag(tagType) || !tokens[0].startsWith("$"))) { //NOI18N | ||
| if (tokens.length > 0 && (isReturnTag(tagType) || !isVariableName(tokens[0]))) { //NOI18N | ||
| if (findParameterStartPosition(tokens[0]) != -1) { | ||
| // e.g. @method voidReturn((X&Y)|Z $param) | ||
| types.add(Type.VOID); | ||
|
|
@@ -320,18 +324,23 @@ private List<String> getTypes(String description, AnnotationParsedLine tagType) | |
| return types; | ||
| } | ||
|
|
||
| private String getVaribleName(String description) { | ||
| private String getVariableName(String description) { | ||
| String[] tokens = description.trim().split("[ \n\t]+"); //NOI18N | ||
| String variable = null; | ||
|
|
||
| if (tokens.length > 0 && tokens[0].length() > 0 && tokens[0].charAt(0) == '$') { | ||
| if (tokens.length > 0 && tokens[0].length() > 0 && isVariableName(tokens[0])) { | ||
| variable = tokens[0].trim(); | ||
| } else if ((tokens.length > 1) && (tokens[1].charAt(0) == '$')) { | ||
| } else if ((tokens.length > 1) && isVariableName(tokens[1])) { | ||
| variable = tokens[1].trim(); | ||
| } | ||
| return variable; | ||
| } | ||
|
|
||
| public static boolean isVariableName(String token) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: do we need |
||
| return token.startsWith("$") /* variable */ | ||
| || token.startsWith("...$") /* variadic variable */; | ||
| } | ||
|
|
||
| private String getMethodName(String description) { | ||
| String name = null; | ||
| int index = findParameterStartPosition(description); | ||
|
|
@@ -366,7 +375,7 @@ private List<PHPDocVarTypeTag> findMethodParams(String description, int startOfD | |
| String[] tokens = parameters.split("[,]+"); //NOI18N | ||
| String paramName; | ||
| for (String token : tokens) { | ||
| paramName = getVaribleName(token.trim()); | ||
| paramName = getVariableName(token.trim()); | ||
| if (paramName != null) { | ||
| int startOfParamName = findStartOfDocNode(description, startOfDescription, paramName, position); | ||
| if (startOfParamName != -1) { | ||
|
|
||
12 changes: 12 additions & 0 deletions
12
...les/org/netbeans/modules/php/editor/parser/PHPDocCommentParserTest/NonvarargsParam01.pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <PHPDocBlock start='3' end='23'> | ||
| <Tags> | ||
| <PHPDocVarTypeTag start='3' end='26' kind='param'> | ||
| <Variable> | ||
| <PHPDocNode start='20' end='26' value='$param'/> | ||
| </Variable> | ||
| <Types> | ||
| <PHPDocTypeNode start='13' end='19' value='string' isArray='false'/> | ||
| </Types> | ||
| </PHPDocVarTypeTag> | ||
| </Tags> | ||
| </PHPDocBlock> |
11 changes: 11 additions & 0 deletions
11
...les/org/netbeans/modules/php/editor/parser/PHPDocCommentParserTest/NonvarargsParam02.pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <PHPDocBlock start='3' end='16'> | ||
| <Tags> | ||
| <PHPDocVarTypeTag start='3' end='19' kind='param'> | ||
| <Variable> | ||
| <PHPDocNode start='13' end='19' value='$param'/> | ||
| </Variable> | ||
| <Types> | ||
| </Types> | ||
| </PHPDocVarTypeTag> | ||
| </Tags> | ||
| </PHPDocBlock> |
12 changes: 12 additions & 0 deletions
12
...nfiles/org/netbeans/modules/php/editor/parser/PHPDocCommentParserTest/VarargsParam01.pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <PHPDocBlock start='3' end='26'> | ||
| <Tags> | ||
| <PHPDocVarTypeTag start='3' end='29' kind='param'> | ||
| <Variable> | ||
| <PHPDocNode start='23' end='29' value='$param'/> | ||
| </Variable> | ||
| <Types> | ||
| <PHPDocTypeNode start='13' end='19' value='string' isArray='false'/> | ||
| </Types> | ||
| </PHPDocVarTypeTag> | ||
| </Tags> | ||
| </PHPDocBlock> |
11 changes: 11 additions & 0 deletions
11
...nfiles/org/netbeans/modules/php/editor/parser/PHPDocCommentParserTest/VarargsParam02.pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <PHPDocBlock start='3' end='19'> | ||
| <Tags> | ||
| <PHPDocVarTypeTag start='3' end='22' kind='param'> | ||
| <Variable> | ||
| <PHPDocNode start='16' end='22' value='$param'/> | ||
| </Variable> | ||
| <Types> | ||
| </Types> | ||
| </PHPDocVarTypeTag> | ||
| </Tags> | ||
| </PHPDocBlock> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
//NOI18Ncan be removed.