Java 类org.eclipse.xtext.xtext.UsedRulesFinder 实例源码

项目:xtext-core    文件:FlattenedGrammarAccess.java   
public FlattenedGrammarAccess(final RuleNames names, final RuleFilter filter) {
  final Grammar grammar = names.getContextGrammar();
  Grammar flattenedGrammar = this.<Grammar>copy(grammar);
  flattenedGrammar.setName(grammar.getName());
  LinkedHashMap<RuleWithParameterValues, AbstractRule> origToCopy = Maps.<RuleWithParameterValues, AbstractRule>newLinkedHashMap();
  final ArrayList<AbstractRule> copies = this.copyRuleStubs(names, origToCopy, filter.getRules(grammar), filter.isDiscardRuleTypeRef());
  EList<AbstractRule> _rules = flattenedGrammar.getRules();
  Iterables.<AbstractRule>addAll(_rules, copies);
  Multimap<TerminalRule, AbstractRule> calledFrom = this.copyRuleBodies(copies, origToCopy);
  this.setHiddenTokens(flattenedGrammar, grammar, origToCopy);
  this.markAsFragment(calledFrom);
  boolean _isDiscardUnreachableRules = filter.isDiscardUnreachableRules();
  if (_isDiscardUnreachableRules) {
    Set<AbstractRule> usedRules = CollectionLiterals.<AbstractRule>newHashSet();
    boolean _isDiscardTerminalRules = filter.isDiscardTerminalRules();
    boolean _not = (!_isDiscardTerminalRules);
    if (_not) {
      usedRules.addAll(GrammarUtil.allTerminalRules(flattenedGrammar));
    }
    UsedRulesFinder finder = new UsedRulesFinder(usedRules);
    finder.compute(flattenedGrammar);
    flattenedGrammar.getRules().retainAll(usedRules);
  }
  this.flattenedGrammar = flattenedGrammar;
  new OriginalGrammar(grammar).attachToEmfObject(flattenedGrammar);
}
项目:xtext-extras    文件:XbaseGeneratorFragment.java   
/**
 * @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");
        }
    });
}
项目:xtext-core    文件:XbaseUsageDetector.java   
public boolean usesXImportSection(final Grammar grammar) {
  final Set<AbstractRule> usedRules = CollectionLiterals.<AbstractRule>newHashSet();
  new UsedRulesFinder(usedRules).compute(grammar);
  final Function1<AbstractRule, Boolean> _function = (AbstractRule it) -> {
    return Boolean.valueOf((Objects.equal(it.getName(), "XImportSection") && Objects.equal(GrammarUtil.getGrammar(it).getName(), "org.eclipse.xtext.xbase.Xtype")));
  };
  return IterableExtensions.<AbstractRule>exists(usedRules, _function);
}
项目:dsl-devkit    文件:FixedXbaseGeneratorFragment.java   
@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");
    }
  });
}