use of edu.uah.rsesc.aadlsimulator.xtext.TestReferenceTypeResolver in project AGREE by loonwerks.
the class InputConstraintDialog method main.
public static void main(final String[] args) {
new Display();
final com.google.inject.Injector injector = new InputConstraintStandaloneSetup().createInjectorAndDoEMFRegistration();
final InputConstraintHelper icHelper = injector.getInstance(InputConstraintHelper.class);
final TestReferenceTypeResolver resolver = new TestReferenceTypeResolver();
// Create model to provide information to the dialog.
final Model model = new Model() {
@Override
public String unparse(final InputConstraint ic) {
return icHelper.unparse(ic);
}
@Override
public InputConstraintHelper.Result parseAndValidate(final String str, final ResultType expectedType, final int numberOfPreviousSteps) {
return icHelper.parseAndValidate(str, resolver, expectedType, numberOfPreviousSteps);
}
@Override
public InputConstraintHelper.Result validate(final InputConstraint ic, final ResultType expectedType, final int numberOfPreviousSteps) {
return icHelper.validate(ic, resolver, expectedType, numberOfPreviousSteps);
}
@Override
public Stream<ElementRefExpression> getVariables() {
final Stream.Builder<ElementRefExpression> builder = Stream.builder();
builder.add(createElementRefExpression("a1", "b", "d"));
builder.add(createElementRefExpression("a1"));
builder.add(createElementRefExpression("a1", "b"));
builder.add(createElementRefExpression("a1", "b", "c"));
builder.add(createElementRefExpression("a2", "b"));
builder.add(createElementRefExpression("a2"));
return builder.build();
}
private ElementRefExpression createElementRefExpression(String... ids) {
final ElementRefExpression result = InputConstraintFactory.eINSTANCE.createElementRefExpression();
result.getIds().addAll(Arrays.asList(ids));
return result;
}
@Override
public ResultType getElementReferenceType(final ElementRefExpression reference) {
return resolver.getElementReferenceType(reference);
}
@Override
public Stream<ConstRefExpression> getConstants() {
final Stream.Builder<ConstRefExpression> builder = Stream.builder();
builder.add(createConstRefExpression("C1", "my_pkg"));
builder.add(createConstRefExpression("C2", "my_pkg", "inner_pkg"));
builder.add(createConstRefExpression("C3A", "my_pkg", "inner_pkg", "inner_inner_pkg"));
builder.add(createConstRefExpression("C3B", "my_pkg", "inner_pkg", "inner_inner_pkg"));
builder.add(createConstRefExpression("C3C", "my_pkg", "inner_pkg", "inner_inner_pkg"));
builder.add(createConstRefExpression("C3D", "my_pkg", "inner_pkg", "inner_inner_pkg"));
return builder.build();
}
private ConstRefExpression createConstRefExpression(final String constantName, final String... packageSegments) {
final ConstRefExpression result = InputConstraintFactory.eINSTANCE.createConstRefExpression();
result.setConstantName(constantName);
result.getPackageSegments().addAll(Arrays.asList(packageSegments));
return result;
}
@Override
public ResultType getConstReferenceType(final ConstRefExpression reference) {
return resolver.getConstReferenceType(reference);
}
};
// Show the dialog
final InputConstraint initialConstraint = icHelper.parse("5 + 5").getInputConstraint();
final Result result = InputConstraintDialog.show(null, model, "z", initialConstraint, ResultType.INTEGER, 1);
if (result == null) {
System.out.println("Dialog canceled");
} else {
System.out.println("Result:");
System.out.println(result.inputConstraint);
}
}
Aggregations