Skip to content

Commit

Permalink
Merge pull request umple#866 from umple/issue841
Browse files Browse the repository at this point in the history
Fix for issue umple#841. Singleton class should not have any subclasses.
  • Loading branch information
TimLethbridge authored Jun 28, 2016
2 parents 87f7fac + 81d0bd0 commit 94b3744
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 2 deletions.
21 changes: 21 additions & 0 deletions build/reference/9040SingletonHasSubclass.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
E040 Singleton Has Subclasses
Errors and Warnings
noreferences

@@description

<h2>Umple semantic error generated when a singleton class has subclasses</h2>

<p>Singleton is a software pattern to allow only one instance of a class. A singleton class has a private constructor and cannot be inherited.</p>

<p>
</p>

@@example
@@source manualexamples/E040_singleton_inherited.ump
@@endexample

@@example
@@source manualexamples/E040_singleton_inheritedFix.ump
@@endexample

15 changes: 15 additions & 0 deletions cruise.umple/src/UmpleInternalParser_CodeClass.ump
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,21 @@ class UmpleInternalParser

//Issue 686
checkCodeInjections();
//issue 841
checkSingletonParent();
}
}

//Issue 841
private void checkSingletonParent()
{
for (UmpleClass uClass: model.getUmpleClasses())
{
if(uClass.getExtendsClass()!=null) {
if(uClass.getExtendsClass().getIsSingleton()) {
getParseResult().addErrorMessage(new ErrorMessage(40,uClass.getPosition(0),uClass.getName(),uClass.getExtendsClass().getName()));
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion cruise.umple/src/en.error
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
37: 2, "http://cruise.eecs.uottawa.ca/umple/E037UninitializedConstantObject.html", 'const' variable '{0}' of type '{1}' was not initialized. Since '{1}' is not a built-in Umple data type no default value could be found. '{0}' must be initialized. ;
38: 2, "http://cruise.eecs.uottawa.ca/umple/W9999FeatureUnderDevelopment.html", Attribute '{0}' has a name conflict with attribute auto generated by '{1}' variable '{2}';
39: 3, "http://cruise.eecs.uottawa.ca/umple/W033MissingSuperclass.html", The interface {0} extends from an interface {1} that does not exist and has been ignored. Declare {1} to be external if it is defined outside this Umple system ;

40: 2, "http://cruise.eecs.uottawa.ca/umple/E040SingletonHasSubclasses.html", Singleton class has private constructor and cannot be extended. So class {0} cannot be a subclass of singleton class {1}.;
44: 3, "http://cruise.eecs.uottawa.ca/umple/W044AttributeDuplicatedinSuperclass.html", Class '{0}' has attribute name {1} that duplicates an attribute inherited from a superclass '{2}'. New definition is being disconsidered.;
45: 4, "http://cruise.eecs.uottawa.ca/umple/W045InitializedValueinKey.html", Attribute '{0}' in class '{1}' is in the key. Initializing it will result in all instances having this same value and being treated as equal ;
46: 4, "http://cruise.eecs.uottawa.ca/umple/W046AttributeHasTemplateType.html", Attribute {0} in class {1} is declared using a collection template type {2}. Use a directed association (->) or multi-valued attribute([]) to follow proper modelling conventions ;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

class Airplane
{
singleton;
}
class F16
{
isA Airplane;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

class FlyingObject
{

}
class Airplane
{
isA FlyingObject;
singleton;
}

class Fighters
{
class F16
{
isA Airplane;
}
}
7 changes: 6 additions & 1 deletion cruise.umple/test/cruise/umple/compiler/UmpleParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,12 @@ public void multiple_Class_Inheritance()
{
assertFailedParse("007_isA_MultipleInher.ump", 34);
}

@Test
public void Singleton_Class_Extended()
{
assertFailedParse("007_singleton_extended.ump", 40);
assertFailedParse("007_singleton_extended2.ump", 40);
}
@Test
public void singleIsA_MultipleClass_Inheritance()
{
Expand Down
10 changes: 10 additions & 0 deletions umpleonline/ump/manualexamples/E040_singleton_inherited.ump
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

// In this example a singleton class has subclasses and it generates an error
class Airplane
{
singleton;
}
class F16
{
isA Airplane;
}
14 changes: 14 additions & 0 deletions umpleonline/ump/manualexamples/E040_singleton_inheritedFix.ump
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

//I this example the singleton class does not have a subclass and is correct
class Airplane
{

}
class TheAirplane
{
singleton;
}
class F16
{
isA Airplane;
}

0 comments on commit 94b3744

Please sign in to comment.