astah* API User Guide


[Programming Language Information for Project]

In astah*, programming language information such as Java, C# and C++ are represented by stereotypes, tagged values and attributes of models.

Programming language information

Project model (IModel) has tagged value to set the language information.

Language Item Tagged Value Stereotype Model Attribute Model
Java Java Project [Key]jude.profile.java [Value]true/false - - Project Model(IModel)
C# C# Project [Key]jude.profile.c_sharp [Value]true/false - - Project Model(IModel)
C++ C++ Project [Key]jude.profile.c_plus [Value]true/false - - Project Model(IModel)

How to recognize Java or C# (Class, Attribute, Operation)

Use the checkboxes in the language tab of the property view for class, attribute and operation. For example, when Java checkbox is set to ON for class, A stereotype, "Java Class", will be set. (However, it will not displayed in the property view or diagram editor.)

Language Model Stereotype
Java Class (IClass) Java Class
Java Attribute (IAttribute) Java Attribute
Java Operation (IOperation) Java Method
C# Class (IClass) C# Class
C# Attribute (IAttribute) C# Attribute
C# Operation (IOperation) C# Method
C++ Class (IClass) C++ Class
C++ Attribute (IAttribute) C++ Attribute
C++ Operation (IOperation) C++ Method

Programming language information for Class, Attribute and Operation

In astah*, programming language information such as Java, C# and C++ is set in stereotypes, tagged values and attributes in models. In the language tab of the property view for class, attribute or operation, values for setup items are set to either tagged value, stereotype, model attribute.
Language Item Stereotype Tagged Value Model Attribute Model
Java <<enum>> <<enum>> - - Class (IClass)
Java annotations - [Key]jude.java.annotations [Value]Optional - Class (IClass), Attribute (IAttribute), Operation (IOperation)
Java @interface - [Key]jude.java.atmark_interface [Value]true/false - Class (IClass)
Java strictfp - [Key]jude.java.strictfp[Value]true/false - Class (IClass),Operation(IOperation)
Java [Class]final - - IClass.isLeaf() Class (IClass)
Java <<enum constant>> <<enum constant>> - - Attribute (IAttribute)
Java transient - [Key]jude.java.transient [Value]true/false - Attribute (IAttribute)
Java volatile - [Key]jude.java.volatile [Value]true/false - Attribute (IAttribute)
Java [Attribute]final - - IAttribute.isChangeable() Attribute (IAttribute)
Java synchronized - [Key]jude.java.synchronized [Value]true/false - Operation (IOperation)
Java native - [Key]jude.java.native [Value]true/false - Operation (IOperation)
Java [Operation]final - - IClass.isLeaf() Operation (IOperation)
C# <<delegate>> <<delegate>> - - Class (IClass)
C# <<struct>> <<struct>> - - Class (IClass)
C# <<enum>> <<enum>> - - Class (IClass)
C# attributes - [Key]jude.c_sharp.attributes [Value]Optional - Class (IClass), Attribute (IAttribute), Operation( IOperation)
C# sealed - [Key]jude.c_sharp.sealed [Value]true/false - Class (IClass)
C# static - [Key]jude.c_sharp.static [Value]true/false - Class (IClass)
C# internal - [Key]jude.c_sharp.internal [Value]true/false - Class (IClass), Attribute (IAttribute), Operation (IOperation)
C# <<property>> <<property>> - - Attribute (IAttribute)
C# <<property>> get - [Key]jude.c_sharp.property_get [Value]true/false - Attribute (IAttribute)
C# <<property>> set - [Key]jude.c_sharp.property_set [Value]true/false - Attribute (IAttribute)
C# <<enum constant>> <<enum constant>> - - Attribute (IAttribute)
C# const - [Key]jude.c_sharp.const [Value]true/false - Attribute (IAttribute)
C# volatile - [Key]jude.c_sharp.volatile [Value]true/false - Attribute (IAttribute)
C# [Attribute]readonly - - IAttribute.getChangeable() Attribute (IAttribute)
C# <<event>> <<event>> - - Operation (IOperation)
C# <<event>> add - [Key]jude.c_sharp.event_add [Value]true/false - Operation (IOperation)
C# <<event>> remove - [Key]jude.c_sharp.event_remove [Value]true/false - Operation (IOperation)
C# <<indexer>> <<indexer>> - - Operation (IOperation)
C# <<indexer>> get - [Key]jude.c_sharp.indexer_get [Value]true/false - Operation (IOperation)
C# <<indexer>> set - [Key]jude.c_sharp.indexer_set [Value]true/false - Operation (IOperation)
C# extern - [Key]jude.c_sharp.extern [Value]true/false - Operation (IOperation)
C# override - [Key]jude.c_sharp.override [Value]true/false - Operation (IOperation)
C# sealed - [Key]jude.c_sharp.sealed [Value]true/false - Operation (IOperation)
C# unsafe - [Key]jude.c_sharp.unsafe [Value]true/false - Operation (IOperation)
C# virtual - [Key]jude.c_sharp.virtual [Value]true/false - Operation (IOperation)
C# extension method - [Key]jude.c_sharp.extension_method [Value]true/false - Operation (IOperation)
C++ Type Modifier - [Key]type_modifier[Value]Type Modifie String IElement.getTypeModifier(),ITemplateBinding.getActualParameterTypeModifier() -
C++ <<enum>> <<enum>> - - Class (IClass)
C++ <<struct>> <<struct>> - - Class (IClass)
C++ <<union>> <<union>> - - Class (IClass)
C++ <<enum constant>> <<enum constant>> - - Attribute (IAttribute)
C++ const - [Key]jude.c_plus.const[Value]true/false - Attribute (IAttribute),Operation(IOperation)
C++ mutable - [Key]jude.c_plus.mutable[Value]true/false - Attribute (IAttribute)
C++ volatile - [Key]jude.c_plus.volatile[Value]true/false - Attribute (IAttribute)
C++ friend - [Key]jude.c_plus.friend[Value]true/false - Operation (IOperation)
C++ explicit - [Key]jude.c_plus.explicit[Value]true/false - Operation (IOperation)
C++ inline - [Key]jude.c_plus.inline[Value]true/false - Operation (IOperation)
C++ virtual - [Key]jude.c_plus.virtual[Value]true/false - Operation (IOperation)

How to get language information for project

Get project language information

    public void getLanguageInfomataion() {
        BasicModelEditor bme = ModelEditorFactory.getBasicModelEditor();
        IModel project = AstahAPI.getAstahAPI().getProjectAccessor().getProject();
        try {
            if (isJavaProject(project)) {
                System.out.println("Java Language");
            }
            if (isCSharpProject(project)) {
                System.out.println("C# Language");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private boolean isJavaProject(IModel project) {
        ITaggedValue[] tags = project.getTaggedValues();
        for (int i = 0; i < tags.length; i++) {
            ITaggedValue tag = tags[i];
            String key = tag.getKey();
            if ("jude.profile.java".eqauls(key) {
                if ("true".equals(tag.getValue()) {
                    return true;
                }
            }
        }
        return false;
    }
    
    private boolean isCSharpProject(IModel project) {
        ITaggedValue[] tags = project.getTaggedValues();
        for (int i = 0; i < tags.length; i++) {
            ITaggedValue tag = tags[i];
            String key = tag.getKey();
            if ("jude.profile.c_sharp".eqauls(key) {
                if ("true".equals(tag.getValue()) {
                    return true;
                }
            }
        }
        return false;
    }

How to set language information for project

Set project language information

    public void testSetLanguageCSharp() throws ClassNotFoundException,
    InvalidEditingException, ProjectNotFoundException {
        BasicModelEditor bme = ModelEditorFactory.getBasicModelEditor();
        IModel project = AstahAPI.getAstahAPI().getProjectAccessor().getProject();
        try {
            TransactionManager.beginTransaction();
            
            //Java:OFF
            bme.setLanguageJava(project, false);
            //C#:OFF
            bme.setLanguageCSharp(project, false);
            //Java:ON
            bme.setLanguageJava(project, true);
            //C#:ON
            bme.setLanguageCSharp(project, true);
            
            TransactionManager.endTransaction();
        } catch (InvalidEditingException e) {
            TransactionManager.abortTransaction();
            e.printStackTrace();
            fail();
        }
    }

Check if Java language information is set to class, or class is strictfp


    public void testGetJavaClassStrictfp() {
        BasicModelEditor bme = ModelEditorFactory.getBasicModelEditor();
        IModel project = AstahAPI.getAstahAPI().getProjectAccessor().getProject();
        try {
            IElement element = getElement(project.getOwnedElements(), "Class0");
            if (isJavaClass(element)) {
                System.out.println("Class0 has \"Java Class\" stereotype");
                if (isJavaClassStrictfp(element)) {
                    System.out.println("Class0 has \"jude.java.strictfp\" TaggedValue");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }
    }
    
    protected INamedElement getElement(INamedElement[] elements, String elementName) {
        for (int i = 0; i < elements.length; i++) {
            if (elements[i].getName().equals(elementName)) {
                return elements[i];
            }
        }
        return null;
    }
    
    private boolean isJavaClass(IElement element) {
        String[] sterotyopes = element.getStereotypes();
        for (int i =0 ; i < sterotyopes.length; i++) {
            if ("Java Class".equals(sterotyopes[i])) {
                return true;
            }
        }
        return false;
    }
    
    private boolean isJavaClassStrictfp(IElement element) {
        ITaggedValue[] tags = element.getTaggedValues();
        for (int i =0 ; i < tags.length; i++) {
            ITaggedValue tag = tags[i];
            if ("jude.java.strictfp".equals(tag.getKey())) {
                if ("true".equals(tag.getValue())) {
                    return true;
                }
            }
        }
        return false;
    }
    

Set Java language information to project and class, then set strictfp to class

Set project language information

    public void testJavaAttributeStereotypeInClass() throws InvalidEditingException, ClassNotFoundException {
        BasicModelEditor bme = ModelEditorFactory.getBasicModelEditor();
        try {
            TransactionManager.beginTransaction();
            
            bme.setLanguageJava(project, true);
            IElement element = getElement(project.getOwnedElements(), "Class0");
            element.addStereotype("Java Class");
            bme.createTaggedValue(element, "jude.java.strictfp", "true");
            
            TransactionManager.endTransaction();
            
        } catch (InvalidEditingException e) {
            TransactionManager.abortTransaction();
            fail();
        }
    }

Home