本文整理汇总了Java中org.eclipse.xtext.GrammarUtil.isOptionalCardinality方法的典型用法代码示例。如果您正苦于以下问题:Java GrammarUtil.isOptionalCardinality方法的具体用法?Java GrammarUtil.isOptionalCardinality怎么用?Java GrammarUtil.isOptionalCardinality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.GrammarUtil
的用法示例。
在下文中一共展示了GrammarUtil.isOptionalCardinality方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: caseCharacterRange
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Boolean caseCharacterRange(CharacterRange object) {
boolean result = false;
if (object.getLeft().getValue().length() != 1 || object.getRight().getValue().length() != 1)
throw new IllegalStateException("ranges cannot use strings as left or right, that are longer then 1 character.");
OUTER: do {
if (eof())
break OUTER;
char left = object.getLeft().getValue().charAt(0);
char right = object.getRight().getValue().charAt(0);
char candidate = input.charAt(input.getOffset());
if (left <= candidate && right >= candidate) {
input.incOffset();
result = true;
continue OUTER;
}
break OUTER;
} while(GrammarUtil.isMultipleCardinality(object));
return result || GrammarUtil.isOptionalCardinality(object);
}
示例2: caseGroup
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Boolean caseGroup(Group object) {
boolean result = false;
OUTER: do {
IMarker marker = markerFactory.mark();
for(AbstractElement element: object.getElements()) {
if (!doSwitch(element)) {
marker.rollback();
break OUTER;
}
}
result = true;
continue OUTER;
} while(GrammarUtil.isMultipleCardinality(object));
return result || GrammarUtil.isOptionalCardinality(object);
}
示例3: caseNegatedToken
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Boolean caseNegatedToken(NegatedToken object) {
boolean result = false;
OUTER: do {
if (eof())
break OUTER;
IMarker marker = markerFactory.mark();
if (!doSwitch(object.getTerminal())) {
result = true;
input.incOffset();
continue OUTER;
}
marker.rollback();
break OUTER;
} while(GrammarUtil.isMultipleCardinality(object));
return result || GrammarUtil.isOptionalCardinality(object);
}
示例4: getAdjustedRequiredRuleNames
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
/**
* @since 2.14
*/
protected String[][] getAdjustedRequiredRuleNames(Param param, AbstractElement elementToParse,
String originalRuleName) {
String adjustedRuleName = adjustRuleName(originalRuleName, param);
if (!(GrammarUtil.isOptionalCardinality(elementToParse)
|| GrammarUtil.isOneOrMoreCardinality(elementToParse))) {
return new String[][] { { adjustedRuleName } };
}
EObject container = elementToParse.eContainer();
if (container instanceof Group) {
Group group = (Group) container;
List<AbstractElement> filteredElements = getFilteredElements(group.getElements(), param);
int idx = filteredElements.indexOf(elementToParse) + 1;
if (idx != filteredElements.size()) {
String adjustedSecondRule = getAdjustedSecondRule(param, group, idx);
return getRuleNamesInGroup(param, elementToParse, adjustedRuleName, adjustedSecondRule);
}
}
return new String[][] { { adjustedRuleName } };
}
示例5: caseAssignment
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Boolean caseAssignment(Assignment object) {
EClassifier wasType = currentType;
if (currentType == null) {
if (context.getType() != null)
currentType = context.getType().getClassifier();
}
if (object.getTerminal() != null)
if (doSwitch(object.getTerminal()))
return true;
if (object == stopElement)
return true;
if (GrammarUtil.isOptionalCardinality(object))
currentType = getCompatibleType(currentType, wasType, object);
return false;
}
示例6: getMissingMandatoryElements
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public List<AbstractElement> getMissingMandatoryElements() {
List<AbstractElement> result = missingMandatoryElements;
if (result == null) {
String predicate = getRecognitionException().toString();
int idx = predicate.indexOf("grammarAccess");
int lastIdx = predicate.lastIndexOf('(');
predicate = predicate.substring(idx + "grammarAccess.".length(), lastIdx);
String ruleMethodGetter = predicate.substring(0, predicate.indexOf('('));
String elementGetter = predicate.substring(predicate.indexOf('.') + 1);
IGrammarAccess grammarAccess = getGrammarAccess();
Object ruleAccess = invokeNoArgMethod(ruleMethodGetter, grammarAccess);
UnorderedGroup group = (UnorderedGroup) invokeNoArgMethod(elementGetter, ruleAccess);
List<AbstractElement> missingElements = Lists.newArrayList();
for(int i = 0; i < group.getElements().size(); i++) {
AbstractElement element = group.getElements().get(i);
if (!GrammarUtil.isOptionalCardinality(element) && unorderedGroupHelper.canSelect(group, i)) {
missingElements.add(element);
}
}
result = ImmutableList.copyOf(missingElements);
missingMandatoryElements = result;
}
return result;
}
示例7: isAlternativeWithEmptyPath
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private boolean isAlternativeWithEmptyPath(AbstractElement abstractElement) {
if (abstractElement instanceof Alternatives) {
Alternatives alternatives = (Alternatives) abstractElement;
for (AbstractElement path : alternatives.getElements()) {
if (GrammarUtil.isOptionalCardinality(path))
return true;
}
}
return false;
}
示例8: State
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
public State(UnorderedGroup group) {
frames = new Stack<Frame>();
EList<AbstractElement> elements = group.getElements();
alternatives = elements.size();
mandatoryAlternatives = new boolean[alternatives];
mandatoryAlternativeCount = 0;
for(int i = 0; i < alternatives; i++) {
boolean isMandatory = !GrammarUtil.isOptionalCardinality(elements.get(i));
if (isMandatory) {
mandatoryAlternatives[i] = true;
mandatoryAlternativeCount++;
}
}
}
示例9: caseUntilToken
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Boolean caseUntilToken(UntilToken object) {
if (GrammarUtil.isOptionalCardinality(object) || GrammarUtil.isMultipleCardinality(object))
throw new IllegalStateException("cardinality has to be default for until tokens");
IMarker marker = markerFactory.mark();
while (!eof()) {
if (doSwitch(object.getTerminal())) {
return true;
}
input.incOffset();
}
marker.rollback();
return false;
}
示例10: isOptionalGroup
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
private static boolean isOptionalGroup(Group group) {
if (GrammarUtil.containedAssignments(group).size() != 1)
return false;
if (GrammarUtil.isOptionalCardinality(group))
return true;
if (group.eContainer() instanceof Group)
return isOptionalGroup((Group) group.eContainer());
if (group.eContainer() instanceof UnorderedGroup)
return isOptionalUnorderedGroup((UnorderedGroup) group.eContainer());
return false;
}
示例11: caseRuleCall
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Boolean caseRuleCall(RuleCall object) {
if (object.getRule() == null)
return Boolean.FALSE;
if (ruleStack.contains(object.getRule())) {
createErrorMessages(object);
return GrammarUtil.isOptionalCardinality(object);
}
callStack.add(object);
Boolean result = doSwitch(object.getRule());
callStack.remove(callStack.size() - 1);
if (!result.booleanValue())
return GrammarUtil.isOptionalCardinality(object);
return result;
}
示例12: caseCompoundElement
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Pair<Boolean, Boolean> caseCompoundElement(CompoundElement object) {
boolean valid = true;
boolean instantiated = false;
for(AbstractElement element: object.getElements()) {
Pair<Boolean, Boolean> elementResult = doSwitch(element);
instantiated |= elementResult.getSecond().booleanValue();
if (!instantiated)
valid &= elementResult.getFirst().booleanValue();
}
valid |= instantiated;
instantiated &= !(GrammarUtil.isOptionalCardinality(object));
return Tuples.create(valid, instantiated);
}
示例13: caseAlternatives
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Boolean caseAlternatives(Alternatives object) {
if (GrammarUtil.isOptionalCardinality(object))
return Boolean.FALSE;
for(AbstractElement element: object.getElements()) {
if (!doSwitch(element))
return Boolean.FALSE;
}
return Boolean.TRUE;
}
示例14: caseUnorderedGroup
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@Override
public Boolean caseUnorderedGroup(UnorderedGroup object) {
Boolean result = Boolean.TRUE;
for(AbstractElement element: object.getElements()) {
if (!doSwitch(element))
result = Boolean.FALSE;
}
return result || GrammarUtil.isOptionalCardinality(object);
}
示例15: getRequiredRuleNames
import org.eclipse.xtext.GrammarUtil; //导入方法依赖的package包/类
@SuppressWarnings("restriction")
@Override
public String[][] getRequiredRuleNames(Param param) {
if (isFiltered(param)) {
return EMPTY_ARRAY;
}
AbstractElement elementToParse = param.elementToParse;
String ruleName = param.ruleName;
if (ruleName == null) {
if (elementToParse instanceof RuleCall) {
RuleCall call = (RuleCall) elementToParse;
if (call.getRule() instanceof ParserRule) {
String antlrRuleName = getRuleNames().getAntlrRuleName(call.getRule());
if (!call.getArguments().isEmpty()) {
Set<Parameter> context = param.getAssignedParametes();
Set<Parameter> arguments = getAssignedArguments(call, context);
int config = getParameterConfig(arguments);
antlrRuleName = getRuleNames().getAntlrRuleName(call.getRule(), config);
}
return new String[][] { { antlrRuleName } };
}
}
return EMPTY_ARRAY;
}
String adjustedRuleName = adjustRuleName(ruleName, param);
if (!(GrammarUtil.isOptionalCardinality(elementToParse)
|| GrammarUtil.isOneOrMoreCardinality(elementToParse))) {
return new String[][] { { adjustedRuleName } };
}
if ((elementToParse.eContainer() instanceof Group)) {
List<AbstractElement> tokens = getFilteredElements(((Group) elementToParse.eContainer()).getElements(),
param);
int idx = tokens.indexOf(elementToParse) + 1;
if (idx != tokens.size()) {
String secondRule = param.getBaseRuleName((AbstractElement) elementToParse.eContainer());
secondRule = secondRule.substring(0, secondRule.lastIndexOf('_') + 1) + idx;
String adjustedSecondRule = adjustRuleName(secondRule, param);
if (GrammarUtil.isMultipleCardinality(elementToParse))
return new String[][] { { adjustedRuleName }, { adjustedRuleName, adjustedSecondRule } };
return new String[][] { { adjustedRuleName, adjustedSecondRule } };
}
}
// Fix is here. Original method returns the original ruleName instead of the adjusted rule name.
return new String[][] { { adjustedRuleName } };
}