當前位置: 首頁>>代碼示例>>Java>>正文


Java Assert類代碼示例

本文整理匯總了Java中org.eclipse.core.runtime.Assert的典型用法代碼示例。如果您正苦於以下問題:Java Assert類的具體用法?Java Assert怎麽用?Java Assert使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Assert類屬於org.eclipse.core.runtime包,在下文中一共展示了Assert類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rewriteAST

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel positionGroups) throws CoreException {
	final ASTRewrite rewrite = cuRewrite.getASTRewrite();
	VariableDeclarationFragment fragment = null;
	for (int i = 0; i < fNodes.length; i++) {
		final ASTNode node = fNodes[i];

		final AST ast = node.getAST();

		fragment = ast.newVariableDeclarationFragment();
		fragment.setName(ast.newSimpleName(NAME_FIELD));

		final FieldDeclaration declaration = ast.newFieldDeclaration(fragment);
		declaration.setType(ast.newPrimitiveType(PrimitiveType.LONG));
		declaration.modifiers().addAll(ASTNodeFactory.newModifiers(ast, Modifier.PRIVATE | Modifier.STATIC | Modifier.FINAL));

		if (!addInitializer(fragment, node)) {
			continue;
		}

		if (fragment.getInitializer() != null) {

			final TextEditGroup editGroup = createTextEditGroup(FixMessages.SerialVersion_group_description, cuRewrite);
			if (node instanceof AbstractTypeDeclaration) {
				rewrite.getListRewrite(node, ((AbstractTypeDeclaration) node).getBodyDeclarationsProperty()).insertAt(declaration, 0, editGroup);
			} else if (node instanceof AnonymousClassDeclaration) {
				rewrite.getListRewrite(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
			} else if (node instanceof ParameterizedType) {
				final ParameterizedType type = (ParameterizedType) node;
				final ASTNode parent = type.getParent();
				if (parent instanceof ClassInstanceCreation) {
					final ClassInstanceCreation creation = (ClassInstanceCreation) parent;
					final AnonymousClassDeclaration anonymous = creation.getAnonymousClassDeclaration();
					if (anonymous != null) {
						rewrite.getListRewrite(anonymous, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY).insertAt(declaration, 0, editGroup);
					}
				}
			} else {
				Assert.isTrue(false);
			}

			addLinkedPositions(rewrite, fragment, positionGroups);
		}

		final String comment = CodeGeneration.getFieldComment(fUnit, declaration.getType().toString(), NAME_FIELD, "\n" /* StubUtility.getLineDelimiterUsed(fUnit) */);
		if (comment != null && comment.length() > 0 && !"/**\n *\n */\n".equals(comment)) {
			final Javadoc doc = (Javadoc) rewrite.createStringPlaceholder(comment, ASTNode.JAVADOC);
			declaration.setJavadoc(doc);
		}
	}
	if (fragment == null) {
		return;
	}

	positionGroups.setEndPosition(rewrite.track(fragment));
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:57,代碼來源:AbstractSerialVersionOperation.java

示例2: BatchSourceViewerConfiguration

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
 * Creates configuration by given adaptable
 * 
 * @param adaptable
 *            must provide {@link ColorManager} and {@link IFile}
 */
public BatchSourceViewerConfiguration(IAdaptable adaptable) {
	IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
	this.fPreferenceStore = new ChainedPreferenceStore(
			new IPreferenceStore[] { getPreferences().getPreferenceStore(), generalTextStore });

	Assert.isNotNull(adaptable, "adaptable may not be null!");
	this.annotationHoover = new BatchEditorAnnotationHoover();
	
	this.contentAssistant = new ContentAssistant();
	contentAssistProcessor = new BatchEditorSimpleWordContentAssistProcessor();
	contentAssistant.enableColoredLabels(true);
	
	contentAssistant.setContentAssistProcessor(contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
	for (BatchDocumentIdentifier identifier: BatchDocumentIdentifiers.values()){
		contentAssistant.setContentAssistProcessor(contentAssistProcessor, identifier.getId());
	}
	
	contentAssistant.addCompletionListener(contentAssistProcessor.getCompletionListener());

	this.colorManager = adaptable.getAdapter(ColorManager.class);
	Assert.isNotNull(colorManager, " adaptable must support color manager");
	this.defaultTextAttribute = new TextAttribute(
			colorManager.getColor(getPreferences().getColor(COLOR_NORMAL_TEXT)));
	this.adaptable=adaptable;
}
 
開發者ID:de-jcup,項目名稱:eclipse-batch-editor,代碼行數:32,代碼來源:BatchSourceViewerConfiguration.java

示例3: BashSourceViewerConfiguration

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
 * Creates configuration by given adaptable
 * 
 * @param adaptable
 *            must provide {@link ColorManager} and {@link IFile}
 */
public BashSourceViewerConfiguration(IAdaptable adaptable) {
	IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
	this.fPreferenceStore = new ChainedPreferenceStore(
			new IPreferenceStore[] { getPreferences().getPreferenceStore(), generalTextStore });

	Assert.isNotNull(adaptable, "adaptable may not be null!");
	this.annotationHoover = new BashEditorAnnotationHoover();
	
	this.contentAssistant = new ContentAssistant();
	contentAssistProcessor = new BashEditorSimpleWordContentAssistProcessor();
	contentAssistant.enableColoredLabels(true);
	
	contentAssistant.setContentAssistProcessor(contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
	for (BashDocumentIdentifier identifier: BashDocumentIdentifiers.values()){
		contentAssistant.setContentAssistProcessor(contentAssistProcessor, identifier.getId());
	}
	
	contentAssistant.addCompletionListener(contentAssistProcessor.getCompletionListener());

	this.colorManager = adaptable.getAdapter(ColorManager.class);
	Assert.isNotNull(colorManager, " adaptable must support color manager");
	this.defaultTextAttribute = new TextAttribute(
			colorManager.getColor(getPreferences().getColor(COLOR_NORMAL_TEXT)));
	this.adaptable=adaptable;
}
 
開發者ID:de-jcup,項目名稱:eclipse-bash-editor,代碼行數:32,代碼來源:BashSourceViewerConfiguration.java

示例4: HydrographCompletionProposal

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
public HydrographCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition,
        Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo) {
    Assert.isNotNull(replacementString);
    Assert.isTrue(replacementOffset >= 0);
    Assert.isTrue(replacementLength >= 0);
    Assert.isTrue(cursorPosition >= 0);

    fReplacementString = replacementString;
    fReplacementOffset = replacementOffset;
    fReplacementLength = replacementLength;
    fCursorPosition = cursorPosition;
    fImage = image;
    fDisplayString = displayString;
    fContextInformation = contextInformation;
    fAdditionalProposalInfo = additionalProposalInfo;
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:17,代碼來源:HydrographCompletionProposal.java

示例5: addBreakpointToMap

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
private void addBreakpointToMap(IBreakpoint breakpoint) throws CoreException {
	Assert.isTrue(supportsBreakpoint(breakpoint) && breakpoint instanceof ILineBreakpoint);
	if (breakpoint instanceof ILineBreakpoint) {
		ILineBreakpoint lineBreakpoint = (ILineBreakpoint) breakpoint;
		IResource resource = lineBreakpoint.getMarker().getResource();
		IPath location = resource.getLocation();
		String path = location.toOSString();
		String name = location.lastSegment();
		int lineNumber = lineBreakpoint.getLineNumber();

		Source source = new Source().setName(name).setPath(path);

		List<SourceBreakpoint> sourceBreakpoints = targetBreakpoints.computeIfAbsent(source,
				s -> new ArrayList<>());
		sourceBreakpoints.add(new SourceBreakpoint().setLine(lineNumber));
	}
}
 
開發者ID:tracymiranda,項目名稱:dsp4e,代碼行數:18,代碼來源:DSPDebugTarget.java

示例6: deleteBreakpointFromMap

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
private void deleteBreakpointFromMap(IBreakpoint breakpoint) throws CoreException {
	Assert.isTrue(supportsBreakpoint(breakpoint) && breakpoint instanceof ILineBreakpoint);
	if (breakpoint instanceof ILineBreakpoint) {
		ILineBreakpoint lineBreakpoint = (ILineBreakpoint) breakpoint;
		IResource resource = lineBreakpoint.getMarker().getResource();
		IPath location = resource.getLocation();
		String path = location.toOSString();
		String name = location.lastSegment();
		int lineNumber = lineBreakpoint.getLineNumber();
		for (Entry<Source, List<SourceBreakpoint>> entry : targetBreakpoints.entrySet()) {
			Source source = entry.getKey();
			if (Objects.equals(name, source.name) && Objects.equals(path, source.path)) {
				List<SourceBreakpoint> bps = entry.getValue();
				for (Iterator<SourceBreakpoint> iterator = bps.iterator(); iterator.hasNext();) {
					SourceBreakpoint sourceBreakpoint = (SourceBreakpoint) iterator.next();
					if (Objects.equals(lineNumber, sourceBreakpoint.line)) {
						iterator.remove();
					}
				}
			}
		}
	}
}
 
開發者ID:tracymiranda,項目名稱:dsp4e,代碼行數:24,代碼來源:DSPDebugTarget.java

示例7: handleCoreException

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
 * Handles a core exception thrown during a testing environment operation
 */
private void handleCoreException(CoreException e) {
  e.printStackTrace();
  IStatus status = e.getStatus();
  String message = e.getMessage();
  if (status.isMultiStatus()) {
    MultiStatus multiStatus = (MultiStatus) status;
    IStatus[] children = multiStatus.getChildren();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0, max = children.length; i < max; i++) {
      IStatus child = children[i];
      if (child != null) {
        buffer.append(child.getMessage());
        buffer.append(System.getProperty("line.separator"));//$NON-NLS-1$
        Throwable childException = child.getException();
        if (childException != null) {
          childException.printStackTrace();
        }
      }
    }
    message = buffer.toString();
  }
  Assert.isTrue(false, "Core exception in testing environment: " + message); //$NON-NLS-1$
}
 
開發者ID:RuiChen08,項目名稱:dacapobench,代碼行數:27,代碼來源:TestingEnvironment.java

示例8: perform

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
public static List<Match> perform(ASTNode start, ASTNode[] snippet) {
	Assert.isTrue(start instanceof AbstractTypeDeclaration || start instanceof AnonymousClassDeclaration);
	SnippetFinder finder = new SnippetFinder(snippet);
	start.accept(finder);
	for (Iterator<Match> iter = finder.fResult.iterator(); iter.hasNext();) {
		Match match = iter.next();
		ASTNode[] nodes = match.getNodes();
		// doesn't match if the candidate is the left hand side of an
		// assignment and the snippet consists of a single node.
		// Otherwise y= i; i= z; results in y= e(); e()= z;
		if (nodes.length == 1 && isLeftHandSideOfAssignment(nodes[0])) {
			iter.remove();
		}
	}
	return finder.fResult;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:17,代碼來源:SnippetFinder.java

示例9: GradleSourceViewerConfiguration

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
 * Creates configuration by given adaptable
 * 
 * @param adaptable
 *            must provide {@link ColorManager} and {@link IFile}
 */
public GradleSourceViewerConfiguration(IAdaptable adaptable) {
	super(adaptable, COLOR_NORMAL_TEXT);
	Assert.isNotNull(adaptable, "adaptable may not be null!");
	
	
	/* code completion */
	this.contentAssistant = new ContentAssistant();
	this.gradleContentAssistProcessor = new GradleContentAssistProcessor(adaptable, new RelevantCodeCutter());
	contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE);
	contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, GRADLE_APPLY_KEYWORD.getId());
	contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, GRADLE_KEYWORD.getId());
	contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, GRADLE_TASK_KEYWORD.getId());
	contentAssistant.setContentAssistProcessor(gradleContentAssistProcessor, GRADLE_VARIABLE.getId());
	contentAssistant.addCompletionListener(gradleContentAssistProcessor.getCompletionListener());

	// contentAssistant.enableColoredLabels(true); - when...
	// ICompletionProposalExtension6 implemented

	/* enable auto activation */
	contentAssistant.enableAutoActivation(true);

	/* set a propert orientation for proposal */
	contentAssistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
}
 
開發者ID:de-jcup,項目名稱:egradle,代碼行數:31,代碼來源:GradleSourceViewerConfiguration.java

示例10: firstWhitespaceToRight

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
 * Finds the first whitespace character position to the right of (and including)
 * <code>position</code>.
 *
 * @param document the document being modified
 * @param position the first character position in <code>document</code> to be considered
 * @return the position of a whitespace character greater or equal than <code>position</code>
 *         separated only by whitespace, or -1 if none found
 */
private static int firstWhitespaceToRight(IDocument document, int position) {
	int length = document.getLength();
	Assert.isTrue(position >= 0);
	Assert.isTrue(position <= length);

	try {
		while (position < length) {
			char ch = document.getChar(position);
			if (Character.isWhitespace(ch)) return position;
			position++;
		}
		return position;
	} catch (BadLocationException e) {}
	return -1;
}
 
開發者ID:grosenberg,項目名稱:fluentmark,代碼行數:25,代碼來源:SmartAutoEditStrategy.java

示例11: createGridLayout

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
* Create a grid layout with the specified number of columns and the
* standard spacings.
* 
* @param numColumns
*                the number of columns
* @param converter
*                the pixel converter
* @param margins
*                One of <code>MARGINS_DEFAULT</code>,
*                <code>MARGINS_NONE</code> or <code>MARGINS_DIALOG</code>.
* @return the grid layout
*/
  public static GridLayout createGridLayout(int numColumns, PixelConverter converter, int margins) {
  	Assert.isTrue(margins == MARGINS_DEFAULT || margins == MARGINS_NONE || margins == MARGINS_DIALOG);
  	
      final GridLayout layout= new GridLayout(numColumns, false);
      layout.horizontalSpacing= converter.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
      layout.verticalSpacing= converter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
      
      switch (margins) {
      case MARGINS_NONE:
          layout.marginLeft= layout.marginRight= 0;
          layout.marginTop= layout.marginBottom= 0;
          break;
      case MARGINS_DIALOG:
          layout.marginLeft= layout.marginRight= converter.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
          layout.marginTop= layout.marginBottom= converter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
          break;
      case MARGINS_DEFAULT:
          layout.marginLeft= layout.marginRight= layout.marginWidth;
          layout.marginTop= layout.marginBottom= layout.marginHeight;
      }
      layout.marginWidth= layout.marginHeight= 0;
      return layout;
  }
 
開發者ID:subclipse,項目名稱:subclipse,代碼行數:37,代碼來源:SWTUtils.java

示例12: suggestNewVariableName

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
public String suggestNewVariableName(String[] prefixes, String[] suffixes, String oldVariableName, String oldTypeName, String newTypeName) {

		Assert.isNotNull(prefixes);
		Assert.isNotNull(suffixes);
		Assert.isNotNull(oldVariableName);
		Assert.isNotNull(oldTypeName);
		Assert.isNotNull(newTypeName);
		Assert.isTrue(oldVariableName.length() > 0);
		Assert.isTrue(oldTypeName.length() > 0);
		Assert.isTrue(newTypeName.length() > 0);

		final String usedPrefix = findLongestPrefix(oldVariableName, prefixes);
		final String usedSuffix = findLongestSuffix(oldVariableName, suffixes);
		final String strippedVariableName = oldVariableName.substring(usedPrefix.length(), oldVariableName.length() - usedSuffix.length());

		String newVariableName = match(oldTypeName, newTypeName, strippedVariableName);
		return (newVariableName != null) ? usedPrefix + newVariableName + usedSuffix : null;
	}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:19,代碼來源:RenamingNameSuggestor.java

示例13: registerAutoEditVetoer

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
 * Registers our auto edit vetoer with the viewer.
 *
 * @param viewer
 *            the viewer we want to veto ui-triggered changes within linked
 *            positions
 */
private void registerAutoEditVetoer(ITextViewer viewer) {
	try {
		String[] contentTypes = getContentTypes(viewer.getDocument());
		if (viewer instanceof ITextViewerExtension2) {
			ITextViewerExtension2 vExtension = ((ITextViewerExtension2) viewer);
			for (int i = 0; i < contentTypes.length; i++) {
				vExtension.prependAutoEditStrategy(fAutoEditVetoer, contentTypes[i]);
			}
		} else {
			Assert.isTrue(false);
		}

	} catch (BadPartitioningException e) {
		leave(ILinkedModeListener.EXIT_ALL);
	}
}
 
開發者ID:curiosag,項目名稱:ftc,代碼行數:24,代碼來源:TweakedLinkedModeUI.java

示例14: editOccured

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
 * Processes a modify event that occurred in this text cell editor. This
 * framework method performs validation and sets the error message accordingly,
 * and then reports a change via <code>fireEditorValueChanged</code>. Subclasses
 * should call this method at appropriate times. Subclasses may extend or
 * reimplement.
 *
 * @param e
 *            the SWT modify event
 */
protected void editOccured(ModifyEvent e) {
	String value = text.getText();
	if (value == null) {
		value = "";//$NON-NLS-1$
	}
	Object typedValue = value;
	boolean oldValidState = isValueValid();
	boolean newValidState = isCorrect(typedValue);
	if (typedValue == null && newValidState) {
		Assert.isTrue(false, "Validator isn't limiting the cell editor's type range");//$NON-NLS-1$
	}
	if (!newValidState) {
		// try to insert the current value into the error message.
		setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] { value }));
	}
	valueChanged(oldValidState, newValidState);
}
 
開發者ID:NineWorlds,項目名稱:xstreamer,代碼行數:28,代碼來源:NumericCellEditor.java

示例15: createParameterList

import org.eclipse.core.runtime.Assert; //導入依賴的package包/類
/**
 * Creates and returns a parameter list of the given method or type proposal suitable for
 * display. The list does not include parentheses. The lower bound of parameter types is
 * returned.
 * <p>
 * Examples:
 *
 * <pre>
 *   &quot;void method(int i, String s)&quot; -&gt; &quot;int i, String s&quot;
 *   &quot;? extends Number method(java.lang.String s, ? super Number n)&quot; -&gt; &quot;String s, Number n&quot;
 * </pre>
 *
 * </p>
 *
 * @param proposal the proposal to create the parameter list for
 * @return the list of comma-separated parameters suitable for display
 */
public StringBuilder createParameterList(CompletionProposal proposal) {
	int kind= proposal.getKind();
	switch (kind) {
	case CompletionProposal.METHOD_REF:
	case CompletionProposal.CONSTRUCTOR_INVOCATION:
		return appendUnboundedParameterList(new StringBuilder(), proposal);
	case CompletionProposal.TYPE_REF:
	case CompletionProposal.JAVADOC_TYPE_REF:
		return appendTypeParameterList(new StringBuilder(), proposal);
	case CompletionProposal.ANONYMOUS_CLASS_DECLARATION:
	case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION:
		return appendUnboundedParameterList(new StringBuilder(), proposal);
	default:
		Assert.isLegal(false);
		return null; // dummy
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:35,代碼來源:CompletionProposalDescriptionProvider.java


注:本文中的org.eclipse.core.runtime.Assert類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。