Search in sources :

Example 1 with JavaResolveResult

use of com.intellij.psi.JavaResolveResult in project smali by JesusFreke.

the class ClassReferenceTest method testSmaliReferenceFromSmali.

/**
     * Test a reference to a smali class from a smali class
     */
public void testSmaliReferenceFromSmali() throws Exception {
    createFile("blarg.smali", ".class public Lblarg; .super Ljava/lang/Object;");
    SmaliClassTypeElement typeElement = (SmaliClassTypeElement) configureByFileText(".class public Lblah; .super L<ref>blarg;", "blah.smali");
    Assert.assertEquals("blarg", typeElement.getName());
    SmaliClass smaliClass = (SmaliClass) typeElement.resolve();
    Assert.assertNotNull(smaliClass);
    Assert.assertEquals("blarg", smaliClass.getQualifiedName());
    JavaResolveResult resolveResult = typeElement.advancedResolve(false);
    Assert.assertNotNull(resolveResult.getElement());
    Assert.assertEquals("blarg", ((PsiClass) resolveResult.getElement()).getQualifiedName());
    JavaResolveResult[] resolveResults = typeElement.multiResolve(false);
    Assert.assertEquals(1, resolveResults.length);
    Assert.assertNotNull(resolveResults[0].getElement());
    Assert.assertEquals("blarg", ((PsiClass) resolveResults[0].getElement()).getQualifiedName());
}
Also used : SmaliClass(org.jf.smalidea.psi.impl.SmaliClass) SmaliClassTypeElement(org.jf.smalidea.psi.impl.SmaliClassTypeElement) JavaResolveResult(com.intellij.psi.JavaResolveResult)

Example 2 with JavaResolveResult

use of com.intellij.psi.JavaResolveResult in project smali by JesusFreke.

the class ClassReferenceTest method testJavaReferenceFromSmali.

/**
     * Test a reference to a java class from a smali class
     */
public void testJavaReferenceFromSmali() throws Exception {
    SmaliClassTypeElement typeElement = (SmaliClassTypeElement) configureByFileText(".class public Lblah; .super L<ref>java/lang/Object;", "blah.smali");
    Assert.assertNotNull(typeElement);
    Assert.assertEquals("Object", typeElement.getName());
    PsiClass psiClass = typeElement.resolve();
    Assert.assertNotNull(psiClass);
    Assert.assertEquals("java.lang.Object", psiClass.getQualifiedName());
    JavaResolveResult resolveResult = typeElement.advancedResolve(false);
    Assert.assertNotNull(resolveResult.getElement());
    Assert.assertEquals("java.lang.Object", ((PsiClass) resolveResult.getElement()).getQualifiedName());
    JavaResolveResult[] resolveResults = typeElement.multiResolve(false);
    Assert.assertEquals(1, resolveResults.length);
    Assert.assertNotNull(resolveResults[0].getElement());
    Assert.assertEquals("java.lang.Object", ((PsiClass) resolveResults[0].getElement()).getQualifiedName());
}
Also used : SmaliClassTypeElement(org.jf.smalidea.psi.impl.SmaliClassTypeElement) PsiClass(com.intellij.psi.PsiClass) JavaResolveResult(com.intellij.psi.JavaResolveResult)

Example 3 with JavaResolveResult

use of com.intellij.psi.JavaResolveResult in project intellij-community by JetBrains.

the class ResolveVariableUtil method resolveVariable.

public static PsiVariable resolveVariable(@NotNull PsiJavaCodeReferenceElement ref, boolean[] problemWithAccess, boolean[] problemWithStatic) {
    /*
    long time1 = System.currentTimeMillis();
    */
    final VariableResolverProcessor processor = new VariableResolverProcessor(ref, ref.getContainingFile());
    PsiScopesUtil.resolveAndWalk(processor, ref, null);
    /*
    long time2 = System.currentTimeMillis();
    Statistics.resolveVariableTime += (time2 - time1);
    Statistics.resolveVariableCount++;
    */
    final JavaResolveResult[] result = processor.getResult();
    if (result.length != 1)
        return null;
    final PsiVariable refVar = (PsiVariable) result[0].getElement();
    if (problemWithAccess != null) {
        problemWithAccess[0] = !result[0].isAccessible();
    }
    if (problemWithStatic != null) {
        problemWithStatic[0] = !result[0].isStaticsScopeCorrect();
    }
    return refVar;
}
Also used : PsiVariable(com.intellij.psi.PsiVariable) JavaResolveResult(com.intellij.psi.JavaResolveResult)

Aggregations

JavaResolveResult (com.intellij.psi.JavaResolveResult)3 SmaliClassTypeElement (org.jf.smalidea.psi.impl.SmaliClassTypeElement)2 PsiClass (com.intellij.psi.PsiClass)1 PsiVariable (com.intellij.psi.PsiVariable)1 SmaliClass (org.jf.smalidea.psi.impl.SmaliClass)1