Java Code Examples for org.eclipse.xtext.ParserRule#isWildcard()

The following examples show how to use org.eclipse.xtext.ParserRule#isWildcard() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJavaBasedContentProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void lookupCrossReference(CrossReference crossReference, ContentAssistContext contentAssistContext,
		ICompletionProposalAcceptor acceptor, Predicate<IEObjectDescription> filter) {
	ParserRule containingParserRule = GrammarUtil.containingParserRule(crossReference);
	if (!GrammarUtil.isDatatypeRule(containingParserRule)) {
		EReference ref;
		if (containingParserRule.isWildcard()) {
			// TODO we need better ctrl flow analysis here
			// The cross reference may come from another parser rule then the current model 
			ref = GrammarUtil.getReference(crossReference, contentAssistContext.getCurrentModel().eClass());
		} else {
			ref = GrammarUtil.getReference(crossReference);
		}
		if (ref != null) {
			lookupCrossReference(crossReference, ref, contentAssistContext, acceptor, filter);
		}
	}
}
 
Example 2
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isWildcardFragment(AbstractRule rule) {
	if (rule instanceof ParserRule) {
		ParserRule casted = (ParserRule) rule;
		return casted.isFragment() && casted.isWildcard();
	}
	return false;
}
 
Example 3
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isParserRuleFragment(AbstractRule rule) {
	if (rule instanceof ParserRule) {
		ParserRule casted = (ParserRule) rule;
		return casted.isFragment() && !casted.isWildcard();
	}
	return false;
}
 
Example 4
Source File: CurrentTypeFinder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Boolean caseRuleCall(RuleCall object) {
	EClassifier wasType = currentType;
	AbstractRule calledRule = object.getRule();
	if (currentType == null) {
		if (calledRule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) calledRule)) {
			ParserRule parserRule = (ParserRule) calledRule;
			if (parserRule.isFragment()) {
				if (context.getType() != null)
					currentType = context.getType().getClassifier();
				if (!parserRule.isWildcard()) {
					doSwitch(parserRule);
				}
			} else {
				TypeRef returnType = calledRule.getType();
				if (returnType != null) {
					currentType = returnType.getClassifier();
				}
			}
		}
	} else if (isFragmentButNotWildcard(calledRule)) {
		doSwitch(calledRule);
	}
	if (object == stopElement)
		return true;
	if (GrammarUtil.isOptionalCardinality(object))
		currentType = getCompatibleType(currentType, wasType, object);
	return false;
}
 
Example 5
Source File: CurrentTypeFinder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isFragmentButNotWildcard(AbstractRule calledRule) {
	if (calledRule instanceof ParserRule) {
		ParserRule casted = (ParserRule) calledRule;
		return casted.isFragment() && !casted.isWildcard();
	}
	return false;
}
 
Example 6
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private boolean deriveTypeHierarchyFromOverridden(ParserRule rule, Grammar grammar) throws TransformationException {
	AbstractRule parentRule = GrammarUtil.findRuleForName(grammar, rule.getName());
	if (parentRule != null) {
		if (parentRule != rule && parentRule instanceof ParserRule) {
			ParserRule casted = (ParserRule) parentRule;
			if (casted.isFragment() != rule.isFragment()) {
				if (rule.isFragment()) {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"A fragment rule cannot override a production rule.", rule);
				} else {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"Only fragment rule can override other fragment rules.", rule);
				}
			}
			if (casted.isWildcard() != rule.isWildcard()) {
				if (rule.isWildcard()) {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"A wildcard fragment rule cannot override a typed fragment rule.", rule);
				} else {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"Only wildcard fragment rules can override other wildcard fragments.", rule);
				}
			}
			if (rule.isFragment() && !rule.isWildcard() && parentRule.getType() != null) {
				if (rule.getType().getClassifier() != parentRule.getType().getClassifier()) {
					throw new TransformationException(TransformationErrorCode.InvalidFragmentOverride,
							"Overriding fragment rules cannot redeclare their type.", rule.getType());
				}
			}
			checkParameterLists(rule, casted);
		}
		if (parentRule.getType() != null && parentRule != rule) {			
			if (parentRule.getType().getClassifier() instanceof EDataType)
				throw new TransformationException(TransformationErrorCode.InvalidSupertype,
						"Cannot inherit from datatype rule and return another type.", rule.getType());
			EClassifierInfo parentTypeInfo = eClassifierInfos.getInfoOrNull(parentRule.getType());
			if (parentTypeInfo == null)
				throw new TransformationException(TransformationErrorCode.InvalidSupertype,
						"Cannot determine return type of overridden rule.", rule.getType());
			addSuperType(rule, rule.getType(), parentTypeInfo);
			return true;
		}
	}
	return false;
}