Java Code Examples for org.eclipse.xtext.AbstractRule#eIsProxy()

The following examples show how to use org.eclipse.xtext.AbstractRule#eIsProxy() . 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: OverriddenValueInspector.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: TemplateValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkParameters(Variable variable) {
	Codetemplate template = EcoreUtil2.getContainerOfType(variable, Codetemplate.class);
	Codetemplates templates = EcoreUtil2.getContainerOfType(template, Codetemplates.class);
	if (templates != null && template != null) {
		Grammar language = templates.getLanguage();
		AbstractRule rule = template.getContext();
		ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(language);
		if (helper != null && rule != null && !rule.eIsProxy() && rule instanceof ParserRule) {
			String contextTypeId = helper.getId(rule);
			ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(language);
			TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
			if (contextType != null) {
				Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(),
						TemplateVariableResolver.class);
				String type = variable.getType();
				if (type == null)
					type = variable.getName();
				while (resolvers.hasNext()) {
					final TemplateVariableResolver resolver = resolvers.next();
					if (resolver.getType().equals(type)) {
						IInspectableTemplateVariableResolver inspectableResolver = registry
								.toInspectableResolver(resolver);
						if (inspectableResolver != null) {
							inspectableResolver.validateParameters(variable, this);
						}
					}
				}
			}
		}
	}
}
 
Example 3
Source File: GrammarElementTitleSwitch.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: XtextLinker.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@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);
	}
}