use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.
the class LinkingXpectMethod method linkedPathname.
/**
* Similar to {@link #linkedName(IStringExpectation, ICrossEReferenceAndEObject)} but concatenating the fully
* qualified name again instead of using the qualified name provider, as the latter may not create a valid name for
* non-globally available elements.
* <p>
* The qualified name created by retrieving all "name" properties of the target and its containers, using '/' as
* separator.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public void linkedPathname(@StringExpectation IStringExpectation expectation, ICrossEReferenceAndEObject arg1) {
EObject targetObject = (EObject) arg1.getEObject().eGet(arg1.getCrossEReference());
if (targetObject == null) {
Assert.fail("Reference is null");
// to avoid warnings in the following
return;
}
if (targetObject.eIsProxy())
Assert.fail("Reference is a Proxy: " + ((InternalEObject) targetObject).eProxyURI());
Resource targetResource = targetObject.eResource();
if (targetResource instanceof TypeResource)
targetResource = arg1.getEObject().eResource();
if (!(targetResource instanceof XtextResource))
Assert.fail("Referenced EObject is not in an XtextResource.");
Deque<String> segments = new ArrayDeque<>();
do {
EStructuralFeature nameFeature = targetObject.eClass().getEStructuralFeature("name");
if (nameFeature != null) {
Object obj = targetObject.eGet(nameFeature);
if (obj instanceof String) {
segments.push((String) obj);
}
} else {
if (targetObject instanceof NamedElement) {
segments.push(((NamedElement) targetObject).getName());
}
}
targetObject = targetObject.eContainer();
} while (targetObject != null);
String pathname = Joiner.on('/').join(segments);
expectation.assertEquals(pathname);
}
use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.
the class ScopeXpectMethod method binding.
/**
* Checks that a given element is bound to something identified by (simple) qualified name. The check is designed as
* simple as possible. That is, simply the next following expression is tested, and within that we expect a property
* access or a direct identifiable element. The compared name is the simple qualified name, that is container (type)
* followed by elements name, without URIs of modules etc.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public //
void binding(//
@CommaSeparatedValuesExpectation ICommaSeparatedValuesExpectation expectation, //
ICrossEReferenceAndEObject arg1) {
EObject eobj = arg1.getEObject();
ParameterizedPropertyAccessExpression ppae = EcoreUtil2.getContainerOfType(eobj, ParameterizedPropertyAccessExpression.class);
IdentifiableElement element;
if (ppae != null) {
element = ppae.getProperty();
} else if (eobj instanceof IdentifiableElement) {
element = (IdentifiableElement) eobj;
} else {
throw new IllegalArgumentException("Cannot check binding for " + (eobj == null ? "null" : eobj.eClass().getName()));
}
String container = "";
if (element instanceof TMember) {
container = ((TMember) element).getContainingType().getName() + ".";
}
final String qn = container + element.getName();
// URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
expectation.assertEquals(Collections.singleton(qn));
}
use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.
the class ScopeXpectMethod method scope.
@Override
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public //
void scope(//
@CommaSeparatedValuesExpectation ICommaSeparatedValuesExpectation expectation, //
ICrossEReferenceAndEObject arg1) {
EObject eobj = arg1.getEObject();
IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
expectation.assertEquals(new ScopeAllElements(scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, false, scope));
}
use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.
the class ScopeXpectMethod method scopeWithPosition.
/**
* Compares scope including resource name and line number.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public //
void scopeWithPosition(//
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, //
ICrossEReferenceAndEObject arg1) {
EObject eobj = arg1.getEObject();
IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
for (IEObjectDescription eo : scope.getAllElements()) {
eo.getEObjectURI();
}
URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
expectation.assertEquals(new ScopeAwareIterable(uri, true, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, true, scope));
}
use of org.eclipse.xpect.xtext.lib.util.XtextOffsetAdapter.ICrossEReferenceAndEObject in project n4js by eclipse.
the class ScopeXpectMethod method scopeWithResource.
/**
* Compares scope including resource name but not line number.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public //
void scopeWithResource(//
@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, //
ICrossEReferenceAndEObject arg1) {
EObject eobj = arg1.getEObject();
IScope scope = scopeProvider.getScope(eobj, arg1.getCrossEReference());
for (IEObjectDescription eo : scope.getAllElements()) {
eo.getEObjectURI();
}
URI uri = eobj == null ? null : eobj.eResource() == null ? null : eobj.eResource().getURI();
expectation.assertEquals(new ScopeAwareIterable(uri, false, scope), new IsInScopeWithOptionalPositionPredicate(converter, uri, false, scope));
}
Aggregations