本文整理汇总了Java中org.eclipse.core.runtime.Assert.isTrue方法的典型用法代码示例。如果您正苦于以下问题:Java Assert.isTrue方法的具体用法?Java Assert.isTrue怎么用?Java Assert.isTrue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.core.runtime.Assert
的用法示例。
在下文中一共展示了Assert.isTrue方法的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));
}
示例2: 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;
}
示例3: 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));
}
}
示例4: 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();
}
}
}
}
}
}
示例5: 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$
}
示例6: duplicatePressed
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
/**
* Notifies that the Add button has been pressed.
*/
private void duplicatePressed() {
setPresentsDefaultValue(false);
int index = table.getSelectionIndex();
int target = index + 1;
if (index >= 0) {
TableItem[] selection = table.getSelection();
Assert.isTrue(selection.length == 1);
String[] values = new String[columnNames.length];
for (int j = 0; j < columnNames.length; j++) {
values[j] = selection[0].getText(j);
}
TableItem tableItem = new TableItem(table, SWT.NONE, target);
tableItem.setText(values);
table.setSelection(target);
}
selectionChanged();
}
示例7: getRun
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
/**
* Returns a run based on a character.
*
* @param ch
* the character to test
* @return the correct character given <code>ch</code>
*/
private Run getRun(char ch) {
Run run;
if (WHITESPACE.isValid(ch)) {
run = WHITESPACE;
} else if (DELIMITER.isValid(ch)) {
run = DELIMITER;
} else if (CAMELCASE.isValid(ch)) {
run = CAMELCASE;
} else if (OTHER.isValid(ch)) {
run = OTHER;
} else {
Assert.isTrue(false);
return null;
}
run.init();
return run;
}
示例8: getType
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
/**
* Returns the type node for the given declaration.
*
* @param declaration the declaration
* @return the type node or <code>null</code> if the given declaration represents a type
* inferred parameter in lambda expression
*/
public static Type getType(VariableDeclaration declaration) {
if (declaration instanceof SingleVariableDeclaration) {
return ((SingleVariableDeclaration)declaration).getType();
} else if (declaration instanceof VariableDeclarationFragment) {
ASTNode parent= ((VariableDeclarationFragment)declaration).getParent();
if (parent instanceof VariableDeclarationExpression) {
return ((VariableDeclarationExpression)parent).getType();
} else if (parent instanceof VariableDeclarationStatement) {
return ((VariableDeclarationStatement)parent).getType();
} else if (parent instanceof FieldDeclaration) {
return ((FieldDeclaration)parent).getType();
} else if (parent instanceof LambdaExpression) {
return null;
}
}
Assert.isTrue(false, "Unknown VariableDeclaration"); //$NON-NLS-1$
return null;
}
示例9: isWhitespace
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
/**
* Returns <code>true</code> if the given sequence into the underlying text
* represents whitespace, but not a delimiter, <code>false</code> otherwise.
*
* @param offset
* the offset
* @param exclusiveEnd
* the end offset
* @return <code>true</code> if the given range is whitespace
*/
private boolean isWhitespace(int offset, int exclusiveEnd) {
if (exclusiveEnd == DONE || offset == DONE) {
return false;
}
Assert.isTrue(offset >= 0);
Assert.isTrue(exclusiveEnd <= getText().getEndIndex());
Assert.isTrue(exclusiveEnd > offset);
CharSequence seq = fIterator.fText;
while (offset < exclusiveEnd) {
char ch = seq.charAt(offset);
if (!Character.isWhitespace(ch)) {
return false;
}
if (ch == '\n' || ch == '\r') {
return false;
}
offset++;
}
return true;
}
示例10: storeRootFilename
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
/**
* Stores root file name in project preferences
* @param project
* @param rootFilename
*/
public static void storeRootFilename(IProject project, String rootFilename) {
// If this condition does not hold, the subsequent code but also
// AddModuleHandler will not work. The claim is that spec files are
// always in the parent folder of the IProject.
final IPath path = new Path(rootFilename);
Assert.isTrue(ResourceHelper.isProjectParent(path.removeLastSegments(1), project),
project.getLocation().toOSString() + " is *not* a subdirectory of " + rootFilename
+ ". This is commonly caused by a symlink contained in the latter path.");
// Store the filename *without* any path information, but prepend the
// magical PARENT-1-PROJECT-LOC. It indicates that the file can be found
// *one* level up (hence the "1") from the project location.
// readProjectRootFile can later easily deduce the relative location of
// the file.
rootFilename = ResourceHelper.PARENT_ONE_PROJECT_LOC + path.lastSegment();
IEclipsePreferences projectPrefs = getProjectPreferences(project);
projectPrefs.put(IPreferenceConstants.P_PROJECT_ROOT_FILE, rootFilename);
storePreferences(projectPrefs);
}
示例11: 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;
}
示例12: scanBackward
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
/**
* Finds the highest position in <code>document</code> such that the position is <=
* <code>position</code> and > <code>bound</code> and
* <code>document.getChar(position) == ch</code> evaluates to <code>true</code> for at least one
* ch in <code>chars</code> and the position is in the default partition.
*
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
* @param bound the first position in <code>document</code> to not consider any more, with
* <code>scanTo</code> > <code>position</code>
* @param chars an array of <code>char</code> to search for
* @return the highest position of one element in <code>chars</code> in (<code>bound</code>,
* <code>position</code>] that resides in a Java partition, or <code>-1</code> if none
* can be found
*/
private static int scanBackward(IDocument document, int position, String partitioning, int bound, char[] chars) {
Assert.isTrue(bound >= -1);
Assert.isTrue(position < document.getLength());
Arrays.sort(chars);
try {
while (position > bound) {
if (Arrays.binarySearch(chars, document.getChar(position)) >= 0
&& isDefaultPartition(document, position, partitioning))
return position;
position--;
}
} catch (BadLocationException e) {}
return -1;
}
示例13: open
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public int open() {
List<Object[]> selection = getInitialElementSelections();
if (selection == null || selection.size() != fNumberOfPages) {
setInitialSelections(new Object[fNumberOfPages]);
selection = getInitialElementSelections();
}
Assert.isTrue(selection.size() == fNumberOfPages);
return super.open();
}
示例14: editorClosed
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
private void editorClosed(IEditorPart part) {
if (part instanceof ITextEditor) {
ICodeLensController controller = codeLensControllers.remove(part);
if (controller != null) {
controller.uninstall();
Assert.isTrue(null == codeLensControllers.get(part),
"An old ICodeLensController is not un-installed on Text Editor instance");
}
}
}
示例15: handle
import org.eclipse.core.runtime.Assert; //导入方法依赖的package包/类
void handle(Exception e) {
if (e instanceof CoreException) {
handleCoreException((CoreException) e);
} else {
e.printStackTrace();
Assert.isTrue(false);
}
}