Skip to content
Merged
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 @@ -2,7 +2,6 @@

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.Method;
import com.jetbrains.php.lang.psi.elements.MethodReference;
Expand Down Expand Up @@ -59,15 +58,34 @@ protected boolean isCallTo(PsiElement e, Method[] expectedMethods, int deepness)
return false;
}

PhpClass methodClass = PsiTreeUtil.getParentOfType(e, PhpClass.class);
if(null == methodClass) {
// resolve is also called on invalid php code like "use <xxx>"
// so double check the method name before resolve the method
if(!isMatchingMethodName(methodRef, expectedMethods)) {
return false;
}

PsiElement resolvedReference = methodRef.getReference().resolve();
if (!(resolvedReference instanceof Method)) {
return false;
}

Method method = (Method) resolvedReference;
PhpClass methodClass = method.getContainingClass();

for (Method expectedMethod : Arrays.asList(expectedMethods)) {
if (null != expectedMethod
&& expectedMethod.getName().equals(methodRef.getName())
&& isInstanceOf(methodClass, expectedMethod.getContainingClass())) {
&& expectedMethod.getName().equals(method.getName())
&& isInstanceOf(methodClass, expectedMethod.getContainingClass())) {
return true;
}
}

return false;
}

protected boolean isMatchingMethodName(MethodReference methodRef, Method[] expectedMethods) {
for (Method expectedMethod : Arrays.asList(expectedMethods)) {
if(expectedMethod != null && expectedMethod.getName().equals(methodRef.getName())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fr.adrienbrault.idea.symfony2plugin.dic;

import com.intellij.openapi.project.DumbService;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.lang.parser.PhpElementTypes;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.jetbrains.php.lang.psi.resolve.types.PhpType;
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider;
Expand All @@ -26,6 +28,22 @@ public PhpType getType(PsiElement e) {
return null;
}

// filter out method calls without parameter
// $this->get('service_name')
if(!PlatformPatterns.psiElement(PhpElementTypes.METHOD_REFERENCE).withChild(
PlatformPatterns.psiElement(PhpElementTypes.PARAMETER_LIST).withFirstChild(
PlatformPatterns.psiElement(PhpElementTypes.STRING))).accepts(e)) {

return null;
}

// container calls are only on "get" methods
// cant we move it up to PlatformPatterns? withName condition dont looks working
String methodRefName = ((MethodReference) e).getName();
if(methodRefName == null || !methodRefName.equals("get")) {
return null;
}

depth++;
if (depth > 2) {
// Try to avoid too much recursive things ...
Expand Down