本文整理汇总了Java中org.eclipse.xtext.GrammarUtil.getGrammar方法的典型用法代码示例。如果您正苦于以下问题:Java GrammarUtil.getGrammar方法的具体用法?Java GrammarUtil.getGrammar怎么用?Java GrammarUtil.getGrammar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.GrammarUtil
的用法示例。
在下文中一共展示了GrammarUtil.getGrammar方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGrammar
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
* Extracts the grammar from this transition or the NFA if this transition does not point to an
* {@link AbstractElement}.
*/
private Grammar getGrammar(Nfa<ISynState> nfa) {
AbstractElement grammarElement = getGrammarElement();
if (grammarElement == null) {
grammarElement = nfa.getStart().getGrammarElement();
if (grammarElement == null) {
grammarElement = nfa.getStop().getGrammarElement();
if (grammarElement == null) {
Iterator<ISynState> iter = nfa.getStart().getFollowers().iterator();
while (grammarElement == null && iter.hasNext()) {
grammarElement = iter.next().getGrammarElement();
}
}
}
}
Grammar grammar = GrammarUtil.getGrammar(grammarElement);
return grammar;
}
示例2: getInfo
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public EClassifierInfo getInfo(TypeRef typeRef) {
if (typeRef.getClassifier() == null)
return null;
EClassifierInfo result = getInfo(typeRef.getMetamodel(), typeRef.getClassifier().getName());
if (result == null) {
Grammar declaringGrammar = GrammarUtil.getGrammar(typeRef);
if (grammar.equals(declaringGrammar))
return result;
for(EClassifierInfos parent: parents) {
result = parent.getInfo(typeRef);
if (result != null)
return result;
}
}
return result;
}
示例3: getSeverity
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
protected Severity getSeverity(Diagnostic diagnostic) {
Severity result = super.getSeverity(diagnostic);
String issueCode = getIssueCode(diagnostic);
if (result == Severity.WARNING && issueCode != null) {
// only warnings can be suppressed
EObject causer = getCauser(diagnostic);
if (causer != null) {
if (isMarkedAsIgnored(causer, issueCode)) {
return null;
}
if (!(causer instanceof AbstractRule)) {
AbstractRule rule = GrammarUtil.containingRule(causer);
if (rule != null && isMarkedAsIgnored(rule, issueCode)) {
return null;
}
}
Grammar grammar = GrammarUtil.getGrammar(causer);
if (grammar != null && isMarkedAsIgnored(grammar, issueCode)) {
return null;
}
}
}
return result;
}
示例4: getElements
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Iterable<IEObjectDescription> getElements(EObject object) {
if (object instanceof AbstractRule) {
Grammar grammar = GrammarUtil.getGrammar(context);
AbstractRule rule = (AbstractRule) object;
if (GrammarUtil.getGrammar(rule) == grammar) {
return Lists.newArrayList(
EObjectDescription.create(GrammarUtil.getSimpleName(grammar) + "." + rule.getName(), rule),
EObjectDescription.create(grammar.getName() + "." + rule.getName(), rule));
}
List<IEObjectDescription> result = Lists.newArrayList(
EObjectDescription.create(SUPER + "." + rule.getName(), rule),
EObjectDescription.create(GrammarUtil.getSimpleName(grammar) + "." + rule.getName(), rule),
EObjectDescription.create(grammar.getName() + "." + rule.getName(), rule));
AbstractRule contextRule = GrammarUtil.containingRule(context);
if (contextRule != null && contextRule.getName().equals(rule.getName())) {
result.add(0, EObjectDescription.create(SUPER, rule));
}
return result;
}
return Collections.emptyList();
}
示例5: getPackage
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private List<EObject> getPackage(ReferencedMetamodel context, ILeafNode text) {
String nsUri = getMetamodelNsURI(text);
if (nsUri == null)
return Collections.emptyList();
Grammar grammar = GrammarUtil.getGrammar(context);
Set<Grammar> visitedGrammars = new HashSet<Grammar>();
for (Grammar usedGrammar: grammar.getUsedGrammars()) {
List<EObject> result = getPackage(nsUri, usedGrammar, visitedGrammars);
if (result != null)
return result;
}
QualifiedName packageNsURI = QualifiedName.create(nsUri);
EPackage pack = findPackageInScope(context, packageNsURI);
if (pack == null) {
pack = findPackageInAllDescriptions(context, packageNsURI);
if (pack == null) {
pack = loadEPackage(nsUri, context.eResource().getResourceSet());
}
}
if (pack != null)
return Collections.<EObject>singletonList(pack);
return Collections.emptyList();
}
示例6: inspectKeywordHidesTerminalRule
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public void inspectKeywordHidesTerminalRule(Keyword keyword) {
AbstractRule container = GrammarUtil.containingRule(keyword);
if (container instanceof TerminalRule)
return;
Grammar grammar = GrammarUtil.getGrammar(container);
List<TerminalRule> rules = GrammarUtil.allTerminalRules(grammar);
for(TerminalRule rule: rules) {
if (!rule.isFragment()) {
AbstractElement element = rule.getAlternatives();
if (element instanceof Keyword && Strings.isEmpty(element.getCardinality())) {
String value = ((Keyword) element).getValue();
if (value.equals(keyword.getValue()))
acceptor.acceptError(
"The keyword '" + value + "' hides the terminal rule " + rule.getName()+ ".",
keyword,
XtextPackage.Literals.KEYWORD__VALUE,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null);
}
}
}
}
示例7: getElementID
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public int getElementID(EObject ele) {
Integer result = elementIDCache.get(ele);
if (result == null) {
Grammar grammar = GrammarUtil.getGrammar(ele);
if (!elementIDCache.containsKey(grammar)) {
String grammarName = grammar.getName() + "#" + System.identityHashCode(grammar);
List<String> indexed = Lists.newArrayList();
for (EObject o : elementIDCache.keySet())
if (o instanceof Grammar)
indexed.add(((Grammar) o).getName() + "#" + System.identityHashCode(o));
throw new IllegalStateException("No ID found. Wrong grammar. \nRequested: " + grammarName
+ "\nAvailable: " + Joiner.on(", ").join(indexed));
} else
throw new IllegalStateException("No ID found. Not indexed. \nElement: " + EmfFormatter.objPath(ele));
}
return result;
}
示例8: assertNoLeakedGrammarElements
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
final Function1<ISerState, AbstractElement> _function = (ISerState it) -> {
return it.getGrammarElement();
};
Iterable<AbstractElement> _filterNull = IterableExtensions.<AbstractElement>filterNull(IterableExtensions.<ISerState, AbstractElement>map(new NfaUtil().<ISerState>collect(pda), _function));
for (final AbstractElement ele : _filterNull) {
{
final Grammar actual = GrammarUtil.getGrammar(ele);
if ((actual != grammar)) {
String _objPath = EmfFormatter.objPath(ele);
String _plus = ("Element " + _objPath);
String _plus_1 = (_plus + " leaked!");
Assert.fail(_plus_1);
}
}
}
}
示例9: getCrossReferencesWithSameEReference
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private static List<CrossReference> getCrossReferencesWithSameEReference(CrossReference cr) {
Grammar g = GrammarUtil.getGrammar(cr);
EReference ref = GrammarUtil.getReference(cr);
List<CrossReference> result = Lists.newArrayList();
for (CrossReference c : EcoreUtil2.getAllContentsOfType(g, CrossReference.class))
if (GrammarUtil.getReference(c) == ref)
result.add(c);
return result;
}
示例10: getEnumeratedValues
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public List<String> getEnumeratedValues(ParserRule rule) {
CfgAdapter adapter = new CfgAdapter(GrammarUtil.getGrammar(rule));
FollowerFunction<AbstractElement> followers = new FollowerFunctionImpl<AbstractElement, AbstractElement>(adapter);
List<String> result = Lists.newArrayList();
Iterable<AbstractElement> starts = followers.getStarts(rule.getAlternatives());
collect(starts, null, "", result, followers);
return result;
}
示例11: getInheritedGeneratedMetamodels
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected List<GeneratedMetamodel> getInheritedGeneratedMetamodels(ReferencedMetamodel metamodel) {
List<GeneratedMetamodel> allGeneratedMetamodels = new ArrayList<GeneratedMetamodel>();
Grammar grammar = GrammarUtil.getGrammar(metamodel);
Set<Grammar> visited = Sets.newHashSet();
for (Grammar usedGrammar : grammar.getUsedGrammars())
Iterables.addAll(allGeneratedMetamodels, getAllGeneratedMetamodels(usedGrammar, visited));
if (allGeneratedMetamodels.isEmpty())
return Collections.emptyList();
return allGeneratedMetamodels;
}
示例12: isReferencedByUsedGrammar
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private boolean isReferencedByUsedGrammar(GeneratedMetamodel generatedMetamodel, String nsURI) {
final Grammar grammar = GrammarUtil.getGrammar(generatedMetamodel);
if (grammar != null) {
final Set<Grammar> visitedGrammars = Sets.newHashSet(grammar);
for (Grammar usedGrammar: grammar.getUsedGrammars()) {
if (isReferencedByUsedGrammar(usedGrammar, nsURI, visitedGrammars))
return true;
}
}
return false;
}
示例13: getConsumerClassName
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
* @param rule
* - the rule
* @return <code>firstLetterToUpper(rule.name) + "Consumer"</code>
*/
public static String getConsumerClassName(AbstractRule rule) {
Grammar grammar = GrammarUtil.getGrammar(rule);
return (grammar != null ? GrammarUtil.getSimpleName(grammar) : "")
+ (rule.getName() == null ? "Consumer" : Strings.toFirstUpper(rule.getName()) + "Consumer");
}
示例14: _getter
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
protected StringConcatenationClient _getter(final ParserRule it, final Grammar original) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _grammarFragmentToString = GrammarAccessFragment2.this._grammarAccessExtensions.grammarFragmentToString(it, "//");
_builder.append(_grammarFragmentToString);
_builder.newLineIfNotEmpty();
{
Grammar _grammar = GrammarUtil.getGrammar(it);
boolean _tripleEquals = (_grammar == original);
if (_tripleEquals) {
_builder.append("public ");
String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
_builder.append(_gaRuleAccessorClassName);
_builder.append(" ");
String _gaElementsAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
_builder.append(_gaElementsAccessor);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return ");
String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
_builder.append(_gaRuleAccessorLocalVarName, "\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
} else {
_builder.append("public ");
TypeReference _grammarAccess = GrammarAccessFragment2.this._grammarAccessExtensions.getGrammarAccess(GrammarUtil.getGrammar(it));
_builder.append(_grammarAccess);
_builder.append(".");
String _gaBaseRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaBaseRuleAccessorClassName(it);
_builder.append(_gaBaseRuleAccessorClassName);
_builder.append(" ");
String _gaElementsAccessor_1 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
_builder.append(_gaElementsAccessor_1);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return ");
String _gaGrammarAccessLocalVarName = GrammarAccessFragment2.this.gaGrammarAccessLocalVarName(GrammarUtil.getGrammar(it));
_builder.append(_gaGrammarAccessLocalVarName, "\t");
_builder.append(".");
String _gaBaseElementsAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaBaseElementsAccessor(it);
_builder.append(_gaBaseElementsAccessor, "\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("public ParserRule ");
String _gaRuleAccessor = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessor(it);
_builder.append(_gaRuleAccessor);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return ");
String _gaElementsAccessor_2 = GrammarAccessFragment2.this._grammarAccessExtensions.gaElementsAccessor(it);
_builder.append(_gaElementsAccessor_2, "\t");
_builder.append(".getRule();");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
return _client;
}