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);
}
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);
}
}
}
}
}
Aggregations