TestComponent(Component component) { super(component.getSimpleName()); mWrappedComponent = component; }
@Override public String getName() { return mComponent.getSimpleName(); }
@Nullable public synchronized String getSimpleName() { return mRoot == null ? null : mRoot.getSimpleName(); }
/** @return A simpler canonical name for this component. Suitable to present to the user. */ public String getSimpleName() { return mComponent.getComponent().getSimpleName(); }
CreateLayoutException(Component c, Throwable cause) { super(c.getSimpleName()); initCause(cause); setStackTrace(new StackTraceElement[0]); } }
private static String getMountItemName(MountItem mountItem) { String traceName = mountItem.getComponent().getSimpleName(); if (mountItem.getMountableContent() instanceof DisplayListDrawable) { traceName += "DL"; } return traceName; }
private void logDuplicateManualKeyWarning(Component component, String key) { final ComponentsLogger logger = mScopedContext.getLogger(); if (logger != null) { logger.emitMessage( ComponentsLogger.LogLevel.WARNING, "The manual key " + key + " you are setting on this " + component.getSimpleName() + " is a duplicate and will be changed into a unique one. " + "This will result in unexpected behavior if you don't change it."); } }
private void recordRenderData(Component component) { if (!component.needsPreviousRenderData()) { throw new RuntimeException( "Trying to record previous render data for component that doesn't support it"); } final String key = component.getGlobalKey(); // Sanity check like in StateHandler if (mSeenGlobalKeys.contains(key)) { // We found two components with the same global key. throw new RuntimeException( "Cannot record previous render data for " + component.getSimpleName() + ", found another Component with the same key: " + key); } mSeenGlobalKeys.add(key); final ComponentLifecycle.RenderData existingInfo = mRenderData.get(key); final ComponentLifecycle.RenderData newInfo = component.recordRenderData(existingInfo); mRenderData.put(key, newInfo); }
sb.append(debugComponent.getComponent().getSimpleName());
private void checkIsDuplicateKey(Component component) { if (mKnownGlobalKeys.contains(component.getGlobalKey())) { final String message = "Found another " + component.getSimpleName() + " Component with the same key: " + component.getKey(); final String errorMessage = mLogger == null ? message : getDuplicateKeyMessage(); if (component.hasState()) { throw new RuntimeException(message + "\n" + errorMessage); } if (mLogger != null) { mLogger.emitMessage(ComponentsLogger.LogLevel.ERROR, message + "\n" + errorMessage); } } }
private String generateKey(ComponentContext parentContext) { final Component parentScope = parentContext.getComponentScope(); final String key = getKey(); final String globalKey; if (parentScope == null) { globalKey = key; } else { if (parentScope.getGlobalKey() == null) { final ComponentsLogger logger = parentContext.getLogger(); if (logger != null) { logger.emitMessage( ComponentsLogger.LogLevel.ERROR, "Trying to generate parent-based key for component " + getSimpleName() + " , but parent " + parentScope.getSimpleName() + " has a null global key \"." + " This is most likely a configuration mistake, check the value of ComponentsConfiguration.useGlobalKeys."); } globalKey = "null" + key; } else { globalKey = parentScope.generateUniqueGlobalKeyForChild(this, key); } } return globalKey; }
@ThreadSafe(enableChecks = false) void preAllocateMountContent(boolean shouldPreallocatePerMountSpec) { final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection("preAllocateMountContent:" + mComponent.getSimpleName()); } if (mMountableOutputs != null && !mMountableOutputs.isEmpty()) { for (int i = 0, size = mMountableOutputs.size(); i < size; i++) { final Component component = mMountableOutputs.get(i).getComponent(); if (shouldPreallocatePerMountSpec && !component.canPreallocate()) { continue; } if (Component.isMountViewSpec(component)) { if (isTracing) { ComponentsSystrace.beginSection("preAllocateMountContent:" + component.getSimpleName()); } ComponentsPools.maybePreallocateContent(mContext.getAndroidContext(), component); if (isTracing) { ComponentsSystrace.endSection(); } } } } if (isTracing) { ComponentsSystrace.endSection(); } }
@ThreadSafe(enableChecks = false) public Object createMountContent(Context c) { final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection("createMountContent:" + ((Component) this).getSimpleName()); } try { return onCreateMountContent(c); } finally { if (isTracing) { ComponentsSystrace.endSection(); } } }
private static LayoutOutput createDrawableLayoutOutput( Component component, LayoutState layoutState, InternalNode node, boolean hasHostView) { final boolean isTracing = ComponentsSystrace.isTracing(); try { if (isTracing) { ComponentsSystrace.beginSection("createDrawableLayoutOutput:" + component.getSimpleName()); } return createLayoutOutput( component, layoutState, node, false /* useNodePadding */, IMPORTANT_FOR_ACCESSIBILITY_NO, layoutState.mShouldDuplicateParentState, hasHostView, false); } finally { if (isTracing) { ComponentsSystrace.endSection(); } } }
/** Set a key on the component that is local to its parent. */ public T key(@Nullable String key) { if (key == null) { final ComponentsLogger logger = mContext.getLogger(); if (logger != null) { final String componentName = mContext.getComponentScope() != null ? mContext.getComponentScope().getSimpleName() : "unknown component"; final String message = "Setting a null key from " + componentName + " which is usually a mistake! If it is not, explicitly set the String 'null'"; logger.emitMessage(ComponentsLogger.LogLevel.ERROR, message); } key = "null"; } mComponent.setKey(key); return getThis(); }
void bind(ComponentContext c, Object mountedContent) { c.enterNoStateUpdatesMethod("bind"); final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection("onBind:" + ((Component) this).getSimpleName()); } try { onBind(c, mountedContent); } finally { if (isTracing) { ComponentsSystrace.endSection(); } } c.exitNoStateUpdatesMethod(); }
@VisibleForTesting static InternalNode createTree( Component component, ComponentContext context) { final ComponentsLogger logger = context.getLogger(); final PerfEvent createLayoutPerfEvent = logger != null ? LogTreePopulator.populatePerfEventFromLogger( context, logger, logger.newPerformanceEvent(EVENT_CREATE_LAYOUT)) : null; if (createLayoutPerfEvent != null) { createLayoutPerfEvent.markerAnnotate(PARAM_COMPONENT, component.getSimpleName()); } final InternalNode root = component.createLayout(context, true /* resolveNestedTree */); if (createLayoutPerfEvent != null) { logger.logPerfEvent(createLayoutPerfEvent); } return root; }
void mount(ComponentContext c, Object convertContent) { c.enterNoStateUpdatesMethod("mount"); final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection("onMount:" + ((Component) this).getSimpleName()); } try { onMount(c, convertContent); } catch (Exception e) { c.exitNoStateUpdatesMethod(); dispatchErrorEvent(c, e); } finally { if (isTracing) { ComponentsSystrace.endSection(); } } c.exitNoStateUpdatesMethod(); }
@Test public void testLayoutOutputsForEnabledFalseDoesntWrap() { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(final ComponentContext c) { return create(c) .child(create(c).child(TestDrawableComponent.create(c).enabled(false))) .build(); } }; final LayoutState layoutState = calculateLayoutState( application, component, -1, makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY)); assertThat(layoutState.getMountableOutputCount()).isEqualTo(2); assertThat(layoutState.getMountableOutputAt(0).getNodeInfo()).isNull(); assertThat(layoutState.getMountableOutputAt(0).getComponent().getSimpleName()) .isEqualTo("HostComponent"); assertThat(layoutState.getMountableOutputAt(1).getComponent().getSimpleName()) .isEqualTo("TestDrawableComponent"); assertThat(MountItem.isTouchableDisabled(layoutState.getMountableOutputAt(1).getFlags())) .isTrue(); }
private static LayoutOutput createHostLayoutOutput( LayoutState layoutState, InternalNode node, boolean isPhantom) { final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection( "createHostLayoutOutput:" + node.getRootComponent().getSimpleName()); } final LayoutOutput hostOutput = createLayoutOutput( HostComponent.create(), layoutState, node, false /* useNodePadding */, node.getImportantForAccessibility(), node.isDuplicateParentStateEnabled(), false, isPhantom); ViewNodeInfo viewNodeInfo = hostOutput.getViewNodeInfo(); if (node.hasStateListAnimatorResSet()) { viewNodeInfo.setStateListAnimatorRes(node.getStateListAnimatorRes()); } else { viewNodeInfo.setStateListAnimator(node.getStateListAnimator()); } if (isTracing) { ComponentsSystrace.endSection(); } return hostOutput; }