org.eclipse.xtext.util.Arrays Java Examples

The following examples show how to use org.eclipse.xtext.util.Arrays. 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: N4JSProjectExplorerContentProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object getParent(Object element) {

	// Required by editor - navigator linking to locate parent item in tree.
	if (element instanceof IProject && workingSetManagerBroker.isWorkingSetTopLevel()) {
		final WorkingSetManager activeManager = workingSetManagerBroker.getActiveManager();
		if (activeManager != null) {
			for (final WorkingSet workingSet : activeManager.getWorkingSets()) {
				final IAdaptable[] elements = workingSet.getElements();
				if (!Arrays2.isEmpty(elements) && Arrays.contains(elements, element)) {
					return workingSet;
				}
			}
		}
	}

	return super.getParent(element);
}
 
Example #2
Source File: PreparationStep.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void copyReference(EReference eReference, EObject eObject, EObject copyEObject) {
	final boolean needsRewiring = Arrays.contains(REWIRED_REFERENCES, eReference);
	if (needsRewiring) {
		if (!(copyEObject instanceof ReferencingElement_IM)) {
			throw new IllegalStateException(
					"an EObject with a cross-reference that requires rewiring must have a copy of type ReferencingElement_IM;"
							+ "\nin object: " + eObject
							+ "\nin resource: " + eObject.eResource().getURI());
		}
		rewire(eObject, (ReferencingElement_IM) copyEObject);
		// note: suppress default behavior (references "id", "property", "declaredType" should stay at 'null')
	} else {
		super.copyReference(eReference, eObject, copyEObject);
	}
}
 
Example #3
Source File: SARLQuickfixProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Remove the element related to the issue, and the whitespaces before the element until one of the given
 * keywords is encountered.
 *
 * @param issue the issue.
 * @param document the document.
 * @param keyword1 the first keyword to consider.
 * @param otherKeywords other keywords.
 * @return <code>true</code> if one keyword was found, <code>false</code> if not.
 * @throws BadLocationException if there is a problem with the location of the element.
 */
public boolean removeToPreviousKeyword(Issue issue, IXtextDocument document,
		String keyword1, String... otherKeywords) throws BadLocationException {
	// Skip spaces before the element
	int index = issue.getOffset() - 1;
	char c = document.getChar(index);
	while (Character.isWhitespace(c)) {
		index--;
		c = document.getChar(index);
	}

	// Skip non-spaces before the identifier
	final StringBuffer kw = new StringBuffer();
	while (!Character.isWhitespace(c)) {
		kw.insert(0, c);
		index--;
		c = document.getChar(index);
	}

	if (kw.toString().equals(keyword1) || Arrays.contains(otherKeywords, kw.toString())) {
		// Skip spaces before the previous keyword
		while (Character.isWhitespace(c)) {
			index--;
			c = document.getChar(index);
		}

		final int delta = issue.getOffset() - index - 1;
		document.replace(index + 1, issue.getLength() + delta, ""); //$NON-NLS-1$

		return true;
	}

	return false;
}
 
Example #4
Source File: EObjectDescriptionDeltaProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isUserDataEqual(IEObjectDescription oldObj, IEObjectDescription newObj) {
	String[] oldKeys = oldObj.getUserDataKeys();
	String[] newKeys = newObj.getUserDataKeys();
	if (oldKeys.length != newKeys.length)
		return false;
	for (String key : oldKeys) {
		if (!Arrays.contains(newKeys, key))
			return false;
		String oldValue = oldObj.getUserData(key);
		String newValue = newObj.getUserData(key);
		if (!Objects.equal(oldValue, newValue))
			return false;
	}
	return true;
}
 
Example #5
Source File: ValidationTestHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void assertNoError(final Resource resource, final String issuecode, final String userData) {
	final List<Issue> validate = validate(resource);
	Iterable<Issue> issues = filter(validate, new Predicate<Issue>() {
		@Override
		public boolean apply(Issue input) {
			if (issuecode.equals(input.getCode())) {
				return userData == null || Arrays.contains(input.getData(), userData);
			}
			return false;
		}
	});
	if (!isEmpty(issues))
		fail("Expected no error '" + issuecode + "' but got " + getIssuesAsString(resource, issues, new StringBuilder()));
}
 
Example #6
Source File: XtextLinkingDiagnostic.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param data optional user data. May not contain <code>null</code> entries.
 * @throws NullPointerException if node is <code>null</code> or data contains <code>null</code>.
 */
public XtextLinkingDiagnostic(INode node, String message, String code, String... data) {
	if (node == null)
		throw new NullPointerException("node may not be null");
	if (Arrays.contains(data, null)) {
		throw new NullPointerException("data may not contain null");
	}
	this.node = node;
	this.message = message;
	this.code = code;
	this.data = data;
}
 
Example #7
Source File: DefaultResourceDescriptionDelta.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean equals(IEObjectDescription oldObj, IEObjectDescription newObj) {
	if (oldObj == newObj)
		return true;
	if (oldObj.getEClass() != newObj.getEClass())
		return false;
	if (oldObj.getName() != null && !oldObj.getName().equals(newObj.getName()))
		return false;
	if (!oldObj.getEObjectURI().equals(newObj.getEObjectURI()))
		return false;
	String[] oldKeys = oldObj.getUserDataKeys();
	String[] newKeys = newObj.getUserDataKeys();
	if (oldKeys.length != newKeys.length)
		return false;
	for (String key : oldKeys) {
		if (!Arrays.contains(newKeys, key))
			return false;
		String oldValue = oldObj.getUserData(key);
		String newValue = newObj.getUserData(key);
		if (oldValue == null) {
			if (newValue != null)
				return false;
		} else if (!oldValue.equals(newValue)) {
			return false;
		}
	}
	return true;
}
 
Example #8
Source File: AbstractValidationDiagnostic.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param issueData optional user data. May not contain <code>null</code> entries.
 */
protected AbstractValidationDiagnostic(int severity, String message, EObject source, CheckType checkType, String issueCode, String... issueData) {
	if (Arrays.contains(issueData, null)) {
		throw new NullPointerException("issueData may not contain null");
	}
	this.source = source;
	this.severity = severity;
	this.message = message;
	this.issueCode = issueCode;
	this.checkType = checkType;
	this.issueData = issueData;
}
 
Example #9
Source File: ValidationTestHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
public void assertNoError(final Resource resource, final String issuecode, final String userData) {
	final List<Issue> validate = validate(resource);
	Iterable<Issue> issues = filter(validate, new Predicate<Issue>() {
		@Override
		public boolean apply(Issue input) {
			if (issuecode.equals(input.getCode())) {
				return userData == null || Arrays.contains(input.getData(), userData);
			}
			return false;
		}
	});
	if (!isEmpty(issues))
		fail("Expected no error '" + issuecode + "' but got " + getIssuesAsString(resource, issues, new StringBuilder()));
}
 
Example #10
Source File: JavaTypeQuickfixes.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean isUseJavaSearch(EReference unresolvedReference, Issue issue) {
	if (isConstructorReference(unresolvedReference))
		return true;
	if (isTypeReference(unresolvedReference))
		return true;
	if (Arrays.contains(issue.getData(), UnresolvedFeatureCallTypeAwareMessageProvider.TYPE_LITERAL)) {
		return true;
	}
	return false;
}
 
Example #11
Source File: ProjectComparisonEntry.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
public ProjectComparisonEntry getChildForElementImpl(@SuppressWarnings("hiding") EObject elementImpl) {
	if (elementImpl == null)
		throw new IllegalArgumentException("elementImpl may not be null");
	for (ProjectComparisonEntry currE : getChildren())
		if (Arrays.contains(currE.elementImpl, elementImpl))
			return currE;
	return null;
}
 
Example #12
Source File: N4JSResourceDescriptionDelta.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean equals(IEObjectDescription oldObj, IEObjectDescription newObj) {
	if (oldObj == newObj)
		return true;
	if (oldObj.getEClass() != newObj.getEClass())
		return false;
	if (oldObj.getName() != null && !oldObj.getName().equals(newObj.getName()))
		return false;
	if (!oldObj.getEObjectURI().equals(newObj.getEObjectURI()))
		return false;
	String[] oldKeys = oldObj.getUserDataKeys();
	String[] newKeys = newObj.getUserDataKeys();
	if (oldKeys.length != newKeys.length)
		return false;
	for (String key : oldKeys) {
		// ------------------------------------------------ START of changes w.r.t. super class
		if (isIgnoredUserDataKey(key)) {
			continue;
		}
		// ------------------------------------------------ END of changes w.r.t. super class
		if (!Arrays.contains(newKeys, key))
			return false;
		String oldValue = oldObj.getUserData(key);
		String newValue = newObj.getUserData(key);
		if (oldValue == null) {
			if (newValue != null)
				return false;
		} else if (!oldValue.equals(newValue)) {
			return false;
		}
	}
	return true;
}
 
Example #13
Source File: N4JSMemberRedefinitionValidator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private String cfOtherImplementedMembers(MemberMatrix mm, TMember... filteredMembers) {
	String others = validatorMessageHelper.descriptions(
			StreamSupport.stream(mm.implemented().spliterator(), false)
					.filter(m -> !Arrays.contains(filteredMembers, m))
					.collect(Collectors.toList()));
	if (others.length() == 0) {
		return "";
	}
	return " Also cf. " + others + ".";
}
 
Example #14
Source File: ImportsAwareReferenceProposalCreator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates proposal taking semantics of the N4JS imports into account.
 *
 * @param candidate
 *            the original input for which we create proposal
 * @param reference
 *            the reference
 * @param context
 *            the context
 * @return candidate proposal adjusted to the N4JS imports
 */
private IEObjectDescription getAliasedDescription(IEObjectDescription candidate, EReference reference,
		ContentAssistContext context) {

	// Content assist at a location where only simple names are allowed:
	// We found a qualified name and we'd need an import to be allowed to use
	// that name. Consider only the simple name of the element from the index
	// and make sure that the import is inserted as soon as the proposal is applied
	QualifiedName inputQN = candidate.getName();
	int inputNameSegmentCount = inputQN.getSegmentCount();
	if (inputNameSegmentCount > 1
			&& Arrays.contains(referencesSupportingImportedElements, reference))
		return new AliasedEObjectDescription(QualifiedName.create(inputQN.getLastSegment()), candidate);

	// filter out non-importable things:
	// globally provided things should never be imported:
	if (inputNameSegmentCount == 2 && N4TSQualifiedNameProvider.GLOBAL_NAMESPACE_SEGMENT
			.equals(inputQN.getFirstSegment()))
		return new AliasedEObjectDescription(QualifiedName.create(inputQN.getLastSegment()), candidate);

	// special handling for default imports:
	if (inputQN.getLastSegment().equals(N4JSLanguageConstants.EXPORT_DEFAULT_NAME)) {
		if (TExportableElement.class.isAssignableFrom(candidate.getEClass().getInstanceClass())) {
			if (N4JSResourceDescriptionStrategy.getExportDefault(candidate)) {
				return new AliasedEObjectDescription(inputQN, candidate);
			}
		}
		// not accessed via namespace
		QualifiedName nameNoDefault = inputQN.skipLast(1);
		QualifiedName moduleName = nameNoDefault.getSegmentCount() > 1
				? QualifiedName.create(nameNoDefault.getLastSegment())
				: nameNoDefault;
		return new AliasedEObjectDescription(moduleName, candidate);
	}
	// no special handling, return original input
	return candidate;
}
 
Example #15
Source File: WorkingSetAdapter.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean isVisible() {
	final WorkingSet[] visibleWorkingSets = delegate.getWorkingSetManager().getWorkingSets();
	return Arrays.contains(visibleWorkingSets, delegate);
}
 
Example #16
Source File: FilteringMenuManager.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean allowItem(IContributionItem itemToAdd) {
	if (itemToAdd.getId() != null && Arrays.contains(exclusionSet, itemToAdd.getId()))
		itemToAdd.setVisible(false);
	return super.allowItem(itemToAdd);
}
 
Example #17
Source File: DiagramPartitioningEditor.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean allowItem(IContributionItem itemToAdd) {
	if (Arrays.contains(exclude, itemToAdd.getId())) {
		itemToAdd.setVisible(false);
	}
	return true;
}