Ejemplo n.º 1
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.º 2
0
 def test_fill_one_class_with_one_property_should_succeed(self):
     tree = self.parse('''
         class A {
             public int a;
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(errors, empty())
     assert_that(classifiers, equal_to({
         'A': Class('A', properties=[
             Property('a', INT_TYPE, Visibility.PUBLIC, is_static=False)
         ]),
         'int': INT_TYPE.classifier,
     }))
 def visit_VariableDeclarator(self, declaration):
     classifier = self.__current_classifier()
     if classifier.has_property(declaration.variable.name):
         self.errors.append(
             VariableRedeclaration(classifier, declaration.variable))
         return False
     if self.__field:
         classifier.properties.append(
             Property(
                 type=self.__get_classifier_type(
                     VariableType(self.__field, declaration.variable)),
                 name=declaration.variable.name,
                 visibility=get_visibility(self.__field),
                 is_static='static' in self.__field.modifiers,
                 owner=classifier,
             ))
         return True
Ejemplo n.º 4
0
 def test_fill_one_class_with_two_same_property_should_return_error(self):
     tree = self.parse('''
         class A {
             public int a;
             public float a;
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(len(errors), equal_to(1))
     assert_that(str(errors[0]), equal_to(
         'error: redeclaration of variable "a" in class "A"'))
     assert_that(classifiers, equal_to({
         'A': Class('A', properties=[
             Property('a', INT_TYPE, Visibility.PUBLIC, is_static=False),
         ]),
         'int': INT_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())
 def decorator_component(self):
     return Property('component', self.component_type(), is_static=False)
 def abstraction_implementor(self):
     return Property('implementor',
                     self.implementor_type(),
                     is_static=False)
Ejemplo n.º 8
0
 def handler_next(self):
     return Property('next', self.handler_type(), is_static=False)
 def decorator_component(self):
     return Property('component',
                     self.component_type(),
                     Visibility.PUBLIC,
                     is_static=False)
 def concrete_adapter_adaptee(self):
     return Property('adaptee',
                     self.adaptee_type(),
                     Visibility.PRIVATE,
                     is_static=False)
 def caretaker_memento(self):
     return Property('memento', self.memento_type(), Visibility.PUBLIC,
                     is_static=False)