use of org.osate.annexsupport.AnnexTextPositionResolver in project osate2 by osate.
the class Aadl2EObjectAtOffsetHelper method resolveCrossReferencedElementAt.
/**
* @return the cross referenced EObject under, right or left to the cursor (in that order) or
* <code>null</code> if there is no cross referenced object next to the offset.
*/
@Override
public EObject resolveCrossReferencedElementAt(XtextResource resource, int offset) {
INode annexLeaf = AnnexUtil.findAnnexLeafNode(resource, offset);
if (annexLeaf != null) {
if (textpositionresolverregistry == null) {
initTextPositionResolverRegistry();
}
if (textpositionresolverregistry != null) {
EObject obj = NodeModelUtils.findActualSemanticObjectFor(annexLeaf);
if (obj instanceof NamedElement) {
String annexName = ((NamedElement) obj).getName();
// find the actual subclause or library instead of the default one found from the NodeModel
if (obj instanceof AnnexSubclause || obj instanceof AnnexLibrary) {
AnnexTextPositionResolver atpr = textpositionresolverregistry.getTextPositionResolver(annexName);
EObject actualAnnexElement = AnnexUtil.getParsedAnnex(obj);
if (atpr != null && actualAnnexElement != null) {
TextPositionInfo tpo = atpr.resolveCrossReferencedElementAt(actualAnnexElement, offset);
return tpo.getModelObject();
}
}
}
}
// now try xtext based annexes via adapted ParseResult
annexLeaf = getLeafInParsedAnnex((ILeafNode) annexLeaf, offset);
annexLeaf = findCrossReferenceNode(annexLeaf);
if (annexLeaf != null) {
return getCrossReferencedElement(annexLeaf);
}
}
INode node = getCrossReferenceNode(resource, new TextRegion(offset, 0));
if (node != null) {
return getCrossReferencedElement(node);
}
return null;
}
use of org.osate.annexsupport.AnnexTextPositionResolver in project osate2 by osate.
the class Aadl2EObjectAtOffsetHelper method resolveElementAt.
/*
* resolve the element, first by attempting as CrossReference and then as element itself
*
* @see org.eclipse.xtext.resource.EObjectAtOffsetHelper#resolveElementAt(org.eclipse.xtext.resource.XtextResource, int)
*/
@Override
public EObject resolveElementAt(XtextResource resource, int offset) {
INode annexLeaf = AnnexUtil.findAnnexLeafNode(resource, offset);
if (annexLeaf != null) {
EObject obj = NodeModelUtils.findActualSemanticObjectFor(annexLeaf);
if (textpositionresolverregistry == null) {
initTextPositionResolverRegistry();
}
if (textpositionresolverregistry != null) {
if (obj instanceof NamedElement) {
String annexName = ((NamedElement) obj).getName();
// find the actual subclause or library instead of the default one found from the NodeModel
if (obj instanceof AnnexSubclause || obj instanceof AnnexLibrary) {
AnnexTextPositionResolver atpr = textpositionresolverregistry.getTextPositionResolver(annexName);
EObject actualAnnexElement = AnnexUtil.getParsedAnnex(obj);
if (atpr != null && actualAnnexElement != null) {
TextPositionInfo tpo = atpr.resolveElementAt(actualAnnexElement, offset);
return tpo.getModelObject();
}
}
}
}
// now try xtext based annexes via adapted ParseResult
annexLeaf = getLeafInParsedAnnex((ILeafNode) annexLeaf, offset);
if (annexLeaf != null) {
return NodeModelUtils.findActualSemanticObjectFor(annexLeaf);
} else {
return obj;
}
}
INode node = getCrossReferenceNode(resource, new TextRegion(offset, 0));
if (node != null) {
return getCrossReferencedElement(node);
}
IParseResult parseResult = resource.getParseResult();
if (parseResult != null && parseResult.getRootNode() != null) {
ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
if (leaf != null && leaf.isHidden() && leaf.getOffset() == offset) {
leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset - 1);
}
if (leaf != null) {
return NodeModelUtils.findActualSemanticObjectFor(leaf);
}
}
return null;
// return internalResolveElementAt(resource, offset, true);
}
use of org.osate.annexsupport.AnnexTextPositionResolver in project osate2 by osate.
the class Aadl2HyperlinkHelper method createHyperlinksByOffset.
@Override
public void createHyperlinksByOffset(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) {
INode annexLeaf = findAnnexTextLeafNode(resource, offset);
if (annexLeaf != null) {
// handle extensionpoint based text position
EObject obj = NodeModelUtils.findActualSemanticObjectFor(annexLeaf);
if (obj instanceof NamedElement) {
EObject actualAnnexElement = AnnexUtil.getParsedAnnex(obj);
if (actualAnnexElement != null) {
String annexName = ((NamedElement) obj).getName();
if (textpositionresolverregistry == null) {
initTextPositionResolverRegistry();
}
if (textpositionresolverregistry != null) {
AnnexTextPositionResolver atpr = textpositionresolverregistry.getTextPositionResolver(annexName);
if (atpr != null) {
TextPositionInfo tpo = atpr.resolveCrossReferencedElementAt(actualAnnexElement, offset);
if (tpo.getModelObject() != null && !tpo.getModelObject().eIsProxy()) {
Region region = new Region(tpo.getOffset(), tpo.getLength());
createHyperlinksTo(resource, region, tpo.getModelObject(), acceptor);
}
}
}
}
}
}
// xtext based position is getting resolved by Aadl2EObjectAtOffsetHelper
INode crossRefNode = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(offset, 0));
if (crossRefNode == null) {
return;
}
EObject crossLinkedEObject = eObjectAtOffsetHelper.getCrossReferencedElement(crossRefNode);
if (crossLinkedEObject != null && !crossLinkedEObject.eIsProxy()) {
Region region = new Region(crossRefNode.getOffset(), crossRefNode.getLength());
createHyperlinksTo(resource, region, crossLinkedEObject, acceptor);
}
}
Aggregations