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

Issue410 #685

Merged
merged 6 commits into from Jan 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions cruise.umple/src/UmpleInternalParser_CodeClass.ump
Expand Up @@ -2554,11 +2554,47 @@ class UmpleInternalParser
makeCodeInject(injectToken,injection,cb,uClassifier);
injection.setSnippet(cb);
if (uClassifier instanceof UmpleClass) {
checkCodeInjectionValidity(injectToken, operationName.toString(), uClassifier);
((UmpleClass)uClassifier).addCodeInjection(injection);
} else if (uClassifier instanceof UmpleTrait){
((UmpleTrait)uClassifier).addCodeInjection(injection);
}
}

private boolean checkCodeInjectionValidity(Token injectToken, String operationName, UmpleClassifier uClassifier) {
for(String operation : operationName.split(","))
{
Boolean matches = false;
UmpleClass uClass = (UmpleClass) uClassifier;

ArrayList<String> methodNames = new ArrayList<String>();
for(Method aMethod : uClass.getMethods())
{
methodNames.add(aMethod.getName());
}

for(Attribute attr : uClass.getAttributes())
{
methodNames.addAll(attr.getMethodNames());
}

methodNames.add(uClass.getName());
methodNames.add("delete");

for(String methodName : methodNames)
{
if (uClass.matchOperationMethod(operation, methodName)) {
matches = true;
}
}

if(!matches) {
getParseResult().addErrorMessage(new ErrorMessage(1012, injectToken.getPosition(), operation));
}
}

return false;
}

//TODO I changed the parameter's type. please remove this comment;
private void makeCodeInject(Token injectToken,CodeInjection injection, CodeBlock cb, UmpleClassifier uClassifier)
Expand Down
90 changes: 70 additions & 20 deletions cruise.umple/src/UmpleInternalParser_CodeTrait_StateMachine.ump
Expand Up @@ -31,9 +31,10 @@ class UmpleInternalParser
tempTraiStateMachine = gatherStateMachinesFromTrait(uTrait,inClass.getGeneralTPAppliedByName(uTrait.getName()),inClass);
CheckSMFromTraitIsNotAvaialbleInOtherTraits(traiStateMachine, tempTraiStateMachine, inClass);
if ( ! getParseResult().getWasSuccess() ) return;
if (!CheckSMFromTraitIsNotAvaialbleInClass(inClass,tempTraiStateMachine)) return;

AddStateMachineMapToAnother(traiStateMachine,tempTraiStateMachine);
}
if (!CheckSMFromTraitIsNotAvaialbleInClass(inClass,traiStateMachine)) return;
for (UmpleTrait t1 : traiStateMachine.keySet()) {
if (traiStateMachine.get(t1)!=null){
for (StateMachine sMachine : traiStateMachine.get(t1)) {
Expand Down Expand Up @@ -200,14 +201,8 @@ class UmpleInternalParser
}else {
if (cSMachine.getName().equals(tSMachine.getName())){
if (!cSMachine.getStartState().getName().equals(tSMachine.getStartState().getName())){
StateMachine newStateMachine = new StateMachine(cSMachine.getName());
newStateMachine.addState(cSMachine.getName());
newStateMachine.getState(0).setIsStartState(true);
cSMachine.setName(cSMachine.getStartState().getName());
newStateMachine.getState(0).addNestedStateMachine(cSMachine);
tSMachine.setName(tSMachine.getStartState().getName());
newStateMachine.getState(0).addNestedStateMachine(tSMachine);
listBeRemoved.put(newStateMachine,cSMachine.getName());
StateMachine checkSM = mergeTwoStateMachineWithTheSameNameDifferentInitialState(cSMachine,tSMachine);
if (checkSM!=null) listBeRemoved.put(checkSM,cSMachine.getName());
tListBeRemoved.add(tSMachine);
} else {
addExtraStatesAndTransitions(cSMachine, tSMachine);
Expand Down Expand Up @@ -260,14 +255,8 @@ class UmpleInternalParser
} else {
if (sMachine.getName().equals(tSMachine.getName())){
if (!sMachine.getStartState().getName().equals(tSMachine.getStartState().getName())){
StateMachine newStateMachine = new StateMachine(sMachine.getName());
newStateMachine.addState(sMachine.getName());
newStateMachine.getState(0).setIsStartState(true);
sMachine.setName(sMachine.getStartState().getName());
newStateMachine.getState(0).addNestedStateMachine(sMachine);
tSMachine.setName(tSMachine.getStartState().getName());
newStateMachine.getState(0).addNestedStateMachine(tSMachine);
listBeRemoved.put(newStateMachine,sMachine);
StateMachine checkSM = mergeTwoStateMachineWithTheSameNameDifferentInitialState(sMachine,tSMachine);
if (checkSM!=null) listBeRemoved.put(checkSM,sMachine);
mustBeRemoved.add(tSMachine);
} else {
addExtraStatesAndTransitions(sMachine, tSMachine);
Expand All @@ -288,7 +277,28 @@ class UmpleInternalParser
}
return true;
}

//---------------------------------end----------------------------------------
//----------------------------------------------------------------------------
//---------------------------------Start--------------------------------------
private StateMachine mergeTwoStateMachineWithTheSameNameDifferentInitialState(StateMachine inSMachine1, StateMachine inSMachine2) {
StateMachine newStateMachine = new StateMachine(inSMachine1.getName());
if (inSMachine1.getParentState()==null)
{
newStateMachine.addState(inSMachine1.getName());
newStateMachine.getState(0).setIsStartState(true);
inSMachine1.setName(inSMachine1.getStartState().getName());
newStateMachine.getState(0).addNestedStateMachine(inSMachine1);
inSMachine2.setName(inSMachine2.getStartState().getName());
newStateMachine.getState(0).addNestedStateMachine(inSMachine2);
} else {
State parentState = inSMachine1.getParentState();
inSMachine1.setName(inSMachine1.getStartState().getName());
inSMachine2.setName(inSMachine2.getStartState().getName());
parentState.addNestedStateMachine(inSMachine2);
return null;
}
return newStateMachine;
}
//---------------------------------end----------------------------------------
//----------------------------------------------------------------------------
//---------------------------------Start--------------------------------------
Expand All @@ -315,7 +325,11 @@ class UmpleInternalParser
UmpleClassifier uClassifier = inSMachine1.getUmpleClass();
if (uClassifier==null) {
uClassifier = inSMachine1.getUmpleTrait();
getParseResult().addErrorMessage(new ErrorMessage(228,uClassifier.getPosition(0),inSMachine1.getName(),"tait", uClassifier.getName()));
if (uClassifier!=null){
getParseResult().addErrorMessage(new ErrorMessage(228,uClassifier.getPosition(0),inSMachine1.getName(),"tait", uClassifier.getName()));
} else {
//TODO please write a proper action and error description when this happens
}
} else {
getParseResult().addErrorMessage(new ErrorMessage(228,uClassifier.getPosition(0),inSMachine1.getName(),"class", uClassifier.getName()));
}
Expand All @@ -334,6 +348,18 @@ class UmpleInternalParser
State mainState = inSMachine1.findState(state.getName());
if (mainState ==null){
return false;
} else if (state.numberOfNestedStateMachines()==mainState.numberOfNestedStateMachines()){
for (StateMachine sm2: state.getNestedStateMachines()){
boolean found = false;
for(StateMachine sm1 : mainState.getNestedStateMachines()){
if (compareStateMachineName(sm1, sm2)){
found = true;
}
}
if (!found) return false;
}
} else {
return false;
}
for(Transition trans : state.getTransitions() ){
boolean find = false;
Expand Down Expand Up @@ -374,7 +400,31 @@ class UmpleInternalParser
if (i>0) i--;
}
}
}
for (int i=0; i<state.numberOfNestedStateMachines();i++){
StateMachine comingSM = state.getNestedStateMachine(i);
boolean equal = false;
for(StateMachine comparingSM:mainState.getNestedStateMachines()){
if (compareStateMachineName(comparingSM, comingSM)){
equal = true;
}
}
if (!equal){
//
if (mainState.getNestedStateMachines().size()<=0){
mainState.addNestedStateMachine(state.getNestedStateMachine(0));
} else {
if (!mainState.getNestedStateMachine(0).getStartState().getName().equals(state.getNestedStateMachine(0).getStartState().getName())){
StateMachine checkSM = mergeTwoStateMachineWithTheSameNameDifferentInitialState(mainState.getNestedStateMachine(0), state.getNestedStateMachine(0));
if (checkSM!=null ) mainState.addNestedStateMachine(checkSM);
i--;
} else {
addExtraStatesAndTransitions(mainState.getNestedStateMachine(0),state.getNestedStateMachine(0));
}
}
////
}
}
}
}
}
//---------------------------------end----------------------------------------
Expand Down
90 changes: 90 additions & 0 deletions cruise.umple/src/Umple_Code.ump
Expand Up @@ -1123,6 +1123,40 @@ class UmpleClass
return all;
}

public Boolean matchOperationMethod(String fullOperation, String method) {
String formattedMethod = StringFormatter.toUnderscore(method);
TriState isMatch = new TriState(false);
TriState isMatchOnExclude = new TriState(true);

String[] allOperations = fullOperation.split(",");
for (String operation : allOperations)
{
boolean isNot = false;
if (operation.startsWith("!"))
{
isNot = true;
operation = operation.substring(1);
}

String regexOperation = StringFormatter.toUnderscore(operation);
regexOperation = regexOperation.replace("_*", "*");
regexOperation = regexOperation.replace("*", ".*");
boolean isCurrentMatch = formattedMethod.matches(regexOperation);

if (isNot && isCurrentMatch)
{
isMatch.setStatus(false);
isMatchOnExclude.setStatus(false);
}
else if (!isNot && isCurrentMatch)
{
isMatch.setStatus(true);
}
}

return isMatchOnExclude.isTrue() || isMatch.isTrue();
}

public List<CodeInjection> getApplicableCodeInjections(String type, String method)
{
ArrayList<CodeInjection> all = new ArrayList<CodeInjection>();
Expand Down Expand Up @@ -1648,6 +1682,21 @@ class Attribute
return (varIsImmutable || classIsImmutable);
}

public boolean isInternal()
{
return "internal".equals(getModifier());
}

public boolean isSettable()
{
return "settable".equals(getModifier());
}

public boolean isDefaulted()
{
return "defaulted".equals(getModifier());
}

public String getValue()
{
String possibleValue = codeblock.getCode();
Expand All @@ -1672,6 +1721,47 @@ class Attribute
return this.getType() + (this.getIsList() ? "[]" : "");
}

public ArrayList<String> getMethodNames()
{
ArrayList<String> methodNames = new ArrayList<String>();
String attributeCapitalizedName = this.getUpperCaseName();
if (!this.isIsList())
{
if(!this.isInternal())
{
methodNames.add("get" + attributeCapitalizedName);
}
if(this.isIsLazy() || this.isSettable() || this.isDefaulted())
{
methodNames.add("set" + attributeCapitalizedName);
}
if(this.isDefaulted())
{
methodNames.add("reset" + attributeCapitalizedName);
methodNames.add("getDefault" + attributeCapitalizedName);
}
if(this.getType() != null && this.getType().equals("Boolean"))
{
methodNames.add("is" + attributeCapitalizedName);
}
}
else
{
if(!this.isInternal())
{
methodNames.add("get" + attributeCapitalizedName);
methodNames.add("numberOf" + attributeCapitalizedName);
methodNames.add("has" + attributeCapitalizedName);
methodNames.add("indexOf" + attributeCapitalizedName);
}
if(this.isIsLazy() || this.isSettable() || this.isDefaulted())
{
methodNames.add("add" + attributeCapitalizedName);
methodNames.add("remove" + attributeCapitalizedName);
}
}
return methodNames;
}
}

/*
Expand Down
1 change: 1 addition & 0 deletions cruise.umple/src/en.error
Expand Up @@ -168,6 +168,7 @@
1009: 4, "http://cruise.eecs.uottawa.ca/umple/PageBeingDeveloped.html", Method '{0}' has a name conflict with automatic generated getter/setter methods for attribute '{1}'. The user definition is being disconsidered. Please use a different name ;
1010: 3, "http://cruise.eecs.uottawa.ca/umple/PageBeingDeveloped.html", Constraint syntax, {0}, could not be processed. It has been considered as Extra Code ;
1011: 3, "http://cruise.eecs.uottawa.ca/umple/W1011InvalidAssociationClassKey.html", AssociationClass '{0}' missing needed '{1}' key, provided {2} ;
1012: 3, "http://cruise.eecs.uottawa.ca/umple/PageBeingDeveloped.html", Method '{0}' cannot be found. Injection was ignored. ;

1500 : 1, "http://cruise.eecs.uottawa.ca/umple/E15xxParsingError.html", Parsing error: '{0}' not understood ;
1501 : 1, "http://cruise.eecs.uottawa.ca/umple/E15xxParsingError.html", Parsing error: Arguments to '{0}' not understood ;
Expand Down