This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 257977
Collapse All | Expand All

(-)a/php.editor/src/org/netbeans/modules/php/editor/parser/PHPDocCommentParser.java (-11 / +36 lines)
Lines 203-213 Link Here
203
                blockDescription = description + line;
203
                blockDescription = description + line;
204
            } else {
204
            } else {
205
                description = description + line;
205
                description = description + line;
206
                String tagDescription = description.length() > 0 && description.charAt(description.length() - 1) == '\n'
207
                        ? description.substring(0, description.length() - 1)
208
                        : description;
206
                PHPDocTag tag = createTag(
209
                PHPDocTag tag = createTag(
207
                        startOffset + 3 + lastStartIndex,
210
                        startOffset + 3 + lastStartIndex,
208
                        startOffset + 3 + lastEndIndex,
211
                        startOffset + 3 + lastEndIndex,
209
                        lastTag,
212
                        lastTag,
210
                        description.substring(0, description.length() - 1),
213
                        tagDescription,
211
                        comment,
214
                        comment,
212
                        startOffset + 3);
215
                        startOffset + 3);
213
                if (tag != null) {
216
                if (tag != null) {
Lines 228-234 Link Here
228
                PHPDocNode varibaleNode = null;
231
                PHPDocNode varibaleNode = null;
229
                if (variable != null) {
232
                if (variable != null) {
230
                    int startOfVariable = findStartOfDocNode(originalComment, originalCommentStart, variable, start);
233
                    int startOfVariable = findStartOfDocNode(originalComment, originalCommentStart, variable, start);
231
                    varibaleNode = new PHPDocNode(startOfVariable, startOfVariable + variable.length(), variable);
234
                    if (startOfVariable != -1) {
235
                        varibaleNode = new PHPDocNode(startOfVariable, startOfVariable + variable.length(), variable);
236
                    }
232
                } else if (type.equals(PHPDocTag.Type.PARAM)) {
237
                } else if (type.equals(PHPDocTag.Type.PARAM)) {
233
                    varibaleNode = new PHPDocNode(start, start, ""); //NOI18N
238
                    varibaleNode = new PHPDocNode(start, start, ""); //NOI18N
234
                }
239
                }
Lines 240-248 Link Here
240
                String name = getMethodName(description);
245
                String name = getMethodName(description);
241
                if (name != null) {
246
                if (name != null) {
242
                    int startOfVariable = findStartOfDocNode(originalComment, originalCommentStart, name, start);
247
                    int startOfVariable = findStartOfDocNode(originalComment, originalCommentStart, name, start);
243
                    PHPDocNode methodNode = new PHPDocNode(startOfVariable, startOfVariable + name.length(), name);
248
                    if (startOfVariable != -1) {
244
                    List<PHPDocVarTypeTag> params = findMethodParams(description, findStartOfDocNode(originalComment, originalCommentStart, description, start));
249
                        PHPDocNode methodNode = new PHPDocNode(startOfVariable, startOfVariable + name.length(), name);
245
                    return new PHPDocMethodTag(start, end, type, docTypes, methodNode, params, description);
250
                        int startOfDescription = findStartOfDocNode(originalComment, originalCommentStart, description, start);
251
                        if (startOfDescription != -1) {
252
                            List<PHPDocVarTypeTag> params = findMethodParams(description, startOfDescription);
253
                            return new PHPDocMethodTag(start, end, type, docTypes, methodNode, params, description);
254
                        }
255
                    }
246
                }
256
                }
247
                return null;
257
                return null;
248
            } else if (type.equals(PHPDocTag.Type.RETURN) || type.equals(PHPDocTag.Type.VAR)) {
258
            } else if (type.equals(PHPDocTag.Type.RETURN) || type.equals(PHPDocTag.Type.VAR)) {
Lines 272-277 Link Here
272
        for (String stype : getTypes(description, isReturnTag)) {
282
        for (String stype : getTypes(description, isReturnTag)) {
273
            stype = removeHTMLTags(stype);
283
            stype = removeHTMLTags(stype);
274
            int startDocNode = findStartOfDocNode(originalComment, originalCommentStart, stype, startDescription);
284
            int startDocNode = findStartOfDocNode(originalComment, originalCommentStart, stype, startDescription);
285
            if (startDocNode == -1) {
286
                continue;
287
            }
275
            int index = stype.indexOf("::");    //NOI18N
288
            int index = stype.indexOf("::");    //NOI18N
276
            boolean isArray = (stype.indexOf('[') > 0 && stype.indexOf(']') > 0);
289
            boolean isArray = (stype.indexOf('[') > 0 && stype.indexOf(']') > 0);
277
            if (isArray) {
290
            if (isArray) {
Lines 354-364 Link Here
354
                paramName = getVaribleName(token.trim());
367
                paramName = getVaribleName(token.trim());
355
                if (paramName != null) {
368
                if (paramName != null) {
356
                    int startOfParamName = findStartOfDocNode(description, startOfDescription, paramName, position);
369
                    int startOfParamName = findStartOfDocNode(description, startOfDescription, paramName, position);
357
                    PHPDocNode paramNameNode = new PHPDocNode(startOfParamName, startOfParamName + paramName.length(), paramName);
370
                    if (startOfParamName != -1) {
358
                    List<PHPDocTypeNode> types = token.trim().indexOf(' ') > -1
371
                        PHPDocNode paramNameNode = new PHPDocNode(startOfParamName, startOfParamName + paramName.length(), paramName);
359
                            ? findTypes(token, position, description, startOfDescription)
372
                        List<PHPDocTypeNode> types = token.trim().indexOf(' ') > -1
360
                            : Collections.EMPTY_LIST;
373
                                ? findTypes(token, position, description, startOfDescription)
361
                    result.add(new PHPDocVarTypeTag(position, startOfParamName + paramName.length(), PHPDocTag.Type.PARAM, token, types, paramNameNode));
374
                                : Collections.EMPTY_LIST;
375
                        result.add(new PHPDocVarTypeTag(position, startOfParamName + paramName.length(), PHPDocTag.Type.PARAM, token, types, paramNameNode));
376
                    }
362
                }
377
                }
363
                position = position + token.length() + 1;
378
                position = position + token.length() + 1;
364
            }
379
            }
Lines 379-387 Link Here
379
        return value;
394
        return value;
380
    }
395
    }
381
396
397
    /**
398
     * Find the start position of the specified string in the comment.
399
     *
400
     * @param originalComment the comment
401
     * @param originalStart the offset of the original comment
402
     * @param what the target string
403
     * @param from the start offset
404
     * @return the start position of the specified string if it is found,
405
     * otherwise -1.
406
     */
382
    private int findStartOfDocNode(String originalComment, int originalStart, String what, int from) {
407
    private int findStartOfDocNode(String originalComment, int originalStart, String what, int from) {
383
        int pos = originalComment.indexOf(what, from - originalStart);
408
        int pos = originalComment.indexOf(what, from - originalStart);
384
        return originalStart + pos;
409
        return pos == -1 ? pos : originalStart + pos;
385
    }
410
    }
386
411
387
    private String removeStarAndTrim(String text) {
412
    private String removeStarAndTrim(String text) {
(-)a/php.editor/test/unit/src/org/netbeans/modules/php/editor/parser/PHPDocCommentParserTest.java (+30 lines)
Lines 224-229 Link Here
224
        assertNotNull(block);
224
        assertNotNull(block);
225
    }
225
    }
226
226
227
    public void testIssue257977() throws Exception {
228
        /**
229
         * @since 2012-02-14
230
         * @since 2012-02-15
231
         *
232
         * Test
233
         */
234
        String comment =
235
                  " * @since 2012-02-14\n"
236
                + " * @since 2012-02-15\n"
237
                + " *\n"
238
                + " * Test";
239
        PHPDocCommentParser parser = new PHPDocCommentParser();
240
        PHPDocBlock block = parser.parse(-3, comment.length(), comment);
241
        List<PHPDocTag> tags = block.getTags();
242
        assertEquals(2, tags.size());
243
244
        PHPDocTag firstTag = tags.get(0);
245
        AnnotationParsedLine firstLine = firstTag.getKind();
246
        assertTrue(firstLine instanceof UnknownAnnotationLine);
247
        assertEquals("2012-02-14", firstLine.getDescription());
248
        assertEquals(" 2012-02-14", firstTag.getDocumentation());
249
250
        PHPDocTag secondTag = tags.get(1);
251
        AnnotationParsedLine secondLine = secondTag.getKind();
252
        assertTrue(secondLine instanceof UnknownAnnotationLine);
253
        assertEquals("2012-02-15", secondLine.getDescription());
254
        assertEquals(" 2012-02-15\n\nTest", secondTag.getDocumentation());
255
    }
256
227
    public void testProperty01() throws Exception {
257
    public void testProperty01() throws Exception {
228
        String comment = " * PHP Template.\n" +
258
        String comment = " * PHP Template.\n" +
229
                " * @property string $name\n" +
259
                " * @property string $name\n" +
(-)a/spellchecker.bindings.php/test/unit/src/org/netbeans/modules/spellchecker/bindings/php/PHPTokenListTest.java (+11 lines)
Lines 171-176 Link Here
171
        );
171
        );
172
    }
172
    }
173
173
174
    public void testIssue257977() throws Exception {
175
        tokenListTest(
176
                "  /**\n"
177
                + " * @since   2016-02-12\n"
178
                + " *\n"
179
                + " * Test\n"
180
                + " */",
181
                "Test"
182
        );
183
    }
184
174
    public void testPositions() throws Exception {
185
    public void testPositions() throws Exception {
175
        Document doc = new PlainDocument();
186
        Document doc = new PlainDocument();
176
        doc.putProperty(Language.class, PHPTokenId.language());
187
        doc.putProperty(Language.class, PHPTokenId.language());

Return to bug 257977