From 065225aaaef03c7389cdbda064c95348515dbf31 Mon Sep 17 00:00:00 2001 From: Junichi Yamamoto Date: Fri, 21 Oct 2022 14:47:10 +0900 Subject: [PATCH 1/2] Support `{@inheritdoc}` for fields and constants #4686 --- .../php/editor/completion/DocRenderer.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java b/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java index 4a475ec0cf13..16d59cc1ae28 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java @@ -811,6 +811,12 @@ private List getInheritedElements() { } else if (indexedElement instanceof InterfaceElement) { InterfaceElement interfaceElement = (InterfaceElement) indexedElement; inheritedElements.addAll(getAllInheritedInterfaces(interfaceElement)); + } else if (indexedElement instanceof FieldElement) { + FieldElement fieldElement = (FieldElement) indexedElement; + inheritedElements.addAll(getAllOverriddenFields(fieldElement)); + } else if (indexedElement instanceof TypeConstantElement) { + TypeConstantElement constElement = (TypeConstantElement) indexedElement; + inheritedElements.addAll(getAllOverriddenConstants(constElement)); } return inheritedElements; } @@ -975,6 +981,62 @@ private static Set getInheritedMethods(MethodElement method) { return index.getInheritedMethods(type); } + private static List getAllOverriddenFields(FieldElement field) { + List fields = new ArrayList<>(); + getOverriddenFields(field, fields); + return fields; + } + + private static void getOverriddenFields(FieldElement field, List fields) { + Set overriddenFields = getOverriddenFields(field); + fields.addAll(overriddenFields); + for (FieldElement overriddenField : overriddenFields) { + getOverriddenFields(overriddenField, fields); + } + } + + private static Set getOverriddenFields(FieldElement field) { + ElementFilter fieldNameFilter = ElementFilter.forName(NameKind.exact(field.getName())); + return fieldNameFilter.filter(getInheritedFields(field)); + } + + private static Set getInheritedFields(FieldElement field) { + Index index = getIndex(field); + TypeElement type = field.getType(); + if (type == null) { + return Collections.emptySet(); + } + return index.getInheritedFields(type); + } + + private static List getAllOverriddenConstants(TypeConstantElement constant) { + List constants = new ArrayList<>(); + getOverriddenConstants(constant, constants); + return constants; + } + + private static void getOverriddenConstants(TypeConstantElement constant, List constants) { + Set overriddenConstants = getOverriddenConstants(constant); + constants.addAll(overriddenConstants); + for (TypeConstantElement overriddenConstant : overriddenConstants) { + getOverriddenConstants(overriddenConstant, constants); + } + } + + private static Set getOverriddenConstants(TypeConstantElement constant) { + ElementFilter constantNameFilter = ElementFilter.forName(NameKind.exact(constant.getName())); + return constantNameFilter.filter(getInheritedConstants(constant)); + } + + private static Set getInheritedConstants(TypeConstantElement constant) { + Index index = getIndex(constant); + TypeElement type = constant.getType(); + if (type == null) { + return Collections.emptySet(); + } + return index.getInheritedTypeConstants(type); + } + @CheckForNull private PHPDocBlock getPhpDocBlock(final PhpElement phpElement) { if (!canBeProcessed(phpElement)) { From 13ee697b21b6f8c986b091db9dcfc3ac39075c5d Mon Sep 17 00:00:00 2001 From: Junichi Yamamoto Date: Fri, 21 Oct 2022 15:46:17 +0900 Subject: [PATCH 2/2] Replace `{@inheritdoc}` with whole parent sentences #4686 Phpdocumentor separates sentences into the header and description. Then, it replaces `{@inheritdoc}` with description. However, if there is only one sentence in the parent PHPDoc, `{@inheritdoc}` is not replaced anything in the child PHPDoc. So, just replace `{@inheritdoc}` with whole parent sentences by default. --- .../php/editor/completion/DocRenderer.java | 18 ++- .../completion/documentation/inheritdoc.php | 119 ++++++++++++++++++ ...stInheritdocChildMethodSingleSentence.html | 10 ++ ....php.testInheritdocClassWithInlineTag.html | 2 +- ...docClassWithInlineTagForPhpDocumentor.html | 9 ++ ...tdoc.php.testInheritdocConstInlineTag.html | 10 ++ ...eritdocConstInlineTagForPhpDocumentor.html | 10 ++ ...ritdoc.php.testInheritdocConstOnlyTag.html | 9 ++ ...testInheritdocConstWithSingleSentence.html | 9 ++ ....php.testInheritdocConstWithoutPhpDoc.html | 9 ++ ...tdoc.php.testInheritdocFieldInlineTag.html | 10 ++ ...eritdocFieldInlineTagForPhpDocumentor.html | 10 ++ ...ritdoc.php.testInheritdocFieldOnlyTag.html | 10 ++ ...testInheritdocFieldWithSingleSentence.html | 9 ++ ....php.testInheritdocFieldWithoutPhpDoc.html | 10 ++ ....testInheritdocInterfaceWithInlineTag.html | 2 +- ...nterfaceWithInlineTagForPhpDocumentor.html | 9 ++ ...php.testInheritdocMethodWithInlineTag.html | 2 +- ...ocMethodWithInlineTagForPhpDocumentor.html | 13 ++ .../completion/PHPCCDocumentationTest.java | 66 ++++++++++ 20 files changed, 341 insertions(+), 5 deletions(-) create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocChildMethodSingleSentence.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocClassWithInlineTagForPhpDocumentor.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstInlineTag.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstInlineTagForPhpDocumentor.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstOnlyTag.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstWithSingleSentence.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstWithoutPhpDoc.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldInlineTag.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldInlineTagForPhpDocumentor.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldOnlyTag.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldWithSingleSentence.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldWithoutPhpDoc.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocInterfaceWithInlineTagForPhpDocumentor.html create mode 100644 php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocMethodWithInlineTagForPhpDocumentor.html diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java b/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java index 16d59cc1ae28..8c7379639bbf 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java @@ -239,6 +239,17 @@ static final class PHPDocExtractor { private static final Pattern DESC_HEADER_PATTERN = Pattern.compile("(\r?\n)*(.*?((\r?\n){2,}|\\.\\s*\r?\n)|.*)", Pattern.DOTALL); // NOI18N private static final Pattern INLINE_INHERITDOC_PATTERN = Pattern.compile("\\{@inheritdoc *\\}", Pattern.CASE_INSENSITIVE); // NOI18N private static final ArrayList LINK_TAGS = new ArrayList<>(); + // see: https://pear.php.net/package/PhpDocumentor/docs/latest/phpDocumentor/tutorial_tags.inlineinheritdoc.pkg.html + // phpdocumentor separates a doc comment into a header and description. + // only description is replaced. + // e.g. + // /** + // * Header. + // * Description. + // */ + // /** {@inheritdoc} */ -> /** Description. */ + private static final boolean INHERITDOC_FOR_PHPDOCUMENTOR = Boolean.getBoolean("nb.php.editor.inheritDocForPhpdocumentor"); // NOI18N + static volatile boolean UNIT_TEST_INHERITDOC_FOR_PHPDOCUMENTER = false; // for unit tests static { LINK_TAGS.add("@link"); // NOI18N @@ -633,12 +644,15 @@ private String replaceInheritdocForDescription(@NullAllowed String description, if (description == null) { return parentDescription; } - if (description != null && hasInlineInheritdoc(description)) { + if (hasInlineInheritdoc(description)) { if (parentDescription != null && !parentDescription.trim().isEmpty()) { if (INLINE_INHERITDOC_PATTERN.matcher(description.trim()).matches()) { return parentDescription; } - String inheritdoc = removeDescriptionHeader(parentDescription); + String inheritdoc = parentDescription; + if (INHERITDOC_FOR_PHPDOCUMENTOR || UNIT_TEST_INHERITDOC_FOR_PHPDOCUMENTER) { + inheritdoc = removeDescriptionHeader(parentDescription); + } return replaceInlineInheritdoc(description, inheritdoc); } } diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php index 5a2177c2c2d7..2b1fff719465 100644 --- a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php @@ -8,6 +8,68 @@ */ class BaseClass { + /** + * The summary of BaseClass CONSTANT. + */ + public const CONSTANT_SINGLE_SENTENCE = 0; + + /** + * The summary of BaseClass CONSTANT. + * + * Description of BaseClass CONSTANT. + */ + public const CONSTANT_ONLY_TAG = 0; + + /** + * The summary of BaseClass CONSTANT. + * + * Description of BaseClass CONSTANT. + */ + public const CONSTANT_INLINE_TAG = 0; + + /** + * The summary of BaseClass CONSTANT. + * + * Description of BaseClass CONSTANT. + */ + public const CONSTANT_WITHOUT_PHPDOC = 0; + + /** + * The summary of BaseClass $field. + * @var int + */ + public int $fieldSingleSentence = 0; + + /** + * The summary of BaseClass $field. + * + * Description of BaseClass $field. + * @var int + */ + public int $fieldOnlyTag = 0; + + /** + * The summary of BaseClass $field. + * + * Description of BaseClass $field. + * @var int + */ + public int $fieldInlineTag = 0; + + /** + * The summary of BaseClass $field. + * + * Description of BaseClass $field. + * @var int + */ + public int $fieldWithoutPHPDoc = 0; + + /** + * testSingleSentence method of BaseClass. + */ + public function testSingleSentence() { + } + /** * testOnlyTag method of BaseClass. * @@ -70,6 +132,54 @@ public function testNoDoc() { */ class ChildClass extends BaseClass { + /** + * {@inheritDoc} Description of ChildClass CONSTANT. + */ + public const CONSTANT_SINGLE_SENTENCE = 0; + + /** + * {@inheritDoc} + */ + public const CONSTANT_ONLY_TAG = 0; + + /** + * The summary of ChildClass CONSTANT. + * + * {@inheritDoc} Description of ChildClass CONSTANT. + */ + public const CONSTANT_INLINE_TAG = 0; + + public const CONSTANT_WITHOUT_PHPDOC = 0; + + /** + * {@inheritDoc} Description of ChildClass $field. + * @var int + */ + public int $fieldSingleSentence = 0; + + /** + * {@inheritDoc} + */ + public int $fieldOnlyTag = 0; + + /** + * The summary of ChildClass $field. + * + * {@inheritDoc} Description of ChildClass $field. + * @var int + */ + public int $fieldInlineTag = 0; + + public int $fieldWithoutPHPDoc = 0; + + /** + * testSingleSentence method of ChildClass. + * + * {@inheritDoc} Description of ChildClass. + */ + public function testSingleSentence() { + } + /** * {@inheritdoc } */ @@ -181,6 +291,15 @@ public function childInterfaceMethod() { } $childClass = new ChildClass(); +ChildClass::CONSTANT_SINGLE_SENTENCE; +ChildClass::CONSTANT_ONLY_TAG; +ChildClass::CONSTANT_INLINE_TAG; +ChildClass::CONSTANT_WITHOUT_PHPDOC; +$childClass->fieldSingleSentence; +$childClass->fieldOnlytag; +$childClass->fieldInlineTag; +$childClass->fieldWithoutPhpDoc; +$childClass->testSingleSentence(); $childClass->testOnlyTag($param1, $param2); $childClass->testMissingParam($param1); $childClass->testNoDoc(); diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocChildMethodSingleSentence.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocChildMethodSingleSentence.html new file mode 100644 index 000000000000..5d1dcb71892e --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocChildMethodSingleSentence.html @@ -0,0 +1,10 @@ + +
Code completion result for source line:
+$childClass->testSingle|Sentence();
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+METHOD     testSingleSentence()            [PUBLIC]   ChildClass
+

Documentation:

testSingleSentence

+testSingleSentence method of ChildClass.

testSingleSentence method of BaseClass. + Description of ChildClass. +
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocClassWithInlineTag.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocClassWithInlineTag.html index e2885b43181a..3bacb51304eb 100644 --- a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocClassWithInlineTag.html +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocClassWithInlineTag.html @@ -4,6 +4,6 @@ (QueryType=COMPLETION, prefixSearch=false, caseSensitive=true) CLASS ChildInlineTagClass [PUBLIC] inheritdoc.php

Documentation:

ChildInlineTagClass

-The summary of ChildInlineTagClass.

Description of BaseClass. Description of ChildInlineTagClass. +The summary of ChildInlineTagClass.

The summary of BaseClass.

Description of BaseClass. Description of ChildInlineTagClass.
diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocClassWithInlineTagForPhpDocumentor.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocClassWithInlineTagForPhpDocumentor.html new file mode 100644 index 000000000000..e2885b43181a --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocClassWithInlineTagForPhpDocumentor.html @@ -0,0 +1,9 @@ + +
Code completion result for source line:
+class GrandchildInlineTagClass extends ChildInlineTagC|lass {
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+CLASS      ChildInlineTagClass             [PUBLIC]   inheritdoc.php
+

Documentation:

ChildInlineTagClass

+The summary of ChildInlineTagClass.

Description of BaseClass. Description of ChildInlineTagClass. +
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstInlineTag.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstInlineTag.html new file mode 100644 index 000000000000..a02c912fcbdc --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstInlineTag.html @@ -0,0 +1,10 @@ + +
Code completion result for source line:
+ChildClass::CONSTANT_INLIN|E_TAG;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+CONSTANT   CONSTANT_INLINE_TAG 0           [PUBLIC]   ChildClass
+

Documentation:

CONSTANT_INLINE_TAG = 0

+The summary of ChildClass CONSTANT.

The summary of BaseClass CONSTANT.

Description of BaseClass CONSTANT. + Description of ChildClass CONSTANT. +
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstInlineTagForPhpDocumentor.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstInlineTagForPhpDocumentor.html new file mode 100644 index 000000000000..d1c20af92396 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstInlineTagForPhpDocumentor.html @@ -0,0 +1,10 @@ + +
Code completion result for source line:
+ChildClass::CONSTANT_INLIN|E_TAG;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+CONSTANT   CONSTANT_INLINE_TAG 0           [PUBLIC]   ChildClass
+

Documentation:

CONSTANT_INLINE_TAG = 0

+The summary of ChildClass CONSTANT.

Description of BaseClass CONSTANT. + Description of ChildClass CONSTANT. +
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstOnlyTag.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstOnlyTag.html new file mode 100644 index 000000000000..cf77710b1de1 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstOnlyTag.html @@ -0,0 +1,9 @@ + +
Code completion result for source line:
+ChildClass::CONSTANT_ONL|Y_TAG;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+CONSTANT   CONSTANT_ONLY_TAG 0             [PUBLIC]   ChildClass
+

Documentation:

CONSTANT_ONLY_TAG = 0

+The summary of BaseClass CONSTANT.

Description of BaseClass CONSTANT. +
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstWithSingleSentence.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstWithSingleSentence.html new file mode 100644 index 000000000000..874e4ea53d86 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstWithSingleSentence.html @@ -0,0 +1,9 @@ + +
Code completion result for source line:
+ChildClass::CONSTANT_SINGLE_|SENTENCE;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+CONSTANT   CONSTANT_SINGLE_SENTENCE 0      [PUBLIC]   ChildClass
+

Documentation:

CONSTANT_SINGLE_SENTENCE = 0



The summary of BaseClass CONSTANT. + Description of ChildClass CONSTANT. +
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstWithoutPhpDoc.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstWithoutPhpDoc.html new file mode 100644 index 000000000000..9767f96ce94a --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocConstWithoutPhpDoc.html @@ -0,0 +1,9 @@ + +
Code completion result for source line:
+ChildClass::CONSTANT_WITHOUT_PH|PDOC;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+CONSTANT   CONSTANT_WITHOUT_PHPDOC 0       [PUBLIC]   ChildClass
+

Documentation:

CONSTANT_WITHOUT_PHPDOC = 0

+The summary of BaseClass CONSTANT.

Description of BaseClass CONSTANT. +
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldInlineTag.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldInlineTag.html new file mode 100644 index 000000000000..f1cdee629b86 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldInlineTag.html @@ -0,0 +1,10 @@ + +
Code completion result for source line:
+$childClass->fieldInli|neTag;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+VARIABLE   int fieldInlineTag              [PUBLIC]   ChildClass
+

Documentation:

$fieldInlineTag

+The summary of ChildClass $field.

The summary of BaseClass $field.

Description of BaseClass $field. Description of ChildClass $field.
+ +
Type:int
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldInlineTagForPhpDocumentor.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldInlineTagForPhpDocumentor.html new file mode 100644 index 000000000000..d1d181ce3ad3 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldInlineTagForPhpDocumentor.html @@ -0,0 +1,10 @@ + +
Code completion result for source line:
+$childClass->fieldInlineT|ag;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+VARIABLE   int fieldInlineTag              [PUBLIC]   ChildClass
+

Documentation:

$fieldInlineTag

+The summary of ChildClass $field.

Description of BaseClass $field. Description of ChildClass $field.
+ +
Type:int
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldOnlyTag.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldOnlyTag.html new file mode 100644 index 000000000000..9a086dd063b9 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldOnlyTag.html @@ -0,0 +1,10 @@ + +
Code completion result for source line:
+$childClass->fieldOnl|ytag;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+VARIABLE   int fieldOnlyTag                [PUBLIC]   ChildClass
+

Documentation:

$fieldOnlyTag

+The summary of BaseClass $field.

Description of BaseClass $field.
+ +
Type:int
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldWithSingleSentence.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldWithSingleSentence.html new file mode 100644 index 000000000000..b5541d2a3bb5 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldWithSingleSentence.html @@ -0,0 +1,9 @@ + +
Code completion result for source line:
+$childClass->fieldSingle|Sentence;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+VARIABLE   int fieldSingleSentence         [PUBLIC]   ChildClass
+

Documentation:

$fieldSingleSentence



The summary of BaseClass $field. Description of ChildClass $field.
+ +
Type:int
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldWithoutPhpDoc.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldWithoutPhpDoc.html new file mode 100644 index 000000000000..d7fb09fda988 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocFieldWithoutPhpDoc.html @@ -0,0 +1,10 @@ + +
Code completion result for source line:
+$childClass->fieldWithoutP|hpDoc;
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+VARIABLE   int fieldWithoutPHPDoc          [PUBLIC]   ChildClass
+

Documentation:

$fieldWithoutPHPDoc

+The summary of BaseClass $field.

Description of BaseClass $field.
+ +
Type:int
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocInterfaceWithInlineTag.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocInterfaceWithInlineTag.html index 31fe8e452f6e..8e6dc01ac27a 100644 --- a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocInterfaceWithInlineTag.html +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocInterfaceWithInlineTag.html @@ -4,6 +4,6 @@ (QueryType=COMPLETION, prefixSearch=false, caseSensitive=true) CLASS ChildInlineTagInterface [PUBLIC] inheritdoc.php

Documentation:

ChildInlineTagInterface

-The summary of ChildInlineTagInterface.

Description of BaseInterface. Description of ChildInlineTagInterface. +The summary of ChildInlineTagInterface.

The summary of BaseInterface.

Description of BaseInterface. Description of ChildInlineTagInterface.
diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocInterfaceWithInlineTagForPhpDocumentor.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocInterfaceWithInlineTagForPhpDocumentor.html new file mode 100644 index 000000000000..31fe8e452f6e --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocInterfaceWithInlineTagForPhpDocumentor.html @@ -0,0 +1,9 @@ + +
Code completion result for source line:
+interface GrandchildInlineTagInterface extends ChildInlineTagI|nterface {
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+CLASS      ChildInlineTagInterface         [PUBLIC]   inheritdoc.php
+

Documentation:

ChildInlineTagInterface

+The summary of ChildInlineTagInterface.

Description of BaseInterface. Description of ChildInlineTagInterface. +
+ diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocMethodWithInlineTag.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocMethodWithInlineTag.html index 442471bcf2c3..dadf28a9dd89 100644 --- a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocMethodWithInlineTag.html +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocMethodWithInlineTag.html @@ -4,7 +4,7 @@ (QueryType=COMPLETION, prefixSearch=false, caseSensitive=true) METHOD testInline($param1, $param2) [PUBLIC] GrandchildClass

Documentation:

testInline

-The summary of GrandChildClass.

testInline method description of BaseClass. Description of GrandChildClass.
+The summary of GrandChildClass.

testInline method of BaseClass.

testInline method description of BaseClass. Description of GrandChildClass.

Parameters:

diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocMethodWithInlineTagForPhpDocumentor.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocMethodWithInlineTagForPhpDocumentor.html new file mode 100644 index 000000000000..442471bcf2c3 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/inheritdoc.php.testInheritdocMethodWithInlineTagForPhpDocumentor.html @@ -0,0 +1,13 @@ + +
Code completion result for source line:
+$grandchildClass->testInlin|e($param1, $param2);
+(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true)
+METHOD     testInline($param1, $param2)    [PUBLIC]   GrandchildClass
+

Documentation:

testInline

+The summary of GrandChildClass.

testInline method description of BaseClass. Description of GrandChildClass.
+

Parameters:

+
 type$param1param1 description of BaseClass param1 description of GrandchildClass
+ + +
 type$param1param1 description of BaseClass param1 description of GrandchildClass
 type$param2param2 description of BaseClass param2 description of GrandchildClass
+ diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCCDocumentationTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCCDocumentationTest.java index 602745b76acd..8f4d2cda70a0 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCCDocumentationTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCCDocumentationTest.java @@ -113,6 +113,10 @@ public void testInheritdocClassWithInlineTag() throws Exception { checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "class GrandchildInlineTagClass extends ChildInlineTagC^lass {", false, ""); } + public void testInheritdocClassWithInlineTagForPhpDocumentor() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "class GrandchildInlineTagClass extends ChildInlineTagC^lass {", false, "", true); + } + public void testInheritdocInterfaceOnlyTag() throws Exception { checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "class GrandchildClass extends ChildClass implements ChildInterf^ace {", false, ""); } @@ -121,6 +125,14 @@ public void testInheritdocInterfaceWithInlineTag() throws Exception { checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "interface GrandchildInlineTagInterface extends ChildInlineTagI^nterface {", false, ""); } + public void testInheritdocInterfaceWithInlineTagForPhpDocumentor() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "interface GrandchildInlineTagInterface extends ChildInlineTagI^nterface {", false, "", true); + } + + public void testInheritdocChildMethodSingleSentence() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->testSingle^Sentence();", false, ""); + } + public void testInheritdocChildMethodOnlyTag() throws Exception { checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->testOnlyT^ag($param1, $param2);", false, ""); } @@ -145,6 +157,10 @@ public void testInheritdocMethodWithInlineTag() throws Exception { checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$grandchildClass->testInlin^e($param1, $param2);", false, ""); } + public void testInheritdocMethodWithInlineTagForPhpDocumentor() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$grandchildClass->testInlin^e($param1, $param2);", false, "", true); + } + public void testInheritdocMethodWithMissingParam() throws Exception { checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->testMissing^Param($param1);", false, ""); } @@ -155,6 +171,46 @@ public void testInheritdocMethodWithInvalidTag() throws Exception { checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->testInvalidT^ag();", false, ""); } + public void testInheritdocConstWithSingleSentence() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "ChildClass::CONSTANT_SINGLE_^SENTENCE;", false, ""); + } + + public void testInheritdocConstOnlyTag() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "ChildClass::CONSTANT_ONL^Y_TAG;", false, ""); + } + + public void testInheritdocConstInlineTag() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "ChildClass::CONSTANT_INLIN^E_TAG;", false, ""); + } + + public void testInheritdocConstInlineTagForPhpDocumentor() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "ChildClass::CONSTANT_INLIN^E_TAG;", false, "", true); + } + + public void testInheritdocConstWithoutPhpDoc() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "ChildClass::CONSTANT_WITHOUT_PH^PDOC;", false, ""); + } + + public void testInheritdocFieldWithSingleSentence() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->fieldSingle^Sentence;", false, ""); + } + + public void testInheritdocFieldOnlyTag() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->fieldOnl^ytag;", false, ""); + } + + public void testInheritdocFieldInlineTag() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->fieldInli^neTag;", false, ""); + } + + public void testInheritdocFieldInlineTagForPhpDocumentor() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->fieldInlineT^ag;", false, "", true); + } + + public void testInheritdocFieldWithoutPhpDoc() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/inheritdoc.php", "$childClass->fieldWithoutP^hpDoc;", false, ""); + } + public void testFieldTypedWithoutPhpDoc() throws Exception { checkCompletionDocumentation("testfiles/completion/documentation/fieldWithoutPhpDoc.php", "$this->typ^ed;", false, ""); } @@ -222,6 +278,16 @@ protected String alterDocumentationForTest(String documentation) { return documentation; } + public void checkCompletionDocumentation(final String file, final String caretLine, final boolean includeModifiers, final String itemPrefix, boolean followPhpdocumentor) throws Exception { + if (followPhpdocumentor) { + DocRenderer.PHPDocExtractor.UNIT_TEST_INHERITDOC_FOR_PHPDOCUMENTER = true; + } + checkCompletionDocumentation(file, caretLine, includeModifiers, itemPrefix); + if (followPhpdocumentor) { + DocRenderer.PHPDocExtractor.UNIT_TEST_INHERITDOC_FOR_PHPDOCUMENTER = false; + } + } + @Override protected Map createClassPathsForTest() { return Collections.singletonMap(