Skip to content

Commit

Permalink
Fixed methods in Abstract class from Interface.
Browse files Browse the repository at this point in the history
Resolved an issue where Umple was incorrectly generating default implementation of an interface's methods in abstract child classes. In the old behaviour, a class would always be forced to implement the methods from an interface. In the new behaviour, abstract methods will not implement the methods, and instead Umple will search for unimplemented methods for both the current class' parent interfaces and the whole chain of superclasses.

Fixes umple#608

Signed-off-by: Victoria Lacroix <[email protected]>
  • Loading branch information
vtrlx committed Jan 16, 2016
1 parent 3f79521 commit d9524e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
29 changes: 25 additions & 4 deletions cruise.umple/src/UmpleInternalParser_CodeClass.ump
Original file line number Diff line number Diff line change
Expand Up @@ -1304,12 +1304,32 @@ class UmpleInternalParser
}
}
for(UmpleClass uClass: getModel().getUmpleClasses()) {
for (UmpleInterface uInterface : uClass.getParentInterface()) {
addImplementedMethodsFromInterface(uInterface, uClass);
}
for (UmpleInterface uInterface : getAllParentInterface(uClass)) {
addImplementedMethodsFromInterface(uInterface, uClass);
}
}
}

private java.util.List<UmpleInterface> getAllParentInterface(UmpleClass uClass){

java.util.ArrayList<UmpleInterface> temp = new java.util.ArrayList<UmpleInterface>(uClass.getParentInterface());
java.util.ArrayList<UmpleClass> uClassChain = new java.util.ArrayList<UmpleClass>();

for (UmpleClass uClassCurrent = uClass; uClassCurrent != null && !uClassChain.contains(uClassCurrent); uClassCurrent = uClassCurrent.getExtendsClass())
{
uClassChain.add(uClassCurrent);
for (UmpleInterface uInterface : uClassCurrent.getParentInterface())
{
if (!temp.contains(uInterface))
{
temp.add(uInterface);
}
}
}

return temp;
}

private void addImplementedMethodsFromInterface(UmpleInterface parentInterface, UmpleClass uClass)
{
//GET AND SET METHODS CHECK?
Expand All @@ -1318,7 +1338,8 @@ class UmpleInternalParser
for (Method aMethod : parentInterface.getMethods())
{
boolean shouldAddMethod = verifyIfMethodIsConstructorOrGetSet(uClass, aMethod);
if (!(uClass.hasImplementedMethodIncludingWithinParentClasses(aMethod)) && !(uClass.hasMethodInTraits(aMethod)) && shouldAddMethod)
if (!(uClass.hasImplementedMethodIncludingWithinParentClasses(aMethod))
&& !(uClass.hasMethodInTraits(aMethod)) && !(uClass.isIsAbstract()) && shouldAddMethod)
{
aMethod.setIsImplemented("".equals(aMethod.getMethodBody().getExtraCode("")));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
interface I {
Integer I1();
}

class A {
isA I;
}

class B {
isA A;
}

class C {
abstract;
isA I;
}

class D {
isA C;
}
15 changes: 15 additions & 0 deletions cruise.umple/test/cruise/umple/compiler/UmpleParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,21 @@ public void abstractInheritanceClass()
Assert.assertEquals(false,model.getUmpleClass("E").getIsAbstract());
}

@Test
public void abstractInterfaceExtends()
{
assertSimpleParse("423_interfaceInheritanceAbstract.ump");

Assert.assertEquals(1,model.getUmpleInterface("I").numberOfMethods());
Assert.assertEquals("I1",model.getUmpleInterface("I").getMethod(0).getName());
Assert.assertEquals(1,model.getUmpleClass("A").numberOfMethods());
Assert.assertEquals("I1",model.getUmpleClass("A").getMethod(0).getName());
Assert.assertEquals(0,model.getUmpleClass("B").numberOfMethods());
Assert.assertEquals(0,model.getUmpleClass("C").numberOfMethods());
Assert.assertEquals(1,model.getUmpleClass("D").numberOfMethods());
Assert.assertEquals("I1",model.getUmpleClass("D").getMethod(0).getName());
}

@Test
public void immutableClass()
{
Expand Down

0 comments on commit d9524e3

Please sign in to comment.