use of org.eclipse.n4js.n4JS.NamedElement 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.n4js.n4JS.NamedElement in project n4js by eclipse.
the class N4ClassDeclarationImpl method getExportedName.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getExportedName() {
boolean _isExported = this.isExported();
if (_isExported) {
EObject _eContainer = this.eContainer();
final ExportDeclaration exportDecl = ((ExportDeclaration) _eContainer);
boolean _isDefaultExport = exportDecl.isDefaultExport();
if (_isDefaultExport) {
return "default";
}
final ExportableElement me = this;
String _switchResult = null;
boolean _matched = false;
if (me instanceof NamedElement) {
_matched = true;
_switchResult = ((NamedElement) me).getName();
}
if (!_matched) {
if (me instanceof IdentifiableElement) {
_matched = true;
_switchResult = ((IdentifiableElement) me).getName();
}
}
return _switchResult;
}
return null;
}
use of org.eclipse.n4js.n4JS.NamedElement in project n4js by eclipse.
the class N4TypeDeclarationImpl method getExportedName.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getExportedName() {
boolean _isExported = this.isExported();
if (_isExported) {
EObject _eContainer = this.eContainer();
final ExportDeclaration exportDecl = ((ExportDeclaration) _eContainer);
boolean _isDefaultExport = exportDecl.isDefaultExport();
if (_isDefaultExport) {
return "default";
}
final ExportableElement me = this;
String _switchResult = null;
boolean _matched = false;
if (me instanceof NamedElement) {
_matched = true;
_switchResult = ((NamedElement) me).getName();
}
if (!_matched) {
if (me instanceof IdentifiableElement) {
_matched = true;
_switchResult = ((IdentifiableElement) me).getName();
}
}
return _switchResult;
}
return null;
}
Aggregations