Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: //NOI18N can be removed.

if (findParameterStartPosition(tokens[0]) != -1) {
// e.g. @method voidReturn((X&Y)|Z $param)
types.add(Type.VOID);
Expand All @@ -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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: do we need //NOI18N to be used in this method?

return token.startsWith("$") /* variable */
|| token.startsWith("...$") /* variadic variable */;
}

private String getMethodName(String description) {
String name = null;
int index = findParameterStartPosition(description);
Expand Down Expand Up @@ -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) {
Expand Down
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>
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>
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>
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>
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,26 @@ public void testReturnTypeObjectShapes02() throws Exception {
perform(comment, "ReturnTypeObjectShapes02");
}

public void testVarargsParam01() throws Exception {
String comment = " * @param string ...$param";
perform(comment, "VarargsParam01");
}

public void testVarargsParam02() throws Exception {
String comment = " * @param ...$param";
perform(comment, "VarargsParam02");
}

public void testNonvarargsParam01() throws Exception {
String comment = " * @param string $param";
perform(comment, "NonvarargsParam01");
}

public void testNonvarargsParam02() throws Exception {
String comment = " * @param $param";
perform(comment, "NonvarargsParam02");
}

public void perform(String comment, String filename) throws Exception {
PHPDocCommentParser parser = new PHPDocCommentParser();
PHPDocBlock block = parser.parse(0, comment.length(), comment);
Expand Down
Loading