use of org.eclipse.n4js.ts.types.SyntaxRelatedTElement in project n4js by eclipse.
the class JSDoc2SpecAcceptor method toPos.
private String toPos(EObject eobj) {
if (eobj == null)
return "";
StringBuilder strb = new StringBuilder();
String res = null;
if (eobj.eResource() != null) {
res = eobj.eResource().getURI().toString();
if (res.startsWith("platform:/resource/")) {
res = res.substring("platform:/resource/".length());
}
}
if (res != null)
strb.append(res);
EObject astNode = eobj instanceof SyntaxRelatedTElement ? ((SyntaxRelatedTElement) eobj).getAstElement() : eobj;
ICompositeNode node = NodeModelUtils.findActualNodeFor(astNode);
if (node != null) {
strb.append(":").append(node.getStartLine());
}
return strb.toString();
}
use of org.eclipse.n4js.ts.types.SyntaxRelatedTElement in project n4js by eclipse.
the class N4JSUnloader method unload.
private void unload(ObjectToFragment element, URI resourceURI) {
InternalEObject eObject = (InternalEObject) element.object;
if (eObject instanceof SyntaxRelatedTElement) {
SyntaxRelatedTElement casted = (SyntaxRelatedTElement) eObject;
EObject astElementOrProxy = (EObject) casted.eGet(TypesPackage.Literals.SYNTAX_RELATED_TELEMENT__AST_ELEMENT, false);
if (astElementOrProxy != null && !astElementOrProxy.eIsProxy()) {
// release the reference to the AST
casted.eSetDeliver(false);
casted.setAstElement(null);
}
}
eObject.eSetProxyURI(resourceURI.appendFragment(element.fragment));
}
use of org.eclipse.n4js.ts.types.SyntaxRelatedTElement in project n4js by eclipse.
the class EObjectDescriptionToNameWithPositionMapper method descriptionToNameWithPosition.
/**
* Returns a string with name and position of the described object. The position is specified by line number (if
* possible, otherwise the uri fragment of the proxy is used). If the object is a {@link SyntaxRelatedTElement}, a
* "T" is used as a prefix of the line number.
*
* The following examples shows different mappings, depending on the described object:
* <table>
* <tr>
* <th>Mapping</th>
* <th>Described Object</th>
* </tr>
* <tr>
* <td><code>bar - 42</code></td>
* <td>Some element "bar", located in same resource on line 42</td>
* </tr>
* <tr>
* <td><code>foo - T23</code></td>
* <td>A type "foo" (or other syntax related element, a function is a type) which syntax related element (from which
* the type is build) is located in same file on line 23</td>
* </tr>
* <tr>
* <td><code>Infinity - global.n4ts:3</code></td>
* <td>An element "Infinity", located in another resource "global.n4ts" on line 3.</td>
* </tr>
* <tr>
* <td><code>decodeURI - global.n4ts:11</code></td>
* <td>An element "decodeURI", located in another resource "global.n4ts" on line 11. Although the element may be a
* type, there is no syntax related element because "n4ts" directly describes types.</td>
* </tr>
* </table>
*
* @param currentURI
* the current resource's URI, if described object is in same resource, resource name is omitted
* @param desc
* the object descriptor
*/
public static String descriptionToNameWithPosition(URI currentURI, boolean withLineNumber, IEObjectDescription desc) {
String name = desc.getName().toString();
EObject eobj = desc.getEObjectOrProxy();
if (eobj == null) {
return "No EObject or proxy for " + name + " at URI " + desc.getEObjectURI();
}
String location = "";
if (eobj instanceof SyntaxRelatedTElement) {
EObject syntaxElement = ((SyntaxRelatedTElement) eobj).getAstElement();
if (syntaxElement != null) {
location += "T";
eobj = syntaxElement;
}
}
Resource eobjRes = eobj.eResource();
URI uri = eobjRes == null ? null : eobjRes.getURI();
if (uri != currentURI && uri != null) {
location = uri.lastSegment();
if (eobj.eIsProxy() || withLineNumber) {
location += ":";
}
}
if (eobj.eIsProxy()) {
URI proxyUri = desc.getEObjectURI();
location += "proxy:" + simpleURIString(proxyUri);
} else if (withLineNumber) {
INode node = NodeModelUtils.findActualNodeFor(eobj);
if (node == null) {
location += "no node:" + simpleURIString(desc.getEObjectURI());
} else {
location += node.getStartLine();
}
}
return name + SEPARATOR + location;
}
use of org.eclipse.n4js.ts.types.SyntaxRelatedTElement in project n4js by eclipse.
the class HyperlinkXpectMethod method getTarget.
private EObject getTarget(XtextResource resource, IHyperlink hyperlink) {
final ResourceSet resourceSet = resource != null ? resource.getResourceSet() : null;
final URI uri = hyperlink instanceof XtextHyperlink ? ((XtextHyperlink) hyperlink).getURI() : null;
final EObject target = resourceSet != null && uri != null ? resourceSet.getEObject(uri, true) : null;
if (target instanceof SyntaxRelatedTElement)
return ((SyntaxRelatedTElement) target).getAstElement();
return target;
}
use of org.eclipse.n4js.ts.types.SyntaxRelatedTElement in project n4js by eclipse.
the class N4JSResource method proxifyASTReferences.
private void proxifyASTReferences(EObject object) {
if (object instanceof SyntaxRelatedTElement) {
SyntaxRelatedTElement element = (SyntaxRelatedTElement) object;
EObject astElement = element.getAstElement();
if (astElement != null && !astElement.eIsProxy()) {
InternalEObject proxy = (InternalEObject) EcoreUtil.create(astElement.eClass());
proxy.eSetProxyURI(EcoreUtil.getURI(astElement));
element.setAstElement(proxy);
}
}
for (EObject child : object.eContents()) {
proxifyASTReferences(child);
}
}
Aggregations