Package org.exolab.javasource

Examples of org.exolab.javasource.JMethod


     * @param fieldInfo the collectionInfo to translate
     * @param jClass the jClass to add the method to.
     */
    private void createSetAsCopyMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod("set" + fieldInfo.getMethodSuffix());
        JParameter parameter = new JParameter(fieldInfo.getXSList().getJType(),
                fieldInfo.getContentName() + "List");
        method.addParameter(parameter);

        // create Javadoc
        JDocComment comment = method.getJDocComment();
        comment.appendComment("Sets the value of '");
        comment.appendComment(fieldInfo.getName());
        comment.appendComment(
                "' by copying the given Vector. All elements will be checked for type safety.");
        JDocDescriptor jDesc = comment.getParamDescriptor(parameter.getName());
        jDesc.setDescription("the Vector to copy.");

        // create code
        JSourceCode sourceCode = method.getSourceCode();

        sourceCode.add("// copy vector");
        sourceCode.add("this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".clear();");
View Full Code Here


     * @param jClass the jClass to add the method to.
     * @param useJava50 java version flag
     */
    private void createSetAsReferenceMethod(final CollectionInfo fieldInfo,
            final JClass jClass, final boolean useJava50) {
        JMethod method = new JMethod("set" + fieldInfo.getMethodSuffix()
                + fieldInfo.getReferenceSuffix());
        final JType collectionJType = new XMLInfoNature(fieldInfo).getSchemaType().getJType();
        JParameter parameter = new JParameter(
                collectionJType, fieldInfo.getParameterPrefix() + collectionJType.getLocalName());
        method.addParameter(parameter);

        // create Javadoc
        JDocComment comment = method.getJDocComment();
        comment.appendComment("Sets the value of '");
        comment.appendComment(fieldInfo.getName());
        comment.appendComment("' by setting it to the given Vector.");
        comment.appendComment(" No type checking is performed.");
        comment.appendComment("\n@deprecated");
        JDocDescriptor jDesc = comment.getParamDescriptor(parameter.getName());
        jDesc.setDescription("the Vector to set.");

        // create code
        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(" = ");
        sourceCode.append(parameter.getName());
        sourceCode.append(";");
View Full Code Here

     * @param fieldInfo the collectionInfo to translate
     * @param jClass the jClass to add the method to.
     */
    protected void createSetByIndexMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod("set" + fieldInfo.getMethodSuffix());

        method.addException(SGTypes.INDEX_OUT_OF_BOUNDS_EXCEPTION,
                            "if the index given is outside the bounds of the collection");
        method.addParameter(new JParameter(JType.INT, "index"));
        method.addParameter(new JParameter(fieldInfo.getContentType().getJType(),
                fieldInfo.getContentName()));

        JSourceCode sourceCode = method.getSourceCode();
        this.addIndexCheck(fieldInfo, sourceCode, method.getName());

        sourceCode.add("this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".set(index, ");
        sourceCode.append(fieldInfo.getContentType().createToJavaObjectCode(
View Full Code Here

            ++count;
        }

        //-- finish init method
        final JMethod method = jClass.getMethod(this.getInitMethodName(_maxSuffix), 0);
        method.getSourceCode().add("return members;");

        //-- add memberTable to the class, we can only add this after all the types,
        //-- or we'll create source code that will generate null pointer exceptions,
        //-- because calling init() will try to add null values to the hashtable.
        jClass.addField(fHash);
View Full Code Here

        modifiers.setFinal(true);
        modifiers.makePrivate();
        jField.setModifiers(modifiers);
        jEnum.addField(jField);

        JMethod valueMethod = new JMethod("value", new JClass("java.lang.String"),
                "the value of this constant");
        valueMethod.setSourceCode("return this.value;");
        jEnum.addMethod(valueMethod, false);

        JMethod fromValueMethod = new JMethod("fromValue", jEnum, "the constant for this value");
        fromValueMethod.addParameter(new JParameter(new JClass("java.lang.String"), "value"));
        JSourceCode sourceCode = new JSourceCode();
        sourceCode.add("for (" + jEnum.getLocalName() + " c: "
                + jEnum.getLocalName() + ".values()) {");
        sourceCode.indent();
        sourceCode.add("if (c.value.equals(value)) {");
        sourceCode.indent();
        sourceCode.add("return c;");
        sourceCode.unindent();
        sourceCode.add("}");
        sourceCode.unindent();
        sourceCode.add("}");
        sourceCode.add("throw new IllegalArgumentException(value);");
        fromValueMethod.setSourceCode(sourceCode);
        modifiers = new JModifiers();
        modifiers.setStatic(true);
        fromValueMethod.setModifiers(modifiers);
        jEnum.addMethod(fromValueMethod, false);

        JMethod setValueMethod = new JMethod("setValue");
        setValueMethod.addParameter(new JParameter(new JClass("java.lang.String"), "value"));
        jEnum.addMethod(setValueMethod, false);

        JMethod toStringMethod = new JMethod("toString",
                new JClass("java.lang.String"), "the value of this constant");
        toStringMethod.setSourceCode("return this.value;");
        jEnum.addMethod(toStringMethod, false);

        JConstructor constructor = jEnum.createConstructor();
        constructor.addParameter(new JParameter(new JClass("java.lang.String"), "value"));
        constructor.setSourceCode("this.value = value;");
View Full Code Here

     * as needed.
     * @param jClass The JClass instance for which an init method needs to be added
     * @return the JSourceCode instance for the current init() method
     */
    private JSourceCode getSourceCodeForInitMethod(final JClass jClass) {
        final JMethod currentInitMethod = jClass.getMethod(getInitMethodName(_maxSuffix), 0);
        if (currentInitMethod.getSourceCode().size() > _maxEnumerationsPerClass) {
            ++_maxSuffix;
            JMethod mInit = createInitMethod(jClass);
            currentInitMethod.getSourceCode().add("members.putAll(" + mInit.getName() + "());");
            currentInitMethod.getSourceCode().add("return members;");

            return mInit.getSourceCode();
        }
        return currentInitMethod.getSourceCode();
    }
View Full Code Here

     * Creates 'getType()' method for this enumeration class.
     * @param jClass The enumeration class to create this method for.
     * @param className The name of the class.
     */
    private void createGetTypeMethod(final JClass jClass, final String className) {
        JMethod mGetType = new JMethod("getType", JType.INT, "the type of this " + className);
        mGetType.getSourceCode().add("return this.type;");
        JDocComment jdc = mGetType.getJDocComment();
        jdc.appendComment("Returns the type of this " + className);
        jClass.addMethod(mGetType);
    }
View Full Code Here

     * @param jClass The enumeration class to create this method for.
     */
    private void createReadResolveMethod(final JClass jClass) {
        JDocComment jdc;
        JSourceCode jsc;
        JMethod mReadResolve = new JMethod("readResolve", SGTypes.OBJECT,
                                           "this deserialized object");
        mReadResolve.getModifiers().makePrivate();
        jClass.addMethod(mReadResolve);
        jdc = mReadResolve.getJDocComment();
        jdc.appendComment(" will be called during deserialization to replace ");
        jdc.appendComment("the deserialized object with the correct constant ");
        jdc.appendComment("instance.");
        jsc = mReadResolve.getSourceCode();
        jsc.add("return valueOf(this.stringValue);");
    }
View Full Code Here

     * @param jClass The enumeration class to create this method for.
     * @return an 'init()' method for this enumeration class.
     */
    private JMethod createInitMethod(final JClass jClass) {
        final String initMethodName = getInitMethodName(_maxSuffix);
        JMethod mInit = new JMethod(initMethodName,
                SGTypes.createHashtable(getConfig().useJava50()),
                "the initialized Hashtable for the member table");
        jClass.addMethod(mInit);
        mInit.getModifiers().makePrivate();
        mInit.getModifiers().setStatic(true);
        if (getConfig().useJava50()) {
            mInit.getSourceCode().add("java.util.Hashtable<Object, Object> members"
                    + " = new java.util.Hashtable<Object, Object>();");
        } else {
            mInit.getSourceCode().add("java.util.Hashtable members = new java.util.Hashtable();");
        }
        return mInit;
    }
View Full Code Here

     * Creates 'toString()' method for this enumeration class.
     * @param jClass The enumeration class to create this method for.
     * @param className The name of the class.
     */
    private void createToStringMethod(final JClass jClass, final String className) {
        JMethod mToString = new JMethod("toString", SGTypes.STRING,
                                        "the String representation of this " + className);
        jClass.addMethod(mToString);
        JDocComment jdc = mToString.getJDocComment();
        jdc.appendComment("Returns the String representation of this ");
        jdc.appendComment(className);
        mToString.getSourceCode().add("return this.stringValue;");
    }
View Full Code Here

TOP

Related Classes of org.exolab.javasource.JMethod

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.