use of org.eclipse.xtext.ui.codetemplates.templates.Codetemplates in project xtext-eclipse by eclipse.
the class SingleCodetemplateSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == TemplatesPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case TemplatesPackage.CODETEMPLATE:
sequence_Codetemplate(context, (Codetemplate) semanticObject);
return;
case TemplatesPackage.CODETEMPLATES:
sequence_Codetemplates(context, (Codetemplates) semanticObject);
return;
case TemplatesPackage.DOLLAR:
sequence_Dollar(context, (Dollar) semanticObject);
return;
case TemplatesPackage.LITERAL:
sequence_Literal(context, (Literal) semanticObject);
return;
case TemplatesPackage.TEMPLATE_BODY:
sequence_TemplateBody(context, (TemplateBody) semanticObject);
return;
case TemplatesPackage.VARIABLE:
sequence_Variable(context, (Variable) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.xtext.ui.codetemplates.templates.Codetemplates in project xtext-eclipse by eclipse.
the class TemplateValidator method checkParameters.
@Check
public void checkParameters(Variable variable) {
Codetemplate template = EcoreUtil2.getContainerOfType(variable, Codetemplate.class);
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) {
String contextTypeId = helper.getId(rule);
ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(language);
TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
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();
if (resolver.getType().equals(type)) {
IInspectableTemplateVariableResolver inspectableResolver = registry.toInspectableResolver(resolver);
if (inspectableResolver != null) {
inspectableResolver.validateParameters(variable, this);
}
}
}
}
}
}
}
use of org.eclipse.xtext.ui.codetemplates.templates.Codetemplates in project xtext-eclipse by eclipse.
the class CodetemplatesSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == TemplatesPackage.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case TemplatesPackage.CODETEMPLATE:
sequence_Codetemplate(context, (Codetemplate) semanticObject);
return;
case TemplatesPackage.CODETEMPLATES:
sequence_Codetemplates(context, (Codetemplates) semanticObject);
return;
case TemplatesPackage.DOLLAR:
sequence_Dollar(context, (Dollar) semanticObject);
return;
case TemplatesPackage.LITERAL:
sequence_Literal(context, (Literal) semanticObject);
return;
case TemplatesPackage.TEMPLATE_BODY:
sequence_TemplateBody(context, (TemplateBody) semanticObject);
return;
case TemplatesPackage.VARIABLE:
sequence_Variable(context, (Variable) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
use of org.eclipse.xtext.ui.codetemplates.templates.Codetemplates in project xtext-eclipse by eclipse.
the class CodetemplatesProposalProvider method completeCodetemplate_KeywordContext.
@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);
}
}
}
}
}
use of org.eclipse.xtext.ui.codetemplates.templates.Codetemplates in project xtext-eclipse by eclipse.
the class SemanticHighlighter method provideHighlightingFor.
@Override
public void provideHighlightingFor(XtextResource resource, final IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
if (resource == null || resource.getContents().isEmpty())
return;
Codetemplates templates = (Codetemplates) resource.getContents().get(0);
Grammar grammar = templates.getLanguage();
if (grammar != null && !grammar.eIsProxy()) {
TemplateBodyHighlighter highlighter = getHighlighter(grammar);
if (highlighter != null) {
ContextTypeIdHelper helper = registry.getContextTypeIdHelper(grammar);
ContextTypeRegistry contextTypeRegistry = registry.getContextTypeRegistry(grammar);
for (Codetemplate template : templates.getTemplates()) {
operationCanceledManager.checkCanceled(cancelIndicator);
if (template.getBody() != null) {
final EvaluatedTemplate evaluatedTemplate = new EvaluatedTemplate(template);
highlighter.provideHighlightingFor(evaluatedTemplate.getMappedString(), new IHighlightedPositionAcceptor() {
@Override
public void addPosition(int offset, int length, String... id) {
int beginOffset = evaluatedTemplate.getOriginalOffset(offset);
int endOffset = evaluatedTemplate.getOriginalOffset(offset + length);
int fixedLength = endOffset - beginOffset;
acceptor.addPosition(beginOffset, fixedLength, id);
}
});
String id = null;
TemplateContextType contextType = null;
if (template.getContext() != null) {
id = helper.getId(template.getContext());
if (id != null)
contextType = contextTypeRegistry.getContextType(id);
}
Set<String> defaultResolvers = Sets.newHashSet();
if (contextType != null) {
Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(), TemplateVariableResolver.class);
while (resolvers.hasNext()) {
TemplateVariableResolver resolver = resolvers.next();
defaultResolvers.add(resolver.getType());
}
}
for (TemplatePart part : template.getBody().getParts()) {
if (part instanceof Variable) {
Variable variable = (Variable) part;
ICompositeNode node = NodeModelUtils.findActualNodeFor(variable);
if (node != null) {
for (ILeafNode leafNode : node.getLeafNodes()) {
if (leafNode.getGrammarElement() instanceof Keyword) {
acceptor.addPosition(leafNode.getTotalOffset(), leafNode.getTotalLength(), TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE);
}
}
List<INode> typeNodes = NodeModelUtils.findNodesForFeature(variable, TemplatesPackage.Literals.VARIABLE__TYPE);
if (typeNodes.isEmpty()) {
if (defaultResolvers.contains(variable.getName())) {
List<INode> nameNodes = NodeModelUtils.findNodesForFeature(variable, TemplatesPackage.Literals.VARIABLE__NAME);
for (INode nameNode : nameNodes) {
highlightNode(nameNode, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE, acceptor);
}
}
} else {
for (INode typeNode : typeNodes) {
highlightNode(typeNode, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE, acceptor);
}
}
List<INode> parameterNodes = NodeModelUtils.findNodesForFeature(variable, TemplatesPackage.Literals.VARIABLE__PARAMETERS);
for (INode parameterNode : parameterNodes) {
highlightNode(parameterNode, TemplatesHighlightingConfiguration.TEMPLATE_VARIABLE_ARGUMENT, acceptor);
}
}
}
}
}
}
}
}
}
Aggregations