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; }
@Override public Object caseComment(Comment comment) { String body = comment.getBody(); if (!isEmpty(body) && options != null && !OPTION__IGNORE.equals(options.get(OPTION__COMMENTS))) { for (Element annotatedElement : comment.getAnnotatedElements()) { EModelElement eModelElement = (EModelElement) doSwitch(annotatedElement); if (eModelElement != null) { processComment(eModelElement, body, options, diagnostics, context); } } } return super.caseComment(comment); }
comment.getAnnotatedElements().add(element); comment.setBody(documentation);
@Override public Object caseComment(Comment comment) { AnyType extension = getExtension(resource, comment); if (extension != null) { Object value = getValue(extension.getAnyAttribute(), "body", true); //$NON-NLS-1$ if (value instanceof String) { comment.setBody((String) value); } EObject eObject = getEObject(extension, resource, "bodyExpression", true); //$NON-NLS-1$ if (eObject instanceof StringExpression) { UMLUtil.setTaggedValue(comment, getUML2Stereotype( comment, STEREOTYPE__COMMENT), TAG_DEFINITION__BODY_EXPRESSION, eObject); } } return super.caseComment(comment); }
/** * Get the comments for a UML Element. This will be a string with each * comment separated by a 2 newlines. * * @param element * @return concatenated string */ public static String getComment(final Element element) { if (element==null) { return null; } final StringBuilder commentString = new StringBuilder(); final Collection<Comment> comments = element.getOwnedComments(); for (final Comment comment : comments) { if (commentString.length()>0) { commentString.append("\n\n"); } commentString.append(comment.getBody()); } return cleanText(commentString.toString()); }
/** * Get the comments for a UML Element. This will be a string with each * comment separated by a 2 newlines. * * @param element * @return concatenated string */ public static String getComment(final Element element) { if (element==null) { return null; } final StringBuilder commentString = new StringBuilder(); final Collection<Comment> comments = element.getOwnedComments(); for (final Comment comment : comments) { if (commentString.length()>0) { commentString.append("\n\n"); } commentString.append(comment.getBody()); } return cleanText(commentString.toString()); }
@SuppressWarnings("unchecked") private void generateJavadoc(AST ast, Comment comment, Javadoc javadoc) { String[] commentContents = parseComment(comment.getBody()); for (String commentContent : commentContents) { TagElement tagElement = ast.newTagElement(); tagElement.setTagName(commentContent); javadoc.tags().add(tagElement); } }
/** * If documentation is present, i.e. to add toDoTag or skip a line if not * @return true is documentation comment or Documentation stereotype is present * @see org.andromda.metafacades.uml.ModelElementFacade#isDocumentationPresent() */ @Override protected boolean handleIsDocumentationPresent() { boolean rtn = false; final Collection<Comment> comments = this.metaObject.getOwnedComments(); if (comments != null && !comments.isEmpty()) { for (Comment comment : comments) { final String commentString = StringUtils.trimToEmpty(comment.getBody()); // if there isn't anything in the body, try the name if (StringUtils.isNotBlank(commentString)) { rtn = true; break; } } } if (!rtn && StringUtils.isNotBlank((String)this.findTaggedValue(UMLProfile.TAGGEDVALUE_DOCUMENTATION))) { rtn = true; } return rtn; }
@SuppressWarnings("unchecked") private void generateJavadoc(AST ast, Comment comment, Javadoc javadoc) { String[] commentContents = parseComent(comment.getBody()); for (String commentContent : commentContents) { TagElement tagElement = ast.newTagElement(); tagElement.setTagName(commentContent); javadoc.tags().add(tagElement); } }
/** * If documentation is present, i.e. to add toDoTag or skip a line if not * @return true is documentation comment or Documentation stereotype is present * @see org.andromda.metafacades.uml.ModelElementFacade#isDocumentationPresent() */ @Override protected boolean handleIsDocumentationPresent() { boolean rtn = false; final Collection<Comment> comments = this.metaObject.getOwnedComments(); if (comments != null && !comments.isEmpty()) { for (Comment comment : comments) { final String commentString = StringUtils.trimToEmpty(comment.getBody()); // if there isn't anything in the body, try the name if (StringUtils.isNotBlank(commentString)) { rtn = true; break; } } } if (!rtn && StringUtils.isNotBlank((String)this.findTaggedValue(UMLProfile.TAGGEDVALUE_DOCUMENTATION))) { rtn = true; } return rtn; }
final String commentString = StringUtils.trimToEmpty(comment.getBody());
final String commentString = StringUtils.trimToEmpty(comment.getBody());
String commentString = StringUtils.trimToEmpty(comment.getBody()); documentation.append(StringUtils.trimToEmpty(commentString)); documentation.append(SystemUtils.LINE_SEPARATOR);
String commentString = StringUtils.trimToEmpty(comment.getBody()); documentation.append(StringUtils.trimToEmpty(commentString)); documentation.append(SystemUtils.LINE_SEPARATOR);
@SuppressWarnings("unchecked") @Test public void testGenerateClassJavadoc() { AST ast = AST.newAST(AST.JLS3); ast.newCompilationUnit(); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(true); Modifier modifier = ast .newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD); td.modifiers().add(modifier); td.setName(ast.newSimpleName("Company")); Class clazz = mock(Class.class, Answers.RETURNS_DEEP_STUBS.get()); EList<Comment> comments = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); Iterator<Comment> commentIterator = mock(Iterator.class); Comment comment = mock(Comment.class, Answers.RETURNS_DEEP_STUBS.get()); when(clazz.getOwnedComments()).thenReturn(comments); when(comments.iterator()).thenReturn(commentIterator); when(commentIterator.hasNext()).thenReturn(true, false); when(commentIterator.next()).thenReturn(comment); when(comment.getBody()).thenReturn( "Comment...\nTest\n@author: Lofi Dewanto"); interfaceGenerator.generateClassJavadoc(clazz, ast, td); assertEquals( "/** \n * Comment...\n * Test\n * @author: Lofi Dewanto\n */\npublic interface Company {\n}\n", td.toString()); }
@SuppressWarnings("unchecked") @Test public void testGenerateMethodJavadoc() { AST ast = AST.newAST(AST.JLS3); ast.newCompilationUnit(); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(true); Modifier modifier = ast .newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD); td.modifiers().add(modifier); td.setName(ast.newSimpleName("Company")); MethodDeclaration md = ast.newMethodDeclaration(); md.setName(ast.newSimpleName("calculateAge")); Operation operation = mock(Operation.class, Answers.RETURNS_DEEP_STUBS.get()); EList<Comment> comments = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); Iterator<Comment> commentIterator = mock(Iterator.class); Comment comment = mock(Comment.class, Answers.RETURNS_DEEP_STUBS.get()); when(operation.getOwnedComments()).thenReturn(comments); when(comments.iterator()).thenReturn(commentIterator); when(commentIterator.hasNext()).thenReturn(true, false); when(commentIterator.next()).thenReturn(comment); when(comment.getBody()).thenReturn( "Comment...\nTest\n@author: Lofi Dewanto"); interfaceGenerator.generateMethodJavadoc(ast, operation, md); assertEquals( "/** \n * Comment...\n * Test\n * @author: Lofi Dewanto\n */\nvoid calculateAge();\n", md.toString()); }
@SuppressWarnings("unchecked") @Test public void testGenerateGetterSetterJavadoc() { AST ast = AST.newAST(AST.JLS3); ast.newCompilationUnit(); TypeDeclaration td = ast.newTypeDeclaration(); td.setInterface(true); Modifier modifier = ast .newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD); td.modifiers().add(modifier); td.setName(ast.newSimpleName("Company")); MethodDeclaration md = ast.newMethodDeclaration(); md.setName(ast.newSimpleName("calculateAge")); Property property = mock(Property.class, Answers.RETURNS_DEEP_STUBS.get()); EList<Comment> comments = mock(EList.class, Answers.RETURNS_DEEP_STUBS.get()); Iterator<Comment> commentIterator = mock(Iterator.class); Comment comment = mock(Comment.class, Answers.RETURNS_DEEP_STUBS.get()); when(property.getOwnedComments()).thenReturn(comments); when(comments.iterator()).thenReturn(commentIterator); when(commentIterator.hasNext()).thenReturn(true, false); when(commentIterator.next()).thenReturn(comment); when(comment.getBody()).thenReturn( "Comment...\nTest\n@author: Lofi Dewanto"); interfaceGenerator.generateGetterSetterJavadoc(ast, property, md); assertEquals( "/** \n * Comment...\n * Test\n * @author: Lofi Dewanto\n */\nvoid calculateAge();\n", md.toString()); }
StringBuilder sb = new StringBuilder(); for (Comment comment : model.getOwnedComments()) { sb.append(comment.getBody());