Package org.openquark.cal.internal.javamodel

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


                JavaExpression assign = new Assignment (field, mv);
                constructorBody.addStatement(new ExpressionStatement(assign));
                i++;
            }

            JavaConstructor constructor = new JavaConstructor (Modifier.PROTECTED, argNames, argTypes, className.getUnqualifiedJavaSourceName());
            constructor.addStatement(constructorBody);

            return constructor;
        }
View Full Code Here


            // private final int tag;
            JavaFieldDeclaration tagField = new JavaFieldDeclaration (Modifier.PRIVATE | Modifier.FINAL, JavaTypeName.INT, "tag", null);
            tagDCClassRep.addFieldDeclaration(tagField);

            // public TagDC(int tagVal) {this.tag = tagVal;}
            JavaConstructor javaConstructor = new JavaConstructor(Modifier.PUBLIC, new String[]{"tagVal"}, new JavaTypeName[]{JavaTypeName.INT}, "TagDC");
            tagDCClassRep.addConstructor(javaConstructor);
            Assignment tagAssign = new Assignment (new JavaField.Instance(null, "tag", JavaTypeName.INT), METHODVAR_TAGVAL);
            javaConstructor.addStatement(new ExpressionStatement(tagAssign));



            // public final int getArity() {return 0;}
            int modifiers = Modifier.PUBLIC | Modifier.FINAL;
View Full Code Here

        private void createConstructor() {
            int modifiers = Modifier.PRIVATE;

            // Add the method to the class.
            if (functions.getNFunctions() <= 1) {
                JavaConstructor javaConstructor =
                    new JavaConstructor(modifiers,
                                        new String[]{},
                                        new JavaTypeName[]{},
                                        ((JavaTypeName.Reference.Object)className).getBaseName());
                    javaClassRep.addConstructor(javaConstructor);
            } else {
                JavaConstructor javaConstructor =
                new JavaConstructor(modifiers,
                                    new String[]{"scIndex", "arityValue"},
                                    new JavaTypeName[]{JavaTypeName.INT, JavaTypeName.INT},
                                    ((JavaTypeName.Reference.Object)className).getBaseName());
                javaClassRep.addConstructor(javaConstructor);

                // Now fill in the constructor body.

                // assign the tag field.
                JavaField tagField = new JavaField.Instance(null, SCDefinitionBuilder.functionTagFieldName, JavaTypeName.INT);
                MethodVariable tagArgument = new MethodVariable("scIndex");
                JavaExpression.Assignment tagAssign = new JavaExpression.Assignment(tagField, tagArgument);
                javaConstructor.addStatement(new ExpressionStatement(tagAssign));

                // asign the arity.
                JavaExpression.Assignment assignArity =
                    new JavaExpression.Assignment(
                            new JavaField.Instance(null, "arity", JavaTypeName.INT),
                            new MethodVariable("arityValue"));

                javaConstructor.addStatement (new ExpressionStatement (assignArity));
            }
        }
View Full Code Here

                    argTypes[i+1] = SCJavaDefn.typeExprToTypeName(mf.getParameterTypes()[i]);
                }
            }

            // Add the constructor to the class.
            JavaConstructor javaConstructor =
                new JavaConstructor(Modifier.PUBLIC, argNames, argTypes, constructorName);

            // Add the body of the constructor

            // Check for null argument values via assert.
            JavaExpression argCheck = new OperatorExpression.Binary (JavaOperator.NOT_EQUALS_OBJECT, argVars[0], LiteralWrapper.NULL);
            for (int i = 1; i < argNames.length; ++i) {
                // We only do the null pointer check on arguments of type RTValue.
                // It is valid to have an external object (ex. String) which is null.
                if (argTypes[i].equals(JavaTypeNames.RTVALUE)) {
                    JavaExpression compareArg = new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_OBJECT, new MethodVariable(argNames[i]), LiteralWrapper.NULL);
                    argCheck = new JavaExpression.OperatorExpression.Binary(JavaOperator.CONDITIONAL_AND, argCheck, compareArg);
                }
            }
            javaConstructor.addStatement(
                    new AssertStatement(
                            argCheck,
                            new MethodInvocation.Instance(null, "badConsArgMsg", JavaTypeName.STRING, MethodInvocation.InvocationType.VIRTUAL),
                            JavaTypeName.STRING));

            // Assign the argument values to the class fields.
            javaConstructor.addStatement(new ExpressionStatement(new Assignment(functionField, new MethodVariable(argNames[0]))));
            for (int i = 1; i < argNames.length; i++) {
                JavaField field = functionArgumentMemberFields[i-1];
                Assignment memberAssignment = new Assignment(field, new MethodVariable(argNames[i]));
                javaConstructor.addStatement(new ExpressionStatement(memberAssignment));

            }

            return javaConstructor;
        }
View Full Code Here

                argNames[i+1] = "$" + CALToJavaNames.fixupVarName(mf.getParameterNames()[i]);
                argVars[i+1] = new MethodVariable(argNames[i+1]);
            }

            // Create the constructor.
            JavaConstructor javaConstructor =
                new JavaConstructor(Modifier.PUBLIC, argNames, argTypes, constructorName);

            // Add the body of the constructor


            // We check for null argument values via assert.
            JavaExpression argCheck = new OperatorExpression.Binary (JavaOperator.NOT_EQUALS_OBJECT, argVars[0], LiteralWrapper.NULL);
            for (int i = 1; i < argNames.length; ++i) {
                JavaExpression compareArg = new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_OBJECT, argVars[i], LiteralWrapper.NULL);
                argCheck = new JavaExpression.OperatorExpression.Binary(JavaOperator.CONDITIONAL_AND, argCheck, compareArg);
            }
            javaConstructor.addStatement(
                    new AssertStatement(argCheck,
                                        new MethodInvocation.Instance(null, "badConsArgMsg", JavaTypeName.STRING, MethodInvocation.InvocationType.VIRTUAL),
                                        JavaTypeName.STRING));

            // Assign the constructor arguments to the class fields.
            javaConstructor.addStatement(new ExpressionStatement(new Assignment(functionField, argVars[0])));
            for (int i = 1; i < argNames.length; i++) {
                JavaField field = functionArgumentMemberFields[i-1];
                Assignment memberAssignment = new Assignment(field, argVars[i]);
                javaConstructor.addStatement(new ExpressionStatement(memberAssignment));
            }

            return javaConstructor;
        }
View Full Code Here

        //
        // Also, this makes the assumption that if the class name has passed validation thus far, the JavaTypeName
        // is in fact a JavaTypeName.Reference.Object
        //
        final String classConstructorName = ((JavaTypeName.Reference.Object)classJavaTypeName).getInternalUnqualifiedName();
        return new JavaConstructor(Modifier.PRIVATE, classConstructorName);
    }
View Full Code Here

TOP

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

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.