本文整理汇总了Java中org.eclipse.xtext.GrammarUtil.allRules方法的典型用法代码示例。如果您正苦于以下问题:Java GrammarUtil.allRules方法的具体用法?Java GrammarUtil.allRules怎么用?Java GrammarUtil.allRules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.GrammarUtil
的用法示例。
在下文中一共展示了GrammarUtil.allRules方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calcRootFollowers
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public static List<AbstractElement> calcRootFollowers(Grammar g) {
List<AbstractElement> callees = new ArrayList<AbstractElement>();
for (AbstractRule r : GrammarUtil.allRules(g))
if (r instanceof ParserRule) {
ParserRule pr = (ParserRule) r;
if (!GrammarUtil.isDatatypeRule(pr) && !pr.isFragment())
callees.add(pr.getAlternatives());
}
return callees;
}
示例2: createAllRules
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
* @since 2.11
*/
protected Map<String, AbstractRule> createAllRules(Grammar grammar) {
Map<String, AbstractRule> allRules = Maps.newHashMap();
for (AbstractRule rule: GrammarUtil.allRules(grammar)) {
if(rule instanceof TerminalRule)
allRules.put(rule.getName().toUpperCase(), rule);
else
allRules.put(rule.getName(), rule);
}
return allRules;
}
示例3: isCalled
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public boolean isCalled(final AbstractRule rule, final Grammar grammar) {
boolean _xblockexpression = false;
{
final List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
_xblockexpression = ((allRules.indexOf(rule) == 0) || IterableExtensions.<RuleCall>exists(Iterables.<RuleCall>concat(ListExtensions.<AbstractRule, List<RuleCall>>map(allRules, ((Function1<AbstractRule, List<RuleCall>>) (AbstractRule it) -> {
return GrammarUtil.containedRuleCalls(it);
}))), ((Function1<RuleCall, Boolean>) (RuleCall ruleCall) -> {
AbstractRule _rule = ruleCall.getRule();
return Boolean.valueOf(Objects.equal(_rule, rule));
})));
}
return _xblockexpression;
}
示例4: testAllRules
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Test
public void testAllRules() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://1\'");
_builder.newLine();
_builder.append("Rule:");
_builder.newLine();
_builder.append("\t");
_builder.append("name=super::STRING;");
_builder.newLine();
_builder.append("terminal STRING: \'\"\';");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
final Function1<AbstractRule, String> _function = (AbstractRule it) -> {
return it.getName();
};
Assert.assertEquals(
Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("Rule", "STRING", "ID", "INT", "STRING", "ML_COMMENT", "SL_COMMENT", "WS", "ANY_OTHER")).toString(),
ListExtensions.<AbstractRule, String>map(allRules, _function).toString());
}
示例5: getRules
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public List<AbstractRule> getRules(Grammar grammar) {
return GrammarUtil.allRules(grammar);
}
示例6: RuleNames
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public RuleNames(Grammar grammar, boolean installAdapter) {
this.contextGrammar = grammar;
Adapter adapter = new Adapter(this);
if (installAdapter) {
installAdapterIfMissing(adapter, grammar);
}
List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
ImmutableListMultimap.Builder<String, AbstractRule> simpleNameToRulesBuilder = ImmutableListMultimap.builder();
ImmutableMap.Builder<String, AbstractRule> qualifiedNameToRuleBuilder = ImmutableMap.builder();
ImmutableBiMap.Builder<String, AbstractRule> uniqueNameToRuleBuilder = ImmutableBiMap.builder();
ImmutableBiMap.Builder<String, AbstractRule> antlrNameToRuleBuilder = ImmutableBiMap.builder();
Map<String, AbstractRule> names = Maps.newHashMap();
Set<String> usedAntlrNames = Sets.newHashSet();
Set<String> usedUniqueNames = Sets.newHashSet();
for(AbstractRule rule: allRules) {
String name = rule.getName();
simpleNameToRulesBuilder.put(name, rule);
String qualifiedName = getQualifiedName(rule);
qualifiedNameToRuleBuilder.put(qualifiedName, rule);
String uniqueName = name;
String antlrRuleName;
if (names.containsKey(name)) {
name = qualifiedName;
uniqueName = getInheritedUniqueName(rule, usedUniqueNames);
antlrRuleName = getInheritedAntlrRuleName(rule, usedAntlrNames);
} else {
antlrRuleName = getDefaultAntlrRuleName(rule);
}
names.put(name, rule);
if (!usedUniqueNames.add(uniqueName)) {
throw new IllegalStateException(uniqueName);
}
uniqueNameToRuleBuilder.put(uniqueName, rule);
if (!usedAntlrNames.add(antlrRuleName)) {
throw new IllegalStateException(antlrRuleName);
}
antlrNameToRuleBuilder.put(antlrRuleName, rule);
if (installAdapter) {
installAdapterIfMissing(adapter, rule);
}
}
simpleNameToRules = simpleNameToRulesBuilder.build();
qualifiedNameToRule = qualifiedNameToRuleBuilder.build();
nameToRule = ImmutableBiMap.copyOf(names);
uniqueNameToRule = uniqueNameToRuleBuilder.build();
antlrNameToRule = antlrNameToRuleBuilder.build();
this.allRules = ImmutableList.copyOf(allRules);
}
示例7: getRules
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
protected Iterable<? extends AbstractRule> getRules() {
return GrammarUtil.allRules(getGrammar());
}