check if android metadata is present before inlining property
This commit is contained in:
committed by
Yan Zhulanow
parent
79cbfcd750
commit
35b1cb4fc7
@@ -1889,19 +1889,21 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
|
||||
JetFile file = DescriptorToSourceUtils.getContainingFile(propertyDescriptor);
|
||||
if (file != null && file.getName() == "ANDROIDXML.kt") {
|
||||
if (file != null && file.getName() == AndroidConst.SYNTHETIC_FILENAME) {
|
||||
|
||||
String userData = (String) file.getUserData(AndroidConst.ANDROID_SYNTHETIC);
|
||||
String androidPackage = file.getUserData(AndroidConst.ANDROID_USER_PACKAGE);
|
||||
String userData = file.getUserData(AndroidConst.ANDROID_SYNTHETIC);
|
||||
if (userData != null && userData.equals("OK")) {
|
||||
String androidPackage = file.getUserData(AndroidConst.ANDROID_USER_PACKAGE);
|
||||
|
||||
Type retType = typeMapper.mapType(propertyDescriptor.getReturnType());
|
||||
v.load(0, Type.getType("Landroid/app/Activity;"));
|
||||
v.getstatic(androidPackage.replace(".", "/") + "/R$id",
|
||||
propertyDescriptor.getName().asString(), "I");
|
||||
v.invokevirtual("android/app/Activity", "findViewById", "(I)" + "Landroid/view/View;");
|
||||
v.checkcast(retType);
|
||||
Type retType = typeMapper.mapType(propertyDescriptor.getReturnType());
|
||||
v.load(0, Type.getType("Landroid/app/Activity;"));
|
||||
v.getstatic(androidPackage.replace(".", "/") + "/R$id",
|
||||
propertyDescriptor.getName().asString(), "I");
|
||||
v.invokevirtual("android/app/Activity", "findViewById", "(I)" + "Landroid/view/View;", false);
|
||||
v.checkcast(retType);
|
||||
|
||||
return StackValue.onStack(retType);
|
||||
return StackValue.onStack(retType);
|
||||
}
|
||||
}
|
||||
|
||||
boolean directToField =
|
||||
|
||||
@@ -21,4 +21,5 @@ import com.intellij.openapi.util.Key;
|
||||
public class AndroidConst {
|
||||
public static final Key<String> ANDROID_SYNTHETIC = Key.create("ANDROID_SYNTHETIC");
|
||||
public static final Key<String> ANDROID_USER_PACKAGE = Key.create("ANDROID_USER_PACKAGE");
|
||||
public static final String SYNTHETIC_FILENAME = "ANDROIDXML.kt";
|
||||
}
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ abstract class AndroidUIXmlParser {
|
||||
if (cacheState == null) return null
|
||||
return if (cacheState == CacheAction.MISS || lastCachedPsi == null) {
|
||||
try {
|
||||
val vf = LightVirtualFile("ANDROIDXML.kt", renderString())
|
||||
val vf = LightVirtualFile(SYNTHETIC_FILENAME, renderString())
|
||||
val psiFile = PsiManager.getInstance(project).findFile(vf) as JetFile
|
||||
psiFile.putUserData(ANDROID_SYNTHETIC, "OK")
|
||||
psiFile.putUserData(ANDROID_USER_PACKAGE, androidAppPackage)
|
||||
|
||||
Reference in New Issue
Block a user