use of org.eclipse.n4js.n4JS.PropertyNameOwner in project n4js by eclipse.
the class FindReferencesXpectMethod method findReferences.
/**
* This Xpect methods compares all computed references at a given EObject to the expected references. The expected
* references include the line number.
*/
@Xpect
@ParameterParser(syntax = "('at' arg1=OFFSET)?")
public void findReferences(@N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectation, IEObjectCoveringRegion offset) {
// When you write Xpect test methods, ALWAYS retrieve eObject via IEObjectCoveringRegion to get the right
// eObject!
// Do NOT use EObject arg1!
EObject context = offset.getEObject();
EObject argEObj = offsetHelper.resolveElementAt((XtextResource) context.eResource(), offset.getOffset());
// If not a cross-reference element, use context instead
if (argEObj == null)
argEObj = context;
EObject eObj = argEObj;
if (argEObj instanceof ParameterizedTypeRef)
eObj = ((ParameterizedTypeRef) argEObj).getDeclaredType();
List<EObject> refs = findReferenceHelper.findReferences(eObj);
ArrayList<String> result = Lists.newArrayList();
for (EObject ref : refs) {
if (ref instanceof PropertyNameOwner)
ref = ((PropertyNameOwner) ref).getDeclaredName();
ICompositeNode srcNode = NodeModelUtils.getNode(ref);
int line = srcNode.getStartLine();
String moduleName;
if (ref.eResource() instanceof N4JSResource) {
N4JSResource n4jsResource = (N4JSResource) ref.eResource();
moduleName = n4jsResource.getModule().getQualifiedName();
} else {
moduleName = "(unknown resource)";
}
String text = NodeModelUtils.getTokenText(srcNode);
if (ref instanceof GenericDeclaration)
text = ((GenericDeclaration) ref).getDefinedType().getName();
String resultText = moduleName + " - " + text + " - " + line;
result.add(resultText);
}
expectation.assertEquals(result);
}
Aggregations