Search in sources :

Example 1 with IGrammarConstraintProvider

use of org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider in project xtext-core by eclipse.

the class GrammarConstraintProviderAssignedActionTest method getParserRule.

private String getParserRule(String body) throws Exception {
    Grammar grammar = (Grammar) getModel(HEADER + body);
    IGrammarConstraintProvider gcp = get(IGrammarConstraintProvider.class);
    // try {
    // new ActionFilter2Dot().draw(grammar, getName() + ".pdf", "-T pdf");
    // } catch (IOException e) {
    // if (log.isDebugEnabled())
    // log.debug(e.getMessage(), e);
    // }
    SerializationContextMap<IConstraint> constraints = gcp.getConstraints(grammar);
    List<String> result = Lists.newArrayList();
    for (SerializationContextMap.Entry<IConstraint> r : constraints.sortedCopy().values()) {
        result.add(Joiner.on(", ").join(r.getContexts()) + ":");
        result.add("  " + r.getValue());
    }
    return Joiner.on("\n").join(result);
}
Also used : SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) IConstraint(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint) Grammar(org.eclipse.xtext.Grammar)

Example 2 with IGrammarConstraintProvider

use of org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider in project xtext-core by eclipse.

the class GrammarConstraintProviderAssignedActionTest method testXtext.

@Test
public void testXtext() {
    IGrammarConstraintProvider gcp = get(IGrammarConstraintProvider.class);
    Grammar grammar = getGrammarAccess().getGrammar();
    // try {
    // new ActionFilter2Dot().draw(getGrammarAccess().getGrammar(),
    // getName() + ".pdf", "-T pdf");
    // } catch (IOException e) {
    // if (log.isDebugEnabled())
    // log.debug(e.getMessage(), e);
    // }
    // SerializationContextMap<IConstraint> constraints =
    gcp.getConstraints(grammar);
// List<String> result = Lists.newArrayList();
// Set<IConstraint> visited = Sets.newHashSet();
// for (Entry<ISerializationContext, IConstraint> r :
// constraints.entrySet()) {
// ISerializationContext context = r.getKey();
// IConstraint constraint = r.getValue();
// result.add(context.toString());
// if (visited.add(constraint))
// result.add(" " + constraint.toString());
// }
// System.out.println(Joiner.on("\n").join(result));
}
Also used : IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) Grammar(org.eclipse.xtext.Grammar) Test(org.junit.Test)

Example 3 with IGrammarConstraintProvider

use of org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider in project xtext-core by eclipse.

the class GrammarConstraintProviderTest method getParserRule.

private String getParserRule(String body) throws Exception {
    Grammar grammar = (Grammar) getModel(HEADER + body);
    IGrammarConstraintProvider gcp = get(IGrammarConstraintProvider.class);
    SerializationContextMap<IConstraint> constraints = gcp.getConstraints(grammar);
    List<String> result = Lists.newArrayList();
    for (Entry<IConstraint> r : constraints.sortedCopy().values()) {
        result.add(Joiner.on(", ").join(r.getContexts()) + ":");
        result.add("  " + r.getValue());
    }
    return Joiner.on("\n").join(result);
}
Also used : IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) IConstraint(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint) Grammar(org.eclipse.xtext.Grammar)

Aggregations

Grammar (org.eclipse.xtext.Grammar)3 IGrammarConstraintProvider (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider)3 IConstraint (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint)2 SerializationContextMap (org.eclipse.xtext.serializer.analysis.SerializationContextMap)1 Test (org.junit.Test)1