Example usage for org.eclipse.jdt.core.jdom DOMFactory createClass

List of usage examples for org.eclipse.jdt.core.jdom DOMFactory createClass

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.jdom DOMFactory createClass.

Prototype

@Override
    public IDOMType createClass() 

Source Link

Usage

From source file:ac.at.tuwien.dsg.uml.stereotype.export.transformation.rules.DataTypeTransformationRule.java

License:Open Source License

public Object createTarget(ITransformContext context) {
    DOMFactory domFactory = new DOMFactory();

    //create output content
    IDOMType target = domFactory.createClass();

    /**// w w w .j  a  v a  2 s  . co  m
     * Get the transformation UML Class
     */
    DataType dataType = (DataType) context.getSource();
    target.setName(dataType.getName());

    //get all properties
    for (Property attribute : dataType.getAllAttributes()) {

        String name = attribute.getName();
        Type type = attribute.getType();
        String typeName = type.getName();

        org.eclipse.uml2.uml.Package packageType = type.getPackage();
        /**
         * Create Java field/class variable for each attribute 
         */
        Namespace namespace = attribute.getNamespace();

        IDOMField field = domFactory.createField();
        field.setName(name);
        field.setFlags(Flags.AccPrivate);
        /**
         * In case the model is incomplete, we add the field with Object as type
         */
        if (typeName == null) {
            field.setType("Object");
            //add in the generated code a comment explaining why field type is Object
            field.setComment(
                    "/*Type for attribute \"" + name + "\" on stereotype \"" + dataType + "\" is null */");
            System.err
                    .println("Type for attribute \"" + name + "\" on stereotype \"" + dataType + "\" is null");
        } else {
            field.setType(typeName);
        }

        target.addChild(field);

        /**
         * Add setter/getter for the added field
         */
        IDOMMethod setter = domFactory.createMethod();
        /**
         * Capitalize the first letter of the variable name so we have nice camel-case 
         */
        setter.setName("set" + name.substring(0, 1).toUpperCase() + name.substring(1));
        setter.setFlags(Flags.AccPublic);
        setter.setReturnType("void");
        setter.addParameter(typeName, name);
        setter.setBody("{ \n this." + name + "=" + name + ";\n }");

        target.addChild(setter);

        IDOMMethod getter = domFactory.createMethod();
        getter.setName("get" + name.substring(0, 1).toUpperCase() + name.substring(1));
        getter.setFlags(Flags.AccPublic);
        getter.setReturnType(typeName);
        getter.setBody("{ \n return this." + name + ";\n }");

        target.addChild(getter);

    }

    //create Java file from UML class
    JavaClassOutputter.outputFile(context, target);

    return target;
}

From source file:ac.at.tuwien.dsg.uml.stereotype.export.transformation.rules.SignalTransformationRule.java

License:Open Source License

public Object createTarget(ITransformContext context) {
    DOMFactory domFactory = new DOMFactory();

    //create output content
    IDOMType target = domFactory.createClass();

    /**//from  w w w  .j  a  v a2  s.  c  o m
     * Get the transformation UML Class
     */
    Signal signal = (Signal) context.getSource();
    target.setName(signal.getName());

    //get all properties
    for (Property attribute : signal.getAllAttributes()) {

        String name = attribute.getName();
        Type type = attribute.getType();
        String typeName = type.getName();

        org.eclipse.uml2.uml.Package packageType = type.getPackage();
        /**
         * Create Java field/class variable for each attribute 
         */
        Namespace namespace = attribute.getNamespace();

        IDOMField field = domFactory.createField();
        field.setName(name);
        field.setFlags(Flags.AccPrivate);
        /**
         * In case the model is incomplete, we add the field with Object as type
         */
        if (typeName == null) {
            field.setType("Object");
            //add in the generated code a comment explaining why field type is Object
            field.setComment(
                    "/*Type for attribute \"" + name + "\" on stereotype \"" + signal + "\" is null */");
            System.err.println("Type for attribute \"" + name + "\" on stereotype \"" + signal + "\" is null");
        } else {
            field.setType(typeName);
        }

        target.addChild(field);

        /**
         * Add setter/getter for the added field
         */
        IDOMMethod setter = domFactory.createMethod();
        /**
         * Capitalize the first letter of the variable name so we have nice camel-case 
         */
        setter.setName("set" + name.substring(0, 1).toUpperCase() + name.substring(1));
        setter.setFlags(Flags.AccPublic);
        setter.setReturnType("void");
        setter.addParameter(typeName, name);
        setter.setBody("{ \n this." + name + "=" + name + ";\n }");

        target.addChild(setter);

        IDOMMethod getter = domFactory.createMethod();
        getter.setName("get" + name.substring(0, 1).toUpperCase() + name.substring(1));
        getter.setFlags(Flags.AccPublic);
        getter.setReturnType(typeName);
        getter.setBody("{ \n return this." + name + ";\n }");

        target.addChild(getter);

    }

    //create Java file from UML class
    JavaClassOutputter.outputFile(context, target);

    return target;
}

From source file:ac.at.tuwien.dsg.uml.stereotype.export.transformation.rules.StereotypeTransformationRule.java

License:Open Source License

public Object createTarget(ITransformContext context) {
    DOMFactory domFactory = new DOMFactory();

    //create output content
    IDOMType target = domFactory.createClass();

    /**/*w  w w .j  ava2  s .c  o m*/
     * Get the transformation UML Class
     */
    Class umlCls = (Class) context.getSource();
    target.setName(umlCls.getName());

    Stereotype stereotype = (Stereotype) context.getSource();

    //get all properties
    for (Property attribute : stereotype.getAllAttributes()) {

        String name = attribute.getName();
        Type type = attribute.getType();
        String typeName = type.getName();

        org.eclipse.uml2.uml.Package packageType = type.getPackage();
        /**
         * Create Java field/class variable for each attribute 
         */
        Namespace namespace = attribute.getNamespace();

        IDOMField field = domFactory.createField();
        field.setName(name);
        field.setFlags(Flags.AccPrivate);
        /**
         * In case the model is incomplete, we add the field with Object as type
         */
        if (typeName == null) {
            field.setType("Object");
            //add in the generated code a comment explaining why field type is Object
            field.setComment(
                    "/*Type for attribute \"" + name + "\" on stereotype \"" + stereotype + "\" is null */");
            System.err.println(
                    "Type for attribute \"" + name + "\" on stereotype \"" + stereotype + "\" is null");
        } else {
            field.setType(typeName);
        }

        target.addChild(field);

        /**
         * Add setter/getter for the added field
         */
        IDOMMethod setter = domFactory.createMethod();
        /**
         * Capitalize the first letter of the variable name so we have nice camel-case 
         */
        setter.setName("set" + name.substring(0, 1).toUpperCase() + name.substring(1));
        setter.setFlags(Flags.AccPublic);
        setter.setReturnType("void");
        setter.addParameter(typeName, name);
        setter.setBody("{ \n this." + name + "=" + name + ";\n }");

        target.addChild(setter);

        IDOMMethod getter = domFactory.createMethod();
        getter.setName("get" + name.substring(0, 1).toUpperCase() + name.substring(1));
        getter.setFlags(Flags.AccPublic);
        getter.setReturnType(typeName);
        getter.setBody("{ \n return this." + name + ";\n }");

        target.addChild(getter);

    }

    //create Java file from UML class
    JavaClassOutputter.outputFile(context, target);

    return target;
}