Skip to content

Commit

Permalink
Merge pull request #41 from Haehnchen/hotfix/ide-freeze-2
Browse files Browse the repository at this point in the history
another fix for ide freeze
  • Loading branch information
adrienbrault committed Apr 25, 2013
2 parents 02f2959 + 64a3318 commit 3313c1d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
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
@@ -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

0 comments on commit 3313c1d

Please sign in to comment.