Search in sources :

Example 11 with LeafNode

use of org.eclipse.xtext.nodemodel.impl.LeafNode in project n4js by eclipse.

the class N4JSDocumentationProvider method getDocumentationNodes.

/**
 * Returns documentation nodes for N4JS AST and type elements (in which case the method returns the nodes of the
 * corresponding AST element). If the AST element has no documentation nodes itself, but is an exportable element,
 * then the documentation of the export statement is returned if present.
 */
@Override
public List<INode> getDocumentationNodes(EObject object) {
    final EObject astNode = N4JSASTUtils.getCorrespondingASTNode(object);
    if (astNode != null) {
        List<INode> nodes = super.getDocumentationNodes(astNode);
        if (nodes.isEmpty() && astNode instanceof VariableDeclaration) {
            TypeRef typeRef = ((VariableDeclaration) astNode).getDeclaredTypeRef();
            if (typeRef != null) {
                nodes = getDocumentationNodes(typeRef);
            }
        }
        if (nodes.isEmpty()) {
            if (astNode instanceof ExportedVariableDeclaration && astNode.eContainer() instanceof ExportedVariableStatement) {
                EList<VariableDeclaration> decls = ((ExportedVariableStatement) astNode.eContainer()).getVarDecl();
                if (decls.size() == 1) {
                    return getDocumentationNodes(astNode.eContainer());
                }
            }
            if (astNode instanceof ExportableElement && astNode.eContainer() instanceof ExportDeclaration) {
                nodes = super.getDocumentationNodes(astNode.eContainer());
            }
        }
        if (nodes.isEmpty()) {
            // failure case, was ASI grabbing the doc?
            // backward search for first non-hidden element, over-stepping if it is a LeafNodeWithSyntaxError from
            // ASI.
            ICompositeNode ptNodeOfASTNode = NodeModelUtils.getNode(astNode);
            LeafNode lNode = searchLeafNodeDocumentation(ptNodeOfASTNode);
            if (lNode != null) {
                return Collections.<INode>singletonList(lNode);
            }
        }
        return nodes;
    }
    return super.getDocumentationNodes(object);
}
Also used : ExportedVariableDeclaration(org.eclipse.n4js.n4JS.ExportedVariableDeclaration) ExportableElement(org.eclipse.n4js.n4JS.ExportableElement) INode(org.eclipse.xtext.nodemodel.INode) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) EObject(org.eclipse.emf.ecore.EObject) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) ExportedVariableDeclaration(org.eclipse.n4js.n4JS.ExportedVariableDeclaration) VariableDeclaration(org.eclipse.n4js.n4JS.VariableDeclaration) ExportDeclaration(org.eclipse.n4js.n4JS.ExportDeclaration) ExportedVariableStatement(org.eclipse.n4js.n4JS.ExportedVariableStatement)

Example 12 with LeafNode

use of org.eclipse.xtext.nodemodel.impl.LeafNode in project statecharts by Yakindu.

the class SGenSemanticHighlightingCalculator method provideHighlightingFor.

public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
    if (resource == null || resource.getParseResult() == null)
        return;
    TreeIterator<EObject> allContents = resource.getAllContents();
    while (allContents.hasNext()) {
        final EObject object = allContents.next();
        if (object instanceof GeneratorEntry) {
            GeneratorEntry entry = (GeneratorEntry) object;
            List<INode> nodes = NodeModelUtils.findNodesForFeature(entry, SGenPackage.Literals.GENERATOR_ENTRY__CONTENT_TYPE);
            List<INode> features = NodeModelUtils.findNodesForFeature(entry, SGenPackage.Literals.GENERATOR_ENTRY__FEATURES);
            for (INode node : nodes) {
                if (node instanceof LeafNode && !((LeafNode) node).isHidden()) {
                    acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), DefaultHighlightingConfiguration.KEYWORD_ID);
                }
            }
            for (INode node : features) {
                if (node.getSemanticElement() instanceof FeatureConfigurationImpl) {
                    FeatureConfigurationImpl feature = (FeatureConfigurationImpl) node.getSemanticElement();
                    DeprecatableElement deprecatableElement = feature.getType();
                    if (deprecatableElement != null && deprecatableElement.isDeprecated()) {
                        acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), SGenHighlightingConfiguration.DEPRECATION);
                    }
                }
            }
        // allContents.prune();
        } else if (object instanceof ElementReferenceExpression && !((ElementReferenceExpression) object).getReference().eIsProxy()) {
            List<INode> nodes = NodeModelUtils.findNodesForFeature(object, ExpressionsPackage.Literals.ELEMENT_REFERENCE_EXPRESSION__REFERENCE);
            for (INode node : nodes) {
                String name = ((Property) ((ElementReferenceExpression) object).getReference()).getName();
                switch(name) {
                    case SCT_VERSION_VAR:
                    case SHA256:
                    case SCTFILE:
                    case TIMESTAMP_VAR:
                    case USER_VAR:
                    case HOSTNAME_VAR:
                        acceptor.addPosition(node.getTotalOffset(), node.getTotalLength(), DefaultHighlightingConfiguration.KEYWORD_ID);
                }
            }
        }
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) GeneratorEntry(org.yakindu.sct.model.sgen.GeneratorEntry) EObject(org.eclipse.emf.ecore.EObject) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) DeprecatableElement(org.yakindu.sct.model.sgen.DeprecatableElement) FeatureConfigurationImpl(org.yakindu.sct.model.sgen.impl.FeatureConfigurationImpl) List(java.util.List) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression)

Aggregations

LeafNode (org.eclipse.xtext.nodemodel.impl.LeafNode)12 INode (org.eclipse.xtext.nodemodel.INode)8 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)6 Test (org.junit.Test)6 EObject (org.eclipse.emf.ecore.EObject)4 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)4 List (java.util.List)3 CompositeNode (org.eclipse.xtext.nodemodel.impl.CompositeNode)3 NodeModelBuilder (org.eclipse.xtext.nodemodel.impl.NodeModelBuilder)3 EAnnotation (org.eclipse.emf.ecore.EAnnotation)2 EClass (org.eclipse.emf.ecore.EClass)2 EReference (org.eclipse.emf.ecore.EReference)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 InternalEList (org.eclipse.emf.ecore.util.InternalEList)2 ValueConverterException (org.eclipse.xtext.conversion.ValueConverterException)2 ILinkingService (org.eclipse.xtext.linking.ILinkingService)2 IllegalNodeException (org.eclipse.xtext.linking.impl.IllegalNodeException)2 LinkingDiagnosticMessageProvider (org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)2 HiddenLeafNode (org.eclipse.xtext.nodemodel.impl.HiddenLeafNode)2