Java Code Examples for org.eclipse.core.runtime.Assert#isTrue()

The following examples show how to use org.eclipse.core.runtime.Assert#isTrue() . 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: XBookmarksPlugin.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param imgid IMG_* constant
 * @return Image 
 */
public Image getCachedImage(int imgid) {
	if (hmCachedImages == null) { 
		return null; // hbz
	}
	Integer key = new Integer(imgid);
	Image img = hmCachedImages.get(key);
	if (img == null) {
		Assert.isTrue(imgid>=0 && imgid<IMG_SOURCES.length, "getCachedImage - wrong Image id=" + imgid); //$NON-NLS-1$
		IPath path = new Path(IMG_SOURCES[imgid]); 
		URL   url  = FileLocator.find(XBookmarksPlugin.getDefault().getBundle(), path, null);
		if (url != null) {
			img = ImageDescriptor.createFromURL(url).createImage();
		}
		if (img != null) {
			hmCachedImages.put(key, img);
		}
	}
	return img;
}
 
Example 2
Source File: ExtractTempRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public ExtractTempRefactoring(ICompilationUnit unit, int selectionStart, int selectionLength, Map formatterOptions) {
	Assert.isTrue(selectionStart >= 0);
	Assert.isTrue(selectionLength >= 0);
	fSelectionStart = selectionStart;
	fSelectionLength = selectionLength;
	fCu = unit;
	fCompilationUnitNode = null;

	fReplaceAllOccurrences = true; // default
	fDeclareFinal = false; // default
	fTempName = ""; //$NON-NLS-1$

	fLinkedProposalModel = null;
	fCheckResultForCompileProblems = true;
	fFormatterOptions = formatterOptions;
}
 
Example 3
Source File: ExtractTempRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static ASTNode[] getArrayPrefix(ASTNode[] array, int prefixLength) {
	Assert.isTrue(prefixLength <= array.length);
	Assert.isTrue(prefixLength >= 0);
	ASTNode[] prefix = new ASTNode[prefixLength];
	for (int i = 0; i < prefix.length; i++) {
		prefix[i] = array[i];
	}
	return prefix;
}
 
Example 4
Source File: ExtractConstantRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public ExtractConstantRefactoring(CompilationUnit astRoot, int selectionStart, int selectionLength, Map formatterOptions) {
	Assert.isTrue(selectionStart >= 0);
	Assert.isTrue(selectionLength >= 0);
	Assert.isTrue(astRoot.getTypeRoot() instanceof ICompilationUnit);

	fSelectionStart = selectionStart;
	fSelectionLength = selectionLength;
	fCu = (ICompilationUnit) astRoot.getTypeRoot();
	fCuRewrite = new CompilationUnitRewrite(null, fCu, astRoot, formatterOptions);
	fLinkedProposalModel = null;
	fConstantName = ""; //$NON-NLS-1$
	fCheckResultForCompileProblems = true;
	fFormatterOptions = formatterOptions;
}
 
Example 5
Source File: DeleteChangeCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static Change createDeleteChange(IJavaElement javaElement) throws JavaModelException {
	Assert.isTrue(! ReorgUtils.isInsideCompilationUnit(javaElement));

	switch(javaElement.getElementType()){
		case IJavaElement.PACKAGE_FRAGMENT_ROOT:
			return createPackageFragmentRootDeleteChange((IPackageFragmentRoot)javaElement);

		case IJavaElement.PACKAGE_FRAGMENT:
			return createSourceManipulationDeleteChange((IPackageFragment)javaElement);

		case IJavaElement.COMPILATION_UNIT:
			return createSourceManipulationDeleteChange((ICompilationUnit)javaElement);

		case IJavaElement.CLASS_FILE:
			//if this assert fails, it means that a precondition is missing
			Assert.isTrue(((IClassFile)javaElement).getResource() instanceof IFile);
			return createDeleteChange(((IClassFile)javaElement).getResource());

		case IJavaElement.JAVA_MODEL: //cannot be done
			Assert.isTrue(false);
			return null;

		case IJavaElement.JAVA_PROJECT: //handled differently
			Assert.isTrue(false);
			return null;

		case IJavaElement.TYPE:
		case IJavaElement.FIELD:
		case IJavaElement.METHOD:
		case IJavaElement.INITIALIZER:
		case IJavaElement.PACKAGE_DECLARATION:
		case IJavaElement.IMPORT_CONTAINER:
		case IJavaElement.IMPORT_DECLARATION:
			Assert.isTrue(false);//not done here
			return new NullChange();
		default:
			Assert.isTrue(false);//there's no more kinds
			return new NullChange();
	}
}
 
Example 6
Source File: RenameAnalyzeUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method analyzes a set of local variable renames inside one cu. It checks whether
 * any new compile errors have been introduced by the rename(s) and whether the correct
 * node(s) has/have been renamed.
 *
 * @param analyzePackages the LocalAnalyzePackages containing the information about the local renames
 * @param cuChange the TextChange containing all local variable changes to be applied.
 * @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit
 * @param recovery whether statements and bindings recovery should be performed when parsing the changed CU
 * @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found
 * @throws CoreException thrown if there was an error greating the preview content of the change
 */
public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException {

	RefactoringStatus result= new RefactoringStatus();
	ICompilationUnit compilationUnit= (ICompilationUnit) oldCUNode.getJavaElement();

	String newCuSource= cuChange.getPreviewContent(new NullProgressMonitor());
	CompilationUnit newCUNode= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null);

	result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode));
	if (result.hasError()) {
		return result;
	}

	for (int i= 0; i < analyzePackages.length; i++) {
		ASTNode enclosing= getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode);

		// get new declaration
		IRegion newRegion= RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange);
		ASTNode newDeclaration= NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength());
		Assert.isTrue(newDeclaration instanceof Name);

		VariableDeclaration declaration= getVariableDeclaration((Name) newDeclaration);
		Assert.isNotNull(declaration);

		SimpleName[] problemNodes= ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange);
		result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes));
	}
	return result;
}
 
Example 7
Source File: Log.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private Remote findRemote(String refName) throws URISyntaxException {
	Assert.isLegal(refName.startsWith(Constants.R_REMOTES), NLS.bind("Expected Ref starting with {0} was {1}", Constants.R_REMOTES, refName));
	IPath remoteNameCandidate = new Path(refName).removeFirstSegments(2);
	List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig());
	for (int i = 1; i < remoteNameCandidate.segmentCount(); i++) {
		for (RemoteConfig remoteConfig : remoteConfigs) {
			IPath uptoSegment = remoteNameCandidate.uptoSegment(i);
			if (remoteConfig.getName().equals(uptoSegment.toString()))
				return new Remote(cloneLocation, db, remoteConfig.getName());
		}
	}
	Assert.isTrue(false, NLS.bind("Could not find Remote for {0}", refName));
	return null;
}
 
Example 8
Source File: JdtFlags.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static int getVisibilityCode(IMember member) throws JavaModelException {
	if (isPublic(member)) {
		return Modifier.PUBLIC;
	} else if (isProtected(member)) {
		return Modifier.PROTECTED;
	} else if (isPackageVisible(member)) {
		return Modifier.NONE;
	} else if (isPrivate(member)) {
		return Modifier.PRIVATE;
	}
	Assert.isTrue(false);
	return VISIBILITY_CODE_INVALID;
}
 
Example 9
Source File: DotExportRadioGroupFieldEditor.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
public DotExportRadioGroupFieldEditor(String name, String labelText,
		String dotExportHintText, int numColumns,
		String[][] labelsAndValues, Composite parent, boolean useGroup) {
	init(name, labelText);
	if (labelsAndValues != null) {
		Assert.isTrue(checkArray(labelsAndValues));
	}
	this.labelsAndValues = labelsAndValues;
	this.numColumns = numColumns;
	this.useGroup = useGroup;
	this.parent = parent;
	this.dotExportHintText = dotExportHintText;
	createControl(parent);
}
 
Example 10
Source File: ChangeMethodSignatureProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public ChangeMethodSignatureProposal(String label, ICompilationUnit targetCU, ASTNode invocationNode,
		IMethodBinding binding, ChangeDescription[] paramChanges, ChangeDescription[] exceptionChanges,
		int relevance) {
	super(label, CodeActionKind.QuickFix, targetCU, null, relevance);

	Assert.isTrue(binding != null && Bindings.isDeclarationBinding(binding));

	fInvocationNode= invocationNode;
	fSenderBinding= binding;
	fParameterChanges= paramChanges;
	fExceptionChanges= exceptionChanges;
}
 
Example 11
Source File: DocumentPartitioner.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * May be extended by subclasses.
 * </p>
 * 
 * @since 2.2
 */
@Override
public synchronized void documentAboutToBeChanged(DocumentEvent e) {
	if (fIsInitialized) {

		Assert.isTrue(e.getDocument() == fDocument);

		fStartOffset = -1;
		fEndOffset = -1;
		fDeleteOffset = -1;
	}
}
 
Example 12
Source File: MultiLineTextFieldEditor.java    From uml2solidity with Eclipse Public License 1.0 4 votes vote down vote up
public void setValidateStrategy(int value) {
	Assert.isTrue(value == VALIDATE_ON_FOCUS_LOST
			|| value == VALIDATE_ON_KEY_STROKE);
	validateStrategy = value;
}
 
Example 13
Source File: SequenceCharacterIterator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private void invariant() {
	Assert.isTrue(fIndex >= fFirst);
	Assert.isTrue(fIndex <= fLast);
}
 
Example 14
Source File: TestingEnvironment.java    From dacapobench with Apache License 2.0 4 votes vote down vote up
private void checkAssertion(String message, boolean b) {
  Assert.isTrue(b, message);
}
 
Example 15
Source File: ParentChecker.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private IResource getCommonResourceParent() {
	Assert.isNotNull(fResources);
	Assert.isTrue(fResources.length > 0);//safe - checked before
	return fResources[0].getParent();
}
 
Example 16
Source File: FixedScopedPreferenceStore.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Set the search contexts to scopes. When searching for a value the seach
 * will be done in the order of scope contexts and will not search the
 * storeContext unless it is in this list.
 * <p>
 * If the given list is <code>null</code>, then clear this store's search
 * contexts. This means that only this store's scope context and default
 * scope will be used during preference value searching.
 * </p>
 * <p>
 * The defaultContext will be added to the end of this list automatically
 * and <em>MUST NOT</em> be included by the user.
 * </p>
 * 
 * @param scopes
 *            a list of scope contexts to use when searching, or
 *            <code>null</code>
 */
public void setSearchContexts(IScopeContext[] scopes) {
	if (scopes == null) {
		return;
	}
	this.searchContexts = scopes.clone();

	// Assert that the default was not included (we automatically add it to
	// the end)
	for (int i = 0; i < scopes.length; i++) {
		if (scopes[i].equals(defaultContext)) {
			Assert
					.isTrue(
							false,
							org.eclipse.ui.internal.WorkbenchMessages.ScopedPreferenceStore_DefaultAddedError);
		}
	}
}
 
Example 17
Source File: RefactoringSearchEngine2.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets the severity of the generated status entries.
 * <p>
 * This method must be called before start searching. The default is a severity of {@link RefactoringStatus#OK}.
 *
 * @param severity the severity to set
 */
public final void setSeverity(final int severity) {
	Assert.isTrue(severity == RefactoringStatus.WARNING || severity == RefactoringStatus.INFO || severity == RefactoringStatus.FATAL || severity == RefactoringStatus.ERROR);
	fSeverity= severity;
}
 
Example 18
Source File: ListDialogField.java    From xtext-eclipse with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets the index of the 'remove' button in the button label array passed in
 * the constructor. The behavior of the button marked as the 'remove' button
 * will then be handled internally. (enable state, button invocation
 * behavior)
 */
public void setRemoveButtonIndex(int removeButtonIndex) {
	Assert.isTrue(removeButtonIndex < fButtonLabels.length);
	fRemoveButtonIndex = removeButtonIndex;
}
 
Example 19
Source File: NLSElement.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Returns the accessor class reference for this element.
 * <p>
 * Note: this call is only valid when the element is
 * using the Eclipse NLS mechanism.
 * </p>
 *
 * @return the accessor class reference
 * @since 3.1
 */
public AccessorClassReference getAccessorClassReference() {
	Assert.isTrue(fIsEclipseNLS);
	return fAccessorClassReference;
}
 
Example 20
Source File: NLSElement.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets the accessor class reference for this element.
 * <p>
 * Note: this call is only valid when the element is
 * using the Eclipse NLS mechanism.
 * </p>
 *
 * @param accessorClassRef the accessor class reference
 * @since 3.1
 */
public void setAccessorClassReference(AccessorClassReference accessorClassRef) {
	Assert.isTrue(fIsEclipseNLS);
	fAccessorClassReference= accessorClassRef;
}