Java Code Examples for org.eclipse.xtext.EcoreUtil2#getPlatformResourceOrNormalizedURI()

The following examples show how to use org.eclipse.xtext.EcoreUtil2#getPlatformResourceOrNormalizedURI() . 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: ConcreteSyntaxAwareReferenceFinder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void checkValue(EObject value, Resource localResource, Predicate<URI> targetURIs, EObject sourceCandidate,
		URI sourceURI, EReference ref, Acceptor acceptor) {
	EObject instanceOrProxy = toValidInstanceOrNull(localResource, targetURIs,
			value);

	if (instanceOrProxy != null) {
		URI refURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(instanceOrProxy);
		// CUSTOM BEHAVIOR: handle composed members
		if (referenceHasBeenFound(targetURIs, refURI, instanceOrProxy)) {
			sourceURI = (sourceURI == null) ? EcoreUtil2
					.getPlatformResourceOrNormalizedURI(sourceCandidate) : sourceURI;
			acceptor.accept(sourceCandidate, sourceURI, ref, -1, instanceOrProxy, refURI);
		}
	}

}
 
Example 2
Source File: ConcreteSyntaxAwareReferenceFinder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private boolean referenceHasBeenFound(Predicate<URI> targetURIs, URI refURI, EObject instanceOrProxy) {
	boolean result = false;
	// If the EObject is a composed member, we compare the target URIs with the URIs of the constituent members.
	if (instanceOrProxy instanceof TMember && ((TMember) instanceOrProxy).isComposed()) {
		TMember member = (TMember) instanceOrProxy;
		if (member.isComposed()) {
			for (TMember constituentMember : member.getConstituentMembers()) {
				URI constituentReffURI = EcoreUtil2
						.getPlatformResourceOrNormalizedURI(constituentMember);
				result = result || targetURIs.apply(constituentReffURI);
			}
		}
	} else {
		// Standard case
		result = targetURIs.apply(refURI);
	}
	return result;
}
 
Example 3
Source File: MultimapBasedSelectable.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) {
	if (allDescriptions.isEmpty())
		return Collections.emptyList();
	final URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(object);
	return Iterables.filter(allDescriptions, new Predicate<IEObjectDescription>() {
		@Override
		public boolean apply(IEObjectDescription input) {
			if (input.getEObjectOrProxy() == object)
				return true;
			if (uri.equals(input.getEObjectURI())) {
				return true;
			}
			return false;
		}
	});
}
 
Example 4
Source File: LayeredTypeResourceDescription.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) {
	final URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(object);
	Iterable<IEObjectDescription> additionallyFiltered = Iterables.filter(getExportedObjects(), new Predicate<IEObjectDescription>() {
		@Override
		public boolean apply(IEObjectDescription input) {
			if (input.getEObjectOrProxy() == object)
				return true;
			if (uri.equals(input.getEObjectURI())) {
				return true;
			}
			return false;
		}
	});
	return Iterables.concat(delegate.getExportedObjectsByObject(object), additionallyFiltered);
}
 
Example 5
Source File: DotReferenceFinder.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Using the @Override notation leads to a compile error on some (e.g NEON,
 * OXYGEN, PHOTON, ...) platforms, since this internal Xtext API has been
 * changed over time.
 *
 * see
 * https://github.com/eclipse/xtext-core/commit/69064ac12f0144b60d8c7511d41c834db44a67f2
 *
 * This method will be invoked on ...LUNA, MARS, platforms
 */
public void findReferences(TargetURIs targetURIs, Resource resource,
		Acceptor acceptor, IProgressMonitor monitor) {
	// add DOT specific references
	for (URI targetURI : targetURIs) {
		EObject target = resource.getEObject(targetURI.fragment());
		// currently, only a selection of a nodeId is supported
		if (target instanceof NodeId) {
			acceptor.accept(target, targetURI, null, -1, target, targetURI);
			NodeId selectedNodeId = (NodeId) target;
			for (NodeId source : DotAstHelper
					.getAllNodeIds(selectedNodeId)) {
				URI sourceURI = EcoreUtil2
						.getPlatformResourceOrNormalizedURI(source);
				acceptor.accept(source, sourceURI, null, -1, target,
						targetURI);
			}
		}
	}
}
 
Example 6
Source File: EObjectDescriptionLookUp.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) {
	if (allDescriptions.isEmpty())
		return Collections.emptyList();
	final URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(object);
	return Iterables.filter(allDescriptions, new Predicate<IEObjectDescription>() {
		@Override
		public boolean apply(IEObjectDescription input) {
			if (input.getEObjectOrProxy() == object)
				return true;
			if (uri.equals(input.getEObjectURI())) {
				return true;
			}
			return false;
		}
	});
}
 
Example 7
Source File: TerminalMapBasedScope.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<IEObjectDescription> getElements(final EObject object) {
	final URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(object);
	final IEObjectDescription[] result = new IEObjectDescription[1];
	elements.forEachPair((s, input) -> {
		if (input.getEObjectOrProxy() == object || uri.equals(input.getEObjectURI())) {
			result[0] = input;
			return false;
		}
		return true;
	});

	return result[0] == null ? Collections.EMPTY_LIST : Arrays.asList(result);
}
 
Example 8
Source File: GamlScopeProvider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getExportedObjectsByObject(final EObject object) {
	if (descriptions == null) { return Collections.emptyList(); }
	final URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(object);
	return Iterables.filter(descriptions, input -> {
		if (input.getEObjectOrProxy() == object) { return true; }
		if (uri.equals(input.getEObjectURI())) { return true; }
		return false;
	});
}
 
Example 9
Source File: AbstractScope.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<IEObjectDescription> getElements(final EObject object) {
	final URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(object);
	Iterable<IEObjectDescription> localElements = getLocalElementsByEObject(object, uri);
	Iterable<IEObjectDescription> parentElements = getParentElements(new Provider<Iterable<IEObjectDescription>>() {
		@Override
		public Iterable<IEObjectDescription> get() {
			return getParent().getElements(object);
		}
	});
	Iterable<IEObjectDescription> result = Iterables.concat(localElements, parentElements);
	return result;
}
 
Example 10
Source File: CrossReferenceSerializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node,
		Acceptor errors) {
	if ((target == null || target.eIsProxy()) && node != null)
		return tokenUtil.serializeNode(node);

	final EReference ref = GrammarUtil.getReference(crossref, semanticObject.eClass());
	final IScope scope = scopeProvider.getScope(semanticObject, ref);
	if (scope == null) {
		if (errors != null)
			errors.accept(diagnostics.getNoScopeFoundDiagnostic(semanticObject, crossref, target));
		return null;
	}
	
	if (target != null && target.eIsProxy()) {
		target = handleProxy(target, semanticObject, ref);
	}

	if (target != null && node != null) {
		String text = linkingHelper.getCrossRefNodeAsString(node, true);
		QualifiedName qn = qualifiedNameConverter.toQualifiedName(text);
		URI targetURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(target);
		for (IEObjectDescription desc : scope.getElements(qn)) {
			if (targetURI.equals(desc.getEObjectURI()))
				return tokenUtil.serializeNode(node);
		}
	}

	return getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors);
}
 
Example 11
Source File: DefaultReferenceDescription.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public DefaultReferenceDescription(EObject from, EObject to, EReference eReference, int i, URI containerEObjectURI) {
	this.sourceEObjectUri = EcoreUtil2.getPlatformResourceOrNormalizedURI(from);
	this.targetEObjectUri = EcoreUtil2.getPlatformResourceOrNormalizedURI(to);
	this.eReference = eReference;
	this.indexInList = i;
	this.containerEObjectURI = containerEObjectURI;
}
 
Example 12
Source File: XtendReferenceFinder.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void addReferenceIfTarget(final EObject candidate, final Predicate<URI> targetURISet, final EObject sourceElement, final EReference reference, final IReferenceFinder.Acceptor acceptor) {
  final URI candidateURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(candidate);
  boolean _apply = targetURISet.apply(candidateURI);
  if (_apply) {
    final URI sourceURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(sourceElement);
    acceptor.accept(sourceElement, sourceURI, reference, (-1), candidate, candidateURI);
  }
}
 
Example 13
Source File: IRenameContextFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected IRenameElementContext createLocalRenameElementContext(EObject targetElement, XtextEditor editor,
		ITextSelection selection, XtextResource resource) {
	final URI targetElementURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(targetElement);
	IRenameElementContext.Impl renameElementContext = new IRenameElementContext.Impl(targetElementURI,
			targetElement.eClass(), editor, selection, resource.getURI());
	return renameElementContext;
}
 
Example 14
Source File: FindReferencesHandler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ReferenceQueryExecutor getQueryExecutor(EObject target) {
	if (target == null) {
		return null;
	}
	URI targetURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(target);
	if(targetURI != null) {
		ReferenceQueryExecutor queryExecutor = globalServiceProvider.findService(targetURI.trimFragment(), ReferenceQueryExecutor.class);
		if (queryExecutor != null) {
			queryExecutor.init(target);
			return queryExecutor;
		}
	}
	return null;
}
 
Example 15
Source File: DefaultReferenceFinder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Deprecated
protected Map<EObject, URI> createExportedElementsMap(final Resource resource) {
	return new ForwardingMap<EObject, URI>() {

		private Map<EObject, URI> delegate;
		
		@Override
		protected Map<EObject, URI> delegate() {
			if (delegate != null) {
				return delegate;
			}
			URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(resource);
			IResourceServiceProvider resourceServiceProvider = getServiceProviderRegistry().getResourceServiceProvider(uri);
			if (resourceServiceProvider == null) {
				return delegate = Collections.emptyMap();
			}
			IResourceDescription.Manager resourceDescriptionManager = resourceServiceProvider.getResourceDescriptionManager();
			if (resourceDescriptionManager == null) {
				return delegate = Collections.emptyMap();
			}
			IResourceDescription resourceDescription = resourceDescriptionManager.getResourceDescription(resource);
			Map<EObject, URI> exportedElementMap = newIdentityHashMap();
			if (resourceDescription != null) {
				for (IEObjectDescription exportedEObjectDescription : resourceDescription.getExportedObjects()) {
					EObject eObject = resource.getEObject(exportedEObjectDescription.getEObjectURI().fragment());
					if (eObject != null)
						exportedElementMap.put(eObject, exportedEObjectDescription.getEObjectURI());
				}
			}
			return delegate = exportedElementMap;
		}

		
	};
}
 
Example 16
Source File: TargetURICollector.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void doAdd(EObject object, TargetURIs targetURIs) {
	URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(object);
	targetURIs.addURI(uri);
}
 
Example 17
Source File: N4JSReferenceQueryExecutor.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Here, we add overridden/overriding members or super/subclasses if needed depending on user preferences when
 * finding references.
 */
@Override
protected Iterable<URI> getTargetURIs(EObject primaryTarget) {
	@SuppressWarnings("restriction")
	Iterable<URI> originalResult = super.getTargetURIs(primaryTarget);
	List<URI> newResult = Lists.newArrayList(originalResult);

	if (primaryTarget instanceof LiteralOrComputedPropertyName) {
		primaryTarget = primaryTarget.eContainer();
	}

	// Handling for various configurations e.g. consider overriden members
	List<EObject> realTargets = new ArrayList<>();
	if (primaryTarget instanceof TMember && ((TMember) primaryTarget).isComposed()) {
		// In case of composed member, add the constituent members instead.
		List<TMember> constituentMembers = ((TMember) primaryTarget).getConstituentMembers();
		for (TMember constituentMember : constituentMembers) {
			realTargets.add(constituentMember);
		}
	} else {
		// Standard case
		realTargets.add(primaryTarget);
	}

	for (EObject realTarget : realTargets) {
		if (N4JSReferenceQueryExecutor.considerOverridenMethods) {
			// Add overriden members
			if (realTarget instanceof N4MemberDeclaration
					// Only consider members within a classifier.Ignore TStructMember.
					|| (realTarget instanceof TMember && realTarget.eContainer() instanceof TClassifier)) {
				TMember tmember;
				if (primaryTarget instanceof N4MemberDeclaration) {
					tmember = ((N4MemberDeclaration) primaryTarget).getDefinedTypeElement();
				} else {
					tmember = (TMember) primaryTarget;
				}
				for (TMember inheritedOrImplementedMember : getInheritedAndImplementedMembers(tmember)) {
					URI uri = EcoreUtil2.getPlatformResourceOrNormalizedURI(inheritedOrImplementedMember);
					newResult.add(uri);
				}
			}
		}
	}

	return newResult;
}