Skip to content

Commit

Permalink
support Doc Tag support in constructors
Browse files Browse the repository at this point in the history
#add PHP test class
  • Loading branch information
podhy committed Sep 14, 2017
1 parent e8b8508 commit a8b23a6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/de/espend/idea/php/toolbox/matcher/php/docTag/PhpDocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ public static Collection<PhpDocParamTag> getDocTagsForScope(@NotNull PsiElement
}

PsiElement parent = parameterList.getParent();
if(!(parent instanceof FunctionReference)) {
return null;
}

FunctionReference methodReference = (FunctionReference) parent;
PsiReference psiReference = methodReference.getReference();
if (null == psiReference) {
PsiReference psiReference = getElementReference(parent);
if (psiReference == null) {
return null;
}

Expand All @@ -63,7 +58,9 @@ public static Collection<PhpDocParamTag> getDocTagsForScope(@NotNull PsiElement
Parameter parameter = implementedParameters[currentIndex.getIndex()];
PsiElement implementedParameterList = parameter.getContext();

if(implementedParameterList instanceof ParameterList) {
if(implementedParameterList instanceof ParameterList
|| implementedParameterList instanceof Method
) {
PhpDocParamTag phpDocParamTag = parameter.getDocTag();
if(phpDocParamTag != null) {
phpDocParamTags.add(phpDocParamTag);
Expand All @@ -81,6 +78,16 @@ public static Collection<PhpDocParamTag> getDocTagsForScope(@NotNull PsiElement
return phpDocParamTags;
}

private static PsiReference getElementReference(PsiElement element) {
if (element instanceof NewExpression) {
return ((NewExpression) element).getClassReference();
} else if (element instanceof FunctionReference) {
return element.getReference();
} else {
return null;
}
}

private static Method[] getImplementedMethods(@NotNull Method method) {
ArrayList<Method> items = getImplementedMethods(method.getContainingClass(), method, new ArrayList<>());
return items.toArray(new Method[items.size()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public void testFunctionSupport() {
assertCompletionContains(PhpFileType.INSTANCE, "<?php car(null, '<caret>');", "DateTime");
assertCompletionNotContains(PhpFileType.INSTANCE, "<?php car('<caret>');", "DateTime");
}

public void testConstructorSupport() {
assertCompletionContains(PhpFileType.INSTANCE, "<?php new \\TestClass('<caret>', null);", "DateTime");
assertCompletionNotContains(PhpFileType.INSTANCE, "<?php new \\TestClass(null, '<caret>');", "DateTime");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ class DateTime
{
public function format($foobar) {}
}

class TestClass
{
/**
* @param string $var #Class
*/
public function __construct($var, $foo)
{
}
}
}

0 comments on commit a8b23a6

Please sign in to comment.