String umlQualifiedTypeName = type.getQualifiedName(); List<String> templateSubstitutions = getTemplateParameterSubstitution(type); if (templateSubstitutions.size() != 0) { int index = 0; .substringAfter(umlTypeName, "<"); paramTypeNames = StringUtils.removeEnd(paramTypeNames, ">"); EList<String> paramTypeNameList = convertStringToList( paramTypeNames, ",");
@SuppressWarnings({ "rawtypes", "unchecked" }) public String formatComment(Element element, String prefix, String propertyFileName) { String comment = ""; EList comments = new BasicEList(); createAnnotationSourceKey(propertyFileName); for (Iterator<String> iter = annotationSourceKeyMap.keySet().iterator(); iter .hasNext();) { String source = iter.next(); String key = annotationSourceKeyMap.get(source); comment = findDocumentationAnnotation(element, source, key); if (comment != null) { break; } } if (comment != null) { comments.add(comment); } else { comments = element.getOwnedComments(); } return getFormatedComment(comments, prefix, null); }
private String getFormatedComment(EList<?> comments, String prefix, String annotation) { String s = ""; if (!comments.isEmpty()) { for (int i = 0; i < comments.size(); i++) { Object commentsObject = comments.get(i); String text = ""; if (commentsObject instanceof String) { text = (String) commentsObject; } else if (commentsObject instanceof Comment) { Comment c = (Comment) comments.get(i); text = c.getBody(); } if (text != null && !"".equals(text)) { s = doFormatting(text, s, prefix, annotation); } else { s = "* "; } } } else { s = "* "; } return s; }
private void generateMethodReturnType(AST ast, TypeDeclaration td, Operation operation, MethodDeclaration md) { Type type = operation.getType(); String umlTypeName = type.getName(); String umlQualifiedTypeName = type.getQualifiedName(); logger.log(Level.FINE, "UmlQualifiedTypeName: " + umlQualifiedTypeName + " - " + "umlTypeName: " + umlTypeName); if (operation.getUpper() >= 0) { // Upper Cardinality 0..1 // Only for parameterized type if (dataTypeUtils.isParameterizedType(umlTypeName)) { Map<String, String> types = umlHelper .checkParameterizedTypeForTemplateParameterSubstitution(type); umlTypeName = types.get("umlTypeName"); umlQualifiedTypeName = types.get("umlQualifiedTypeName"); } jdtHelper.createReturnType(ast, td, md, umlTypeName, umlQualifiedTypeName, sourceDirectoryPackageName); } else { // Upper Cardinality 0..* generateAssociationEndUpperCardinalityMultiples(ast, td, operation, md, umlTypeName, umlQualifiedTypeName); } }
@Test public void testGetTemplateParameterSubstitutionNotPrimitiveTypeButJavaType() { Classifier clazzifier = prepareMocks(); when(dataTypeUtils.isPrimitiveType(Mockito.anyString())).thenReturn( false); when(dataTypeUtils.isJavaType(Mockito.anyString())).thenReturn(true); when(clazzifier.getName()).thenReturn("Data::datatype::String"); when(clazzifier.getQualifiedName()).thenReturn( "Data::datatype::de::test::String"); List<String> results = umlHelper.getTemplateParameterSubstitution(type); assertEquals("Data::datatype::String", results.get(0)); }
/** * Collects all associations the classifier and their interfaces have. * * @param classifier * The classifier the associations should be collected * @return An <code>EList</code> with all collected associations */ @SuppressWarnings("unchecked") public EList<Association> getAllAssociations(Classifier classifier) { EList<Association> associations = new UniqueEList<Association>(); associations.addAll(classifier.getAssociations()); if (classifier instanceof org.eclipse.uml2.uml.Class) { Class clazz = (Class) classifier; for (int i = 0; i < clazz.getImplementedInterfaces().size(); i++) { associations.addAll(getAllInterfaceAssociations(clazz .getImplementedInterfaces().get(i))); } } return associations; }
/** * Calculate the full qualified packagename of the given type. * * @param type * The <code>org.eclipse.uml2.uml.Type</code> to calculate the * full qualified name for * @return The full qualified name as <code>java.lang.String</code> */ public String getFQNPackageName(Type type) { String pn = ""; Package p = findNearestPackage(type); while (p != null) { pn = p.getName() + "." + pn; p = findNearestPackage(p); } if (pn.endsWith(".")) { pn = pn.substring(0, pn.length() - 1); } return pn; }
/** * Calculate the full qualified componentname of the given type. * * @param type * The <code>org.eclipse.uml2.uml.Type</code> to calculate the * full qualified name for * @return The full qualified name as <code>java.lang.String</code> */ public String getFQNComponentName(Type type) { String pn = ""; Component cp = null; // looking for start component if (type instanceof Component) { cp = (Component) type; } else { cp = findNearestComponent(type); } // stepping up component hierarchy while (cp != null) { pn = cp.getName() + "." + pn; cp = findNearestComponent(cp); } if (pn.endsWith(".")) { pn = pn.substring(0, pn.length() - 1); } return pn; }
@SuppressWarnings("unchecked") @Test public void testCheckParameterizedTypeForTemplateParameterSubstitutionWithNoSubstitution() { prepareMocks(); Iterator<Element> iteratorElement = mock(Iterator.class); when(iteratorElement.hasNext()).thenReturn(false); when(type.getName()).thenReturn("Data::datatype::Collection<Person>"); when(type.getQualifiedName()).thenReturn( "Data::datatype::Collection<de::test::Person>"); Map<String, String> results = umlHelper .checkParameterizedTypeForTemplateParameterSubstitution(type); String umlTypeName = results.get("umlTypeName"); String umlQualifiedTypeName = results.get("umlQualifiedTypeName"); assertEquals("Data::datatype::Collection<Person>", umlTypeName); assertEquals("Data::datatype::Collection<de::test::Person>", umlQualifiedTypeName); }
@Test public void testGetTemplateParameterSubstitutionPrimitiveType() { Classifier clazzifier = prepareMocks(); when(dataTypeUtils.isPrimitiveType(Mockito.anyString())).thenReturn( true); when(clazzifier.getName()).thenReturn("Data::datatype::Integer"); when(clazzifier.getQualifiedName()).thenReturn( "Data::datatype::de::test::Integer"); List<String> results = umlHelper.getTemplateParameterSubstitution(type); assertEquals("Data::datatype::Integer", results.get(0)); }
/** * Collects all associations of the given interface needed to implement by a * implementing class. * * @param iFace * The interface to collect the associations from * @return An <code>EList</code> with all collected associations */ @SuppressWarnings({ "rawtypes", "unchecked" }) private EList getAllInterfaceAssociations(Interface iFace) { EList associations = new UniqueEList(); associations.addAll(iFace.getAssociations()); if (iFace.getGeneralizations().size() > 0) { for (int i = 0; i < iFace.getGeneralizations().size(); i++) { associations .addAll(getAllInterfaceAssociations((Interface) iFace .getGeneralizations().get(i).getGeneral())); } } return associations; }
@Test public void testCheckParameterizedTypeForTemplateParameterSubstitution() { Classifier clazzifier = prepareMocks(); when(type.getName()).thenReturn("Data::datatype::Collection<Integer>"); when(type.getQualifiedName()).thenReturn( "Data::datatype::Collection<Integer>"); when(dataTypeUtils.isPrimitiveType(Mockito.anyString())).thenReturn( true); when(clazzifier.getName()).thenReturn("Integer"); when(clazzifier.getQualifiedName()).thenReturn( "Data::datatype::de::test::Integer"); Map<String, String> results = umlHelper .checkParameterizedTypeForTemplateParameterSubstitution(type); String umlTypeName = results.get("umlTypeName"); String umlQualifiedTypeName = results.get("umlQualifiedTypeName"); assertEquals("Data::datatype::Collection<Integer>", umlTypeName); assertEquals("Data::datatype::Collection<Integer>", umlQualifiedTypeName); }
String comment = ""; EList comments = new BasicEList(); createAnnotationSourceKey(propertyFileName); for (Iterator iter = annotationSourceKeyMap.keySet().iterator(); iter .hasNext();) { String source = (String) iter.next(); String key = annotationSourceKeyMap.get(source); comment = findDocumentationAnnotation(parameter, source, key); if (comment != null) { break; : parameter.getName()); } else { comment = getFormatedComment( comments, prefix,
@Test public void testGetTemplateParameterSubstitutionNotPrimitiveType() { Classifier clazzifier = prepareMocks(); when(dataTypeUtils.isPrimitiveType(Mockito.anyString())).thenReturn( false); when(clazzifier.getName()).thenReturn("Data::datatype::Company"); when(clazzifier.getQualifiedName()).thenReturn( "Data::datatype::de::test::Company"); List<String> results = umlHelper.getTemplateParameterSubstitution(type); assertEquals("Data::datatype::de::test::Company", results.get(0)); }
/** * Collects all dependencies the NamedElement has. In the case of a Class * the dependencies of its interfaces will be processed too. * * @param element * The NamedElement the dependencies should be collected * @return An <code>EList</code> with all collected dependencies */ @SuppressWarnings("unchecked") public EList<Dependency> getAllDependencies(NamedElement element) { EList<Dependency> dependencies = new UniqueEList<Dependency>(); dependencies.addAll(element.getClientDependencies()); if (element instanceof org.eclipse.uml2.uml.Class) { Class clazz = (Class) element; for (int i = 0; i < clazz.getImplementedInterfaces().size(); i++) { dependencies.addAll(getAllInterfaceAssociations(clazz .getImplementedInterfaces().get(i))); } } EList<Dependency> depsFiltered = new UniqueEList<Dependency>(); for (Iterator<Dependency> iter = dependencies.iterator(); iter .hasNext();) { Dependency e = iter.next(); if (!(e instanceof InterfaceRealization)) { depsFiltered.add(e); } } return depsFiltered; }
.checkParameterizedTypeForTemplateParameterSubstitution(type); umlTypeName = types.get("umlTypeName"); umlQualifiedTypeName = types
when( umlHelper .checkParameterizedTypeForTemplateParameterSubstitution(type)) .thenReturn(types); doNothing().when(jdtHelper).createParameterTypes(ast, td, md,
.checkParameterizedTypeForTemplateParameterSubstitution(type); umlTypeName = types.get("umlTypeName"); umlQualifiedTypeName = types.get("umlQualifiedTypeName");