org.eclipse.core.runtime.Assert类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(243)

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

Assert介绍

[英]Assert is useful for for embedding runtime sanity checks in code. The predicate methods all test a condition and throw some type of unchecked exception if the condition does not hold.

Assertion failure exceptions, like most runtime exceptions, are thrown when something is misbehaving. Assertion failures are invariably unspecified behavior; consequently, clients should never rely on these being thrown (and certainly should not be catching them specifically).

This class can be used without OSGi running.

This class is not intended to be instantiated or sub-classed by clients.
[中]Assert对于在代码中嵌入运行时健全性检查非常有用。谓词方法都测试一个条件,如果条件不成立,则抛出某种类型的未检查异常。
与大多数运行时异常一样,断言失败异常是在出现错误时抛出的。断言失败总是未指定的行为;因此,客户永远不应该依赖于抛出的这些数据(当然也不应该专门捕捉它们)。
该类可以在不运行OSGi的情况下使用。
该类不打算由客户端实例化或子类。

代码示例

代码示例来源:origin: org.eclipse.core/runtime

Assert.isNotNull(descriptor);
Assert.isTrue(!CompatibilityHelper.hasPluginObject(descriptor), NLS.bind(Messages.plugin_deactivatedLoad, this.getClass().getName(), descriptor.getUniqueIdentifier() + " is not activated")); //$NON-NLS-1$
this.descriptor = descriptor;

代码示例来源:origin: eclipse/eclipse.jdt.ls

public Destination(Object destination, int location) {
  Assert.isNotNull(destination);
  Assert.isLegal(location == LOCATION_AFTER || location == LOCATION_BEFORE || location == LOCATION_ON);
  fDestination= destination;
  fLocation= location;
}

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

/**
 * Only constructor which needs an input definition.
 *
 * @param inputDefinition
 *            The input definition.
 */
public RootEditorInput(InputDefinition inputDefinition) {
  Assert.isNotNull(inputDefinition);
  this.inputDefinition = inputDefinition;
}

代码示例来源:origin: org.eclipse.core/runtime

private void assertInitialized() {
  //avoid the Policy.bind if assertion is true
  if (!initialized)
    Assert.isTrue(false, Messages.meta_appNotInit);
}

代码示例来源:origin: org.eclipse.equinox/common

/** Asserts that an argument is legal. If the given boolean is
 * not <code>true</code>, an <code>IllegalArgumentException</code>
 * is thrown.
 *
 * @param expression the outcome of the check
 * @return <code>true</code> if the check passes (does not return
 *    if the check fails)
 * @exception IllegalArgumentException if the legality test failed
 */
public static boolean isLegal(boolean expression) {
  return isLegal(expression, ""); //$NON-NLS-1$
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.editors

@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
  Assert.isTrue(fDelegate != null);
  ITextViewer viewer= parentRuler.getTextViewer();
  Assert.isLegal(viewer instanceof ISourceViewer);
  fViewer= (ISourceViewer) viewer;
  initialize();
  Control control= fDelegate.createControl(parentRuler, parentControl);
  return control;
}

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

/**
 * {@inheritDoc}
 */
@Override
public void setInputDefinition(InputDefinition inputDefinition) {
  Assert.isNotNull(inputDefinition);
  this.inputDefinition = inputDefinition;
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

/**
 * Sets the granularity to use during the searches.
 * <p>
 * This method must be called before start searching. The default is a granularity of {@link #GRANULARITY_SEARCH_MATCH}.
 *
 * @param granularity The granularity to use. Must be one of the <code>GRANULARITY_XXX</code> constants.
 */
public final void setGranularity(final int granularity) {
  Assert.isTrue(granularity == GRANULARITY_COMPILATION_UNIT || granularity == GRANULARITY_SEARCH_MATCH);
  fGranularity= granularity;
}

代码示例来源:origin: org.eclipse.equinox/common

/**
 * Sets the severity.
 *
 * @param severity the severity; one of <code>OK</code>, <code>ERROR</code>, 
 * <code>INFO</code>, <code>WARNING</code>,  or <code>CANCEL</code>
 */
protected void setSeverity(int severity) {
  Assert.isLegal(severity == OK || severity == ERROR || severity == WARNING || severity == INFO || severity == CANCEL);
  this.severity = severity;
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

protected void setGroups(ActionGroup[] groups) {
  Assert.isTrue(fGroups == null);
  Assert.isNotNull(groups);
  fGroups= groups;
}

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

/**
 * {@inheritDoc}
 */
@Override
public void setRootEditor(IRootEditor rootEditor) {
  Assert.isNotNull(rootEditor);
  this.rootEditor = rootEditor;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

public Destination(Object destination, int location) {
  Assert.isNotNull(destination);
  Assert.isLegal(location == LOCATION_AFTER || location == LOCATION_BEFORE || location == LOCATION_ON);
  fDestination= destination;
  fLocation= location;
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

public static void assertVisibility(int visibility){
  Assert.isTrue(	visibility == Modifier.PUBLIC ||
          visibility == Modifier.PROTECTED ||
          visibility == Modifier.NONE ||
          visibility == Modifier.PRIVATE);
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

@Override
public void setOptions(CleanUpOptions options) {
  Assert.isLegal(options != null);
  fOptions = options;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

/**
 * Creates a new processor on the given document and using the given tab width.
 * 
 * @param document the document
 * @param tabWidth the tabulator width in space equivalents, must be <code>&gt;=0</code>
 */
public SelectionProcessor(IDocument document, int tabWidth) {
  Assert.isNotNull(document);
  Assert.isTrue(tabWidth >= 0);
  fDocument= document;
  fTabWidth= tabWidth;
}

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

/**
 * @return the rootEditor
 */
protected IRootEditor getRootEditor() {
  Assert.isNotNull(rootEditor);
  return rootEditor;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ltk.core.refactoring

/**
 * Sets the new name to rename the resource to.
 *
 * @param name
 *            the non-empty new name to set
 */
public void setNewName(final String name) {
  Assert.isNotNull(name);
  Assert.isLegal(!"".equals(name), "Name must not be empty"); //$NON-NLS-1$//$NON-NLS-2$
  fNewName= name;
}

代码示例来源:origin: eclipse/eclipse.jdt.ls

public CopyResourceChange(IResource res, IContainer dest, INewNameQuery newNameQuery) {
  Assert.isTrue(res instanceof IFile || res instanceof IFolder);
  Assert.isTrue(dest instanceof IProject || dest instanceof IFolder);
  fNewNameQuery= newNameQuery;
  fSource= res;
  fTarget= dest;
  // Copy resource change isn't undoable and isn't used
  // as a redo/undo change right now.
  setValidationMethod(SAVE_IF_DIRTY);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui

@Override
public ImageRegistry getImageRegistry() {
  /* Just to be sure that we don't access this
   * plug-ins image registry.
   */
  Assert.isLegal(false);
  return null;
}

代码示例来源:origin: org.eclipse/org.eclipse.ltk.core.refactoring

/**
 * Set the owning refactoring.
 * 
 * @param refactoring the refactoring
 *
 * @since 3.1
 */
/* package */ void setRefactoring(ProcessorBasedRefactoring refactoring) {
  Assert.isTrue(fRefactoring == null, "The refactoring can only be set once"); //$NON-NLS-1$
  Assert.isNotNull(refactoring);
  fRefactoring= refactoring;
}

相关文章

微信公众号

最新文章

更多