Stereotypes

How do i get the stereotypes for attributes and classes?
Is there some where a complete documentation to about stereotypes, and how they will affect the model and/or the codegeneration?

Thanx in advance!

kind regards
Michael Nitschke

Hi Michael Nitschke,

Thanks for your post. Could you please explain more of your meaning “get the stereotype for attributes and classes”?

Below are the stereotypes which will affect the code generated:

Class

  • Interface
  • Enum
  • Struct
  • Delegate
  • Typedef

Attribute

  • Constant
  • Event
  • Property

If there is any further inquiry, please do not hesitate to contact me.

Best regards,
Lilian Wong

Sorry, i did mean, how do i get the stereotypes for attributes and classes show up in the source code and or documentation.
It if create my own.

I read http://resource.visual-paradigm.com/tips_and_tricks/code_engineering/customizing_code_generation.html Appendix A
and the only thing i found was “isStereotypeInterface()” for Class.

Is there another way to find out if this Object (Class, attribute) has a stereotype assigned?

kind regards
Michael Nitschke

Hi Michael Nitschke,

Thanks for replying. Would you mind telling me what is your exact purpose to find out if the object has stereotype? How will you apply the code? Thanks in advance!

Best regards,
Lilian Wong

Hello LilianWong,

this enables me to modify the created source according to the stereotypes.
We use stereotypes to add specific functions/attributes to classes. They differ in some attributes and functionality. It’s like a cross cutting concern but not implemented as AOP.

kind regards
Michael Nitschke

Hi Michael Nitschke,

Thanks for replying. Here is an example for customizing code generation according to stereotype in order to add particular attribute/operation:

Sample Code:

#if( $class.hasStereotypeIgnoreCase( “A” ) )
${baseIndentation}${indentation}private static Object attributeForStereotype__##
$class.getStereotypeIgnoreCase( “a” ).getName()##
;
#end
#if( $class.hasStereotypeIgnoreCase( “B” ) )
${baseIndentation}${indentation}private static void operationForStereotype
##
$class.getStereotypeIgnoreCase( “B” ).getName()##
__() { /* TODO */ }
#end
#if( $class.hasStereotype( “c” ) )
${baseIndentation}${indentation}// has stereotype <>
#end
#if( $class.hasStereotype( “C” ) )
${baseIndentation}${indentation}// has stereotype <>
#end

Example of Generated Code:

public class Class {
private static boolean attributeForStereotype__A__;
private static boolean operationForStereotype__B__() { /* TODO */ }
// has stereotype <>

public void operation() {
throw new UnsupportedOperationException();
}
}

I hope this will help. If there is any further inquiry, please do not hesitate to contact me again.

Best regards,
Lilian Wong

Hello Lilian Wong,

thank you, very much, this was a great help.

Will this also be added to the official documentation?

best regards
Michael Nitschke

Hi Michael Nitschke,

You are welcome. We’ll consider to have the documentation for adding particular attribute/operation in customizing code generation, and I’ll keep you informed for any news about this issue.

If there is anything I can help, please feel free to ask.

Best regards,
Lilian Wong

Hi all.
As I understand, the solution proposed by LilianWong is to create a template file and create inside a “switch”-like construct to check if the class has one stereotype or the other. If I am wrong, please correct me.
I would like to know if Visual Paradigm supports such a feature as “stereotype overrides”. By this I mean that the template used to generate the code for a given class with a given stereotype is chosen automatically based on the class’s stereotype. If the class doesn’t have a stereotype then the default template for code generation is used.
Also I would like to know if Visual Paradigm supports the concept of “UML Profiles”.

Hi Eugen,

Thanks for your post. I’ve forwarded the issue to our engineers, and I’ll come back to you once there is any feedback.

Best regards,
Lilian Wong