def concrete_component(self): return Class('ConcreteComponent', operations=[ Operation('operation', self.VOID, Visibility.PUBLIC, is_static=False), ])
def component(self): return Interface('Component', operations=[ Operation('operation', self.VOID, Visibility.PUBLIC, is_static=False) ])
def concrete_decorator(self): return Class('ConcreteDecorator', operations=[ Operation('operation', self.VOID, Visibility.PUBLIC, is_static=False), ])
def decorator(self): return Interface('Decorator', properties=[ self.decorator_component(), ], operations=[ Operation('operation', self.VOID, Visibility.PUBLIC, is_static=False), ])
def test_fill_class_with_overriding_method_in_object_should_succeed(self): tree = self.parse(''' class A { void g(); void f() { new A() { public void h(); }; } } ''') 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', operations=[ Operation('f', VOID_TYPE, Visibility.PRIVATE, is_static=False), Operation('g', VOID_TYPE, Visibility.PRIVATE, is_static=False), ]), 'void': VOID_TYPE.classifier, }))
def test_fill_one_class_with_local_class_should_succeed(self): tree = self.parse(''' class A { void f() { class B extends A { void g(); } } } ''') 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', operations=[ Operation('f', VOID_TYPE, Visibility.PRIVATE, is_static=False), ]), 'B': Class('B', operations=[ Operation('g', VOID_TYPE, Visibility.PRIVATE, is_static=False), ]), 'void': VOID_TYPE.classifier, }))
def test_fill_one_class_with_two_overloaded_operations_should_succeed(self): tree = self.parse(''' class A { void f(int x); void f(float x); } ''') 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', operations=[ Operation('f', VOID_TYPE, Visibility.PRIVATE, [Parameter('x', INT_TYPE, Direction.IN)], is_static=False), Operation('f', VOID_TYPE, Visibility.PRIVATE, [Parameter('x', FLOAT_TYPE, Direction.IN)], is_static=False), ]), 'void': VOID_TYPE.classifier, 'int': INT_TYPE.classifier, 'float': FLOAT_TYPE.classifier, }))
def test_fill_enum_with_overriding_in_item_should_succeed(self): tree = self.parse(''' enum Enum { Item { @Override public void f() {} }; public abstract void f(); } ''') classifiers, errors = make_classifiers(tree) _, errors = fill_classifiers(tree, classifiers) assert_that(classifiers, equal_to({ 'Enum': Class('Enum', operations=[ Operation('f', VOID_TYPE, Visibility.PUBLIC, is_static=False), ]), 'void': VOID_TYPE.classifier, })) assert_that(errors, empty())
def visit_MethodDeclaration(self, declaration): if self.__current_operation(): return False classifier = self.__current_classifier() if has_duplications(declaration.modifiers): self.errors.append( MethodModifiersDuplication(classifier, declaration)) return False self.__set_operation( Operation( name=declaration.name, visibility=get_visibility(declaration), result=self.__get_classifier_type( MethodReturnType(declaration)), parameters=[], is_static='static' in declaration.modifiers, owner=classifier, )) return True
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 test_fill_one_class_with_two_same_operations_should_return_error(self): tree = self.parse(''' class A { void f(int x); void f(int x); } ''') 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 method "-A::f(in x: int): void" in class ' '"A"') ) assert_that(classifiers, equal_to({ 'A': Class('A', operations=[ Operation('f', VOID_TYPE, Visibility.PRIVATE, [Parameter('x', INT_TYPE, Direction.IN)], is_static=False), ]), 'void': VOID_TYPE.classifier, 'int': INT_TYPE.classifier, }))
def _create(self): return Operation('create', self.abstract_product_type(), Visibility.PUBLIC, is_static=False)
def _visit(): return Operation('visit', visibility=Visibility.PUBLIC)
def concrete_adapter_operation(self): return Operation('operation', visibility=Visibility.PUBLIC, is_static=False)
def adaptee_adapted_operation(self): return Operation('adapted_operation', visibility=Visibility.PUBLIC, is_static=False)
def operation(): return Operation('operation')
def originator_create_memento(self): return Operation('create_memento', self.memento_type(), visibility=Visibility.PUBLIC, is_static=False)
def concrete_implementor_operation_impl(self): return Operation('operation_impl', visibility=Visibility.PUBLIC, is_static=False)
def handle_request(): return Operation('handle_request', visibility=Visibility.PUBLIC, is_static=False)
def _accept(): return Operation('accept', visibility=Visibility.PUBLIC)
def abstraction_operation(self): return Operation('operation', visibility=Visibility.PUBLIC, is_static=False)
def client_invoke_operation(self): return Operation('invoke_operation', invocations=[self.interface_operation()])
def _operation(): return Operation('operation', visibility=Visibility.PUBLIC, is_static=False)
def originator_set_memento(self): return Operation( 'set_memento', visibility=Visibility.PUBLIC, parameters=[ Parameter('memento', self.memento_type(), Direction.IN) ], is_static=False)