Package org.openquark.cal.internal.javamodel

Examples of org.openquark.cal.internal.javamodel.JavaClassRep


            JavaDataClassGenerator javaDataClassGenerator =
                new JavaDataClassGenerator(
                        targetPackage,
                        typeConstructorInfo);
           
            JavaClassRep javaClass = javaDataClassGenerator.generateClassForType();
            classReps.put(tc.getName(), javaClass);
            classLogMessages.put(tc.getName(), javaDataClassGenerator.logMessages);
           
            // Generate the CAL I/O
            CAL_IO_Generator ioGenerator =
View Full Code Here


           
           
            // Import the constructors for each inner class (i.e. each data constructor)
            // Pull in the constructor for the Java class.
            for (int i = 0, n = javaClass.getNInnerClasses(); i < n; ++i) {
                JavaClassRep innerClass = javaClass.getInnerClass(i);
                assert (innerClass.getNConstructors() == 1);
                JavaConstructor constructor = innerClass.getConstructor(0);
                topLevelDefnsList.add(importJavaConstructor(constructor, true));
            }
           
            // Create accessors for fields in the top level class.
            for (FieldName fn : typeConstructorInfo.commonFieldNames) {
View Full Code Here

            TypeExpr[] dcFieldTypeExprs = getFieldTypesForDC(dc);

            JavaConstructor javaConstructor = null;
            if (isInnerClass) {
                for (int i = 0, n = javaClass.getNInnerClasses(); i < n; ++i) {
                    JavaClassRep innerClass = javaClass.getInnerClass(i);
                    if (innerClass.getClassName().getUnqualifiedJavaSourceName().endsWith("." + javaConstructorName)) {
                        javaConstructor = innerClass.getConstructor(0);
                        break;
                    }
                }
            } else {
                javaConstructor = javaClass.getConstructor(0);
View Full Code Here

            JavaTypeName typeConstructorClassName =
                JavaTypeName.make(targetPackage + "." + typeConstructorInfo.javaClassName, false);
   
            TypeConstructor typeConstructor = typeConstructorInfo.typeConstructor;
           
            JavaClassRep outerTypeDefinition =
                new OuterTypeDefinitionGenerator().generateOuterTypeDefinition(typeConstructorClassName);
           
            // Now we need to generate inner classes for each data constructor.
            // This is only necessary if the data type is not an enumeration.
            if (!typeConstructorInfo.isEnumerationType) {
               
                for (int i = 0, n = typeConstructor.getNDataConstructors(); i < n; ++i) {
                    DataConstructor dc = typeConstructor.getNthDataConstructor(i);
                    JavaClassRep dcClass = new InnerDCClassGenerator().generateInnerDCClass(dc, typeConstructorInfo, typeConstructorClassName);
                   
                    outerTypeDefinition.addInnerClass(dcClass);
                }
            }
   
View Full Code Here

                JavaTypeName superClassTypeName = JavaTypeName.OBJECT;
       
                // No interfaces are implemented
                JavaTypeName[] interfaces = IO_Source_Generator.EMPTY_TYPE_NAME_ARRAY;
       
                JavaClassRep javaClassRep =
                    new JavaClassRep(
                            typeConstructorClassName,
                            superClassTypeName,
                            classModifiers,
                            interfaces);
               
                // Add a comment for the top of the source file.
                MultiLineComment mlc = new MultiLineComment("<!--");
                mlc.addLine(" ");
                mlc.addLine("**************************************************************");
                mlc.addLine("This Java source has been automatically generated.");
                mlc.addLine("MODIFICATIONS TO THIS SOURCE MAY BE OVERWRITTEN - DO NOT MODIFY THIS FILE");
                mlc.addLine("**************************************************************");
                mlc.addLine(" ");
                mlc.addLine(" ");
                mlc.addLine("This file (" + javaClassRep.getClassName().getUnqualifiedJavaSourceName() + ".java)");
                mlc.addLine("was generated from CAL type constructor: " + typeConstructorInfo.typeConstructor.getName() + ".");
                mlc.addLine(" ");
                mlc.addLine("Creation date: " + new Date());
                mlc.addLine("--!>");
                mlc.addLine(" ");
               
                javaClassRep.setComment(mlc);
               
                // We want to insert the CALDoc comment for the type as a JavaDoc comment for the class.
                JavaDocComment jdc =
                    new JavaDocComment ("This class (" + javaClassRep.getClassName().getUnqualifiedJavaSourceName() + ") provides a Java data class corresponding to");
                    jdc.addLine("the CAL type constructor " + typeConstructorInfo.typeConstructor.getName() + ".");
                    jdc.addLine("");
                   
                if (typeConstructorInfo.isEnumerationType) {
                    jdc.addLine("This type constructor is an enumeration. (i.e. all data constructors have no fields)");
                    jdc.addLine("The individual data constructors are represented by instances of " + javaClassRep.getClassName().getUnqualifiedJavaSourceName() + " held ");
                    jdc.addLine("in static final fields.");
                } else {
                    jdc.addLine("Because the type constructor has only one data constructor, with the same name");
                    jdc.addLine("as the type constructor this class also represents instances of the data constructor.");
                }
               
                javaClassRep.setJavaDoc(jdc);
               
                // Generate fields in this class for any fields which are common to all data constructors.
                createFields(javaClassRep, typeConstructorInfo);
       
                if (typeConstructorInfo.isEnumerationType) {
                    // Add instance fields for name and ordinal
                    // Add static final fields for each data constructor
                    createFields_Enumeration(typeConstructorInfo.typeConstructor, javaClassRep, typeConstructorClassName);

                    // Add a function which takes an int value for the
                    // ordinal and returns the corresponding enum instance.
                    javaClassRep.addMethod(createMethod_fromOrdinal (typeConstructorClassName));
                }
               
                if (typeConstructorInfo.commonFieldNames.size() > 0) {
                    javaClassRep.addConstructor(createConstructor(typeConstructorInfo, typeConstructorClassName));
                } else {
                    javaClassRep.addConstructor(createConstructor_default(typeConstructorClassName, typeConstructorInfo.isEnumerationType));
                   
                }
               
                // Create a get_FieldName method for each unique field name in the set of
                // data constructors. 
                // If the field is common to all DCs it will be implemented at this
                // level.  Otherwise the implementation at this level throws an error
                // and the DC classes are expected to override it.
                for (FieldName fieldName : typeConstructorInfo.commonFieldNames) {
                    String javaFieldName = (String)typeConstructorInfo.fieldJavaNames.get(fieldName);
                    Set<JavaTypeName> fieldTypes = typeConstructorInfo.allFieldTypeNames.get(fieldName);
                   
                    for (JavaTypeName type  : fieldTypes) {
                        String accessorMethodName = (String)typeConstructorInfo.fieldJavaAccessorMethodNames.get(fieldName);
                        JavaMethod getter = createMethod_getField (
                                accessorMethodName,
                                javaFieldName,
                                type,
                                true);
                       
                        javaClassRep.addMethod(getter);
                       
                        getter.setJavaDocComment(new JavaDocComment ("@return " + fieldName));
                    }
                }
               
   
                javaClassRep.addMethod(createMethod_getDCName(typeConstructorInfo));
               
                javaClassRep.addMethod(createMethod_getDCOrdinal(typeConstructorInfo));
               
                JavaMethod toString = createMethod_toString();
                if (toString != null) {
                    javaClassRep.addMethod (toString);
                }
               
                if (typeConstructorInfo.isEnumerationType) {
                    JavaMethod equals = JavaDataClassGenerator.this.createMethod_equals(
                            typeConstructorClassName,
                            typeConstructorInfo.commonFieldNames,
                            typeConstructorInfo.commonFieldTypes);

                    javaClassRep.addMethod (equals);
                }
               
                createMethod_hashCode (javaClassRep);
               
                return javaClassRep;
View Full Code Here

               
                JavaTypeName dcClassTypeName =
                    JavaTypeName.make(
                            typeConstructorClassName.getFullJavaSourceName() + "$" + dcInfo.innerClassName, false);
               
                JavaClassRep dcClass =
                    new JavaClassRep(
                            dcClassTypeName,
                            typeConstructorClassName,
                            classModifiers,
                            IO_Source_Generator.EMPTY_TYPE_NAME_ARRAY);
   
                JavaDocComment jdc =
                    new JavaDocComment ("This class represents instances of the CAL data constructor " + dc.getName() + ".");
                dcClass.setJavaDoc(jdc);
               
                createFields (dcClass, dc, typeConstructorInfo);
               
                dcClass.addConstructor(createConstructor(dc, typeConstructorInfo, dcClassTypeName));
               
                dcClass.addMethod(createMethod_getDCName(dc.getName().getUnqualifiedName()));
   
                for (FieldName fieldName : dcInfo.fieldTypeNames.keySet()) {
                    if (typeConstructorInfo.commonFieldNames.contains(fieldName)) {
                        continue;
                    }
                    JavaTypeName fieldType = (JavaTypeName)dcInfo.fieldTypeNames.get(fieldName);
                    String javaFieldName = (String)typeConstructorInfo.fieldJavaNames.get(fieldName);
                   
                    String accessorName = (String)typeConstructorInfo.fieldJavaAccessorMethodNames.get(fieldName);
                    JavaMethod getter = createMethod_getField(accessorName, javaFieldName, fieldType, true);
                   
                    dcClass.addMethod(getter);
                }
   
                dcClass.addMethod(createMethod_getDCOrdinal(dc.getOrdinal()));

                dcClass.addMethod (JavaDataClassGenerator.this.createMethod_toString(dcInfo.allFieldNames, dcInfo.fieldTypeNames));

                dcClass.addMethod (
                        JavaDataClassGenerator.this.createMethod_equals(
                                dcClassTypeName,
                                dcInfo.allFieldNames,
                                dcInfo.fieldTypeNames));

                dcClass.addMethod (
                        JavaDataClassGenerator.this.createMethod_hashCode(
                                dcInfo.allFieldNames,
                                dcInfo.fieldTypeNames));

                return dcClass;
View Full Code Here

       
        boolean firstWrite = true;
       
        // Write out each Java class.
        for (Map.Entry<QualifiedName, JavaClassRep> entry : javaClassReps.entrySet()) {
            JavaClassRep classRep = (JavaClassRep)entry.getValue();
            QualifiedName qn = (QualifiedName)entry.getKey();
           
            if (writeJavaClass(generatedCodeRoot, moduleName, targetPackage, classRep)) {
                if (firstWrite) {
                    firstWrite = false;
View Full Code Here

         * The returned class will include any inner classes.
         * @return JavaClassRep
         * @throws CodeGenerationException
         */
        JavaClassRep generateDataConsDefinition() throws CodeGenerationException {
            JavaClassRep dcClass = getDataConsDefinition();
            dcClass.addInnerClass(getDCFieldSelectionClass());

            return dcClass;
        }
View Full Code Here

                // No interfaces are implemented
                JavaTypeName[] interfaces = JavaDefinitionBuilder.EMPTY_TYPE_NAME_ARRAY;

                // Now instantiate the java class representation.
                this.javaClassRep = new JavaClassRep(className, dataTypeClassName, classModifiers, interfaces);

                createFields();

                // There are two situations where we construct a 'data type' object: 1) fully saturated
                // 2) where it is the beginning of an application chain.  For case 1 we need a constructor
View Full Code Here

            // No interfaces are implemented
            JavaTypeName[] interfaces = JavaDefinitionBuilder.EMPTY_TYPE_NAME_ARRAY;
            JavaTypeName fieldSelectionTypeName = CALToJavaNames.createFieldSelectionClassTypeNameFromDC(dc, module);
            // Now instantiate the java class representation.
            JavaClassRep fieldSelectionClass = new JavaClassRep(fieldSelectionTypeName, JavaTypeNames.RTDATACONS_FIELD_SELECTION, classModifiers, interfaces);

            // Add the constructor: FieldSelection (RTValue $dataConsExpr, int $fieldOrdinal, ErrorInfo $errorInfo);
            fieldSelectionClass.addConstructor(createDCFieldSelectionClass_constructor ());

            // Add the method: private final String getFieldNameByOrdinal (int ordinal);
            fieldSelectionClass.addMethod(createDCFieldSelectionClass_method_getFieldNameByOrdinal());

            fieldSelectionClass.addMethod (createDCFieldSelectionClass_method_getDCName());

            return fieldSelectionClass;
        }
View Full Code Here

TOP

Related Classes of org.openquark.cal.internal.javamodel.JavaClassRep

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.