Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 984 and 992 #1006

Merged
merged 8 commits into from Feb 27, 2017
38 changes: 26 additions & 12 deletions cruise.umple/src/UmpleInternalParser_CodeClass.ump
Expand Up @@ -1567,9 +1567,7 @@ private Boolean checkIsDistributed(UmpleInterface uInterface)
}
}
for(UmpleClass uClass: getModel().getUmpleClasses()) {
for (UmpleInterface uInterface : getAllParentInterface(uClass)) {
addImplementedMethodsFromInterface(uInterface, uClass);
}
addImplementedMethodsFromInterface(getAllParentInterface(uClass), uClass);
}
}

Expand All @@ -1593,20 +1591,36 @@ private Boolean checkIsDistributed(UmpleInterface uInterface)
return temp;
}

private void addImplementedMethodsFromInterface(UmpleInterface parentInterface, UmpleClass uClass)
private void addImplementedMethodsFromInterface(List<UmpleInterface> parentInterfaces, UmpleClass uClass)
{
//GET AND SET METHODS CHECK?
if (parentInterface.hasMethods())
// Fix issue 992
List<UmpleInterface> ancestorInterfaces = new Vector<UmpleInterface>();
Stack<UmpleInterface> toProcess = new Stack<UmpleInterface>();
toProcess.addAll(parentInterfaces);
ancestorInterfaces.addAll(parentInterfaces);

while(!toProcess.isEmpty())
{
for (Method aMethod : parentInterface.getMethods())
parentInterfaces = toProcess.pop().getExtendsInterface();
toProcess.addAll(parentInterfaces);
ancestorInterfaces.addAll(parentInterfaces);
}

for (UmpleInterface pi : ancestorInterfaces)
{
if (pi.hasMethods())
{
boolean shouldAddMethod = verifyIfMethodIsConstructorOrGetSet(uClass, aMethod, true);
if (!(uClass.hasImplementedMethodIncludingWithinParentClasses(aMethod))
&& !(uClass.hasMethodInTraits(aMethod)) && !(uClass.isIsAbstract()) && shouldAddMethod)
for (Method aMethod : pi.getMethods())
{
aMethod.setIsImplemented("".equals(aMethod.getMethodBody().getExtraCode("")));
aMethod.setSource(Method.Source.fAuto);
uClass.addMethod(aMethod);
boolean shouldAddMethod = verifyIfMethodIsConstructorOrGetSet(uClass, aMethod, true);
if (!(uClass.hasImplementedMethodIncludingWithinParentClasses(aMethod))
&& !(uClass.hasMethodInTraits(aMethod)) && !(uClass.isIsAbstract()) && shouldAddMethod)
{
aMethod.setIsImplemented("".equals(aMethod.getMethodBody().getExtraCode("")));
aMethod.setSource(Method.Source.fAuto);
uClass.addMethod(aMethod);
}
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions cruise.umple/src/util/SampleFileWriter_Code.ump
Expand Up @@ -180,18 +180,23 @@ class SampleFileWriter
String actualLine = null;

int line = 0;
do
do
{
actualLine = actualReader.readLine();
expectedLine = expectedReader.readLine();
if (ignoreLineComments)
{
// HACK: To deal with // line # comments
while (actualLine != null && actualLine.indexOf("// line") != -1)
{ //Ignore the line, go to next
actualLine = actualReader.readLine();
}
}
expectedLine = expectedReader.readLine();

while (expectedLine != null && expectedLine.indexOf("// line") != -1)
{
expectedLine = expectedReader.readLine();
}
}

line++;

Expand All @@ -202,6 +207,11 @@ class SampleFileWriter
}
}
while (expectedLine != null && actualLine != null);

if(expectedLine == null && line == 1)
{
Assert.fail(("Expected output file is empty."));
}
}
catch (Exception e)
{
Expand Down
Expand Up @@ -40,4 +40,8 @@ interface IFirstChild{

interface ISecondChild{
isA ISomething, IGarbage;
}

class A{
isA ISecondChild;
}
@@ -0,0 +1,51 @@
namespace example;

interface ISomething
{
constant String aVariable = aValue;
constant Integer MAX = 3;

String getCode (String[] aParam, Integer anotherParam);
String isValid();
}

interface IGarbage
{
}

interface ICodeTranslator
{
String translate(String id, Attribute attribute);
String translate(String id, AssociationVariable associationVariable);
}

class CodeTranslator
{
isA ICodeTranslator;
}

class Something
{
isA ISomething;
}

class Garbage
{
isA ISomething, IGarbage;
}

interface IFirstChild{
isA ISomething;
}

interface ISecondChild{
isA ISomething, IGarbage;
}

class A{
isA ISecondChild;
}

class B{
isA A;
}
@@ -0,0 +1,16 @@
namespace example;

interface I{
void test();
}
interface I2{
isA I;
void test2();
}
interface I3{
isA I2;
void test3();
}
class A{
isA I3;
}
Expand Up @@ -47,14 +47,7 @@ public void tearDown()
SampleFileWriter.destroy(pathToInput + "/alloy/ExampleFile.als");
SampleFileWriter.destroy(pathToInput + "/alloy/BankingSystem.als");
}

@Test //@Ignore
public void ExampleFile()
{
assertUmpleTemplateFor("alloy/ExampleFile.ump","alloy/ExampleFile.alloy.txt");
Assert.assertEquals(true, (new File(pathToInput + "/alloy/ExampleFile.als")).exists());
}


@Test //@Ignore
public void BankingSystem()
{
Expand Down