Permalink
Browse files

Merge pull request #1366 from umple/issue_460

Fixes #460 - Add support for nested generics
  • Loading branch information...
TimLethbridge committed Sep 25, 2018
2 parents 453bc83 + 516b8b4 commit 7840197ceeb4b37f2395bf6d457c4a456bfb739f
View
@@ -15,8 +15,7 @@ src-gen-umple/
src-gen/
# generated umpleTL code that is not saved
src-gen-umpleTL/
src-gen-umpletl/
src-gen-[Uu]mple[Tt][Ll]/
# os specific:
.DS_Store
@@ -246,6 +246,50 @@ class Token
}
return stringSoFar;
}
// Set name to flattened string of all child sub-tokens and remove them
public void flatten()
{
StringBuffer answer = new StringBuffer();
flattenValues(answer);
setValue(answer.toString());
subTokens.clear();
}
// Return string buffer with flattened value of tokens
public StringBuffer flattenValues(StringBuffer stringSoFar)
{
if ("START_TOKEN".equals(getValue()))
{
//ignore
}
else if ("STATIC".equals(getValue()))
{
stringSoFar.append(getName());
}
else
{
stringSoFar.append(getValue());
}
for(Token subToken : getSubTokens())
{
subToken.flattenValues(stringSoFar);
}
return stringSoFar;
}
// Recursively flattens a particular token name from bottom up
public void flattenNameRecursive(String tokenName)
{
for (Token t : subTokens)
{
t.flattenNameRecursive(tokenName);
}
if (is(tokenName)) {
flatten();
}
}
// Return a copy of the current token with all its SubTokens
// Removes all SubTokens from the current Token and sets new name and value
@@ -68,7 +68,7 @@ class JavaCodeGenValidator {
parser.setSource(source.toCharArray()); // set source
// In order to parse 1.7 code, some compiler options need to be set to 1.7
// Annotations were not available prior 1.6
Map<String, String> options = JavaCore.getOptions();
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
parser.setCompilerOptions(options);
parser.setResolveBindings(true); // we need bindings later on
@@ -1040,6 +1040,9 @@ class UmpleGenerator
case MULTIPLICITY:
case PARAMETERS:
case TYPED_NAME:
case TYPE:
generateRuleTokenOutput(getRuleTokenByName(ruleNameToken.getValue()), model, uContainer);
break;
case PARAMETER_LIST:
case EXTRA_CODE:
case METHOD_NAME:
@@ -1126,6 +1129,12 @@ class UmpleGenerator
case VALUE:
case VALUE_COLON:
case RULE_NAME:
// #460 - now that type is aggregated, the rule needs to be treated similar to a named token
if (elementRootRuleToken.getValue().equals(RuleName.TYPE.value))
{
buffer.append(getElementProperty(elementRootRuleToken.getValue(), elementRootRuleToken, uContainer));
break;
}
default:
for(Token subToken : elementRootRuleToken.getSubTokens()) {
generateRuleTokenOutput(subToken, model, uContainer);
@@ -255,6 +255,8 @@ class UmpleInternalParser
// Delegate function to analyze a token and send it to the write
private void analyzeToken(Token t, int analysisStep)
{
// See #460 - types are now nested
t.flattenNameRecursive("type");
analyzeMixsetUseStatement(t, analysisStep);
analyzeUSE(t, analysisStep);
analyzeCoreToken(t,analysisStep);
@@ -275,6 +277,8 @@ class UmpleInternalParser
// Analyze an individual token, delegates to the various components in Umple
private void analyzeToken(Token t, UmpleClass aClass, int analysisStep)
{
// See #460 - types are now nested
t.flattenNameRecursive("type");
analyzeCoreToken(t,aClass,analysisStep);
analyzeClassToken(t,aClass,analysisStep);
analyzeStateMachineToken(t,aClass,analysisStep);
@@ -101,4 +101,8 @@ depend- : depend [depend] ;
extraCode- : [**extraCode]
list- : [!list:\[\s*\]]
typedName- : [type]? [[list]]? [~name]
baseType- : [!baseType:[a-zA-Z0-9_$]+]
nestedType- : [[baseType]] ( < [[argType]] > )?
argType- : ( ? | [[nestedType]] [[list]]? ) ( , [[argType]] )?
type : [[nestedType]] ( ... )?
typedName- : [[type]]? [[list]]? [~name]
@@ -0,0 +1,21 @@
class A {
depend java.util.*;
Map<String, String> a1;
List<String> a2;
Map<List<String>,String>a3;
List<String> a4;
List<List<String>> a5;
Map<List<String>, String> a6;
Map<String, List<String>> a7;
Map<List<String>, List<String>> a8;
List<List<String>> a9;
Map<List<Map<String, String>>, String> b1;
Map<String, List<Map<String, String>>> b2;
Map<List<Map<String, String>>, List<String>> b3;
List<List<List<String>>> b4;
TestVector<A,B,C> c1;
private void testVariadic(String test, Object... test2)
{
}
}
@@ -0,0 +1,6 @@
class C {
depend java.util.*;
Map<String, String a1;
Map<String, String> a2; // make sure that the end brace here doesn't create a match
}
@@ -3048,11 +3048,19 @@ public void templateInexistentReference()
assertFailedParse("028_multipleTemplateInexistentReferences.ump",3504);
}
//Issue 460
@Test
public void nestedGenericTypes()
{
assertHasWarningsParse("424_nestedGenerics1.ump", 46);
assertHasWarningsParse("424_nestedGenerics2.ump", 1007);
}
//Issue 546
@Test
public void portPrefixAttributeNameAssignment()
{
assertHasNoWarningsParse("701_validAttributeName.ump");
assertHasNoWarningsParse("701_validAttributeName.ump");
}
public boolean parse(String filename)
@@ -22,6 +22,12 @@
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBigInteger" />
</eGenericType>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="m3" transient="true">
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EMap">
<eTypeArguments eClassifier="#//A" />
<eTypeArguments eClassifier="#//D" />
</eGenericType>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="m4" transient="true">
<eGenericType eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EMap">
<eTypeArguments />
@@ -15,12 +15,12 @@ class JavaParser {
// Parses a complete Java Class
public CompilationUnit parseUnit(String source){
//logger.debug("Parsing Compilation Unit");
ASTParser parser = ASTParser.newParser(AST.JLS8);
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(source.toCharArray()); // set source
// In order to parse 1.7 code, some compiler options need to be set to 1.7
// Annotations were not available prior 1.6
Map<String, String> options = JavaCore.getOptions();
// In order to parse 1.7 code, some compiler options need to be set to 1.7
// Annotations were not available prior 1.6
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
parser.setCompilerOptions(options);
parser.setResolveBindings(true); // we need bindings later on
@@ -41,7 +41,7 @@ class JavaParser {
parser.setSource(source.toCharArray()); // set source
// In order to parse 1.7 code, some compiler options need to be set to 1.7
// Annotations were not available prior 1.6
Map<String, String> options = JavaCore.getOptions();
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
parser.setCompilerOptions(options);
parser.setResolveBindings(true); // we need bindings later on

0 comments on commit 7840197

Please sign in to comment.