Ejemplo n.º 1
0
 def test_make_primitive_should_succeed(self):
     variable_decl = VariableDeclarator(Variable(''))
     field = FieldDeclaration('int', [variable_decl])
     variable_type = VariableType(field, variable_decl.variable)
     assert_that(variable_type.type(None), equal_to(Type()))
     assert_that(variable_type.type_name(), equal_to('int'))
     assert_that(variable_type.classifier_name(), equal_to('int'))
 def __init__(self, classifiers):
     super(ClassifiersMembersFactory, self).__init__()
     self.errors = []
     self.classifiers = classifiers
     self.__classifiers_chain = []
     self.__visited_classifiers = set()
     self.types = dict((c.name, Type(c)) for c in classifiers.values())
Ejemplo n.º 3
0
 def test_make_array_should_succeed(self):
     variable_decl = VariableDeclarator(Variable('', dimensions=1))
     field = FieldDeclaration(PlyjType('A', dimensions=1), [variable_decl])
     variable_type = VariableType(field, variable_decl.variable)
     classifier = Class('A')
     assert_that(variable_type.type(classifier),
                 equal_to(Type(classifier, lower=0, upper=None)))
     assert_that(variable_type.type_name(), equal_to('A[][]'))
     assert_that(variable_type.classifier_name(), equal_to('A'))
Ejemplo n.º 4
0
 def test_fill_recursive_class_should_succeed(self):
     tree = self.parse('''
         class A {
             public A a;
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(errors, empty())
     a_type = Type(Class('A'))
     a_type.classifier.properties = [
         Property('a', a_type, Visibility.PUBLIC, is_static=False),
     ]
     assert_that(classifiers, equal_to({'A': a_type.classifier}))
Ejemplo n.º 5
0
 def test_fill_class_with_field_instance_creation_item_should_succeed(self):
     tree = self.parse('''
         class Class {
             Class value = new Class() {
                 @Override
                 public void f() {};
             };
             public abstract void f();
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     _, errors = fill_classifiers(tree, classifiers)
     class_type = Type(Class('Class', operations=[
         Operation('f', VOID_TYPE, Visibility.PUBLIC, is_static=False),
     ]))
     class_type.classifier.properties = [
         Property('value', class_type, Visibility.PRIVATE, is_static=False)]
     assert_that(classifiers, equal_to({
         'Class': class_type.classifier,
         'void': VOID_TYPE.classifier,
     }))
     assert_that(errors, empty())
Ejemplo n.º 6
0
 def handler_type(self):
     return Type(self.handler())
class Decorator(BaseDecorator, PrimitiveTypes):
    VOID = Type(PrimitiveType('void'))

    @cached_method
    def component(self):
        return Interface('Component',
                         operations=[
                             Operation('operation',
                                       self.VOID,
                                       Visibility.PUBLIC,
                                       is_static=False)
                         ])

    @cached_method
    def component_type(self):
        return Type(self.component())

    @cached_method
    def concrete_component(self):
        return Class('ConcreteComponent',
                     operations=[
                         Operation('operation',
                                   self.VOID,
                                   Visibility.PUBLIC,
                                   is_static=False),
                     ])

    @cached_method
    def decorator_component(self):
        return Property('component',
                        self.component_type(),
                        Visibility.PUBLIC,
                        is_static=False)

    @cached_method
    def decorator(self):
        return Interface('Decorator',
                         properties=[
                             self.decorator_component(),
                         ],
                         operations=[
                             Operation('operation',
                                       self.VOID,
                                       Visibility.PUBLIC,
                                       is_static=False),
                         ])

    @cached_method
    def concrete_decorator(self):
        return Class('ConcreteDecorator',
                     operations=[
                         Operation('operation',
                                   self.VOID,
                                   Visibility.PUBLIC,
                                   is_static=False),
                     ])

    @cached_method
    def create(self):
        base = super(Decorator, self).create()
        return Model(list(base.classifiers) + self.primitive_classifiers())
 def get_type(this):
     return Type(getattr(this, name)(this))
 def adaptee_type(self):
     return Type(self.adaptee())
Ejemplo n.º 10
0
 def abstract_product_type(self):
     return Type(self.abstract_product())
Ejemplo n.º 11
0
        assert_that(variable_type.type(None), equal_to(Type()))
        assert_that(variable_type.type_name(), equal_to('int'))
        assert_that(variable_type.classifier_name(), equal_to('int'))

    def test_make_array_should_succeed(self):
        variable_decl = VariableDeclarator(Variable('', dimensions=1))
        field = FieldDeclaration(PlyjType('A', dimensions=1), [variable_decl])
        variable_type = VariableType(field, variable_decl.variable)
        classifier = Class('A')
        assert_that(variable_type.type(classifier),
                    equal_to(Type(classifier, lower=0, upper=None)))
        assert_that(variable_type.type_name(), equal_to('A[][]'))
        assert_that(variable_type.classifier_name(), equal_to('A'))


VOID_TYPE = Type(PrimitiveType('void'))
INT_TYPE = Type(PrimitiveType('int'))
FLOAT_TYPE = Type(PrimitiveType('float'))


class FillClassifiers(TestCaseWithParser):
    def test_fill_empty_should_succeed(self):
        assert_that(fill_classifiers(self.parse(''), {}), equal_to(({}, [])))

    def test_fill_one_class_with_one_property_should_succeed(self):
        tree = self.parse('''
            class A {
                public int a;
            }
        ''')
        classifiers, errors = make_classifiers(tree)
 def component_type(self):
     return Type(self.component())
 def concrete_element_type(self):
     return Type(self.concrete_element())
 def visitor_type(self):
     return Type(self.visitor())
 def abstraction_type(self):
     return Type(self.abstraction())
 def type(self, classifier):
     lower, upper = ((0, None) if get_dimensions(self.method.return_type) +
                     self.method.extended_dims else (1, 1))
     return Type(classifier, lower, upper)
 def implementor_type(self):
     return Type(self.implementor())
 def type(self, classifier):
     lower, upper = ((0, None) if get_dimensions(self.parameter.type) +
                     self.parameter.variable.dimensions else (1, 1))
     return Type(classifier, lower, upper)
 def decorator_type(self):
     return Type(self.decorator())
 def memento_type(self):
     return Type(self.memento())