当前位置: 首页>>代码示例>>Java>>正文


Java Grammar.getRules方法代码示例

本文整理汇总了Java中org.eclipse.xtext.Grammar.getRules方法的典型用法代码示例。如果您正苦于以下问题:Java Grammar.getRules方法的具体用法?Java Grammar.getRules怎么用?Java Grammar.getRules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.Grammar的用法示例。


在下文中一共展示了Grammar.getRules方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: collectRules

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
private void collectRules(Grammar grammar, Multimap<String, AbstractRule> result, Set<Grammar> visited,
		String name, Set<String> validNames) {
	if (!visited.add(grammar))
		return;

	List<String> allNames = new ArrayList<String>();
	for (AbstractRule rule : grammar.getRules()) {
		if (!validNames.contains(rule.getName())) {
			allNames.add(rule.getName());
			if (rule.getName().equalsIgnoreCase(name))
				result.put(rule.getName(), rule);
		}
	}
	validNames.addAll(allNames);
	for (Grammar usedGrammar : grammar.getUsedGrammars()) {
		collectRules(usedGrammar, result, visited, name, validNames);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:XtextValidator.java

示例2: GrammarElementDeclarationOrder

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
protected GrammarElementDeclarationOrder(Grammar grammar) {
	elementIDCache = Maps.newHashMap();
	List<Grammar> grammars = Lists.newArrayList(grammar);
	grammars.addAll(GrammarUtil.allUsedGrammars(grammar));
	int counter = 0;
	for (Grammar g : grammars) {
		elementIDCache.put(g, counter++);
		for (AbstractRule rule : g.getRules()) {
			elementIDCache.put(rule, counter++);
			TreeIterator<EObject> iterator = rule.eAllContents();
			while (iterator.hasNext()) {
				elementIDCache.put(iterator.next(), counter++);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:GrammarElementDeclarationOrder.java

示例3: FlattenedGrammarAccess

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
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);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:FlattenedGrammarAccess.java

示例4: testBug_266440

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
@Test
public void testBug_266440() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore  generate bugreport \'http://bugreport/266440\'");
  _builder.newLine();
  _builder.append("CompositeModel: (type+=EClassifier)+;");
  _builder.newLine();
  _builder.append("EClassifier: EDataType | EClass;");
  _builder.newLine();
  _builder.append("EClass: \'class\' name=ID;");
  _builder.newLine();
  _builder.append("EDataType: \'dt\' name=ID;");
  String grammar = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammar);
  Assert.assertTrue(resource.getErrors().isEmpty());
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar parsedGrammar = ((Grammar) _head);
  EList<AbstractRule> _rules = parsedGrammar.getRules();
  for (final AbstractRule rule : _rules) {
    {
      final EClassifier classifier = rule.getType().getClassifier();
      EPackage pack = classifier.getEPackage();
      Assert.assertEquals("bugreport", pack.getName());
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:Xtext2EcoreTransformerTest.java

示例5: caseGrammar

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
@Override
public Boolean caseGrammar(Grammar grammar) {
	UsedRulesFinder usedRulesFinder = new UsedRulesFinder(usedRules);
	usedRulesFinder.compute(grammar);
	this.inspectedGrammar = grammar;
	for(AbstractRule rule: grammar.getRules()) {
		if (!validatedRules.contains(rule) && usedRules.contains(rule)) {
			doSwitch(rule);
		}
	}
	return Boolean.FALSE;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:GrammarWithoutLeftRecursionInspector.java

示例6: updateOverriddenRules

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
protected void updateOverriddenRules(Grammar grammar) {
	if (grammar.getUsedGrammars().isEmpty())
		return;
	Map<String, AbstractRule> rulePerName = new HashMap<String, AbstractRule>(grammar.getRules().size());
	for (AbstractRule rule : grammar.getRules())
		rulePerName.put(rule.getName(), rule);
	Set<Grammar> visitedGrammars = new HashSet<Grammar>();
	visitedGrammars.add(grammar);
	for (Grammar usedGrammar : grammar.getUsedGrammars()) {
		updateOverriddenRules(usedGrammar, rulePerName, visitedGrammars);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:XtextLinker.java

示例7: containsAnyParserRule

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
private boolean containsAnyParserRule(Grammar g, Set<Grammar> visited) {
	if (!visited.add(g))
		return false;
	for (AbstractRule rule : g.getRules()) {
		if (rule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) rule))
			return true;
	}
	for (Grammar used : g.getUsedGrammars()) {
		if (containsAnyParserRule(used, visited))
			return true;
	}
	return false;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:XtextValidator.java

示例8: inspect

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
public void inspect(Grammar grammar) {
	this.inspectedGrammar = grammar;
	for(AbstractRule rule: grammar.getRules()) {
		if (!validatedRules.contains(rule)) {
			// different entry points yield different error messages
			Set<AbstractRule> storedRules = validatedRules;
			validatedRules = Sets.newHashSet();
			doSwitch(rule);
			storedRules.addAll(validatedRules);
			storedRules = validatedRules;
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:14,代码来源:PredicateUsesUnorderedGroupInspector.java

示例9: testSelf

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
@Test public void testSelf() {
	Grammar g = getGrammarAccess().getGrammar();
	for (AbstractRule r : g.getRules()) {
		// AbstractRule r = GrammarUtil.findRuleForName(g, "GrammarID");
		// System.out.println("serializing :" + r.getName());
		String s = serialize(r);
		assertNotNull(s, r.getName());
		// System.out.println(s);
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:11,代码来源:XtextGrammarReconcilationTest.java

示例10: testBug310122

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
@Test
public void testBug310122() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar test with org.eclipse.xtext.common.Terminals");
  _builder.newLine();
  _builder.append("generate myDsl \"http://example.xtext.org/MyDsl\"");
  _builder.newLine();
  _builder.append("Model: Sub1 | name=ID \'somekeyword\';");
  _builder.newLine();
  _builder.append("Sub1 returns Model: \'(\' Model \')\';");
  _builder.newLine();
  final String grammarAsString = _builder.toString();
  final XtextResource resource = this.getResourceFromString(grammarAsString);
  EObject _head = IterableExtensions.<EObject>head(resource.getContents());
  final Grammar grammar = ((Grammar) _head);
  AbstractMetamodelDeclaration _head_1 = IterableExtensions.<AbstractMetamodelDeclaration>head(grammar.getMetamodelDeclarations());
  GeneratedMetamodel generatedMetamodel = ((GeneratedMetamodel) _head_1);
  Assert.assertEquals("myDsl", generatedMetamodel.getName());
  Assert.assertEquals(1, generatedMetamodel.getEPackage().getEClassifiers().size());
  EClassifier _type = this.<EClassifier>type(generatedMetamodel.getEPackage(), "Model");
  EClass createdModel = ((EClass) _type);
  Assert.assertEquals(EcorePackage.Literals.ESTRING, this.<EStructuralFeature>feature(createdModel, "name").getEType());
  EList<AbstractRule> _rules = grammar.getRules();
  for (final AbstractRule rule : _rules) {
    Assert.assertEquals(createdModel, rule.getType().getClassifier());
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:28,代码来源:Xtext2EcoreTransformerTest.java

示例11: getFirstParserRule

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
protected ParserRule getFirstParserRule(Grammar grammar) {
	for (AbstractRule r : grammar.getRules())
		if (isParserRule(r))
			return (ParserRule) r;
	throw new RuntimeException("Grammar " + grammar.getName() + " contains no parser rules");
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:7,代码来源:ConcreteSyntaxConstraintProvider.java

示例12: caseGrammar

import org.eclipse.xtext.Grammar; //导入方法依赖的package包/类
public void caseGrammar(Grammar object) {
	for(AbstractRule rule: object.getRules())
		unload(rule);
	unload(object);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:6,代码来源:XtextReferableElementsUnloader.java


注:本文中的org.eclipse.xtext.Grammar.getRules方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。