Search in sources :

Example 1 with EObjectInComment

use of org.eclipse.xtext.documentation.EObjectInComment in project xtext-eclipse by eclipse.

the class XbaseDispatchingEObjectTextHover method getXtextElementAt.

@Override
protected Pair<EObject, IRegion> getXtextElementAt(XtextResource resource, int offset) {
    Pair<EObject, IRegion> original = super.getXtextElementAt(resource, offset);
    if (original != null) {
        EObject object = eObjectAtOffsetHelper.resolveContainedElementAt(resource, offset);
        if (object instanceof XAbstractFeatureCall) {
            JvmIdentifiableElement feature = ((XAbstractFeatureCall) object).getFeature();
            if (feature instanceof JvmExecutable || feature instanceof JvmField || feature instanceof JvmConstructor || feature instanceof XVariableDeclaration || feature instanceof JvmFormalParameter)
                return Tuples.create(object, original.getSecond());
        } else if (object instanceof XConstructorCall) {
            return Tuples.create(object, original.getSecond());
        }
    }
    EObjectInComment eObjectReferencedInComment = javaDocTypeReferenceProvider.computeEObjectReferencedInComment(resource, offset);
    if (eObjectReferencedInComment != null) {
        EObject eObject = eObjectReferencedInComment.getEObject();
        ITextRegion region = eObjectReferencedInComment.getRegion();
        return Tuples.create(eObject, new Region(region.getOffset(), region.getLength()));
    }
    return original;
}
Also used : XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) IRegion(org.eclipse.jface.text.IRegion) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) EObjectInComment(org.eclipse.xtext.documentation.EObjectInComment) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) Region(org.eclipse.jface.text.Region) ITextRegion(org.eclipse.xtext.util.ITextRegion) IRegion(org.eclipse.jface.text.IRegion) JvmField(org.eclipse.xtext.common.types.JvmField)

Example 2 with EObjectInComment

use of org.eclipse.xtext.documentation.EObjectInComment in project xtext-core by eclipse.

the class MultiLineJavaDocTypeReferenceProvider method computeEObjectReferencedInComment.

/**
 * {@inheritDoc}
 */
@Override
public EObjectInComment computeEObjectReferencedInComment(XtextResource resource, int offset) {
    IParseResult parseResult = resource.getParseResult();
    if (parseResult != null) {
        INode rootNode = parseResult.getRootNode();
        INode node = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
        EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
        if (semanticObject != null) {
            EReference reference = getEReference(semanticObject, node, offset);
            if (reference != null) {
                IScope scope = getScope(semanticObject, reference, node, offset);
                List<ReplaceRegion> eObjectReferences = computeTypeRefRegions(node);
                for (ReplaceRegion eObjectReference : eObjectReferences) {
                    if (eObjectReference.getOffset() <= offset && offset <= eObjectReference.getEndOffset()) {
                        String eObjectReferenceText = eObjectReference.getText();
                        if (!Strings.isNullOrEmpty(eObjectReferenceText)) {
                            ITextRegion region = new TextRegion(eObjectReference.getOffset(), eObjectReference.getLength());
                            IEObjectDescription candidate = getElementFromScope(scope, node, region, eObjectReferenceText);
                            if (candidate != null) {
                                EObject eObject = candidate.getEObjectOrProxy();
                                if (eObject != null) {
                                    return new EObjectInComment(eObject, region);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObjectInComment(org.eclipse.xtext.documentation.EObjectInComment) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) IParseResult(org.eclipse.xtext.parser.IParseResult) EReference(org.eclipse.emf.ecore.EReference) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 3 with EObjectInComment

use of org.eclipse.xtext.documentation.EObjectInComment in project xtext-eclipse by eclipse.

the class XbaseHyperLinkHelper method createHyperlinksInJavaDoc.

/**
 * Creates hyperlinks on types referenced in javadoc comments.
 *
 * @since 2.16
 */
protected void createHyperlinksInJavaDoc(XtextResource resource, int offset, IHyperlinkAcceptor acceptor) {
    EObjectInComment eObjectReferencedInComment = javaDocTypeReferenceProvider.computeEObjectReferencedInComment(resource, offset);
    if (eObjectReferencedInComment != null) {
        EObject target = eObjectReferencedInComment.getEObject();
        ITextRegion region = eObjectReferencedInComment.getRegion();
        createHyperlinksTo(resource, new Region(region.getOffset(), region.getLength()), target, acceptor);
    }
}
Also used : EObjectInComment(org.eclipse.xtext.documentation.EObjectInComment) ITextRegion(org.eclipse.xtext.util.ITextRegion) EObject(org.eclipse.emf.ecore.EObject) Region(org.eclipse.jface.text.Region) TextRegion(org.eclipse.xtext.util.TextRegion) ITextRegion(org.eclipse.xtext.util.ITextRegion)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)3 EObjectInComment (org.eclipse.xtext.documentation.EObjectInComment)3 ITextRegion (org.eclipse.xtext.util.ITextRegion)3 Region (org.eclipse.jface.text.Region)2 TextRegion (org.eclipse.xtext.util.TextRegion)2 EReference (org.eclipse.emf.ecore.EReference)1 IRegion (org.eclipse.jface.text.IRegion)1 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)1 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)1 JvmField (org.eclipse.xtext.common.types.JvmField)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)1 INode (org.eclipse.xtext.nodemodel.INode)1 IParseResult (org.eclipse.xtext.parser.IParseResult)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 IScope (org.eclipse.xtext.scoping.IScope)1 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)1 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)1 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)1 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)1