本文整理汇总了Java中org.eclipse.xtext.GrammarUtil.allParserRules方法的典型用法代码示例。如果您正苦于以下问题:Java GrammarUtil.allParserRules方法的具体用法?Java GrammarUtil.allParserRules怎么用?Java GrammarUtil.allParserRules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.GrammarUtil
的用法示例。
在下文中一共展示了GrammarUtil.allParserRules方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectAbstractElements
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public void collectAbstractElements(Grammar grammar, EStructuralFeature feature,
IFollowElementAcceptor followElementAcceptor) {
for (Grammar superGrammar : grammar.getUsedGrammars()) {
collectAbstractElements(superGrammar, feature, followElementAcceptor);
}
EClass declarator = feature.getEContainingClass();
for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
for (Assignment assignment : GrammarUtil.containedAssignments(rule)) {
if (assignment.getFeature().equals(feature.getName())) {
EClassifier classifier = GrammarUtil.findCurrentType(assignment);
EClassifier compType = EcoreUtil2.getCompatibleType(declarator, classifier);
if (compType == declarator) {
followElementAcceptor.accept(assignment);
}
}
}
}
}
示例2: rewriteTypeReferences
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private static void rewriteTypeReferences(N4JSGrammarAccess ga,
ImmutableMap.Builder<AbstractElement, Integer> builder) {
for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Assignment) {
Assignment assignment = (Assignment) obj;
AbstractElement terminal = assignment.getTerminal();
if (terminal instanceof RuleCall) {
AbstractRule calledRule = ((RuleCall) terminal).getRule();
EClassifier classifier = calledRule.getType().getClassifier();
if (classifier instanceof EClass
&& TypeRefsPackage.Literals.TYPE_REF.isSuperTypeOf((EClass) classifier)) {
builder.put(assignment, TYPE_REF_TOKEN);
}
}
}
}
}
}
示例3: rewriteIdentifiers
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private static void rewriteIdentifiers(N4JSGrammarAccess ga,
ImmutableMap.Builder<AbstractElement, Integer> builder) {
ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(
ga.getBindingIdentifierRule(),
ga.getIdentifierNameRule(),
ga.getIDENTIFIERRule());
for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Assignment) {
Assignment assignment = (Assignment) obj;
AbstractElement terminal = assignment.getTerminal();
int type = InternalN4JSParser.RULE_IDENTIFIER;
if (terminal instanceof CrossReference) {
terminal = ((CrossReference) terminal).getTerminal();
type = IDENTIFIER_REF_TOKEN;
}
if (terminal instanceof RuleCall) {
AbstractRule calledRule = ((RuleCall) terminal).getRule();
if (identifierRules.contains(calledRule)) {
builder.put(assignment, type);
}
}
}
}
}
}
示例4: rewriteNumberLiterals
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private static void rewriteNumberLiterals(N4JSGrammarAccess ga,
ImmutableMap.Builder<AbstractElement, Integer> builder) {
for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
if (obj instanceof Assignment) {
Assignment assignment = (Assignment) obj;
AbstractElement terminal = assignment.getTerminal();
if (terminal instanceof RuleCall) {
AbstractRule calledRule = ((RuleCall) terminal).getRule();
EClassifier classifier = calledRule.getType().getClassifier();
if (classifier == EcorePackage.Literals.EBIG_DECIMAL) {
builder.put(assignment, NUMBER_LITERAL_TOKEN);
}
}
}
}
}
}
示例5: Collector
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@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);
}
示例6: getGrammarPDAs
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public SerializationContextMap<Pda<ISerState, RuleCall>> getGrammarPDAs(Grammar grammar) {
RuleNames names = RuleNames.getRuleNames(grammar, true);
RuleFilter filter = new RuleFilter();
filter.setDiscardTerminalRules(true);
filter.setDiscardUnreachableRules(false);
filter.setDiscardRuleTypeRef(false);
Grammar flattened = new FlattenedGrammarAccess(names, filter).getFlattenedGrammar();
Builder<Pda<ISerState, RuleCall>> result = SerializationContextMap.<Pda<ISerState, RuleCall>>builder();
for (ParserRule rule : GrammarUtil.allParserRules(flattened)) {
RuleWithParameterValues withParams = RuleWithParameterValues.findInEmfObject(rule);
AbstractRule original = withParams.getOriginal();
if (original instanceof ParserRule && isValidRule((ParserRule) original)) {
ISerializationContext context = createContext((ParserRule) original, withParams.getParamValues());
try {
Pda<ISerState, RuleCall> pda = createPDA(grammar, rule);
result.put(context, pda);
} catch (Exception e) {
LOG.error("Error creating PDA for context '" + context + "': " + e.getMessage(), e);
}
}
}
return result.create();
}
示例7: collectAbstractElements
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public void collectAbstractElements(Grammar grammar, EStructuralFeature feature, IFollowElementAcceptor followElementAcceptor) {
for (Grammar superGrammar : grammar.getUsedGrammars()) {
collectAbstractElements(superGrammar, feature, followElementAcceptor);
}
EClass declarator = feature.getEContainingClass();
for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
for (Assignment assignment : GrammarUtil.containedAssignments(rule)) {
if (assignment.getFeature().equals(feature.getName())) {
EClassifier classifier = GrammarUtil.findCurrentType(assignment);
EClassifier compType = EcoreUtil2.getCompatibleType(declarator, classifier);
if (compType == declarator) {
followElementAcceptor.accept(assignment);
}
}
}
}
}
示例8: hasParameterizedRules
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
* @since 2.9
*/
protected boolean hasParameterizedRules(Grammar grammar) {
for(ParserRule rule : GrammarUtil.allParserRules(grammar)) {
if (!rule.getParameters().isEmpty()) {
return true;
}
}
return false;
}
示例9: containsUnorderedGroup
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected boolean containsUnorderedGroup(Grammar grammar) {
for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
if (Iterators.filter(rule.eAllContents(), UnorderedGroup.class).hasNext()) {
return true;
}
}
return false;
}
示例10: indexRules
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected Map<ParserRule, Integer> indexRules(Grammar grammar) {
List<ParserRule> rules = GrammarUtil.allParserRules(grammar);
Map<ParserRule, Integer> map = Maps.newHashMap();
for (int i = 0; i < rules.size(); i++) {
map.put(rules.get(i), i);
}
return map;
}
示例11: createKeywordMap
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private BiMap<CharSequence, String> createKeywordMap(Grammar grammar) {
List<ParserRule> parserRules = GrammarUtil.allParserRules(grammar);
List<EnumRule> enumRules = GrammarUtil.allEnumRules(grammar);
Iterator<EObject> iter = Iterators.concat(
EcoreUtil.<EObject>getAllContents(parserRules), EcoreUtil.<EObject>getAllContents(enumRules));
Iterator<Keyword> filtered = Iterators.filter(iter, Keyword.class);
Iterator<String> transformed = Iterators.transform(filtered, new Function<Keyword, String>() {
@Override
public String apply(Keyword from) {
return from.getValue();
}
});
TreeSet<String> treeSet = Sets.newTreeSet(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1.length() == o2.length())
return o1.compareTo(o2);
return Integer.valueOf(o1.length()).compareTo(Integer.valueOf(o2.length()));
}
});
Iterators.addAll(treeSet, transformed);
BiMap<CharSequence, String> result = HashBiMap.create();
for(String s: treeSet) {
CharSequence key = createKey(s);
String readableName = toAntlrTokenIdentifier(s);
if (result.containsValue(readableName)) {
int i = 1;
String next = readableName + "_" + i;
while(result.containsValue(next)) {
i++;
next = readableName + "_" + i;
}
readableName = next;
}
result.put(key, readableName);
}
return result;
}
示例12: compileRules
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
protected CharSequence compileRules(final Grammar g, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
{
List<ParserRule> _allParserRules = GrammarUtil.allParserRules(g);
List<EnumRule> _allEnumRules = GrammarUtil.allEnumRules(g);
Iterable<AbstractRule> _plus = Iterables.<AbstractRule>concat(_allParserRules, _allEnumRules);
Collection<? extends AbstractElement> _allAlternatives = GrammarUtil.getAllAlternatives(g);
Iterable<EObject> _plus_1 = Iterables.<EObject>concat(_plus, _allAlternatives);
Collection<? extends AbstractElement> _allGroups = GrammarUtil.getAllGroups(g);
Iterable<EObject> _plus_2 = Iterables.<EObject>concat(_plus_1, _allGroups);
Collection<? extends AbstractElement> _allUnorderedGroups = GrammarUtil.getAllUnorderedGroups(g);
Iterable<EObject> _plus_3 = Iterables.<EObject>concat(_plus_2, _allUnorderedGroups);
Collection<? extends AbstractElement> _allAssignments = GrammarUtil.getAllAssignments(g);
final Function1<EObject, Boolean> _function = (EObject it) -> {
return Boolean.valueOf(this._grammarAccessExtensions.isCalled(GrammarUtil.containingRule(it), g));
};
Iterable<EObject> _filter = IterableExtensions.<EObject>filter(Iterables.<EObject>concat(_plus_3, _allAssignments), _function);
for(final EObject rule : _filter) {
_builder.newLine();
CharSequence _compileRule = this.compileRule(rule, g, options);
_builder.append(_compileRule);
_builder.newLineIfNotEmpty();
}
}
{
boolean _isCombinedGrammar = this.isCombinedGrammar();
if (_isCombinedGrammar) {
CharSequence _compileTerminalRules = this.compileTerminalRules(g, options);
_builder.append(_compileTerminalRules);
_builder.newLineIfNotEmpty();
}
}
return _builder;
}
示例13: hasParameterizedRules
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected boolean hasParameterizedRules(final Grammar grammar) {
List<ParserRule> _allParserRules = GrammarUtil.allParserRules(grammar);
for (final ParserRule rule : _allParserRules) {
boolean _isEmpty = rule.getParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
return true;
}
}
return false;
}
示例14: containsUnorderedGroup
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected boolean containsUnorderedGroup(final Grammar grammar) {
List<ParserRule> _allParserRules = GrammarUtil.allParserRules(grammar);
for (final ParserRule rule : _allParserRules) {
boolean _hasNext = Iterators.<UnorderedGroup>filter(rule.eAllContents(), UnorderedGroup.class).hasNext();
if (_hasNext) {
return true;
}
}
return false;
}