本文整理汇总了Java中org.eclipse.xtext.GrammarUtil.findCurrentType方法的典型用法代码示例。如果您正苦于以下问题:Java GrammarUtil.findCurrentType方法的具体用法?Java GrammarUtil.findCurrentType怎么用?Java GrammarUtil.findCurrentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.GrammarUtil
的用法示例。
在下文中一共展示了GrammarUtil.findCurrentType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: checkOppositeReferenceUsed
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Check
public void checkOppositeReferenceUsed(Assignment assignment) {
Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(BIDIRECTIONAL_REFERENCE);
if (severity == null || severity == Severity.IGNORE) {
// Don't perform any check if the result is ignored
return;
}
EClassifier classifier = GrammarUtil.findCurrentType(assignment);
if (classifier instanceof EClass) {
EStructuralFeature feature = ((EClass) classifier).getEStructuralFeature(assignment.getFeature());
if (feature instanceof EReference) {
EReference reference = (EReference) feature;
if (reference.getEOpposite() != null && !(reference.isContainment() || reference.isContainer())) {
addIssue("The feature '" + assignment.getFeature() + "' is a bidirectional reference."
+ " This may cause problems in the linking process.",
assignment, XtextPackage.eINSTANCE.getAssignment_Feature(), BIDIRECTIONAL_REFERENCE);
}
}
}
}
示例3: testFindCurrentType_01
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的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());
}
示例4: testFindCurrentType_02
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的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());
}
示例5: testFindCurrentType_03
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的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());
}
示例6: testFindCurrentType_04
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的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());
}
示例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: testFindCurrentType_05
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的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());
}
示例9: testFindCurrentType_06
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的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());
}