Java Code Examples for org.eclipse.emf.common.util.SegmentSequence#Builder

The following examples show how to use org.eclipse.emf.common.util.SegmentSequence#Builder . 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: EcoreUtil2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public static String getFragmentPath(EObject object) {
	SegmentSequence.Builder builder = SegmentSequence.newBuilder("/");
	InternalEObject internalEObject = (InternalEObject) object;
	boolean isContained = internalEObject.eDirectResource() != null;
	for (InternalEObject container = internalEObject.eInternalContainer(); 
		container != null && !isContained; 
		container = internalEObject.eInternalContainer()) {
		builder.append(getFragmentPathSegment(container, internalEObject.eContainingFeature(), internalEObject));
		internalEObject = container;
		if (container.eDirectResource() != null) {
			isContained = true;
		}
	}
	if (!isContained) {
		return "/-1";
	}
	builder.append(getFragmentPathRootSegment(internalEObject));
	builder.append("");
	builder.reverse();
	return builder.toSegmentSequence().toString();
}
 
Example 2
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public URI getFullURI(IVariableBinding binding) {
	SegmentSequence.Builder builder = SegmentSequence.newBuilder("");
	URI uri = getFullURI(binding.getDeclaringClass(), builder);
	builder.append(".");
	builder.append(binding.getName());
	return uri.appendFragment(builder.toString());
}
 
Example 3
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public URI getFullURI(ITypeBinding typeBinding, String method) {
	SegmentSequence.Builder builder = SegmentSequence.newBuilder("");
	URI uri = getFullURI(typeBinding, builder);
	URI[] uris = COMMON_METHOD_URIS.get(uri.lastSegment());
	if (uris != null) {
		for (URI methodURI : uris) {
			String fragment = methodURI.fragment();
			if (fragment.startsWith(method, fragment.length() - method.length() - 2)) {
				return methodURI;
			}
		}
	}
	builder.append(".").append(method).append("()");
	return uri.appendFragment(builder.toString());
}
 
Example 4
Source File: TypeURIHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
protected SegmentSequence.Builder getQualifiedName(ITypeBinding binding, SegmentSequence.Builder builder) {
	if (binding.isParameterizedType()) {
		getQualifiedName(binding.getErasure(), builder);
	}
	else if (binding.isArray()) {
		getQualifiedName(binding.getComponentType(), builder).append("[]");
	}
	else if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive()) {
		builder.append(binding.getQualifiedName());
	} else {
		getQualifiedName(binding.getDeclaringClass(), builder).append('$').append(binding.getName());
	}
	return builder;
}
 
Example 5
Source File: N4JSResource.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * We don't use a {@link IFragmentProvider} here. The implementation is a complete copied from
 * {@link ResourceImpl#getURIFragment}
 *
 * @param eObject
 *            the object the URI fragment should be calculated for.
 * @return the calculated URI fragment
 */
private String defaultGetURIFragment(EObject eObject) {
	// Copied from ResourceImpl.getURIFragment to avoid the caching
	// mechanism which will add a content
	// adapter which in turn will resolve / load the resource (while the
	// purpose of all the code is to
	// avoid resource loading)
	InternalEObject internalEObject = (InternalEObject) eObject;
	if (internalEObject.eDirectResource() == this || unloadingContents != null
			&& unloadingContents.contains(internalEObject)) {
		return "/" + getURIFragmentRootSegment(eObject);
	} else {
		SegmentSequence.Builder builder = SegmentSequence.newBuilder("/");

		boolean isContained = false;
		for (InternalEObject container = internalEObject
				.eInternalContainer(); container != null; container = internalEObject
						.eInternalContainer()) {
			builder.append(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject));
			internalEObject = container;
			if (container.eDirectResource() == this || unloadingContents != null
					&& unloadingContents.contains(container)) {
				isContained = true;
				break;
			}
		}

		if (!isContained) {
			return "/-1";
		}

		builder.append(getURIFragmentRootSegment(internalEObject));
		builder.append("");
		builder.reverse();

		// This comment also resides in ResourceImpl.getURIFragment:
		// Note that we convert it to a segment sequence because the
		// most common use case is that callers of this method will call
		// URI.appendFragment.
		// By creating the segment sequence here, we ensure that it's
		// found in the cache.
		//
		return builder.toSegmentSequence().toString();
	}
}