use of com.intellij.psi.PsiReference in project smali by JesusFreke.
the class UsageTypeTest method doTest.
protected void doTest(@NotNull String fileName, @NotNull String text, @NotNull Object... expectedUsageTypes) throws Exception {
Assert.assertTrue(expectedUsageTypes.length % 2 == 0);
Map<Integer, UsageType> expectedUsageTypesMap = Maps.newHashMap();
for (int i = 0; i < expectedUsageTypes.length; i += 2) {
expectedUsageTypesMap.put((Integer) expectedUsageTypes[i], (UsageType) expectedUsageTypes[i + 1]);
}
PsiFile psiFile = createFile(fileName, REF_PATTERN.matcher(text).replaceAll(""));
Map<Integer, Integer> refIndexMap = getRefIndexes(text);
for (Map.Entry<Integer, Integer> entry : refIndexMap.entrySet()) {
int refId = entry.getKey();
int index = entry.getValue();
PsiReference reference = psiFile.getFirstChild().findReferenceAt(index);
Assert.assertNotNull(reference);
if (reference instanceof PsiMultiReference) {
// If there are multiple reference parents, the default seems to be the last one,
// i.e. the highest parent. We actually want the lowest one here.
reference = ((PsiMultiReference) reference).getReferences()[0];
}
UsageType usageType = usageTypeProvider.getUsageType(reference.getElement());
Assert.assertNotNull(usageType);
Assert.assertSame(expectedUsageTypesMap.get(refId), usageType);
expectedUsageTypesMap.remove(refId);
}
Assert.assertTrue(expectedUsageTypesMap.isEmpty());
}
use of com.intellij.psi.PsiReference in project smali by JesusFreke.
the class MethodReferenceTest method testSmaliReferenceFromJava.
/**
* Test a reference to a smali method from a java class
*/
public void testSmaliReferenceFromJava() throws Exception {
createFile("blarg.smali", ".class public Lblarg; .super Ljava/lang/Object;" + ".method public static blort(ILjava/lang/String;)V\n" + " .locals 0\n" + " return-void\n" + ".end method\n");
String text = "public class blah { public static void something() {" + "blarg.bl<ref>ort(10, \"bob\");" + "}}";
PsiReference methodReference = configureByFileText(text, "blah.java");
Assert.assertNotNull(methodReference);
PsiMethod resolvedMethod = (PsiMethod) methodReference.resolve();
Assert.assertNotNull(resolvedMethod);
Assert.assertEquals("blort", resolvedMethod.getName());
Assert.assertNotNull(resolvedMethod.getContainingClass());
Assert.assertEquals("blarg", resolvedMethod.getContainingClass().getQualifiedName());
Assert.assertEquals(2, resolvedMethod.getParameterList().getParametersCount());
Assert.assertEquals("int", resolvedMethod.getParameterList().getParameters()[0].getType().getCanonicalText());
Assert.assertEquals("java.lang.String", resolvedMethod.getParameterList().getParameters()[1].getType().getCanonicalText());
Assert.assertNotNull(resolvedMethod.getReturnType());
Assert.assertEquals("void", resolvedMethod.getReturnType().getCanonicalText());
}
use of com.intellij.psi.PsiReference in project smali by JesusFreke.
the class ClassReferenceTest method testSmaliReferenceFromJava.
/**
* Test a reference to a smali class from a java class
*/
public void testSmaliReferenceFromJava() throws Exception {
createFile("blarg.smali", ".class public Lblarg; .super Ljava/lang/Object;");
PsiReference reference = configureByFileText("public class blah extends bla<ref>rg { }", "blah.java");
SmaliClass smaliClass = (SmaliClass) reference.resolve();
Assert.assertNotNull(smaliClass);
Assert.assertEquals("blarg", smaliClass.getQualifiedName());
}
use of com.intellij.psi.PsiReference in project intellij-elixir by KronicDeth.
the class Issue480Test method assertResolvedNameArityRange.
private void assertResolvedNameArityRange(@NotNull PsiElement element, @NotNull String name, int arity) {
PsiReference reference = element.getReference();
assertNotNull(reference);
PsiElement resolved = reference.resolve();
assertNotNull(resolved);
assertInstanceOf(resolved, ElixirIdentifier.class);
PsiElement maybeDefMaybeCall = resolved.getParent().getParent().getParent();
assertInstanceOf(maybeDefMaybeCall, Call.class);
Call maybeDefCall = (Call) maybeDefMaybeCall;
assertTrue(CallDefinitionClause.is(maybeDefCall));
assertEquals(pair(name, new IntRange(arity)), nameArityRange(maybeDefCall));
}
use of com.intellij.psi.PsiReference in project intellij-elixir by KronicDeth.
the class Issue480Test method assertUnresolvableReferenceNameArityRange.
/*
* Private Instance Methods
*/
private void assertUnresolvableReferenceNameArityRange(@NotNull String name, int arity) {
PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(elementAtCaret);
PsiElement grandParent = elementAtCaret.getParent().getParent();
assertNotNull(grandParent);
assertInstanceOf(grandParent, Call.class);
Call grandParentCall = (Call) grandParent;
assertEquals(name, grandParentCall.functionName());
assertEquals(arity, grandParentCall.resolvedFinalArity());
PsiReference reference = grandParent.getReference();
assertNotNull(reference);
PsiElement resolved = reference.resolve();
assertNull(resolved);
}
Aggregations