Package org.exolab.javasource

Examples of org.exolab.javasource.JMethod


    private void createGetAsArrayMethod(final CollectionInfo fieldInfo,
            final JClass jClass, final boolean useJava50,
            AnnotationBuilder[] annotationBuilders) {
        JType baseType = fieldInfo.getContentType().getJType();
        JType arrayType = new JArrayType(baseType, useJava50);
        JMethod method = new JMethod(fieldInfo.getReadMethodName(), arrayType,
                                     "this collection as an Array");

        JSourceCode sourceCode = method.getSourceCode();

        // create Javadoc
        JDocComment comment = method.getJDocComment();
        comment.appendComment("Returns the contents of the collection in an Array.  ");

        if (!(baseType.isPrimitive())) {
            // For non-primitive types, we use the API method made for this purpose
            comment.appendComment("<p>");
View Full Code Here


     * @param fieldInfo the collectionInfo to translate
     * @param jClass the jClass to add the method to.
     */
    private void createGetAsReferenceMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod(fieldInfo.getReadMethodName()
                + fieldInfo.getReferenceMethodSuffix(),
                fieldInfo.getXSList().getJType(),
                "a reference to the Vector backing this class");

        // create Javadoc
        JDocComment comment = method.getJDocComment();
        comment.appendComment("Returns a reference to '");
        comment.appendComment(fieldInfo.getName());
        comment.appendComment("'. No type checking is performed on any ");
        comment.appendComment("modifications to the Vector.");

        // create code
        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("return this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(";");

        jClass.addMethod(method);
View Full Code Here

     * @param jClass the jClass to add the method to.
     */
    protected void createGetByIndexMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        XSType contentType = fieldInfo.getContentType();
        JMethod method = new JMethod(fieldInfo.getReadMethodName(), contentType.getJType(),
                "the value of the " + contentType.getJType().toString() + " at the given index");

        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"));

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

        String value = fieldInfo.getName() + ".get(index)";
        sourceCode.add("return ");
        if (contentType.getType() == XSType.CLASS) {
            sourceCode.append("(");
            sourceCode.append(method.getReturnType().toString());
            sourceCode.append(") ");
            sourceCode.append(value);
        } else {
            sourceCode.append(contentType.createFromJavaObjectCode(value));
        }
View Full Code Here

     * @param fieldInfo the collectionInfo to translate
     * @param jClass the jClass to add the method to.
     */
    private void createGetCountMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod(fieldInfo.getReadMethodName() + "Count", JType.INT,
                                     "the size of this collection");

        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("return this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".size();");

        jClass.addMethod(method);
View Full Code Here

     * @param jClass the jClass to add the method to.
     * @param useJava50 java version flag
     */
    protected void createAddByIndexMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod(fieldInfo.getWriteMethodName());
        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"));
        final JParameter parameter = new JParameter(
            fieldInfo.getContentType().getJType(), fieldInfo.getContentName());
        method.addParameter(parameter);

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

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

     * @param jClass the jClass to add the method to.
     * @param useJava50 java version flag
     */
    protected void createIteratorMethod(final CollectionInfo fieldInfo,
            final JClass jClass, final boolean useJava50) {
        JMethod method = new JMethod("iterate" + fieldInfo.getMethodSuffix(),
                SGTypes.createIterator(fieldInfo.getContentType().getJType(), useJava50, true),
                "an Iterator over all possible elements in this collection");

        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("return this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".iterator();");

        jClass.addMethod(method);
View Full Code Here

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

        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".clear();");

        if (fieldInfo.isBound()) {
View Full Code Here

     * @param fieldInfo the collectionInfo to translate
     * @param jClass the jClass to add the method to.
     */
    protected void createRemoveByIndexMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod("remove" + fieldInfo.getMethodSuffix() + "At",
                fieldInfo.getContentType().getJType(),
                "the element removed from the collection");

        method.addParameter(new JParameter(JType.INT, "index"));

        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("java.lang.Object obj = this.");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".remove(index);");

        if (fieldInfo.isBound()) {
            this.createBoundPropertyCode(fieldInfo, sourceCode);
        }

        sourceCode.add("return ");
        if (fieldInfo.getContentType().getType() == XSType.CLASS) {
            sourceCode.append("(");
            sourceCode.append(method.getReturnType().getName());
            sourceCode.append(") obj;");
        } else {
            sourceCode.append(fieldInfo.getContentType().createFromJavaObjectCode("obj"));
            sourceCode.append(";");
        }
View Full Code Here

     * @param fieldInfo the collectionInfo to translate
     * @param jClass the jClass to add the method to.
     */
    private void createRemoveObjectMethod(final CollectionInfo fieldInfo,
            final JClass jClass) {
        JMethod method = new JMethod("remove" + fieldInfo.getMethodSuffix(), JType.BOOLEAN,
                                     "true if the object was removed from the collection.");

        final JParameter parameter = new JParameter(fieldInfo.getContentType().getJType(),
                fieldInfo.getContentName());
        method.addParameter(parameter);

        JSourceCode sourceCode = method.getSourceCode();
        sourceCode.add("boolean removed = ");
        sourceCode.append(fieldInfo.getName());
        sourceCode.append(".remove(");
        sourceCode.append(fieldInfo.getContentType().createToJavaObjectCode(parameter.getName()));
        sourceCode.append(");");
View Full Code Here

     * @param jClass the jClass to add the method to.
     * @param useJava50 java version flag
     */
    private void createSetAsArrayMethod(final CollectionInfo fieldInfo,
            final JClass jClass, final boolean useJava50) {
        JMethod method = new JMethod("set" + fieldInfo.getMethodSuffix());
        final JParameter parameter = new JParameter(new JArrayType(
                fieldInfo.getContentType().getJType(), useJava50),
                fieldInfo.getContentName() + "Array");
        method.addParameter(parameter);

        JSourceCode sourceCode = method.getSourceCode();
        String index = "i";
        if (parameter.getName().equals(index)) {
            index = "j";
        }

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.