Use createTypeFromText instead of createTypebyFQClassName

createTypeByFQClassName doesn't correctly handle primitive types
This commit is contained in:
Ben Gruver 2015-03-21 13:39:58 -07:00
parent 29a71371ad
commit 99d0803eda
3 changed files with 21 additions and 2 deletions

View File

@ -101,7 +101,7 @@ public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> impleme
if (typeElement == null) {
// If we don't have a type (i.e. syntax error), use Object as a safe-ish fallback
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
return factory.createTypeByFQClassName("java.lang.Object", getResolveScope());
return factory.createTypeFromText("java.lang.Object", this);
}
return getTypeElement().getType();
}

View File

@ -59,7 +59,7 @@ public class SmaliMethodPrototype extends SmaliStubBasedPsiElement<SmaliMethodPr
return null;
}
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
return factory.createTypeByFQClassName(returnType, getResolveScope());
return factory.createTypeFromText(returnType, this);
}
PsiTypeElement returnTypeElement = getReturnTypeElement();

View File

@ -33,6 +33,7 @@ package org.jf.smalidea;
import com.intellij.debugger.SourcePosition;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPrimitiveType;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jf.dexlib2.Opcode;
import org.jf.smalidea.psi.impl.*;
@ -287,4 +288,22 @@ public class SmaliMethodTest extends LightCodeInsightFixtureTestCase {
Assert.assertEquals(0, throwsList.getReferencedTypes().length);
Assert.assertEquals(0, throwsList.getReferenceElements().length);
}
public void testPrimitiveReturnType() {
String text = "" +
".class public Lmy/pkg/blah; .super Ljava/lang/Object;\n" +
".method blah()I\n" +
" .registers 123\n" +
" return-void\n" +
".end method";
SmaliFile file = (SmaliFile)myFixture.addFileToProject("my/pkg/blah.smali", text);
SmaliClass smaliClass = file.getPsiClass();
Assert.assertNotNull(smaliClass);
SmaliMethod smaliMethod = smaliClass.getMethods()[0];
Assert.assertNotNull(smaliMethod.getReturnType());
Assert.assertTrue(smaliMethod.getReturnType().isConvertibleFrom(PsiPrimitiveType.INT));
Assert.assertTrue(smaliMethod.getReturnType().isAssignableFrom(PsiPrimitiveType.INT));
}
}