本文整理匯總了Java中org.eclipse.xtext.AbstractRule.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java AbstractRule.getName方法的具體用法?Java AbstractRule.getName怎麽用?Java AbstractRule.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.xtext.AbstractRule
的用法示例。
在下文中一共展示了AbstractRule.getName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getOrComputeReturnType
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
private TypeRef getOrComputeReturnType(AbstractRule rule) {
TypeRef result = rule.getType();
if (result == null) {
EClassifier classifier = getClassifierFor(rule);
if (classifier == null) {
if (rule.getName() == null)
return null;
result = getTypeRef(rule.getName());
} else
result = getTypeRef(classifier);
if (result.getMetamodel() == null) {
AbstractMetamodelDeclaration bestMatch = null;
for (AbstractMetamodelDeclaration decl : grammar.getMetamodelDeclarations()) {
if (decl instanceof GeneratedMetamodel && Strings.isEmpty(decl.getAlias())) {
bestMatch = decl;
break;
}
}
if (result.getMetamodel() == null)
result.setMetamodel(bestMatch);
}
rule.setType(result);
}
return result;
}
示例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();
}
}
示例3: getInheritedUniqueName
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
private String getInheritedUniqueName(AbstractRule rule, Set<String> usedNames) {
String grammarName = GrammarUtil.getSimpleName(GrammarUtil.getGrammar(rule));
String candidate = grammarName + rule.getName();
int i = 1;
while(usedNames.contains(candidate)) {
candidate = grammarName + i + rule.getName();
i++;
}
return candidate;
}
示例4: getDefaultAntlrRuleName
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
private String getDefaultAntlrRuleName(AbstractRule rule) {
if (rule instanceof ParserRule || rule instanceof EnumRule) {
return "rule" + rule.getName();
}
if (rule instanceof TerminalRule) {
return "RULE_" + rule.getName().toUpperCase();
}
throw new IllegalArgumentException(rule.eClass().getName());
}
示例5: testAllRules
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Test
public void testAllRules() 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("name=super::STRING;");
_builder.newLine();
_builder.append("terminal STRING: \'\"\';");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
final Function1<AbstractRule, String> _function = (AbstractRule it) -> {
return it.getName();
};
Assert.assertEquals(
Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("Rule", "STRING", "ID", "INT", "STRING", "ML_COMMENT", "SL_COMMENT", "WS", "ANY_OTHER")).toString(),
ListExtensions.<AbstractRule, String>map(allRules, _function).toString());
}
示例6: unassignedCalledTokenRuleName
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
private CharSequence unassignedCalledTokenRuleName(final AbstractRule rule) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("get");
String _name = rule.getName();
_builder.append(_name);
_builder.append("Token");
return _builder;
}
示例7: addQualified
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
protected String addQualified(String result, AbstractElement ele) {
if (!showQualified && !showRule)
return result;
AbstractRule rule = GrammarUtil.containingRule(ele);
if (rule == null)
return "<AbstractElement not contained in AbstractRule!>:" + result;
if (!showQualified)
return result + ":" + rule.getName();
GrammarElementTitleSwitch others = copy();
others.showQualified = false;
others.showRule = false;
List<AbstractElement> elementsWithSameName = Lists.newArrayList();
for (AbstractElement candidate : EcoreUtil2.getAllContentsOfType(rule, ele.getClass()))
if (candidate == ele || result.equals(others.doSwitch(candidate)))
elementsWithSameName.add(candidate);
if (elementsWithSameName.size() < 2) {
if (showRule)
return rule.getName() + ":" + result;
return result;
}
Map<CompoundElement, Node> nodes = Maps.newHashMap();
for (AbstractElement collision : elementsWithSameName) {
EObject current = EcoreUtil2.getContainerOfType(collision, CompoundElement.class);
Node node = new Node(null, collision == ele ? result : "");
while (current instanceof CompoundElement) {
CompoundElement container = (CompoundElement) current;
Node cntNode = nodes.get(container);
if (cntNode == null)
nodes.put(container, cntNode = new Node(container, null));
if (!cntNode.children.contains(node))
cntNode.children.add(node);
node = cntNode;
current = current.eContainer();
}
}
if (showRule)
return rule.getName() + ":" + nodes.get(rule.getAlternatives());
return nodes.get(rule.getAlternatives()).toString();
}
示例8: caseAbstractRule
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Override
public String caseAbstractRule(AbstractRule object) {
String classifier = object.getType().getClassifier().getName();
if (object.getName().equals(classifier))
return object.getName() + ":";
return object.getName() + " returns " + classifier + ":";
}
示例9: caseRuleCall
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Override
public String caseRuleCall(RuleCall object) {
AbstractRule rule = object.getRule();
String ruleName;
if (rule != null && !rule.eIsProxy())
ruleName = rule.getName();
else
ruleName = "unresolved_rule";
return addCrossRefOrAssignemnt(ruleName, object) + card(object);
}
示例10: _crossrefEbnf
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
protected String _crossrefEbnf(final AbstractRule it, final RuleCall call, final CrossReference ref, final boolean supportActions) {
boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<AbstractRule>getOriginalElement(it));
if (_isDatatypeRule) {
return this._grammarAccessExtensions.ruleName(it);
}
String _name = it.getName();
String _plus = (_name + " is not a datatype rule");
throw new IllegalArgumentException(_plus);
}
示例11: newNode
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Override
protected Node newNode(EObject semanticObject, String label) {
if (semanticObject.eContainer() instanceof AbstractRule) {
AbstractRule rule = (AbstractRule) semanticObject.eContainer();
return new Node(semanticObject, rule.getName() + ":\\n" + label, "record");
} else {
return new Node(semanticObject, label);
}
}
示例12: getRuleName
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
/**
* Returns the effective rule name for the generated Antlr grammar.
* Inherited rules may be prefixed by {@code super[0..9]*}. Otherwise the
* prefix {@code rule or RULE_} is used.
* @since 2.9
*/
public static String getRuleName(AbstractRule rule) {
RuleWithParameterValues parameterValues = RuleWithParameterValues.findInEmfObject(rule);
if (parameterValues != null) {
return rule.getName();
}
RuleNames ruleNames = RuleNames.getRuleNames(rule);
return ruleNames.getAntlrRuleName(rule);
}
示例13: getConsumerClassName
import org.eclipse.xtext.AbstractRule; //導入方法依賴的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: getFqFeatureName
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
public static String getFqFeatureName(final AbstractRule it) {
String _name = it.getName();
return ("_" + _name);
}
示例15: setDefaultValueImpl
import org.eclipse.xtext.AbstractRule; //導入方法依賴的package包/類
@Override
protected void setDefaultValueImpl(EObject obj, EReference ref, IDiagnosticProducer producer) {
if (XtextPackage.eINSTANCE.getTypeRef_Metamodel() == ref) {
final TypeRef typeRef = (TypeRef) obj;
final String typeRefName = GrammarUtil.getTypeRefName(typeRef);
final List<EObject> metamodels = XtextMetamodelReferenceHelper.findBestMetamodelForType(typeRef, "",
typeRefName, scopeProvider.getScope(typeRef, ref));
if (metamodels.isEmpty() || metamodels.size() > 1)
producer.addDiagnostic(new DiagnosticMessage("Cannot find meta model for type '" + typeRefName + "'", Severity.ERROR, null));
else
typeRef.setMetamodel((AbstractMetamodelDeclaration) metamodels.get(0));
} else if (XtextPackage.eINSTANCE.getCrossReference_Terminal() == ref) {
AbstractRule rule = GrammarUtil.findRuleForName(GrammarUtil.getGrammar(obj), "ID");
if (rule == null)
producer.addDiagnostic(new DiagnosticMessage("Cannot resolve implicit reference to rule 'ID'", Severity.ERROR, null));
else {
RuleCall call = XtextFactory.eINSTANCE.createRuleCall();
call.setRule(rule);
((CrossReference) obj).setTerminal(call);
}
} else if (XtextPackage.eINSTANCE.getNamedArgument_Parameter() == ref) {
final NamedArgument argument = (NamedArgument) obj;
if (!argument.isCalledByName()) {
RuleCall ruleCall = EcoreUtil2.getContainerOfType(argument, RuleCall.class);
AbstractRule calledRule = ruleCall.getRule();
if (!(calledRule instanceof ParserRule)) {
producer.addDiagnostic(new DiagnosticMessage("Arguments can only be used with parser rules.", Severity.ERROR, null));
return;
}
if (!calledRule.eIsProxy()) {
ParserRule casted = (ParserRule) calledRule;
int idx = ruleCall.getArguments().indexOf(argument);
if (idx < casted.getParameters().size()) {
argument.setParameter(casted.getParameters().get(idx));
return;
} else if (casted.getParameters().size() == 0) {
producer.addDiagnostic(new DiagnosticMessage(
"Rule " + calledRule.getName() + " has no arguments.", Severity.ERROR, null));
} else {
String message = "Invalid number of arguments for rule " + calledRule.getName() + ", expecting "
+ casted.getParameters().size() + " but was " + (idx+1);
producer.addDiagnostic(new DiagnosticMessage(message, Severity.ERROR, null));
}
}
}
} else {
super.setDefaultValueImpl(obj, ref, producer);
}
}