use of com.stardust.automator.UiGlobalSelector in project Auto.js by hyb1996.
the class CodeGenerator method generateCode.
protected String generateCode(UiSelectorGenerator generator, UiObject root, UiObject target, int maxParentLevel, int maxChildrenLevel, boolean withFind) {
String selector;
if (withFind) {
selector = generator.generateSelectorCode();
} else {
UiGlobalSelector s = generator.generateSelector();
selector = s == null ? null : s.toString();
}
if (selector != null) {
return selector;
}
if (maxChildrenLevel > 0) {
for (int i = 0; i < target.childCount(); i++) {
UiObject child = target.child(i);
if (child == null)
continue;
String childCode = generateCode(root, child, 0, maxChildrenLevel - 1);
if (childCode != null) {
return childCode + ".parent()";
}
}
}
if (maxParentLevel > 0 && target.parent() != null) {
int index = target.indexInParent();
if (index > 0) {
String parentCode = generateCode(root, target.parent(), maxParentLevel - 1, 0);
if (parentCode != null) {
return parentCode + "child(" + index + ")";
}
}
}
return null;
}
Aggregations