diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml index 4fff986..444e457 100644 --- a/META-INF/plugin.xml +++ b/META-INF/plugin.xml @@ -38,6 +38,10 @@ + + + + @@ -79,4 +83,4 @@ com.jetbrains.php com.intellij.modules.platform - \ No newline at end of file + diff --git a/src/org/atoum/intellij/plugin/atoum/MockTypeProvider.java b/src/org/atoum/intellij/plugin/atoum/MockTypeProvider.java new file mode 100644 index 0000000..b4f9623 --- /dev/null +++ b/src/org/atoum/intellij/plugin/atoum/MockTypeProvider.java @@ -0,0 +1,59 @@ +package org.atoum.intellij.plugin.atoum; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.jetbrains.php.lang.psi.elements.*; +import com.jetbrains.php.lang.psi.resolve.types.PhpType; +import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider3; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.Set; + +public class MockTypeProvider implements PhpTypeProvider3 { + + @Override + public char getKey() { + return '\u0102'; + } + + @Nullable + @Override + public PhpType getType(PsiElement psiElement) { + if (psiElement instanceof NewExpression) { + NewExpression expr = (NewExpression) psiElement; + ClassReference ref = expr.getClassReference(); + + if (ref != null && ref.getFQN() != null && ref.getFQN().startsWith("\\mock\\")) { + return new PhpType().add(ref.getFQN().substring("\\mock".length())); + } + } else if (psiElement instanceof MethodReference) { + MethodReference expr = (MethodReference) psiElement; + if (expr.getName() == null || !expr.getName().equals("newMockInstance")) { + return null; + } + + if (expr.getParameters().length == 0) { + return null; + } + + PsiElement param = expr.getParameters()[0]; + + if (param instanceof ClassConstantReference) { + PhpExpression ref = ((ClassConstantReference) param).getClassReference(); + if (ref instanceof ClassReference) { + return new PhpType().add(ref); + } + } else if (param instanceof StringLiteralExpression) { + return new PhpType().add(((StringLiteralExpression) param).getContents()); + } + } + + return null; + } + + @Override + public Collection getBySignature(String s, Set set, int i, Project project) { + return null; + } +}