Java Code Examples for com.facebook.infer.annotation.Assertions#assertNotNull()

The following examples show how to use com.facebook.infer.annotation.Assertions#assertNotNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackagerConnectionSettings.java    From react-native-GPay with MIT License 6 votes vote down vote up
public String getDebugServerHost() {
  // Check host setting first. If empty try to detect emulator type and use default
  // hostname for those
  String hostFromSettings = mPreferences.getString(PREFS_DEBUG_SERVER_HOST_KEY, null);

  if (!TextUtils.isEmpty(hostFromSettings)) {
    return Assertions.assertNotNull(hostFromSettings);
  }

  String host = AndroidInfoHelpers.getServerHost();

  if (host.equals(AndroidInfoHelpers.DEVICE_LOCALHOST)) {
    FLog.w(
      TAG,
      "You seem to be running on device. Run 'adb reverse tcp:8081 tcp:8081' " +
        "to forward the debug server's port to the device.");
  }

  return host;
}
 
Example 2
Source File: TouchEvent.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public boolean canCoalesce() {
  // We can coalesce move events but not start/end events. Coalescing move events should probably
  // append historical move data like MotionEvent batching does. This is left as an exercise for
  // the reader.
  switch (Assertions.assertNotNull(mTouchEventType)) {
    case START:
    case END:
    case CANCEL:
      return false;
    case MOVE:
      return true;
    default:
      throw new RuntimeException("Unknown touch event type: " + mTouchEventType);
  }
}
 
Example 3
Source File: ModuleHolder.java    From react-native-GPay with MIT License 5 votes vote down vote up
@DoNotStrip
public NativeModule getModule() {
  NativeModule module;
  boolean shouldCreate = false;
  synchronized (this) {
    if (mModule != null) {
      return mModule;
    // if mModule has not been set, and no one is creating it. Then this thread should call create
    } else if (!mIsCreating) {
      shouldCreate = true;
      mIsCreating = true;
    } else  {
      // Wait for mModule to be created by another thread
    }
  }
  if (shouldCreate) {
    module = create();
    // Once module is built (and initialized if markInitializable has been called), modify mModule
    // And signal any waiting threads that it is acceptable to read the field now
    synchronized (this) {
      mIsCreating = false;
      this.notifyAll();
    }
    return module;
  } else {
    synchronized (this) {
      // Block waiting for another thread to build mModule instance
      // Since mIsCreating is true until after creation and instantiation (if needed), we wait
      // until the module is ready to use.
      while (mModule == null && mIsCreating) {
        try {
          this.wait();
        } catch (InterruptedException e) {
          continue;
        }
      }
      return Assertions.assertNotNull(mModule);
    }
  }
}
 
Example 4
Source File: ReactViewGroup.java    From react-native-GPay with MIT License 5 votes vote down vote up
private int indexOfChildInAllChildren(View child) {
  final int count = mAllChildrenCount;
  final View[] children = Assertions.assertNotNull(mAllChildren);
  for (int i = 0; i < count; i++) {
    if (children[i] == child) {
      return i;
    }
  }
  return -1;
}
 
Example 5
Source File: XLogSetting.java    From react-native-xlog with MIT License 5 votes vote down vote up
public XLogSetting build() {
    return new XLogSetting(
            level,
            appenderMode,
            cacheDir,
            Assertions.assertNotNull(path),
            Assertions.assertNotNull(namePrefix),
            openConsoleLog);
}
 
Example 6
Source File: ReactShadowNodeImpl.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public final ReactShadowNodeImpl removeNativeChildAt(int i) {
  Assertions.assertNotNull(mNativeChildren);
  ReactShadowNodeImpl removed = mNativeChildren.remove(i);
  removed.mNativeParent = null;
  return removed;
}
 
Example 7
Source File: ReactHorizontalScrollView.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void disableFpsListener() {
  if (isScrollPerfLoggingEnabled()) {
    Assertions.assertNotNull(mFpsListener);
    Assertions.assertNotNull(mScrollPerfTag);
    mFpsListener.disable(mScrollPerfTag);
  }
}
 
Example 8
Source File: ReactViewGroup.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void updateSubviewClipStatus(Rect clippingRect, int idx, int childIndexOffset) {
  View child = Assertions.assertNotNull(mAllChildren)[idx];
  sHelperRect.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
  boolean intersects = clippingRect
      .intersects(sHelperRect.left, sHelperRect.top, sHelperRect.right, sHelperRect.bottom);
  boolean needUpdateClippingRecursive = false;
  // We never want to clip children that are being animated, as this can easily break layout :
  // when layout animation changes size and/or position of views contained inside a listview that
  // clips offscreen children, we need to ensure that, when view exits the viewport, final size
  // and position is set prior to removing the view from its listview parent.
  // Otherwise, when view gets re-attached again, i.e when it re-enters the viewport after scroll,
  // it won't be size and located properly.
  Animation animation = child.getAnimation();
  boolean isAnimating = animation != null && !animation.hasEnded();
  if (!intersects && child.getParent() != null && !isAnimating) {
    // We can try saving on invalidate call here as the view that we remove is out of visible area
    // therefore invalidation is not necessary.
    super.removeViewsInLayout(idx - childIndexOffset, 1);
    needUpdateClippingRecursive = true;
  } else if (intersects && child.getParent() == null) {
    super.addViewInLayout(child, idx - childIndexOffset, sDefaultLayoutParam, true);
    invalidate();
    needUpdateClippingRecursive = true;
  } else if (intersects) {
    // If there is any intersection we need to inform the child to update its clipping rect
    needUpdateClippingRecursive = true;
  }
  if (needUpdateClippingRecursive) {
    if (child instanceof ReactClippingViewGroup) {
      // we don't use {@link sHelperRect} until the end of this loop, therefore it's safe
      // to call this method that may write to the same {@link sHelperRect} object.
      ReactClippingViewGroup clippingChild = (ReactClippingViewGroup) child;
      if (clippingChild.getRemoveClippedSubviews()) {
        clippingChild.updateClippingRect();
      }
    }
  }
}
 
Example 9
Source File: ReactViewGroup.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void updateClippingToRect(Rect clippingRect) {
  Assertions.assertNotNull(mAllChildren);
  int childIndexOffset = 0;
  for (int i = 0; i < mAllChildrenCount; i++) {
    updateSubviewClipStatus(clippingRect, i, childIndexOffset);
    if (!isChildInViewGroup(mAllChildren[i])) {
      childIndexOffset++;
    }
  }
}
 
Example 10
Source File: ReactViewGroup.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void updateClippingRect() {
  if (!mRemoveClippedSubviews) {
    return;
  }

  Assertions.assertNotNull(mClippingRect);
  Assertions.assertNotNull(mAllChildren);

  ReactClippingViewGroupHelper.calculateClippingRect(this, mClippingRect);
  updateClippingToRect(mClippingRect);
}
 
Example 11
Source File: ReactShadowNodeImpl.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public YogaNode cloneNode(YogaNode oldYogaNode,
    YogaNode parent,
    int childIndex) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricReconciler.YogaNodeCloneFunction")
    .flush();
  try {
    ReactShadowNodeImpl parentReactShadowNode = (ReactShadowNodeImpl) parent.getData();
    Assertions.assertNotNull(parentReactShadowNode);
    ReactShadowNodeImpl oldReactShadowNode = (ReactShadowNodeImpl) oldYogaNode.getData();
    Assertions.assertNotNull(oldReactShadowNode);

    if (DEBUG) {
      FLog.d(
        TAG,
        "YogaNode started cloning: oldYogaNode: " + oldReactShadowNode + " - parent: "
          + parentReactShadowNode + " index: " + childIndex);
    }

    ReactShadowNodeImpl newNode = oldReactShadowNode.mutableCopy(oldReactShadowNode.getInstanceHandle());
    parentReactShadowNode.replaceChild(newNode, childIndex);
    return newNode.mYogaNode;
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 12
Source File: ShakeDetector.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Start listening for shakes.
 */
public void start(SensorManager manager) {
  Assertions.assertNotNull(manager);
  Sensor accelerometer = manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  if (accelerometer != null) {
    mSensorManager = manager;
    mLastTimestamp = -1;
    mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI);
    mLastShakeTimestamp = 0;
    reset();
  }
}
 
Example 13
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
  // Rearranging the text (i.e. changing between singleline and multiline attributes) can
  // also trigger onTextChanged, call the event in JS only when the text actually changed
  if (count == 0 && before == 0) {
    return;
  }

  Assertions.assertNotNull(mPreviousText);
  String newText = s.toString().substring(start, start + count);
  String oldText = mPreviousText.substring(start, start + before);
  // Don't send same text changes
  if (count == before && newText.equals(oldText)) {
    return;
  }

  // The event that contains the event counter and updates it must be sent first.
  // TODO: t7936714 merge these events
  mEventDispatcher.dispatchEvent(
      new ReactTextChangedEvent(
          mEditText.getId(),
          s.toString(),
          mEditText.incrementAndGetEventCounter()));

  mEventDispatcher.dispatchEvent(
      new ReactTextInputEvent(
          mEditText.getId(),
          newText,
          oldText,
          start,
          start + before));
}
 
Example 14
Source File: FabricUIManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@DoNotStrip
public synchronized void completeRoot(int rootTag, @Nullable List<ReactShadowNode> childList) {
  SystraceMessage.beginSection(
    Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
    "FabricUIManager.completeRoot")
    .flush();
  try {
    long startTime = SystemClock.uptimeMillis();
    childList = childList == null ? new LinkedList<ReactShadowNode>() : childList;
    if (DEBUG) {
      FLog.d(TAG, "completeRoot rootTag: " + rootTag + ", childList: " + childList);
    }
    ReactShadowNode currentRootShadowNode = getRootNode(rootTag);
    Assertions.assertNotNull(
        currentRootShadowNode,
        "Root view with tag " + rootTag + " must be added before completeRoot is called");

    currentRootShadowNode = calculateDiffingAndCreateNewRootNode(currentRootShadowNode, childList);

    if (DEBUG) {
      FLog.d(
        TAG,
        "ReactShadowNodeHierarchy after diffing: " + currentRootShadowNode.getHierarchyInfo());
    }

    applyUpdatesRecursive(currentRootShadowNode);
    mUIViewOperationQueue.dispatchViewUpdates(
      mCurrentBatch++, startTime, mLastCalculateLayoutTime);

    mRootShadowNodeRegistry.replaceNode(currentRootShadowNode);
  } catch (Exception e) {
    handleException(getRootNode(rootTag), e);
  } finally{
    Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
  }
}
 
Example 15
Source File: ReadableNativeMap.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public ReadableType getType(String name) {
  if (mUseNativeAccessor) {
    mJniCallCounter++;
    return getTypeNative(name);
  }
  if (getLocalTypeMap().containsKey(name)) {
    return Assertions.assertNotNull(getLocalTypeMap().get(name));
  }
  throw new NoSuchKeyException(name);
}
 
Example 16
Source File: DefaultJavaAbiInfo.java    From buck with Apache License 2.0 5 votes vote down vote up
static JarContents load(SourcePathResolverAdapter resolver, SourcePath jarSourcePath)
    throws IOException {
  ImmutableSortedSet<SourcePath> contents;
  Path jarAbsolutePath = resolver.getAbsolutePath(jarSourcePath);
  if (Files.isDirectory(jarAbsolutePath)) {
    BuildTargetSourcePath buildTargetSourcePath = (BuildTargetSourcePath) jarSourcePath;
    contents =
        Files.walk(jarAbsolutePath)
            .filter(path -> !path.endsWith(JarFile.MANIFEST_NAME))
            .map(
                path ->
                    ExplicitBuildTargetSourcePath.of(buildTargetSourcePath.getTarget(), path))
            .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural()));
  } else {
    SourcePath nonNullJarSourcePath = Assertions.assertNotNull(jarSourcePath);
    contents =
        Unzip.getZipMembers(jarAbsolutePath).stream()
            .filter(path -> !path.endsWith(JarFile.MANIFEST_NAME))
            .map(path -> ArchiveMemberSourcePath.of(nonNullJarSourcePath, path))
            .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural()));
  }
  return new JarContents(
      contents,
      contents.stream()
          .map(
              sourcePath -> {
                if (sourcePath instanceof ExplicitBuildTargetSourcePath) {
                  return ((ExplicitBuildTargetSourcePath) sourcePath).getResolvedPath();
                } else {
                  return ((ArchiveMemberSourcePath) sourcePath).getMemberPath();
                }
              })
          .collect(ImmutableSet.toImmutableSet()));
}
 
Example 17
Source File: DisplayMetricsHolder.java    From react-native-GPay with MIT License 5 votes vote down vote up
public static WritableNativeMap getDisplayMetricsNativeMap(double fontScale) {
  Assertions.assertNotNull(
      sWindowDisplayMetrics != null || sScreenDisplayMetrics != null,
      "DisplayMetricsHolder must be initialized with initDisplayMetricsIfNotInitialized or initDisplayMetrics");
  final WritableNativeMap result = new WritableNativeMap();
  result.putMap("windowPhysicalPixels", getPhysicalPixelsNativeMap(sWindowDisplayMetrics, fontScale));
  result.putMap("screenPhysicalPixels", getPhysicalPixelsNativeMap(sScreenDisplayMetrics, fontScale));
  return result;
}
 
Example 18
Source File: ReactAppTestActivity.java    From react-native-GPay with MIT License 4 votes vote down vote up
public View getRootView() {
  return Assertions.assertNotNull(mReactRootView);
}
 
Example 19
Source File: BundleDownloader.java    From react-native-GPay with MIT License 4 votes vote down vote up
private void processBundleResult(
    String url,
    int statusCode,
    Headers headers,
    BufferedSource body,
    File outputFile,
    BundleInfo bundleInfo,
    BundleDeltaClient.ClientType clientType,
    DevBundleDownloadListener callback)
    throws IOException {
  // Check for server errors. If the server error has the expected form, fail with more info.
  if (statusCode != 200) {
    String bodyString = body.readUtf8();
    DebugServerException debugServerException = DebugServerException.parse(bodyString);
    if (debugServerException != null) {
      callback.onFailure(debugServerException);
    } else {
      StringBuilder sb = new StringBuilder();
      sb.append("The development server returned response error code: ").append(statusCode).append("\n\n")
        .append("URL: ").append(url).append("\n\n")
        .append("Body:\n")
        .append(bodyString);
      callback.onFailure(new DebugServerException(sb.toString()));
    }
    return;
  }

  if (bundleInfo != null) {
    populateBundleInfo(url, headers, clientType, bundleInfo);
  }

  File tmpFile = new File(outputFile.getPath() + ".tmp");

  boolean bundleWritten;
  NativeDeltaClient nativeDeltaClient = null;

  if (BundleDeltaClient.isDeltaUrl(url)) {
    // If the bundle URL has the delta extension, we need to use the delta patching logic.
    BundleDeltaClient deltaClient = getBundleDeltaClient(clientType);
    Assertions.assertNotNull(deltaClient);
    Pair<Boolean, NativeDeltaClient> result = deltaClient.processDelta(headers, body, tmpFile);
    bundleWritten = result.first;
    nativeDeltaClient = result.second;
  } else {
    mBundleDeltaClient = null;
    bundleWritten = storePlainJSInFile(body, tmpFile);
  }

  if (bundleWritten) {
    // If we have received a new bundle from the server, move it to its final destination.
    if (!tmpFile.renameTo(outputFile)) {
      throw new IOException("Couldn't rename " + tmpFile + " to " + outputFile);
    }
  }

  callback.onSuccess(nativeDeltaClient);
}
 
Example 20
Source File: ReactShadowNodeImpl.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Override
public final String getViewClass() {
  return Assertions.assertNotNull(mViewClassName);
}