org.eclipse.xtext.xtext.UsedRulesFinder Java Examples

The following examples show how to use org.eclipse.xtext.xtext.UsedRulesFinder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XbaseGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.4
 */
public boolean usesXImportSection(Grammar grammar) {
	Set<AbstractRule> usedRules = newHashSet();
	new UsedRulesFinder(usedRules).compute(grammar);
	return any(usedRules, new Predicate<AbstractRule>() {
		@Override
		public boolean apply(AbstractRule rule) {
			return equal(rule.getName(), "XImportSection") 
					&& equal(GrammarUtil.getGrammar(rule).getName(), "org.eclipse.xtext.xbase.Xtype");
		}
	});
}
 
Example #2
Source File: XtextOutlineTreeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void _createNode(DocumentRootNode parentNode, Grammar grammar) {
	// Hack: we use this hook to calculate unused rule
	calledRules = Sets.newHashSet();
	if (!grammar.getRules().isEmpty()) {
		UsedRulesFinder usedRulesFinder = new UsedRulesFinder(calledRules);
		usedRulesFinder.compute(grammar);
	}
	super._createNode(parentNode, grammar);
}
 
Example #3
Source File: CodetemplatesScopeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: XbaseUsageDetector.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public boolean usesXImportSection(Grammar grammar) {
	Set<AbstractRule> usedRules = new HashSet<>();
	new UsedRulesFinder(usedRules).compute(grammar);
	for (AbstractRule it : usedRules) {
		if ("XImportSection".equals(it.getName())
				&& "org.eclipse.xtext.xbase.Xtype".equals(GrammarUtil.getGrammar(it).getName())) {
			return true;
		}
	}
	return false;
}
 
Example #5
Source File: FixedXbaseGeneratorFragment.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean usesXImportSection(final Grammar grammar) {
  Set<AbstractRule> usedRules = newHashSet();
  new UsedRulesFinder(usedRules).compute(grammar);
  return any(usedRules, new Predicate<AbstractRule>() {
    @Override
    public boolean apply(final AbstractRule rule) {
      return equal(rule.getName(), "XImportSection") && equal(rule.getType().getMetamodel().getEPackage().getName(), "xtype");
    }
  });
}