java.lang.Class.desiredAssertionStatus()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(256)

本文整理了Java中java.lang.Class.desiredAssertionStatus()方法的一些代码示例,展示了Class.desiredAssertionStatus()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.desiredAssertionStatus()方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:desiredAssertionStatus

Class.desiredAssertionStatus介绍

[英]Returns the assertion status for the class represented by this Class. Assertion is enabled / disabled based on the class loader, package or class default at runtime.
[中]返回该类表示的类的断言状态。在运行时根据类加载器、包或类默认值启用/禁用断言。

代码示例

代码示例来源:origin: spring-projects/spring-loaded

public static boolean callDesiredAssertionStatus(Class thiz)
{
  return thiz.desiredAssertionStatus();
}

代码示例来源:origin: org.apache.lucene/lucene-core

private boolean assertFinal() {
 try {
  final Class<?> clazz = getClass();
  if (!clazz.desiredAssertionStatus())
   return true;
  assert clazz.isAnonymousClass() ||
   (clazz.getModifiers() & (Modifier.FINAL | Modifier.PRIVATE)) != 0 ||
   Modifier.isFinal(clazz.getMethod("incrementToken").getModifiers()) :
   "TokenStream implementation classes or at least their incrementToken() implementation must be final";
  return true;
 } catch (NoSuchMethodException nsme) {
  return false;
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

public ClientPropertyContext(Object instance, Setter setter, Class<?>[] types, int[] paramCounts) {
 this.instance = instance;
 this.setter = setter;
 this.simpleType = null;
 this.paramTypes = types;
 this.paramCounts = paramCounts;
 /*
  * Verify input arrays of same length and that the total parameter count,
  * plus one for the root type, equals the total number of types passed in.
  */
 if (ClientPropertyContext.class.desiredAssertionStatus()) {
  assert types.length == paramCounts.length : "Length mismatch " + types.length + " != "
    + paramCounts.length;
  int count = 1;
  for (int i = 0, j = paramCounts.length; i < j; i++) {
   count += paramCounts[i];
  }
  assert count == types.length : "Mismatch in total parameter count " + count + " != "
    + types.length;
 }
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Assert that the given {@link Element} is compatible with this class and
 * automatically typecast it.
 */
public static HeadingElement as(Element elem) {
 if (HeadingElement.class.desiredAssertionStatus()) {
  assert is(elem);
 }
 return (HeadingElement) elem;
}

代码示例来源:origin: com.google.gwt/gwt-servlet

/**
 * Makes a best-effort attempt to get a useful debugging string describing the
 * given JavaScriptObject. In Production Mode with assertions disabled, this
 * will either call and return the JSO's toString() if one exists, or just
 * return "[JavaScriptObject]". In Development Mode, or with assertions
 * enabled, some stronger effort is made to represent other types of JSOs,
 * including inspecting for document nodes' outerHTML and innerHTML, etc.
 */
@Override
public final String toString() {
 return JavaScriptObject.class.desiredAssertionStatus() ?
   toStringVerbose(this) : toStringSimple(this);
}

代码示例来源:origin: stackoverflow.com

public class Assert {
  static final boolean $assertionsDisabled =
    !Assert.class.desiredAssertionStatus();
  public static void main(String[] args) {
    if (!$assertionsDisabled) {
      if (System.currentTimeMillis() != 0L) {
        throw new AssertionError();
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

public class Assert {
  // This method is synthetic.
  static final boolean $assertionsDisabled =
    !Assert.class.desiredAssertionStatus();
  public static void main(String[] args) {
    if (!$assertionsDisabled) {
      if (System.currentTimeMillis() != 0L) {
        throw new AssertionError();
      }
    }
  }
}

代码示例来源:origin: geotools/geotools

/**
 * Tests orthrodromic distance on the equator. The main purpose of this method is actually to
 * get Java assertions to be run, which will compare the Geodetic Calculator results with the
 * Default Ellipsoid computations.
 */
@Test
public void testEquator() {
  assertTrue(GeodeticCalculator.class.desiredAssertionStatus());
  final GeodeticCalculator calculator = new GeodeticCalculator();
  calculator.setStartingGeographicPoint(0, 0);
  double last = Double.NaN;
  for (double x = 0; x <= 180; x += 0.125) {
    calculator.setDestinationGeographicPoint(x, 0);
    final double distance = calculator.getOrthodromicDistance() / 1000; // In kilometers
    /*
     * Checks that the increment is constant and then tapers off.
     */
    assertTrue(
        x == 0
            ? (distance == 0)
            : (x < 179.5
                ? (Math.abs(distance - last - 13.914936) < 2E-6)
                : (distance - last < 13)));
    last = distance;
  }
}

代码示例来源:origin: geotools/geotools

/**
   * Tests {@link GeneralDirectPosition#equals} method between different implementations. The
   * purpose of this test is also to run the assertion in the direct position implementations.
   */
  @Test
  public void testEquals() {
    assertTrue(GeneralDirectPosition.class.desiredAssertionStatus());
    assertTrue(DirectPosition2D.class.desiredAssertionStatus());

    CoordinateReferenceSystem WGS84 = DefaultGeographicCRS.WGS84;
    DirectPosition p1 = new DirectPosition2D(WGS84, 48.543261561072285, -123.47009555832284);
    GeneralDirectPosition p2 =
        new GeneralDirectPosition(48.543261561072285, -123.47009555832284);
    assertFalse(p1.equals(p2));
    assertFalse(p2.equals(p1));

    p2.setCoordinateReferenceSystem(WGS84);
    assertTrue(p1.equals(p2));
    assertTrue(p2.equals(p1));
  }
}

代码示例来源:origin: org.netbeans.html/net.java.html.boot

JsClassLoader(ClassLoader parent) {
    super(parent);
    setDefaultAssertionStatus(JsClassLoader.class.desiredAssertionStatus());
  }
}

代码示例来源:origin: net.wetheinter/gwt-user

private void assertNothingPending() {
 if (getClass().desiredAssertionStatus()) {
  for (TypeInfoComputed tic : typeToTypeInfoComputed.values()) {
   assert (!tic.isPendingInstantiable());
  }
 }
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

private void assertNothingPending() {
 if (getClass().desiredAssertionStatus()) {
  for (TypeInfoComputed tic : typeToTypeInfoComputed.values()) {
   assert (!tic.isPendingInstantiable());
  }
 }
}

代码示例来源:origin: org.netbeans.html/net.java.html.boot

public JsClassLoaderImpl(ClassLoader parent, FindResources f, Fn.Presenter d) {
  super(parent);
  setDefaultAssertionStatus(JsClassLoader.class.desiredAssertionStatus());
  this.f = f;
  this.d = d;
}

代码示例来源:origin: net.wetheinter/gwt-user

/**
 * Assert that the given {@link Element} is compatible with this class and
 * automatically typecast it.
 */
public static HeadingElement as(Element elem) {
 if (HeadingElement.class.desiredAssertionStatus()) {
  assert is(elem);
 }
 return (HeadingElement) elem;
}

代码示例来源:origin: com.vaadin.external.gwt/gwt-user

/**
 * Assert that the given {@link Element} is compatible with this class and
 * automatically typecast it.
 */
public static HeadingElement as(Element elem) {
 if (HeadingElement.class.desiredAssertionStatus()) {
  assert is(elem);
 }
 return (HeadingElement) elem;
}

代码示例来源:origin: com.google.web.bindery/requestfactory-server

/**
 * Makes a best-effort attempt to get a useful debugging string describing the
 * given JavaScriptObject. In Production Mode with assertions disabled, this
 * will either call and return the JSO's toString() if one exists, or just
 * return "[JavaScriptObject]". In Development Mode, or with assertions
 * enabled, some stronger effort is made to represent other types of JSOs,
 * including inspecting for document nodes' outerHTML and innerHTML, etc.
 */
@Override
public final String toString() {
 return JavaScriptObject.class.desiredAssertionStatus() ?
   toStringVerbose(this) : toStringSimple(this);
}

代码示例来源:origin: Geomatys/geotoolkit

/**
 * Creates a new test suite for the given class.
 *
 * @param testing The class to be tested.
 */
protected ImageTestBase(final Class<?> testing) {
  assertTrue(testing.desiredAssertionStatus());
  viewEnabled = Boolean.getBoolean(SwingTestBase.SHOW_PROPERTY_KEY);
}

代码示例来源:origin: org.wildfly.core/wildfly-controller

private OperationTransformerRegistry getRegistryUpdater(final ModelVersion version) {
  int micro = version.getMicro();
  for (int i = micro; i >= 0; i--) {
    ModelVersion currentVersion = ModelVersion.create(version.getMajor(), version.getMinor(), i);
    OperationTransformerRegistry current = registryUpdater.get(this, currentVersion);
    if (current != null) {
      if(micro != i && this.getClass().desiredAssertionStatus()) {
        ControllerLogger.MGMT_OP_LOGGER.couldNotFindTransformerRegistryFallingBack(version, currentVersion);
      }
      return current;
    }
  }
  return null;
}

代码示例来源:origin: Geomatys/geotoolkit

/**
 * Makes sure that J2SE 1.4 assertions are enabled.
 */
@Test
public void testAssertionEnabled() {
  assertTrue("Assertions not enabled.", Hints.class.desiredAssertionStatus());
}

代码示例来源:origin: Geomatys/geotoolkit

/**
 * Creates a new test case using the given hints for fetching the factories.
 *
 * @param type  The base class of the transform being tested.
 * @param hints The hints to use for fetching factories, or {@code null} for the default ones.
 */
protected TransformTestBase(final Class<? extends MathTransform> type, final Hints hints) {
  this(FactoryFinder.getDatumFactory(hints),
     FactoryFinder.getCRSFactory(hints),
     FactoryFinder.getMathTransformFactory(hints));
  assertTrue("Tests should be run with assertions enabled.", type.desiredAssertionStatus());
}

相关文章

Class类方法