public EvaluatedTemplate(Codetemplate template) { TemplateBody body = template.getBody(); StringBuilder buffer = new StringBuilder(); StringBuilder original = new StringBuilder(); mappedOffsetHints = Lists.newArrayList(); int lastOffset = 0; for(TemplatePart part: body.getParts()) { ICompositeNode node = NodeModelUtils.getNode(part); if (node != null) { mappedOffsetHints.add(Tuples.create(buffer.length(), node.getTotalOffset())); lastOffset = node.getTotalOffset() + node.getTotalLength(); original.append(node.getText()); if (part instanceof Literal) { buffer.append(((Literal) part).getValue()); } else if (part instanceof Dollar) { buffer.append("$"); } else if (part instanceof Variable) { if (((Variable) part).getName() != null) { buffer.append(((Variable) part).getName()); } } } } mappedOffsetHints.add(Tuples.create(buffer.length(), lastOffset)); evaluatedResult = buffer.toString(); originalTemplate = original.toString(); }
protected TemplateData(EObject model) { template = EcoreUtil2.getContainerOfType(model, Codetemplate.class); if (template != null) { templates = EcoreUtil2.getContainerOfType(template, Codetemplates.class); language = templates.getLanguage(); rule = template.getContext(); } }
@Check public void checkNameIsNotEmpty(Codetemplate template) { if (Strings.isEmpty(template.getName())) { error("Template name cannot be empty.", TemplatesPackage.Literals.CODETEMPLATE__NAME); } }
ContextTypeRegistry contextTypeRegistry = registry.getContextTypeRegistry(grammar); for(Codetemplate template: templates.getTemplates()) { if (template.getBody() != null) { final EvaluatedTemplate evaluatedTemplate = new EvaluatedTemplate(template); highlighter.provideHighlightingFor(evaluatedTemplate.getMappedString(), new IHighlightedPositionAcceptor() { String id = null; TemplateContextType contextType = null; if (template.getContext() != null) { id = helper.getId(template.getContext()); if (id != null) contextType = contextTypeRegistry.getContextType(id); for(TemplatePart part: template.getBody().getParts()) { if (part instanceof Variable) { Variable variable = (Variable) part;
@Override public void complete_Literal(EObject model, RuleCall ruleCall, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) { if ((mode & NESTED) != 0) { final TemplateData data = new TemplateData(model); if (data.doCreateProposals()) { final EvaluatedTemplate evaluatedTemplate = new EvaluatedTemplate(data.template); temporaryResourceProvider.useTemporaryResource(data.template.eResource().getResourceSet(), data.language, data.rule, evaluatedTemplate.getMappedString(), new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource resource) throws Exception { PartialContentAssistContextFactory delegateFactory = languageRegistry.getPartialContentAssistContextFactory(data.language); delegateFactory.initializeFor(data.rule); String mappedInput = evaluatedTemplate.getMappedString(); int mappedOffset = Math.min(mappedInput.length(), evaluatedTemplate.getMappedOffset(context.getOffset())); DummyDocument document = new DummyDocument(mappedInput); DummyTextViewer dummyViewer = new DummyTextViewer(TextSelection.emptySelection(), document); ContentAssistContext[] contexts = delegateFactory.create(dummyViewer, mappedOffset, resource); ICompletionProposalAcceptor mappingAcceptor = new ProjectionAwareProposalAcceptor(acceptor, evaluatedTemplate); createNestedProposals(contexts, context.getViewer(), mappingAcceptor); } }); } } }
if (templates != null && template != null) { Grammar language = templates.getLanguage(); AbstractRule rule = template.getContext(); ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(language); if (helper != null && rule != null && !rule.eIsProxy() && rule instanceof ParserRule) {