@Inject protected void setGrammar(IGrammarAccess grammar) { this.grammar = grammar.getGrammar(); } }
protected List<AbstractElement> getAbstractElements(EObject obj) { if (obj instanceof AbstractElement) return Collections.singletonList((AbstractElement) obj); if (obj instanceof AbstractRule) { AbstractRule rule = (AbstractRule) obj; if (rule.getType().getClassifier() instanceof EClass) return Collections.singletonList(rule.getAlternatives()); List<AbstractElement> result = Lists.newArrayList(); for (RuleCall rc : grammarAccess.findRuleCalls(rule)) { CrossReference cr = GrammarUtil.containingCrossReference(rc); result.add(cr == null ? rc : cr); } return result; } return null; }
@Inject public void setGrammar(IGrammarAccess grammarAccess) { this.grammar = grammarAccess.getGrammar(); }
protected Set<String> getValuesToEscape() { if (valuesToEscape == null) valuesToEscape = computeValuesToEscape(grammarAccess.getGrammar()); return valuesToEscape; }
private AbstractRule getTemplateRule() { if (templateRule == null) templateRule = GrammarUtil.findRuleForName(grammarAccess.getGrammar(), "Codetemplate"); return templateRule; }
private AbstractRule getTemplatesRule() { if (templatesRule == null) templatesRule = GrammarUtil.findRuleForName(grammarAccess.getGrammar(), "Codetemplates"); return templatesRule; }
protected TerminalRule getWSRule() { // FIXME: make this configurable return (TerminalRule) GrammarUtil.findRuleForName(grammar.getGrammar(), "WS"); }
@Inject private void setGrammar(IGrammarAccess grammar) { wsRule = GrammarUtil.findRuleForName(grammar.getGrammar(), "WS"); }
@Inject protected void init(IContextTypePDAProvider pdaProvider, IGrammarAccess grammar) { pdas = pdaProvider.getContextTypePDAs(grammar.getGrammar()); }
private AbstractRule getTemplatesRule() { if (templatesRule == null) templatesRule = GrammarUtil.findRuleForName(grammarAccess.getGrammar(), "Codetemplates"); return templatesRule; }
private AbstractRule getTemplateRule() { if (templateRule == null) templateRule = GrammarUtil.findRuleForName(grammarAccess.getGrammar(), "Codetemplate"); return templateRule; }
protected List<EObject> findPathToImportSection() { EList<AbstractRule> rules = grammarAccess.getGrammar().getRules(); if(!rules.isEmpty() && rules.get(0) instanceof ParserRule) { LinkedList<EObject> pathToImportSection = newLinkedList(); if(internalFindPathToImportSection(pathToImportSection, new HashSet<ParserRule>(), rules.get(0))) { return pathToImportSection; } } return null; }
@Override protected List<EPackage> getEPackages() { List<EPackage> pkg = new ArrayList<EPackage>(); for (AbstractMetamodelDeclaration a : GrammarUtil.allMetamodelDeclarations(grammar.getGrammar())) pkg.add(a.getEPackage()); return pkg; }
protected int getElementID(AbstractElement ele) { if (elementIDCache == null) { elementIDCache = Maps.newHashMap(); int counter = 0; for (ParserRule pr : GrammarUtil.allParserRules(grammar.getGrammar())) for (AbstractElement e : EcoreUtil2.getAllContentsOfType(pr, AbstractElement.class)) elementIDCache.put(e, counter++); } return elementIDCache.get(ele); }
@Inject public void register(LanguageAcceptor acceptor) { acceptor.accept(grammarAccess.getGrammar(), highlighter, contextTypeRegistry, helper, contentAssistContextFactory, fileExtensionProvider.getFileExtensions().iterator().next()); }
@Inject private void initEntryRule(IGrammarAccess grammar) { initializeFor(grammar.getGrammar().getRules().get(0)); }
@Inject public Collector(IGrammarAccess grammarAccess) { Grammar grammar = grammarAccess.getGrammar(); List<ParserRule> parserRules = GrammarUtil.allParserRules(grammar); List<UnorderedGroup> groups = Lists.newArrayList(); for(ParserRule rule: parserRules) { Iterator<EObject> iter = rule.eAllContents(); while(iter.hasNext()) { EObject next = iter.next(); if (next instanceof UnorderedGroup) { groups.add((UnorderedGroup) next); } } } this.groups = ImmutableList.copyOf(groups); }
protected EObject getRootContext() { for (AbstractRule rule : grammar.getGrammar().getRules()) if (GrammarUtil.isEObjectRule(rule)) return rule; throw new RuntimeException("There is no parser rule in the grammar."); }
public void setGrammarIdToURIMap(String[] grammarIdToURIMap) { grammarIdToGrammarElementMap = new EObject[grammarIdToURIMap.length]; ResourceSet grammarResourceSet = grammarAccess.getGrammar().eResource().getResourceSet(); for (int grammarId = 0; grammarId < grammarIdToURIMap.length; ++grammarId) { URI uri = URI.createURI(grammarIdToURIMap[grammarId], true); EObject grammarElement = grammarResourceSet.getEObject(uri, true); if (grammarElement == null) { throw new IllegalStateException( "Apparently the grammar has changed so that it's no longer possible to identify the " + "serialized grammar elements. The following grammar element URI is no longer valid: " + uri.toString()); } grammarIdToGrammarElementMap[grammarId] = grammarElement; } }
public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) { if (result != null) return result; AbstractRule rule = GrammarUtil.findRuleForName(grammarAccess.getGrammar(), singleLineCommentRule); if (rule == null || !(rule instanceof TerminalRule)) { return null; } calculatePrefixes(rule); return this.result; }