本文整理汇总了Java中org.eclipse.xtext.EnumRule类的典型用法代码示例。如果您正苦于以下问题:Java EnumRule类的具体用法?Java EnumRule怎么用?Java EnumRule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EnumRule类属于org.eclipse.xtext包,在下文中一共展示了EnumRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deriveFeatures
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
private boolean deriveFeatures() {
boolean result = true;
for (AbstractRule rule : grammar.getRules()) {
try {
if (rule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) rule) && !isWildcardFragment(rule)) {
deriveFeatures((ParserRule) rule);
} else if (rule instanceof EnumRule) {
deriveEnums((EnumRule) rule);
}
}
catch (TransformationException e) {
result = false;
reportError(e);
}
}
return result;
}
示例2: checkDataTypeOrEnumRule
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
/**
* Verify that only rule self directives are used for terminal, enum and data type rules.
*
* @param model
* the GrammarRule
*/
@Check
public void checkDataTypeOrEnumRule(final GrammarRule model) {
if (model.getTargetRule() instanceof TerminalRule || model.getTargetRule() instanceof EnumRule
|| (model.getTargetRule() instanceof ParserRule && GrammarUtil.isDatatypeRule((ParserRule) model.getTargetRule()))) {
Iterator<EObject> grammarElementAccessors = collectGrammarElementAccessors(model);
boolean selfAccessOnly = Iterators.all(grammarElementAccessors, new Predicate<EObject>() {
@Override
public boolean apply(final EObject input) {
return input instanceof GrammarElementReference && ((GrammarElementReference) input).getSelf() != null;
}
});
if (!selfAccessOnly) {
error(NLS.bind("For data type, enum or terminal rule {0} only ''rule'' directive may be used", model.getTargetRule().getName()), FormatPackage.Literals.GRAMMAR_RULE__DIRECTIVES, ILLEGAL_DIRECTIVE_CODE);
}
}
}
示例3: caseRuleCall
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
@Override
public Boolean caseRuleCall(RuleCall object) {
AbstractRule calledRule = object.getRule();
if (calledRule == null || calledRule.eIsProxy() || calledRule instanceof TerminalRule || calledRule instanceof EnumRule)
return Boolean.FALSE;
ParserRule parserRule = (ParserRule) calledRule;
if (GrammarUtil.isDatatypeRule(parserRule))
return Boolean.FALSE;
if (parserRule.isFragment()) {
visitFragment(object);
if (GrammarUtil.isMultipleCardinality(object))
visitFragment(object);
}
if (!addVisited(parserRule))
return Boolean.FALSE;
Multimap<String, AbstractElement> prevAssignedFeatures = assignedFeatures;
assignedFeatures = newMultimap();
doSwitch(parserRule.getAlternatives());
for (String feature : assignedFeatures.keySet())
prevAssignedFeatures.put(feature, object);
assignedFeatures = prevAssignedFeatures;
removeVisited(parserRule);
return Boolean.FALSE;
}
示例4: acceptRuleCall
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected void acceptRuleCall(RuleCall rc, Object value, String token, int index, INode node) {
CrossReference crossRef = GrammarUtil.containingCrossReference(rc);
if (crossRef != null) {
if (rc.getRule() instanceof ParserRule)
sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index,
getCompositeNode(node));
else if (rc.getRule() instanceof TerminalRule)
sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, getLeafNode(node));
else if (rc.getRule() instanceof EnumRule)
sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, getCompositeNode(node));
} else {
if (rc.getRule() instanceof ParserRule) {
AbstractRule rule = rc.getRule();
if (rule.getType() != null && rule.getType().getClassifier() instanceof EClass)
acceptEObjectRuleCall(rc, (EObject) value, getCompositeNode(node));
else
sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, getCompositeNode(node));
} else if (rc.getRule() instanceof TerminalRule)
sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, getLeafNode(node));
else if (rc.getRule() instanceof EnumRule)
sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, getCompositeNode(node));
}
}
示例5: acceptNode
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected void acceptNode(INode node) {
Object ge = node.getGrammarElement();
if (ge instanceof Keyword)
acceptUnassignedKeyword((Keyword) ge, node.getText(), (ILeafNode) node);
else if (ge instanceof RuleCall) {
RuleCall rc = (RuleCall) ge;
if (rc.getRule() instanceof TerminalRule)
acceptUnassignedTerminal(rc, node.getText(), (ILeafNode) node);
else if (rc.getRule() instanceof ParserRule) {
StringBuilder text = new StringBuilder();
for (ILeafNode leaf : node.getLeafNodes())
if (text.length() > 0 || !leaf.isHidden())
text.append(leaf.getText());
acceptUnassignedDatatype(rc, text.toString(), (ICompositeNode) node);
} else if (rc.getRule() instanceof EnumRule)
acceptUnassignedEnum(rc, node.getText(), (ICompositeNode) node);
} else if (ge instanceof Action)
acceptUnassignedAction((Action) ge);
else
throw new RuntimeException("Unexpected grammar element: " + node.getGrammarElement());
}
示例6: findValidValueAssignments
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected Set<AbstractElement> findValidValueAssignments(EObject semanticObj,
Iterable<AbstractElement> assignedElements, Object value) {
Set<AbstractElement> result = Sets.newLinkedHashSet();
for (AbstractElement ass : assignedElements) {
if (ass instanceof Keyword && keywordSerializer.isValid(semanticObj, (Keyword) ass, value, null))
result.add(ass);
else if (ass instanceof RuleCall) {
RuleCall rc = (RuleCall) ass;
if (rc.getRule() instanceof EnumRule) {
if (enumLiteralSerializer.isValid(semanticObj, rc, value, null))
result.add(ass);
} else if (valueSerializer.isValid(semanticObj, rc, value, null))
result.add(ass);
}
}
return result;
}
示例7: compileRule
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected CharSequence compileRule(final Object it, final Grammar grammar, final AntlrOptions options) {
if (it instanceof Alternatives) {
return _compileRule((Alternatives)it, grammar, options);
} else if (it instanceof Group) {
return _compileRule((Group)it, grammar, options);
} else if (it instanceof UnorderedGroup) {
return _compileRule((UnorderedGroup)it, grammar, options);
} else if (it instanceof Assignment) {
return _compileRule((Assignment)it, grammar, options);
} else if (it instanceof EnumRule) {
return _compileRule((EnumRule)it, grammar, options);
} else if (it instanceof ParserRule) {
return _compileRule((ParserRule)it, grammar, options);
} else if (it instanceof TerminalRule) {
return _compileRule((TerminalRule)it, grammar, options);
} else if (it instanceof String) {
return _compileRule((String)it, grammar, options);
} else {
throw new IllegalArgumentException("Unhandled parameter types: " +
Arrays.<Object>asList(it, grammar, options).toString());
}
}
示例8: crossrefEbnf
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected String crossrefEbnf(final AbstractRule it, final RuleCall call, final CrossReference ref, final boolean supportActions) {
String _switchResult = null;
boolean _matched = false;
if (it instanceof EnumRule) {
_matched=true;
}
if (!_matched) {
if (it instanceof ParserRule) {
_matched=true;
}
}
if (!_matched) {
if (it instanceof TerminalRule) {
_matched=true;
}
}
if (_matched) {
_switchResult = this._grammarAccessExtensions.ruleName(it);
}
if (!_matched) {
throw new IllegalStateException(("crossrefEbnf is not supported for " + it));
}
return _switchResult;
}
示例9: _assignmentEbnf
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected String _assignmentEbnf(final RuleCall it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
String _switchResult = null;
AbstractRule _rule = it.getRule();
final AbstractRule rule = _rule;
boolean _matched = false;
if (rule instanceof EnumRule) {
_matched=true;
}
if (!_matched) {
if (rule instanceof ParserRule) {
_matched=true;
}
}
if (!_matched) {
if (rule instanceof TerminalRule) {
_matched=true;
}
}
if (_matched) {
_switchResult = this._grammarAccessExtensions.ruleName(rule);
}
if (!_matched) {
throw new IllegalStateException(("assignmentEbnf is not supported for " + rule));
}
return _switchResult;
}
示例10: _cache
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected StringConcatenationClient _cache(final EnumRule it) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("private final ");
String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
_builder.append(_gaRuleAccessorClassName);
_builder.append(" ");
String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
_builder.append(_gaRuleAccessorLocalVarName);
_builder.append(";");
_builder.newLineIfNotEmpty();
}
};
return _client;
}
示例11: _initializer
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected StringConcatenationClient _initializer(final EnumRule it) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("this.");
String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
_builder.append(_gaRuleAccessorLocalVarName);
_builder.append(" = new ");
String _gaRuleAccessorClassName = GrammarAccessFragment2.this._grammarAccessExtensions.gaRuleAccessorClassName(it);
_builder.append(_gaRuleAccessorClassName);
_builder.append("();");
_builder.newLineIfNotEmpty();
}
};
return _client;
}
示例12: getRuleNameForErrorMessage
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
protected String getRuleNameForErrorMessage(AbstractRule rule) {
String ruleName = "datatype ";
if (rule instanceof TerminalRule)
ruleName = "terminal ";
else if (rule instanceof EnumRule)
ruleName = "enum ";
return ruleName;
}
示例13: checkUnassignedRuleCallAllowed
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
@Check
public void checkUnassignedRuleCallAllowed(final RuleCall call) {
if (call.getRule() != null && !call.getRule().eIsProxy() && GrammarUtil.containingAssignment(call) == null) {
AbstractRule container = GrammarUtil.containingRule(call);
if (call.getRule() instanceof ParserRule) {
if (container instanceof TerminalRule) {
getMessageAcceptor().acceptError(
"Cannot call parser rule from terminal rule.",
call,
XtextPackage.Literals.RULE_CALL__RULE,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
null);
} else {
ParserRule parserRule = (ParserRule) call.getRule();
if (!GrammarUtil.isDatatypeRule(parserRule) && !parserRule.isFragment()) {
checkCurrentMustBeUnassigned(call);
}
}
}
if (call.getRule() instanceof EnumRule) {
if (container instanceof TerminalRule) {
getMessageAcceptor().acceptError(
"Cannot call enum rule from terminal rule.",
call,
XtextPackage.Literals.RULE_CALL__RULE,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
null);
}
}
}
}
示例14: checkEnumLiteralIsUnique
import org.eclipse.xtext.EnumRule; //导入依赖的package包/类
@Check
public void checkEnumLiteralIsUnique(EnumLiteralDeclaration decl) {
EnumRule rule = GrammarUtil.containingEnumRule(decl);
List<EnumLiteralDeclaration> declarations = EcoreUtil2.getAllContentsOfType(rule, EnumLiteralDeclaration.class);
String literal = decl.getLiteral().getValue();
if (literal != null) {
for (EnumLiteralDeclaration otherDecl : declarations) {
if (otherDecl != decl && literal.equals(otherDecl.getLiteral().getValue())) {
error("Enum literal '" + literal + "' is used multiple times in enum rule '" + rule.getName() + "'.",
XtextPackage.Literals.ENUM_LITERAL_DECLARATION__LITERAL);
}
}
}
}
示例15: getDefaultAntlrRuleName
import org.eclipse.xtext.EnumRule; //导入依赖的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());
}