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(); } }
/** * @since 2.3 */ @Check public void checkParameterListIsNotEmpty(Variable variable) { if (variable.isExpectingParameters()) { if (variable.getParameters().isEmpty()) { error("Parameter list may not be empty", null); } } }
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(); }
return; Codetemplates templates = (Codetemplates) resource.getContents().get(0); Grammar grammar = templates.getLanguage(); if (grammar != null && !grammar.eIsProxy()) { TemplateBodyHighlighter highlighter = getHighlighter(grammar); ContextTypeIdHelper helper = registry.getContextTypeIdHelper(grammar); 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; if (defaultResolvers.contains(variable.getName())) { List<INode> nameNodes = NodeModelUtils.findNodesForFeature(variable, TemplatesPackage.Literals.VARIABLE__NAME); for(INode nameNode: nameNodes) {
Codetemplates templates = EcoreUtil2.getContainerOfType(template, Codetemplates.class); 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) { if (contextType != null) { Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(), TemplateVariableResolver.class); String type = variable.getType(); if (type == null) type = variable.getName(); while(resolvers.hasNext()) { final TemplateVariableResolver resolver = resolvers.next();
public IScope scope_Codetemplate_context(Codetemplate template, EReference reference) { Codetemplates root = EcoreUtil2.getContainerOfType(template, Codetemplates.class); if (root != null && root.getLanguage() != null) { Grammar grammar = root.getLanguage(); if (!grammar.eIsProxy()) { LinkedHashSet<AbstractRule> usedRules = Sets.newLinkedHashSet(); new UsedRulesFinder(usedRules).compute(grammar); return Scopes.scopeFor(Iterables.filter(usedRules, ParserRule.class)); } } return IScope.NULLSCOPE; }
if (data.template.getBody() != null) { for(Variable variable: Iterables.filter(data.template.getBody().getParts(), Variable.class)) { if (variable != model && variable.getName() != null) { String proposalText = variable.getName(); StyledString displayText = new StyledString(proposalText).append(" - existing variable", StyledString.QUALIFIER_STYLER); if (variable.getType() != null) displayText = displayText.append(" of type " + variable.getType(), StyledString.QUALIFIER_STYLER); ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context); acceptor.accept(proposal);
public void validateParameters(Variable variable, ValidationMessageAcceptor validationMessageAcceptor) { if (!canHaveParameters()) { if (variable.getParameters().size() > 0) validationMessageAcceptor.acceptError(getUnexpectedParametersMessage(), variable, TemplatesPackage.Literals.VARIABLE__PARAMETERS, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); } if (hasMandatoryParameters()) { if (variable.getParameters().isEmpty()) { validationMessageAcceptor.acceptError(getMandatorParametersMessage(), variable, TemplatesPackage.Literals.VARIABLE__TYPE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null); } } }
@Check public void checkDollarEscaped(Dollar dollar) { if (!dollar.isEscaped()) error("Invalid escape sequence '$'", null); }
/** * Constraint: * value=LiteralValue */ protected void sequence_Literal(EObject context, Literal semanticObject) { if(errorAcceptor != null) { if(transientValues.isValueTransient(semanticObject, TemplatesPackage.Literals.LITERAL__VALUE) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, TemplatesPackage.Literals.LITERAL__VALUE)); } INodesForEObjectProvider nodes = createNodeProvider(semanticObject); SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes); feeder.accept(grammarAccess.getLiteralAccess().getValueLiteralValueParserRuleCall_0(), semanticObject.getValue()); feeder.finish(); }
@Check public void checkNameIsNotEmpty(Codetemplate template) { if (Strings.isEmpty(template.getName())) { error("Template name cannot be empty.", TemplatesPackage.Literals.CODETEMPLATE__NAME); } }
public IScope scope_Codetemplates_language(Codetemplates templates, EReference reference) { if (TemplateResourceProvider.SYNTHETIC_SCHEME.equals(templates.eResource().getURI().scheme())) { ResourceSet resourceSet = templates.eResource().getResourceSet(); List<Grammar> grammars = Lists.newArrayListWithExpectedSize(1); for(Resource resource: resourceSet.getResources()) { EObject root = resource.getContents().get(0); if (root instanceof Grammar) { grammars.add((Grammar) root); } } return Scopes.scopeFor(grammars, new Function<Grammar, QualifiedName>() { public QualifiedName apply(Grammar from) { return qualifiedNameConverter.toQualifiedName(from.getName()); } }, IScope.NULLSCOPE); } else { return delegateGetScope(templates, reference); } } }
@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); } }); } } }
@Override public void completeVariable_Parameters(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if ((mode & NORMAL) != 0) { VariableData data = new VariableData(model); if (data.doCreateProposals()) { String variableType = data.variable.getType(); if ("CrossReference".equals(variableType)) { List<CrossReference> crossReferences = GrammarUtil.containedCrossReferences(data.rule); for(CrossReference crossReference: crossReferences) { EReference reference = GrammarUtil.getReference(crossReference); String fqn = reference.getEContainingClass().getName() + "." + reference.getName(); acceptor.accept(createCompletionProposal(fqn, context)); acceptor.accept(createCompletionProposal("'" + fqn + "'", context)); } } else if ("Enum".equals(variableType)) { } super.completeVariable_Parameters(model, assignment, context, acceptor); } } }
/** * @since 2.3 */ @Check public void checkParameterListIsNotEmpty(Variable variable) { if (variable.isExpectingParameters()) { if (variable.getParameters().isEmpty()) { error("Parameter list may not be empty", null); } } }
public IScope scope_Codetemplate_context(Codetemplate template, EReference reference) { Codetemplates root = EcoreUtil2.getContainerOfType(template, Codetemplates.class); if (root != null && root.getLanguage() != null) { Grammar grammar = root.getLanguage(); if (!grammar.eIsProxy()) { LinkedHashSet<AbstractRule> usedRules = Sets.newLinkedHashSet(); new UsedRulesFinder(usedRules).compute(grammar); return Scopes.scopeFor(Iterables.filter(usedRules, ParserRule.class)); } } return IScope.NULLSCOPE; }
@Check public void checkDollarEscaped(Dollar dollar) { if (!dollar.isEscaped()) error("Invalid escape sequence '$'", null); }
@Override public void completeCodetemplate_KeywordContext(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { Codetemplate template = EcoreUtil2.getContainerOfType(model, Codetemplate.class); if (template != null) { Codetemplates templates = EcoreUtil2.getContainerOfType(template, Codetemplates.class); if (templates != null) { Grammar language = templates.getLanguage(); if (language != null && !language.eIsProxy()) { Set<String> keywords = GrammarUtil.getAllKeywords(language); for(String keyword: keywords) { String proposalText = keyword; proposalText = getValueConverter().toString(proposalText, ((RuleCall)assignment.getTerminal()).getRule().getName()); StyledString displayText = new StyledString(proposalText).append(" - Keyword", StyledString.QUALIFIER_STYLER); ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context); getPriorityHelper().adjustCrossReferencePriority(proposal, context.getPrefix()); if (proposal instanceof ConfigurableCompletionProposal) { ((ConfigurableCompletionProposal) proposal).setPriority(((ConfigurableCompletionProposal) proposal).getPriority() - 1); } acceptor.accept(proposal); } } } } }