mirror of
https://github.com/revanced/smali.git
synced 2025-05-29 04:10:13 +02:00
Use createTypeFromText instead of createTypebyFQClassName
createTypeByFQClassName doesn't correctly handle primitive types
This commit is contained in:
parent
29a71371ad
commit
99d0803eda
@ -101,7 +101,7 @@ public class SmaliField extends SmaliStubBasedPsiElement<SmaliFieldStub> impleme
|
|||||||
if (typeElement == null) {
|
if (typeElement == null) {
|
||||||
// If we don't have a type (i.e. syntax error), use Object as a safe-ish fallback
|
// If we don't have a type (i.e. syntax error), use Object as a safe-ish fallback
|
||||||
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||||
return factory.createTypeByFQClassName("java.lang.Object", getResolveScope());
|
return factory.createTypeFromText("java.lang.Object", this);
|
||||||
}
|
}
|
||||||
return getTypeElement().getType();
|
return getTypeElement().getType();
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public class SmaliMethodPrototype extends SmaliStubBasedPsiElement<SmaliMethodPr
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||||
return factory.createTypeByFQClassName(returnType, getResolveScope());
|
return factory.createTypeFromText(returnType, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiTypeElement returnTypeElement = getReturnTypeElement();
|
PsiTypeElement returnTypeElement = getReturnTypeElement();
|
||||||
|
@ -33,6 +33,7 @@ package org.jf.smalidea;
|
|||||||
|
|
||||||
import com.intellij.debugger.SourcePosition;
|
import com.intellij.debugger.SourcePosition;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.PsiPrimitiveType;
|
||||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||||
import org.jf.dexlib2.Opcode;
|
import org.jf.dexlib2.Opcode;
|
||||||
import org.jf.smalidea.psi.impl.*;
|
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.getReferencedTypes().length);
|
||||||
Assert.assertEquals(0, throwsList.getReferenceElements().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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user