use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class ErrorAwareLinkingService method getLinkedObjects.
@Override
public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node) throws IllegalNodeException {
final EClass requiredType = ref.getEReferenceType();
if (requiredType == null)
return Collections.<EObject>emptyList();
final String crossRefString = getCrossRefNodeAsString(context, ref, node);
if (crossRefString != null && !crossRefString.equals("")) {
final IScope scope = getScope(context, ref);
QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
IEObjectDescription eObjectDescription = scope.getSingleElement(qualifiedLinkName);
if (IEObjectDescriptionWithError.isErrorDescription(eObjectDescription) && context.eResource() != null && !n4jsCore.isNoValidate(context.eResource().getURI())) {
addError(context, node, IEObjectDescriptionWithError.getDescriptionWithError(eObjectDescription));
} else if (eObjectDescription instanceof UnresolvableObjectDescription) {
return Collections.<EObject>singletonList((EObject) context.eGet(ref, false));
}
if (eObjectDescription != null) {
EObject candidate = eObjectDescription.getEObjectOrProxy();
if (!candidate.eIsProxy() && candidate.eResource() == null) {
// Error is necessary since EMF catches all exceptions in EcoreUtil#resolve
throw new AssertionError("Found an instance without resource and without URI");
}
// if supported, mark object description as used
if (eObjectDescription instanceof IUsageAwareEObjectDescription) {
((IUsageAwareEObjectDescription) eObjectDescription).markAsUsed();
}
return Collections.singletonList(candidate);
}
}
return Collections.emptyList();
}
use of org.eclipse.xtext.resource.IEObjectDescription in project n4js by eclipse.
the class BuiltInTypeScopePluginTest method testLoadingBuiltInTypes.
@SuppressWarnings("javadoc")
@Test
public void testLoadingBuiltInTypes() {
XtextResourceSet resourceSet = (XtextResourceSet) resourceSetProvider.get(null);
resourceSet.setClasspathURIContext(N4JSResource.class.getClassLoader());
BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet);
IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any"));
Assert.assertNotNull(anyType);
}
use of org.eclipse.xtext.resource.IEObjectDescription in project dsl-devkit by dsldevkit.
the class CheckResourceUtil method allGrammars.
/**
* Gets all available grammars.
* <p>
* The result contains no null entries.
* </p>
*
* @return an iterator over all grammars in the workspace followed by all those in the registry.
*/
private Iterable<Grammar> allGrammars() {
final ResourceSet resourceSetForResolve = new ResourceSetImpl();
final Function<IEObjectDescription, Grammar> description2GrammarTransform = new Function<IEObjectDescription, Grammar>() {
@Override
public Grammar apply(final IEObjectDescription desc) {
EObject obj = desc.getEObjectOrProxy();
if (obj != null && obj.eIsProxy()) {
obj = EcoreUtil.resolve(obj, resourceSetForResolve);
}
if (obj instanceof Grammar && !obj.eIsProxy()) {
return (Grammar) obj;
} else {
return null;
}
}
};
final Iterable<IEObjectDescription> grammarDescriptorsFromIndex = Access.getIResourceDescriptions().get().getExportedObjectsByType(XtextPackage.Literals.GRAMMAR);
return Iterables.concat(Iterables.filter(Iterables.transform(grammarDescriptorsFromIndex, description2GrammarTransform), Predicates.notNull()), allGrammarsFromRegistry());
}
use of org.eclipse.xtext.resource.IEObjectDescription in project dsl-devkit by dsldevkit.
the class ResourceDescriptionDelta method internalHasObjectFingerprints.
/**
* Internal helper method to initialize {@link #objectFingerprints}.
*
* @return {@code true} if this delta has object fingerprints
*/
private boolean internalHasObjectFingerprints() {
IResourceDescription desc = newDesc == null ? oldDesc : getNew();
final Iterator<IEObjectDescription> objectIter = desc.getExportedObjects().iterator();
if (!objectIter.hasNext()) {
return false;
} else {
return objectIter.next().getUserData(IFingerprintComputer.OBJECT_FINGERPRINT) != null;
}
}
use of org.eclipse.xtext.resource.IEObjectDescription in project dsl-devkit by dsldevkit.
the class ResourceDescriptionDelta method internalHasChanges.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "PMD.CompareObjectsWithEquals", "PMD.NPathComplexity" })
protected boolean internalHasChanges() {
if (getNew() == null || oldDesc == null) {
// Deleted or new resource
return true;
}
final Iterator<IEObjectDescription> oldObjectsIter = oldDesc.getExportedObjects().iterator();
final Iterator<IEObjectDescription> newObjectsIter = getNew().getExportedObjects().iterator();
final boolean empty = !oldObjectsIter.hasNext();
if (empty != !newObjectsIter.hasNext()) {
// One is empty, but the other one is not
return true;
} else if (empty) {
// Both are empty
return false;
}
final IEObjectDescription oldFirst = oldObjectsIter.next();
final IEObjectDescription newFirst = newObjectsIter.next();
objectFingerprints = newFirst.getUserData(IFingerprintComputer.OBJECT_FINGERPRINT) != null;
final String oldHash = oldFirst.getUserData(IFingerprintComputer.RESOURCE_FINGERPRINT);
final String newHash = newFirst.getUserData(IFingerprintComputer.RESOURCE_FINGERPRINT);
if (oldHash != null && newHash != null) {
// Both have fingerprints: it suffices to compare those!
return !oldHash.equals(newHash);
}
// At least one has no fingerprint. If both have none, try the default method, otherwise, there is a change.
if (oldHash != newHash) {
if (LOGGER.isDebugEnabled()) {
// $NON-NLS-1$ //$NON-NLS-2$
LOGGER.debug(getNew().getURI().toString() + ": fingerprint has changed from: " + oldHash + " to " + newHash);
}
return true;
}
if (!equals(oldFirst, newFirst)) {
return true;
}
while (oldObjectsIter.hasNext()) {
if (!newObjectsIter.hasNext() || !equals(oldObjectsIter.next(), newObjectsIter.next())) {
return true;
}
}
return newObjectsIter.hasNext();
}
Aggregations