Examples of JavadocComment


Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

                } else {
                    toString = null;
                }

                if (toString != null) {
                    JavaDocComment jdc =
                        new JavaDocComment ("@return a String representing this instance of " + typeConstructorInfo.javaClassName);
                   
                    toString.setJavaDocComment(jdc);
                }
               
                return toString;
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

                    new SwitchStatement.DefaultCase(throwStatement);
                switchStatement.addCase(defaultCase);
               
                fromOrdinal.addStatement(switchStatement);
               
                JavaDocComment jdc =
                    new JavaDocComment ("@param ordinal");
                jdc.addLine("@return the instance of " + typeConstructorInfo.javaClassName + " corresponding to the given ordinal.");
                fromOrdinal.setJavaDocComment(jdc);
               
                return fromOrdinal;
            }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

                    javaMethod.addStatement (new ReturnStatement (new JavaField.Instance (null, ORDINAL_FIELD_NAME, JavaTypeName.INT)));
                } else {
                    javaMethod.addStatement (new ReturnStatement(LiteralWrapper.make (new Integer(-1))));
                }
               
                JavaDocComment jdc =
                    new JavaDocComment ("@return the ordinal of this instance of " + typeConstructorInfo.javaClassName);
                javaMethod.setJavaDocComment(jdc);
               
                return javaMethod;
            }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

                    javaMethod.addStatement (new ReturnStatement (new JavaField.Instance (null, DC_NAME_FIELD_NAME, JavaTypeName.STRING)));
                } else {
                    javaMethod.addStatement (new ReturnStatement(LiteralWrapper.NULL));
                }
               
                JavaDocComment jdc =
                    new JavaDocComment ("@return the name of the data constructor corresponding to this instance of " + typeConstructorInfo.javaClassName);
                javaMethod.setJavaDocComment(jdc);

                return javaMethod;

            }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

                        new JavaFieldDeclaration (
                                Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL,
                                JavaTypeName.INT, ordinalFieldName, initializer);
                    dataTypeClass.addFieldDeclaration(fieldDec);
                   
                    JavaDocComment jdc =
                        new JavaDocComment ("Ordinal value corresponding to the " + dc.getName().getUnqualifiedName() + " data constructor.");
                    fieldDec.setJavaDoc(jdc);
                }
               
                // For each data constructor create a static field
                for (int i = 0, n = typeConstructor.getNDataConstructors(); i < n; ++i) {
                    DataConstructor dc = typeConstructor.getNthDataConstructor(i);
                   
                    String staticFieldName = createEnumFieldName(dc.getName().getUnqualifiedName());
                   
                    JavaExpression initializer =
                        new JavaExpression.ClassInstanceCreationExpression(
                                dataType_TypeName,
                                new JavaExpression[]{
                                        new JavaField.Static(
                                                dataType_TypeName,
                                                staticFieldName + "_ORDINAL",
                                                JavaTypeName.INT),
                                        LiteralWrapper.make(dc.getName().getUnqualifiedName())},
                                constructorArgTypes);
                   
                    JavaFieldDeclaration fieldDec =
                        new JavaFieldDeclaration (
                                Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL,
                                dataType_TypeName, staticFieldName, initializer);

                    JavaDocComment jdc =
                        new JavaDocComment ("This instance of " + typeConstructorInfo.javaClassName + " representing the " + dc.getName().getUnqualifiedName() + " data constructor.");
                    fieldDec.setJavaDoc(jdc);

                    dataTypeClass.addFieldDeclaration(fieldDec);
                }
               
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

        // module with "_internal" appended.
        JavaClassRep bindingClass =
            new JavaClassRep (bindingClassTypeName, JavaTypeName.OBJECT, Modifier.PUBLIC | Modifier.FINAL, EMPTY_TYPE_NAME_ARRAY);
       
        // We want to insert the CALDoc comment for the module as a comment for the class.
        JavaDocComment jdc;
        CALDocComment moduleComment = moduleTypeInfo.getCALDocComment();
        if (moduleComment != null) {
            String convertedComment = calDocCommentToJavaComment (moduleComment, null, true);
            jdc = new JavaDocComment (convertedComment);
        } else {
            // If there is no module comment from the CAL source we should just
            // create a generic one.
            jdc = new JavaDocComment ("This class (" + bindingClassName + ") provides Java constants, methods, etc.");
            jdc.addLine("which make it easier to bind client Java code to the Java code generated");
            jdc.addLine("from CAL source in a safe fashion");
        }
       
        bindingClass.setJavaDoc(jdc);

        // 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 (" + bindingClass.getClassName().getUnqualifiedJavaSourceName() + ".java)");
        mlc.addLine("was generated from CAL module: " + module.getName() + ".");
        mlc.addLine("The constants and methods provided are intended to facilitate accessing the");
        mlc.addLine(module.getName() + " module from Java code.");
        mlc.addLine(" ");
        mlc.addLine("Creation date: " + new Date());
        mlc.addLine("--!>");
        mlc.addLine(" ");
        bindingClass.setComment(mlc);
       
        // Add the module name field.
        JavaFieldDeclaration moduleNameDeclaration =
            new JavaFieldDeclaration (PUBLIC_STATIC_FINAL, JavaTypeName.MODULE_NAME, MODULE_NAME_FIELD_NAME,
                new JavaExpression.MethodInvocation.Static(
                    JavaTypeName.MODULE_NAME,
                    "make",
                    new JavaExpression[]{JavaExpression.LiteralWrapper.make(moduleTypeInfo.getModuleName().toSourceText())},
                    new JavaTypeName[]{JavaTypeName.STRING},
                    JavaTypeName.MODULE_NAME));
       
        bindingClass.addFieldDeclaration(moduleNameDeclaration);
       
        // Add the inner class for type classes.
        buildTypeClassInnerClass(bindingClass, moduleTypeInfo, bindingClassName);
       
        // Add the inner class for type constructors.
        buildTypeConstructorsInnerClass(bindingClass, moduleTypeInfo, bindingClassName);
       
        // Add the inner class for data constructors.
        buildDataConstructorsInnerClass(bindingClass, moduleTypeInfo, bindingClassName);
       
        // Add the inner class for functions.
        buildFunctionsInnerClass(bindingClass, moduleTypeInfo, bindingClassName);
       
        int javaDocHash = computeJavaDocHash(bindingClass);
       
        JavaFieldDeclaration javaDocHashField =
            new JavaFieldDeclaration(PUBLIC_STATIC_FINAL, JavaTypeName.INT, JavaBindingGenerator.JAVADOC_HASH_FIELD_NAME, LiteralWrapper.make(Integer.valueOf(javaDocHash)));
        JavaDocComment javaDocHashFieldComment = new JavaDocComment("A hash of the concatenated JavaDoc for this class (including inner classes).");
        javaDocHashFieldComment.addLine("This value is used when checking for changes to generated binding classes.");
        javaDocHashField.setJavaDoc(javaDocHashFieldComment);
        bindingClass.addFieldDeclaration(javaDocHashField);
       
        return bindingClass;
    }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

                            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));
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

                            Modifier.PRIVATE | Modifier.VOLATILE,
                            JavaTypeName.INT,
                            HASH_CODE_FIELD_NAME,
                            LiteralWrapper.make(new Integer(0)));
               
                hashCodeFieldDecl.setJavaDoc(new JavaDocComment("Lazily initialized, cached hashCode."));
               
                dcClass.addFieldDeclaration(hashCodeFieldDecl);

                for (int i = 0, n = dc.getArity(); i < n; ++i) {
                    FieldName fieldName = dc.getNthFieldName(i);
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

                    JavaTypeName.OBJECT,
                    PUBLIC_STATIC_FINAL,
                    EMPTY_TYPE_NAME_ARRAY);

        // Add the class JavaDoc
        JavaDocComment jdc = new JavaDocComment("This inner class (" + FUNCTION_CLASS_NAME + ") contains constants");
        jdc.addLine("and methods related to binding to CAL functions in the " + moduleTypeInfo.getModuleName() + " module.");
        functionsClass.setJavaDoc(jdc);
       
        // Build up and sort the list of function names.
        Map<String, FunctionalAgent> nameToFuncInfo = new TreeMap<String, FunctionalAgent>();
        for (int i = 0, n = moduleTypeInfo.getNFunctions(); i < n; ++i) {
            Function fe = moduleTypeInfo.getNthFunction(i);
            if (fe.getScope().isPublic() != publicEntities) {
                continue;
            }
            nameToFuncInfo.put(fe.getName().getUnqualifiedName(), fe);
        }
       
        for (int i = 0, n = moduleTypeInfo.getNTypeClasses(); i < n; ++i) {
            TypeClass tc = moduleTypeInfo.getNthTypeClass(i);

           
            for (int j = 0, k = tc.getNClassMethods(); j < k; ++j) {
                ClassMethod cm = tc.getNthClassMethod(j);
                if (cm.getScope().isPublic() == publicEntities) {
                    nameToFuncInfo.put(cm.getName().getUnqualifiedName(), cm);
                }
            }
        }

        if (nameToFuncInfo.size() == 0) {
            return;
        }
       
        bindingClass.addInnerClass(functionsClass);
       
       
        //  Now go over the function names and generate the helper functions and
        // QualifiedName constant.
        for (final Map.Entry<String, FunctionalAgent> entry : nameToFuncInfo.entrySet()) {
          
            String calFuncName = entry.getKey();
            FunctionalAgent functionalAgent = entry.getValue();

            CALDocComment cdc = functionalAgent.getCALDocComment();

            // We need to make sure the name for the helper function/qualified name field is
            // a valid java name.
            String javaFuncName = fixupVarName(calFuncName);
           
            // Add a binding method for the CAL function.
            // Essentially this method builds an application
            // of the function to the supplied arguments using our
            // source model.
           
            // Build up the argument names and types.
            TypeExpr te = functionalAgent.getTypeExpr();
            int nArgs = te.getArity();
            int nNamedArgs = functionalAgent.getNArgumentNames();
           
            String paramNames[] = CALDocToJavaDocUtilities.getArgumentNamesFromCALDocComment(cdc, functionalAgent);
            if (paramNames.length != nArgs)  {
                throw new NullPointerException ("Mismatch between arity and number of arguments for " + calFuncName);
            }
            String origParamNames[] = new String[paramNames.length];
            System.arraycopy(paramNames, 0, origParamNames, 0, origParamNames.length);
           
            JavaTypeName paramTypes[] = new JavaTypeName [paramNames.length];
           
            // If we have named arguments we should use those names.
            Set<String> paramNamesSet = new HashSet<String>();
            for (int i = 0; i < paramNames.length; ++i) {
                String name = paramNames[i];

                if (name == null) {
                    if (i < nNamedArgs) {
                        name = functionalAgent.getArgumentName(i);
                    }
                   
                    if (name == null || name.equals("")) {
                        name = null;
                        // There is no name for this argument in the functional entity.  This
                        // usually occurs with foreign functions and class methods because
                        // you don't have to explicitly name the arguments.
                       
                        // Check to see if there was a CALDoc comment that named the arguments.
                        if (cdc != null && cdc.getNArgBlocks() == paramNames.length) {
                            name = cdc.getNthArgBlock(i).getArgName().getCalSourceForm();
                        }
                       
                        // If we still don't have an argument name just build one.
                        if (name == null) {
                            name = "arg_" + (i+1);
                        }
                    }
                   
                    // Make sure name is unique.
                    String baseName = name;
                    int suffix = 0;
                    while (paramNamesSet.contains(name)) {
                        name = baseName + "_" + suffix++;
                    }
                }
               
                origParamNames[i] = name;
                paramNames[i] = fixupVarName(name);
                paramTypes[i] = SOURCE_MODEL_EXPR_TYPE_NAME;
            }
           
            // Get the JavaDoc for the helper function.  If there is CALDoc
            // for the function we translate it to JavaDoc. 
            JavaDocComment funcComment;
            if (cdc != null) {
                funcComment = new JavaDocComment(calDocCommentToJavaComment(cdc, functionalAgent, false));
                funcComment = fixupJavaDoc(funcComment, origParamNames, paramNames);
            } else {
                funcComment = new JavaDocComment("Helper binding method for function: " + calFuncName + ". ");
                for (int iName = 0; iName < paramNames.length; ++iName) {
                    funcComment.addLine("@param " + paramNames[iName]);
                }
                funcComment.addLine("@return the SourceModule.expr representing an application of " + calFuncName);
            }
           
           
            // Create the method.
            JavaMethod bindingMethod =
                new JavaMethod(PUBLIC_STATIC_FINAL,
                               SOURCE_MODEL_EXPR_TYPE_NAME,
                               paramNames,
                               paramTypes,
                               null, javaFuncName);
            functionsClass.addMethod(bindingMethod);
           
            // Add the JavaDoc
            bindingMethod.setJavaDocComment(funcComment);
           
            // Build up the body of the method.
           
            // We want to us the QualifiedName field.
            JavaField nameField = new JavaField.Static(functionsClassTypeName, javaFuncName, QUALIFIED_NAME_TYPE_NAME);
           
            // Create an instance of SourceModel.Expr.Var for the CAL function.
            JavaExpression sourceModelVarCreation =
                new MethodInvocation.Static(
                        SOURCE_MODEL_EXPR_VAR_TYPE_NAME,
                        "make",
                        nameField,
                        QUALIFIED_NAME_TYPE_NAME,
                        SOURCE_MODEL_EXPR_VAR_TYPE_NAME);
           
            // For the comment for this method we want an @see referring to the previous method.
            String atSee = "@see #" + javaFuncName + "(";
            for (int iArg = 0; iArg < paramNames.length; ++iArg) {
                if (iArg == 0) {
                    atSee = atSee + paramTypes[iArg].getFullJavaSourceName();
                } else {
                    atSee = atSee + ", " + paramTypes[iArg].getFullJavaSourceName();
                }
            }
            atSee = atSee + ")";
           
            if (paramNames.length == 0) {
                // Simply return the Expr.Var
                bindingMethod.addStatement(new ReturnStatement(sourceModelVarCreation));
            } else {
                // Need to create an application.
               
                // Create an array of SourceModel.Expr.  The first element is the SourceModel.Expr.Var
                // for the CAL function the remaining elements are the function arguments.
                JavaExpression arrayElements[] = new JavaExpression[paramNames.length + 1];
                arrayElements[0] = sourceModelVarCreation;
               
                for (int i = 1; i <= paramNames.length; ++i) {
                    arrayElements[i] = new JavaExpression.MethodVariable(paramNames[i-1]);
                }
               
                // Build the array creation expression.
                JavaExpression arrayCreation =
                    new JavaExpression.ArrayCreationExpression(SOURCE_MODEL_EXPR_TYPE_NAME, arrayElements);
               
                // Invoke SourceModel.Expr.Application.make()
                MethodInvocation makeApply =
                    new MethodInvocation.Static(
                            SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME,
                            "make",
                            arrayCreation,
                            JavaTypeName.makeArrayType(SOURCE_MODEL_EXPR_TYPE_NAME),
                            SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME);
               
                bindingMethod.addStatement(new ReturnStatement (makeApply));
           
                // If any of the argument types correspond to a Java type.
                // (eg. Prelude.Int, Prelude.Long, etc. we can generate a version
                // of the binding function that takes these argument types.
                boolean primArgs = false;

                TypeExpr[] pieces = te.getTypePieces();
                for (int i = 0; i < paramNames.length; ++i) {
                    if (canTypeBeUnboxed(pieces[i])) {
                        primArgs = true;
                        // Change the param type.
                        paramTypes[i] = typeExprToTypeName(pieces[i]);
                       
                        // Since the parameter will now be an int, boolean, long, etc. we
                        // need to create the appropriate SourceModel wrapper around the
                        // value.
                        arrayElements[i+1] = wrapArgument(paramNames[i], pieces[i]);
                    }
                }
               
                if (primArgs) {
                    // Create the alternate helper method.
                    bindingMethod =
                        new JavaMethod(PUBLIC_STATIC_FINAL,
                                       SOURCE_MODEL_EXPR_TYPE_NAME,
                                       paramNames,
                                       paramTypes,
                                       null, javaFuncName);
                    functionsClass.addMethod(bindingMethod);
                   
                    JavaStatement.JavaDocComment comment = new JavaStatement.JavaDocComment(atSee);
                    for (int iArg = 0; iArg < paramNames.length; ++iArg) {
                        comment.addLine("@param " + paramNames[iArg]);
                    }                       
                    comment.addLine("@return the SourceModel.Expr representing an application of " + calFuncName);
                    bindingMethod.setJavaDocComment(comment);
                   
                    arrayCreation =
                        new JavaExpression.ArrayCreationExpression(SOURCE_MODEL_EXPR_TYPE_NAME, arrayElements);
                   
                    makeApply =
                        new MethodInvocation.Static(
                                SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME,
                                "make",
                                arrayCreation,
                                JavaTypeName.makeArrayType(SOURCE_MODEL_EXPR_TYPE_NAME),
                                SOURCE_MODEL_EXPR_APPLICATION_TYPE_NAME);
                   
                    bindingMethod.addStatement(new ReturnStatement (makeApply));
   
                }
            }
           
            // Add a field for the function name.
            // 'static final QualifiedName functionName = "functionName";'
            // We need to check for conflict between the functionName
            // and java keywords.  It is valid to have a CAL
            // function called assert but not valid to have java code
            // 'static final Qualifiedname assert = ...
            JavaFieldDeclaration jfd =
                makeQualifiedNameDeclaration(javaFuncName, calFuncName);
            JavaDocComment qfComment = new JavaDocComment("Name binding for function: " + calFuncName + ".");
            qfComment.addLine(atSee);
            jfd.setJavaDoc(qfComment);

           
            functionsClass.addFieldDeclaration(jfd);
        }
View Full Code Here

Examples of org.openquark.cal.internal.javamodel.JavaStatement.JavaDocComment

               
                JavaMethod javaMethod = new JavaMethod(Modifier.PUBLIC, JavaTypeName.INT, GET_DC_ORDINAL_METHOD_NAME);
                // return dc ordinal.
                javaMethod.addStatement (new ReturnStatement(LiteralWrapper.make (new Integer (ordinal))));

                JavaDocComment jdc =
                    new JavaDocComment ("@return the ordinal of this instance of " + typeConstructorInfo.javaClassName);
                javaMethod.setJavaDocComment(jdc);

                return javaMethod;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.