Skip to content

Commit

Permalink
Remove getLifecycle from Component and Section
Browse files Browse the repository at this point in the history
Summary:
No longer needed as they already extend Lifecycle.

Done using `codemod -d . --extensions java,html,md '\.getLifecycle\(\)' ''` (mostly)

Reviewed By: passy

Differential Revision: D6485679

fbshipit-source-id: ae50375f94b57f75265a21f8661ac879dd314b15
  • Loading branch information
IanChilds authored and facebook-github-bot committed Dec 5, 2017
1 parent 50d0f94 commit 03bf1a5
Show file tree
Hide file tree
Showing 28 changed files with 118 additions and 152 deletions.
2 changes: 1 addition & 1 deletion docs/_docs/sections-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Testing other lifecycle methods is as simple as calling the lifecycle method wit
Section<VerySimpleGroupSection> s = mTester.prepare(
VerySimpleGroupSection.create(mTester.getContext()).numberOfDummy(4).build());

s.getLifecycle().dataBound(mTester.getScopedContext(s), s);
s.dataBound(mTester.getScopedContext(s), s);

VerySimpleGroupSection.VerySimpleGroupSectionStateContainerImpl stateContainer =
mTester.getStateContainer(s);
Expand Down
4 changes: 2 additions & 2 deletions docs/javadoc/deprecated-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ <h2 title="Contents">Contents</h2>
<td class="colOne"><a href="com/facebook/litho/Component.html#getEventDispatcher--">com.facebook.litho.Component.getEventDispatcher()</a></td>
</tr>
<tr class="altColor">
<td class="colOne"><a href="com/facebook/litho/Component.html#getLifecycle--">com.facebook.litho.Component.getLifecycle()</a></td>
<td class="colOne"><a href="com/facebook/litho/Component.html#getLifecycle--">com.facebook.litho.Component</a></td>
</tr>
<tr class="rowColor">
<td class="colOne"><a href="com/facebook/litho/sections/Section.html#getLifecycle--">com.facebook.litho.sections.Section.getLifecycle()</a></td>
<td class="colOne"><a href="com/facebook/litho/sections/Section.html#getLifecycle--">com.facebook.litho.sections.Section</a></td>
</tr>
<tr class="altColor">
<td class="colOne"><a href="com/facebook/litho/ComponentHost.html#removeAllViewsInLayout--">com.facebook.litho.ComponentHost.removeAllViewsInLayout()</a></td>
Expand Down
9 changes: 2 additions & 7 deletions litho-core/src/main/java/com/facebook/litho/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ protected Component(Class classType) {
}
}

@Deprecated
public ComponentLifecycle getLifecycle() {
return this;
}

/**
* Mostly used by logging to provide more readable messages.
*/
Expand Down Expand Up @@ -409,7 +404,7 @@ void generateKey(ComponentContext c) {
void applyStateUpdates(ComponentContext c) {
setScopedContext(ComponentContext.withComponentScope(c, this));

getLifecycle().populateTreeProps(this, getScopedContext().getTreeProps());
populateTreeProps(this, getScopedContext().getTreeProps());

if (ComponentsConfiguration.useGlobalKeys) {
final KeyHandler keyHandler = getScopedContext().getKeyHandler();
Expand All @@ -419,7 +414,7 @@ void applyStateUpdates(ComponentContext c) {
}
}

if (getLifecycle().hasState()) {
if (hasState()) {
c.getStateHandler().applyStateUpdatesForComponent(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void onInitializeAccessibilityNodeInfo(
// the root host view's as they are meant to behave as a single
// node in the accessibility framework.
final Component component = mountItem.getComponent();
component.getLifecycle().onPopulateAccessibilityNode(node, component);
component.onPopulateAccessibilityNode(node, component);
} else {
super.onInitializeAccessibilityNodeInfo(host, node);
}
Expand All @@ -91,8 +91,7 @@ protected void getVisibleVirtualViews(List<Integer> virtualViewIds) {

final Component component = mountItem.getComponent();

final int extraAccessibilityNodesCount =
component.getLifecycle().getExtraAccessibilityNodesCount(component);
final int extraAccessibilityNodesCount = component.getExtraAccessibilityNodesCount(component);

// Expose extra accessibility nodes declared by the component to the
// accessibility framework. The actual nodes will be populated in
Expand Down Expand Up @@ -120,7 +119,7 @@ protected void onPopulateNodeForVirtualView(
final Rect bounds = drawable.getBounds();

final Component component = mountItem.getComponent();
final ComponentLifecycle lifecycle = component.getLifecycle();
final ComponentLifecycle lifecycle = component;

node.setClassName(lifecycle.getClass().getName());

Expand Down Expand Up @@ -153,7 +152,7 @@ protected int getVirtualViewAt(float x, float y) {
}

final Component component = mountItem.getComponent();
final ComponentLifecycle lifecycle = component.getLifecycle();
final ComponentLifecycle lifecycle = component;

if (lifecycle.getExtraAccessibilityNodesCount(component) == 0) {
return INVALID_ID;
Expand Down Expand Up @@ -196,8 +195,7 @@ protected boolean onPerformActionForVirtualView(
@Override
public AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View host) {
final MountItem mountItem = getAccessibleMountItem(mView);
if (mountItem != null
&& mountItem.getComponent().getLifecycle().implementsExtraAccessibilityNodes()) {
if (mountItem != null && mountItem.getComponent().implementsExtraAccessibilityNodes()) {
return super.getAccessibilityNodeProvider(host);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,8 @@ ComponentLayout.Builder newLayoutBuilder(
component.generateKey(this);
component.applyStateUpdates(this);

final InternalNode node = (InternalNode) component.getLifecycle().createLayout(
component.getScopedContext(),
component,
false);
final InternalNode node =
(InternalNode) component.createLayout(component.getScopedContext(), component, false);
component.getScopedContext().setTreeProps(null);

if (node != NULL_LAYOUT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,7 @@ && implementsVirtualViews()

private boolean implementsVirtualViews() {
MountItem item = getAccessibleMountItem();
return item != null
&& item.getComponent().getLifecycle().implementsExtraAccessibilityNodes();
return item != null && item.getComponent().implementsExtraAccessibilityNodes();
}

public List<CharSequence> getContentDescriptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public interface RenderData {}
public float baseline(YogaNode cssNode, float width, float height) {
final InternalNode node = (InternalNode) cssNode.getData();
return node.getRootComponent()
.getLifecycle()

.onMeasureBaseline(node.getContext(), (int) width, (int) height);
}
};
Expand Down Expand Up @@ -131,13 +131,11 @@ public long measure(
final Size size = acquireSize(Integer.MIN_VALUE /* initialValue */);

try {
component
.getLifecycle()
.onMeasure(node.getContext(), node, widthSpec, heightSpec, size, component);
component.onMeasure(node.getContext(), node, widthSpec, heightSpec, size, component);

if (size.width < 0 || size.height < 0) {
throw new IllegalStateException(
"MeasureOutput not set, ComponentLifecycle is: " + component.getLifecycle());
"MeasureOutput not set, ComponentLifecycle is: " + component);
}

outputWidth = size.width;
Expand Down Expand Up @@ -433,8 +431,9 @@ protected void onMeasure(
Size size,
Component component) {
throw new IllegalStateException(
"You must override onMeasure() if you return true in canMeasure(), " +
"ComponentLifecycle is: " + component.getLifecycle());
"You must override onMeasure() if you return true in canMeasure(), "
+ "ComponentLifecycle is: "
+ component);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion litho-core/src/main/java/com/facebook/litho/DebugDraw.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static void drawMountBoundsCorners(

private static boolean shouldHighlight(Component component) {
// Don't highlight bounds of background/foreground components.
return !(component.getLifecycle() instanceof DrawableComponent);
return !(component instanceof DrawableComponent);
}

private static int dipToPixels(Resources res, int dips) {
Expand Down
4 changes: 2 additions & 2 deletions litho-core/src/main/java/com/facebook/litho/InternalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2035,8 +2035,8 @@ static void assertContextSpecificStyleNotSet(InternalNode node) {

if (errorTypes != null) {
final CharSequence errorStr = TextUtils.join(", ", errorTypes);
throw new IllegalStateException("You should not set " + errorStr + " to a root layout in "
+ node.getRootComponent().getLifecycle());
throw new IllegalStateException(
"You should not set " + errorStr + " to a root layout in " + node.getRootComponent());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void checkIsDuplicateKey(Component component) {
"Found another " + component.getSimpleName() + " Component with the same key.";
final String errorMessage = mLogger == null ? message : getDuplicateKeyMessage();

if (component.getLifecycle().hasState()) {
if (component.hasState()) {
throw new RuntimeException(message + "\n" + errorMessage);
}

Expand Down
28 changes: 11 additions & 17 deletions litho-core/src/main/java/com/facebook/litho/LayoutState.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private static LayoutOutput createGenericLayoutOutput(
final Component component = node.getRootComponent();

// Skip empty nodes and layout specs because they don't mount anything.
if (component == null || component.getLifecycle().getMountType() == NONE) {
if (component == null || component.getMountType() == NONE) {
return null;
}

Expand Down Expand Up @@ -344,7 +344,7 @@ private static LayoutOutput createLayoutOutput(

layoutOutput.setFlags(flags);

final ComponentLifecycle lifecycle = component.getLifecycle();
final ComponentLifecycle lifecycle = component;
if (isEligibleForCreatingDisplayLists() && lifecycle.shouldUseDisplayList()) {
layoutOutput.initDisplayListContainer(
lifecycle.getClass().getSimpleName(),
Expand Down Expand Up @@ -438,7 +438,7 @@ private static boolean hasViewContent(InternalNode node, LayoutState layoutState

final boolean implementsAccessibility =
(nodeInfo != null && nodeInfo.hasAccessibilityHandlers())
|| (component != null && component.getLifecycle().implementsAccessibility());
|| (component != null && component.implementsAccessibility());

final int importantForAccessibility = node.getImportantForAccessibility();

Expand Down Expand Up @@ -644,7 +644,7 @@ private static void collectResults(
// 3. Now add the MountSpec (either View or Drawable) to the Outputs.
if (isMountSpec(component)) {
// Notify component about its final size.
component.getLifecycle().onBoundsDefined(layoutState.mContext, node, component);
component.onBoundsDefined(layoutState.mContext, node, component);

addMountableOutput(layoutState, layoutOutput);
addLayoutOutputIdToPositionsMap(
Expand Down Expand Up @@ -865,9 +865,8 @@ private static LayoutOutput addDrawableComponent(
ComponentContext.withComponentScope(node.getContext(), drawableComponent));
final boolean isOutputUpdated;
if (recycle != null) {
isOutputUpdated = !drawableComponent.getLifecycle().shouldComponentUpdate(
recycle.getComponent(),
drawableComponent);
isOutputUpdated =
!drawableComponent.shouldComponentUpdate(recycle.getComponent(), drawableComponent);
} else {
isOutputUpdated = false;
}
Expand Down Expand Up @@ -933,10 +932,7 @@ private static LayoutOutput addDrawableLayoutOutput(
long previousId,
boolean isCachedOutputUpdated) {

drawableComponent.getLifecycle().onBoundsDefined(
layoutState.mContext,
node,
drawableComponent);
drawableComponent.onBoundsDefined(layoutState.mContext, node, drawableComponent);

final LayoutOutput drawableLayoutOutput = createDrawableLayoutOutput(
drawableComponent,
Expand Down Expand Up @@ -1226,7 +1222,7 @@ private static void collectDisplayLists(LayoutState layoutState) {

private static boolean shouldCreateDisplayList(LayoutOutput output, Rect rect) {
final Component component = output.getComponent();
final ComponentLifecycle lifecycle = component.getLifecycle();
final ComponentLifecycle lifecycle = component;

if (!lifecycle.shouldUseDisplayList()) {
return false;
Expand Down Expand Up @@ -1286,7 +1282,7 @@ void createDisplayList(LayoutOutput output) {
ComponentsSystrace.beginSection("createDisplayList: " + component.getSimpleName());
}

final ComponentLifecycle lifecycle = component.getLifecycle();
final ComponentLifecycle lifecycle = component;
final DisplayList displayList = DisplayList.createDisplayList(
lifecycle.getClass().getSimpleName());

Expand Down Expand Up @@ -1402,10 +1398,8 @@ static <T extends Component> InternalNode createTree(
createLayoutEvent.addParam(PARAM_COMPONENT, component.getSimpleName());
}

final InternalNode root = (InternalNode) component.getLifecycle().createLayout(
context,
component,
true /* resolveNestedTree */);
final InternalNode root =
(InternalNode) component.createLayout(context, component, true /* resolveNestedTree */);

if (logger != null) {
logger.log(createLayoutEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ private static long calculateLayoutOutputBaseId(
"Level must be non-negative and no greater than " + MAX_LEVEL + " actual level " + level);
}

long componentId = layoutOutput.getComponent() != null ?
layoutOutput.getComponent().getLifecycle().getTypeId() :
0L;
long componentId =
layoutOutput.getComponent() != null ? layoutOutput.getComponent().getTypeId() : 0L;

long componentShifted = componentId << COMPONENT_ID_SHIFT;
long levelShifted = ((long) level) << LEVEL_SHIFT;
Expand All @@ -209,9 +208,8 @@ private static long calculateVisibilityOutputBaseId(
"Level must be non-negative and no greater than " + MAX_LEVEL + " actual level " + level);
}

final long componentId = visibilityOutput.getComponent() != null ?
visibilityOutput.getComponent().getLifecycle().getTypeId() :
0L;
final long componentId =
visibilityOutput.getComponent() != null ? visibilityOutput.getComponent().getTypeId() : 0L;

final long componentShifted = componentId << COMPONENT_ID_SHIFT;
final long levelShifted = ((long) level) << LEVEL_SHIFT;
Expand Down
4 changes: 2 additions & 2 deletions litho-core/src/main/java/com/facebook/litho/MountItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ boolean isAccessible() {
}

return (mNodeInfo != null && mNodeInfo.hasAccessibilityHandlers())
|| mComponent.getLifecycle().implementsAccessibility();
|| mComponent.implementsAccessibility();
}

void release(ComponentContext context) {
// Component hosts are recycled within other hosts instead of the global pool.
if (!ComponentsConfiguration.scrapHostRecyclingForComponentHosts
|| !(mContent instanceof ComponentHost)) {
ComponentsPools.release(context, mComponent.getLifecycle(), mContent);
ComponentsPools.release(context, mComponent, mContent);
}

if (mDisplayListDrawable != null) {
Expand Down
Loading

0 comments on commit 03bf1a5

Please sign in to comment.