Search in sources :

Example 1 with TextPositionInfo

use of org.osate.annexsupport.TextPositionInfo in project osate2 by osate.

the class AadlBaTextPositionResolver method resolveBehaviorAnnexElementAt.

private TextPositionInfo resolveBehaviorAnnexElementAt(int offset) {
    Element e = this.getLinkedElement(offset);
    if (e == null)
        return new TextPositionInfo(null, 0, 0);
    AadlBaLocationReference loc = this.getSourceOffsetElement(offset);
    TextPositionInfo positionInfo;
    if (e instanceof ElementHolder) {
        ElementHolder beh = (ElementHolder) e;
        positionInfo = new TextPositionInfo(beh.getElement(), loc.getOffset(), loc.getLength());
    } else {
        positionInfo = new TextPositionInfo(e, loc.getOffset(), loc.getLength());
    }
    return positionInfo;
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) Element(org.osate.aadl2.Element) ElementHolder(org.osate.ba.aadlba.ElementHolder)

Example 2 with TextPositionInfo

use of org.osate.annexsupport.TextPositionInfo in project osate2 by osate.

the class AadlBaTextPositionResolver method resolveBehaviorAnnexCrossReferencedElementAt.

private TextPositionInfo resolveBehaviorAnnexCrossReferencedElementAt(int offset) {
    Element e = this.getLinkedElement(offset);
    if (e == null)
        return new TextPositionInfo(null, offset, 0);
    AadlBaLocationReference loc = this.getSourceOffsetElement(offset);
    TextPositionInfo positionInfo;
    if (e instanceof ElementHolder) {
        ElementHolder beh = (ElementHolder) e;
        positionInfo = new TextPositionInfo(beh.getElement(), loc.getOffset(), loc.getLength());
    } else {
        positionInfo = new TextPositionInfo(e, loc.getOffset(), loc.getLength());
    }
    return positionInfo;
}
Also used : AadlBaLocationReference(org.osate.ba.utils.AadlBaLocationReference) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) Element(org.osate.aadl2.Element) ElementHolder(org.osate.ba.aadlba.ElementHolder)

Example 3 with TextPositionInfo

use of org.osate.annexsupport.TextPositionInfo 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;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) EObject(org.eclipse.emf.ecore.EObject) AnnexTextPositionResolver(org.osate.annexsupport.AnnexTextPositionResolver) AnnexLibrary(org.osate.aadl2.AnnexLibrary) NamedElement(org.osate.aadl2.NamedElement) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 4 with TextPositionInfo

use of org.osate.annexsupport.TextPositionInfo 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);
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) EObject(org.eclipse.emf.ecore.EObject) AnnexTextPositionResolver(org.osate.annexsupport.AnnexTextPositionResolver) IParseResult(org.eclipse.xtext.parser.IParseResult) AnnexLibrary(org.osate.aadl2.AnnexLibrary) NamedElement(org.osate.aadl2.NamedElement) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 5 with TextPositionInfo

use of org.osate.annexsupport.TextPositionInfo 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);
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) TextRegion(org.eclipse.xtext.util.TextRegion) TextPositionInfo(org.osate.annexsupport.TextPositionInfo) EObject(org.eclipse.emf.ecore.EObject) AnnexTextPositionResolver(org.osate.annexsupport.AnnexTextPositionResolver) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

TextPositionInfo (org.osate.annexsupport.TextPositionInfo)5 EObject (org.eclipse.emf.ecore.EObject)3 INode (org.eclipse.xtext.nodemodel.INode)3 TextRegion (org.eclipse.xtext.util.TextRegion)3 NamedElement (org.osate.aadl2.NamedElement)3 AnnexTextPositionResolver (org.osate.annexsupport.AnnexTextPositionResolver)3 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)2 ITextRegion (org.eclipse.xtext.util.ITextRegion)2 AnnexLibrary (org.osate.aadl2.AnnexLibrary)2 AnnexSubclause (org.osate.aadl2.AnnexSubclause)2 Element (org.osate.aadl2.Element)2 ElementHolder (org.osate.ba.aadlba.ElementHolder)2 AadlBaLocationReference (org.osate.ba.utils.AadlBaLocationReference)2 Region (org.eclipse.jface.text.Region)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1