Search in sources :

Example 1 with TestReferenceTypeResolver

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);
    }
}
Also used : ConstRefExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ConstRefExpression) InputConstraintHelper(edu.uah.rsesc.aadlsimulator.xtext.util.InputConstraintHelper) ResultType(edu.uah.rsesc.aadlsimulator.xtext.util.ResultType) TestReferenceTypeResolver(edu.uah.rsesc.aadlsimulator.xtext.TestReferenceTypeResolver) Stream(java.util.stream.Stream) InputConstraintStandaloneSetup(edu.uah.rsesc.aadlsimulator.xtext.InputConstraintStandaloneSetup) InputConstraint(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.InputConstraint) Display(org.eclipse.swt.widgets.Display) ElementRefExpression(edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ElementRefExpression)

Aggregations

InputConstraintStandaloneSetup (edu.uah.rsesc.aadlsimulator.xtext.InputConstraintStandaloneSetup)1 TestReferenceTypeResolver (edu.uah.rsesc.aadlsimulator.xtext.TestReferenceTypeResolver)1 ConstRefExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ConstRefExpression)1 ElementRefExpression (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.ElementRefExpression)1 InputConstraint (edu.uah.rsesc.aadlsimulator.xtext.inputConstraint.InputConstraint)1 InputConstraintHelper (edu.uah.rsesc.aadlsimulator.xtext.util.InputConstraintHelper)1 ResultType (edu.uah.rsesc.aadlsimulator.xtext.util.ResultType)1 Stream (java.util.stream.Stream)1 Display (org.eclipse.swt.widgets.Display)1