當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractRule.getAlternatives方法代碼示例

本文整理匯總了Java中org.eclipse.xtext.AbstractRule.getAlternatives方法的典型用法代碼示例。如果您正苦於以下問題:Java AbstractRule.getAlternatives方法的具體用法?Java AbstractRule.getAlternatives怎麽用?Java AbstractRule.getAlternatives使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.xtext.AbstractRule的用法示例。


在下文中一共展示了AbstractRule.getAlternatives方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setRule

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
/**
 * @throws IllegalArgumentException if the rule is not a datatype rule or does not match
 *   the pattern <pre>RuleName: 'keyword' | 'other';</pre>
 */
@Override
public void setRule(AbstractRule rule) {
	if (!GrammarUtil.isDatatypeRule(rule))
		throw new IllegalArgumentException(rule.getName() + " is not a data type rule");
	if (!(rule.getAlternatives() instanceof Alternatives)) {
		if (rule.getAlternatives() instanceof RuleCall) {
			delegateRule = ((RuleCall) rule.getAlternatives()).getRule();
			keywords = Collections.emptySet();
			return;
		}
		throw mismatchedRuleBody(rule);
	}
	Alternatives alternatives = (Alternatives) rule.getAlternatives();
	ImmutableSet.Builder<String> builder = ImmutableSet.builder();
	for (AbstractElement element : alternatives.getElements()) {
		processElement(element, rule, builder);
	}
	keywords = builder.build();
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:24,代碼來源:KeywordAlternativeConverter.java

示例2: setRule

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
/**
 * @throws IllegalArgumentException if the rule is not a datatype rule or does not fulfill
 *   the pattern <pre>RuleName: 'keyword' | 'other';</pre>
 */
@Override
public void setRule(AbstractRule rule) {
	this.rule = rule;
	if (!GrammarUtil.isDatatypeRule(rule))
		throw new IllegalArgumentException(rule.getName() + " is not a data type rule");
	if (!(rule.getAlternatives() instanceof Alternatives) && !(rule.getAlternatives() instanceof Keyword)) {
		throw new IllegalArgumentException(rule.getName() + " is not a simple keyword nor an alternative");
	}
	if (rule.getAlternatives() instanceof Keyword) {
		keywords = ImmutableSet.of(keywordToString((Keyword) rule.getAlternatives()));
	} else {
		Alternatives alternatives = (Alternatives) rule.getAlternatives();
		ImmutableSet.Builder<String> builder = ImmutableSet.builder();
		for(AbstractElement element: alternatives.getElements()) {
			if (!(element instanceof Keyword)) {
				throw new IllegalArgumentException(rule.getName() + "'s body does not contain an alternative of keywords");
			}
			builder.add(keywordToString((Keyword) element));
		}
		keywords = builder.build();
	}
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:27,代碼來源:KeywordBasedValueConverter.java

示例3: testRuleCalledSuper

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test public void testRuleCalledSuper() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: super=super;\n" + 
			"super: name=ID;");

	IResourceValidator validator = get(IResourceValidator.class);
	List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("Discouraged rule name 'super'", issues.get(0).getMessage());
	Grammar grammar = (Grammar) resource.getContents().get(0);
	AbstractRule model = grammar.getRules().get(0);
	Assignment assignment = (Assignment) model.getAlternatives();
	RuleCall ruleCall = (RuleCall) assignment.getTerminal();
	assertSame(grammar.getRules().get(1), ruleCall.getRule());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:18,代碼來源:XtextValidationTest.java

示例4: testFindCurrentType_01

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test
public void testFindCurrentType_01() 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("Fragment;");
  _builder.newLine();
  _builder.append("fragment Fragment*: name=ID;");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final AbstractElement fragmentCall = rule.getAlternatives();
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("Rule", currentType.getName());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:25,代碼來源:GrammarUtilTest.java

示例5: testFindCurrentType_02

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test
public void testFindCurrentType_02() 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("Fragment;");
  _builder.newLine();
  _builder.append("fragment Fragment: name=ID {SubRule.named=current};");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final AbstractElement fragmentCall = rule.getAlternatives();
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("SubRule", currentType.getName());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:25,代碼來源:GrammarUtilTest.java

示例6: testFindCurrentType_03

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test
public void testFindCurrentType_03() 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("Fragment;");
  _builder.newLine();
  _builder.append("fragment Fragment: name=ID SecondFragment;");
  _builder.newLine();
  _builder.append("fragment SecondFragment: {SubRule.named=current} value=ID;");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final AbstractElement fragmentCall = rule.getAlternatives();
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("SubRule", currentType.getName());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:27,代碼來源:GrammarUtilTest.java

示例7: testFindCurrentType_04

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test
public void testFindCurrentType_04() 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("Fragment;");
  _builder.newLine();
  _builder.append("fragment Fragment: name=ID SecondFragment?;");
  _builder.newLine();
  _builder.append("fragment SecondFragment: {SubRule.named=current} value=ID;");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final AbstractElement fragmentCall = rule.getAlternatives();
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("Rule", currentType.getName());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:27,代碼來源:GrammarUtilTest.java

示例8: getEntryGrammarElement

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
protected AbstractElement getEntryGrammarElement(ICompositeNode entryPoint) {
	EObject grammarElement = entryPoint.getGrammarElement();
	if (grammarElement instanceof RuleCall) {
		AbstractRule rule = ((RuleCall) grammarElement).getRule();
		if (rule instanceof ParserRule) {
			if (!GrammarUtil.isMultipleCardinality(rule.getAlternatives())) {
				grammarElement = rule.getAlternatives();
			}
		}
	} else if (grammarElement instanceof ParserRule) {
		grammarElement = ((ParserRule) grammarElement).getAlternatives();
	} else if (grammarElement instanceof CrossReference) {
		grammarElement = GrammarUtil.containingAssignment(grammarElement);
	}
	AbstractElement result = (AbstractElement) grammarElement;
	if (result instanceof Action) {
		return getEntryGrammarElement((ICompositeNode) entryPoint.getFirstChild());
	}
	return result;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:21,代碼來源:BaseContentAssistParser.java

示例9: caseAbstractRule

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Override
public Boolean caseAbstractRule(AbstractRule object) {
	if (!validatedRules.add(object))
		return Boolean.FALSE;
	ruleStack.add(object);
	Boolean result = object.getAlternatives() == null ? Boolean.FALSE : doSwitch(object.getAlternatives());
	ruleStack.remove(object);
	return result;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:10,代碼來源:GrammarWithoutLeftRecursionInspector.java

示例10: getUnassignedRuleCallToken

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Override
protected String getUnassignedRuleCallToken(RuleCall ruleCall, INode node) {
	if (node != null)
		return node.getText().trim();
	AbstractRule rule = ruleCall.getRule();
	if (GrammarUtil.isDatatypeRule(rule)) {
		if (rule.getAlternatives() instanceof Keyword)
			return ((Keyword) rule.getAlternatives()).getValue();
		if (rule.getAlternatives() instanceof Alternatives)
			for (AbstractElement ele : ((Alternatives) rule.getAlternatives()).getElements())
				if (ele instanceof Keyword)
					return ((Keyword) ele).getValue();
	}
	return "";
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:16,代碼來源:GenericSyntacticSequencer.java

示例11: testParseCrossRef

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test public void testParseCrossRef() throws Exception {
		Grammar model = (Grammar) getModel("grammar foo with org.eclipse.xtext.common.Terminals " +
				"generate foo 'bar' as boo " +
				"Model returns boo::Model : 'a' stuff+=Stuff*; " +
				"Stuff returns boo::Stuff : 'stuff' name=ID refersTo=[boo::Stuff];");
		AbstractRule rule = model.getRules().get(1);
		Group group = (Group) rule.getAlternatives();
		Assignment assignment = (Assignment) group.getElements().get(2);
		CrossReference reference = (CrossReference) assignment.getTerminal();
		assertEquals("boo", reference.getType().getMetamodel().getAlias());
//		assertWithXtend("'boo'", "eAllContents.typeSelect(xtext::CrossReference).first().type.metamodel.alias", model);
		assertEquals("Stuff", reference.getType().getClassifier().getName());
//		assertWithXtend("'Stuff'", "eAllContents.typeSelect(xtext::CrossReference).first().type.classifier.name", model);
	}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:15,代碼來源:XtextParserTest.java

示例12: testMultiAction4

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test public void testMultiAction4() throws Exception {
	AbstractRule rule = parseRule("Model: 'a' {Type1} | 'b' {Type2} | 'c' | name=ID;");
	Alternatives alt = (Alternatives) rule.getAlternatives();
	assertTypes(nfa.getNFA(alt).getTypes(), "Type1", "Type2", "Model", "null");
	assertTypes(nfa.getNFA(alt.getElements().get(0)).getTypesToCheck(), "Type1");
	assertTypes(nfa.getNFA(alt.getElements().get(1)).getTypesToCheck(), "Type2");
	assertTypes(nfa.getNFA(alt.getElements().get(2)).getTypesToCheck());
	assertTypes(nfa.getNFA(alt.getElements().get(3)).getTypesToCheck(), "Model");
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:10,代碼來源:TreeConstTest.java

示例13: testFQNInSuper_02

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Ignore("Serialization does not have the correct context information")
@Test
public void testFQNInSuper_02() {
	Grammar grammar = load(URI.createURI("classpath:/org/eclipse/xtext/grammarinheritance/InheritanceTestLanguage.xtext"));
	AbstractRule rule = GrammarUtil.findRuleForName(grammar, "FQN");
	Assert.assertNotNull(rule);
	Group group = (Group) rule.getAlternatives();
	RuleCall ruleCall = (RuleCall) group.getElements().get(0);
	TerminalRule id = (TerminalRule) ruleCall.getRule();
	Assert.assertSame(grammar, GrammarUtil.getGrammar(id));
	String string = get(ISerializer.class).serialize(rule.getAlternatives());
	Assert.assertEquals("ID (\".\" ID)*", string);
	// currently wrong result is 
	Assert.assertEquals("super::ID (\".\" super::ID)*", string);
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:16,代碼來源:XtextSerializerTest.java

示例14: testFindCurrentType_05

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test
public void testFindCurrentType_05() 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("Fragment;");
  _builder.newLine();
  _builder.append("fragment Fragment returns Rule:");
  _builder.newLine();
  _builder.append("    ");
  _builder.append("name=ID Fragment?");
  _builder.newLine();
  _builder.append(";");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
  final AbstractElement fragmentCall = rule.getAlternatives();
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("Rule", currentType.getName());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:30,代碼來源:GrammarUtilTest.java

示例15: testFindCurrentType_06

import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test
public void testFindCurrentType_06() 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("Fragment;");
  _builder.newLine();
  _builder.append("fragment Fragment returns Rule:");
  _builder.newLine();
  _builder.append("    ");
  _builder.append("name=ID Fragment?");
  _builder.newLine();
  _builder.append(";");
  _builder.newLine();
  String model = _builder.toString();
  final XtextResource r = this.getResourceFromString(model);
  EObject _get = r.getContents().get(0);
  final Grammar grammar = ((Grammar) _get);
  final AbstractRule rule = IterableExtensions.<AbstractRule>last(grammar.getRules());
  AbstractElement _alternatives = rule.getAlternatives();
  final AbstractElement fragmentCall = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
  final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
  Assert.assertEquals("Rule", currentType.getName());
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:31,代碼來源:GrammarUtilTest.java


注:本文中的org.eclipse.xtext.AbstractRule.getAlternatives方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。