Search in sources :

Example 6 with Type

use of com.sun.javadoc.Type in project com.revolsys.open by revolsys.

the class BaseDoclet method getMemberId.

protected String getMemberId(final ExecutableMemberDoc member) {
    final StringBuilder id = new StringBuilder();
    final ClassDoc classDoc = member.containingClass();
    final String classId = getClassId(classDoc);
    id.append(classId);
    id.append(".");
    final String memberName = member.name();
    id.append(memberName);
    final Parameter[] parameters = member.parameters();
    for (final Parameter parameter : parameters) {
        id.append("-");
        final Type type = parameter.type();
        String typeName = type.qualifiedTypeName();
        typeName = typeName.replaceAll("^java.lang.", "");
        typeName = typeName.replaceAll("^java.io.", "");
        typeName = typeName.replaceAll("^java.util.", "");
        id.append(typeName);
        id.append(type.dimension());
    }
    return id.toString().replaceAll("[^A-Za-z0-9\\-_.]", "_");
}
Also used : Type(com.sun.javadoc.Type) Parameter(com.sun.javadoc.Parameter) ClassDoc(com.sun.javadoc.ClassDoc)

Example 7 with Type

use of com.sun.javadoc.Type in project com.revolsys.open by revolsys.

the class JavaDoclet method methodSignature.

public void methodSignature(final ExecutableMemberDoc member) {
    this.writer.startTag(HtmlElem.A);
    final String anchor = getAnchor(member);
    this.writer.attribute(HtmlAttr.NAME, anchor);
    if (member instanceof MethodDoc) {
        this.writer.startTag(HtmlElem.CODE);
        final MethodDoc method = (MethodDoc) member;
        final Type returnType = method.returnType();
        DocletUtil.typeName(this.writer, returnType);
        this.writer.text(" ");
        this.writer.endTagLn(HtmlElem.CODE);
    }
    if (member.isStatic()) {
        this.writer.startTag(HtmlElem.I);
    }
    this.writer.text(member.name());
    if (member.isStatic()) {
        this.writer.endTag(HtmlElem.I);
    }
    this.writer.startTag(HtmlElem.CODE);
    this.writer.text("(");
    final Parameter[] parameters = member.parameters();
    boolean first = true;
    for (final Parameter parameter : parameters) {
        if (first) {
            first = false;
        } else {
            this.writer.text(", ");
        }
        DocletUtil.typeName(this.writer, parameter.type());
        this.writer.text(" ");
        this.writer.text(parameter.name());
    }
    this.writer.text(")");
    this.writer.endTagLn(HtmlElem.CODE);
    this.writer.endTagLn(HtmlElem.A);
}
Also used : Type(com.sun.javadoc.Type) MethodDoc(com.sun.javadoc.MethodDoc) Parameter(com.sun.javadoc.Parameter)

Example 8 with Type

use of com.sun.javadoc.Type in project wso2-axis2-transports by wso2.

the class ResourceInfoDoclet method start.

public static boolean start(RootDoc root) throws IOException {
    parseOptions(root.options());
    ResourceInfo resourceInfo = new ResourceInfo();
    for (ClassDoc clazz : root.classes()) {
        Resource resource = null;
        for (MethodDoc method : clazz.methods()) {
            if (getAnnotation(method, "org.apache.axis2.transport.testkit.tests.Setup") != null) {
                if (resource == null) {
                    resource = new Resource(clazz.qualifiedName());
                }
                ParamTag[] paramTags = method.paramTags();
                for (Parameter parameter : method.parameters()) {
                    Type type = parameter.type();
                    String name = parameter.name();
                    String comment = null;
                    for (ParamTag paramTag : paramTags) {
                        if (paramTag.parameterName().equals(name)) {
                            comment = paramTag.parameterComment();
                            break;
                        }
                    }
                    if (comment == null) {
                        comment = getFirstSentence(root.classNamed(type.qualifiedTypeName()));
                    }
                    resource.addDependency(type.qualifiedTypeName(), type.dimension().equals("[]") ? "0..*" : "1", comment);
                }
            }
        }
        if (resource != null) {
            resourceInfo.addResource(resource);
        }
    }
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outFile));
    out.writeObject(resourceInfo);
    out.close();
    return true;
}
Also used : ParamTag(com.sun.javadoc.ParamTag) Type(com.sun.javadoc.Type) MethodDoc(com.sun.javadoc.MethodDoc) FileOutputStream(java.io.FileOutputStream) Parameter(com.sun.javadoc.Parameter) ObjectOutputStream(java.io.ObjectOutputStream) ClassDoc(com.sun.javadoc.ClassDoc)

Example 9 with Type

use of com.sun.javadoc.Type in project jdk8u_jdk by JetBrains.

the class StubSkeletonWriter method writeStubMethod.

/**
     * Writes the stub method for the remote method with the given
     * operation number.
     **/
private void writeStubMethod(IndentingWriter p, int opnum) throws IOException {
    RemoteClass.Method method = remoteMethods[opnum];
    MethodDoc methodDoc = method.methodDoc();
    String methodName = methodDoc.name();
    Type[] paramTypes = method.parameterTypes();
    String[] paramNames = nameParameters(paramTypes);
    Type returnType = methodDoc.returnType();
    ClassDoc[] exceptions = method.exceptionTypes();
    /*
         * Declare stub method; throw exceptions declared in remote
         * interface(s).
         */
    p.pln("// implementation of " + Util.getFriendlyUnqualifiedSignature(methodDoc));
    p.p("public " + returnType.toString() + " " + methodName + "(");
    for (int i = 0; i < paramTypes.length; i++) {
        if (i > 0) {
            p.p(", ");
        }
        p.p(paramTypes[i].toString() + " " + paramNames[i]);
    }
    p.plnI(")");
    if (exceptions.length > 0) {
        p.p("throws ");
        for (int i = 0; i < exceptions.length; i++) {
            if (i > 0) {
                p.p(", ");
            }
            p.p(exceptions[i].qualifiedName());
        }
        p.pln();
    }
    p.pOlnI("{");
    /*
         * The RemoteRef.invoke methods throw Exception, but unless
         * this stub method throws Exception as well, we must catch
         * Exceptions thrown from the invocation.  So we must catch
         * Exception and rethrow something we can throw:
         * UnexpectedException, which is a subclass of
         * RemoteException.  But for any subclasses of Exception that
         * we can throw, like RemoteException, RuntimeException, and
         * any of the exceptions declared by this stub method, we want
         * them to pass through unmodified, so first we must catch any
         * such exceptions and rethrow them directly.
         *
         * We have to be careful generating the rethrowing catch
         * blocks here, because javac will flag an error if there are
         * any unreachable catch blocks, i.e. if the catch of an
         * exception class follows a previous catch of it or of one of
         * its superclasses.  The following method invocation takes
         * care of these details.
         */
    List<ClassDoc> catchList = computeUniqueCatchList(exceptions);
    /*
         * If we need to catch any particular exceptions (i.e. this method
         * does not declare java.lang.Exception), put the entire stub
         * method in a try block.
         */
    if (catchList.size() > 0) {
        p.plnI("try {");
    }
    if (version == StubVersion.VCOMPAT) {
        p.plnI("if (useNewInvoke) {");
    }
    if (version == StubVersion.VCOMPAT || version == StubVersion.V1_2) {
        if (!Util.isVoid(returnType)) {
            // REMIND: why $?
            p.p("Object $result = ");
        }
        p.p("ref.invoke(this, " + methodFieldNames[opnum] + ", ");
        if (paramTypes.length > 0) {
            p.p("new java.lang.Object[] {");
            for (int i = 0; i < paramTypes.length; i++) {
                if (i > 0)
                    p.p(", ");
                p.p(wrapArgumentCode(paramTypes[i], paramNames[i]));
            }
            p.p("}");
        } else {
            p.p("null");
        }
        p.pln(", " + method.methodHash() + "L);");
        if (!Util.isVoid(returnType)) {
            p.pln("return " + unwrapArgumentCode(returnType, "$result") + ";");
        }
    }
    if (version == StubVersion.VCOMPAT) {
        p.pOlnI("} else {");
    }
    if (version == StubVersion.V1_1 || version == StubVersion.VCOMPAT) {
        p.pln(REMOTE_CALL + " call = ref.newCall((" + REMOTE_OBJECT + ") this, operations, " + opnum + ", interfaceHash);");
        if (paramTypes.length > 0) {
            p.plnI("try {");
            p.pln("java.io.ObjectOutput out = call.getOutputStream();");
            writeMarshalArguments(p, "out", paramTypes, paramNames);
            p.pOlnI("} catch (java.io.IOException e) {");
            p.pln("throw new " + MARSHAL_EXCEPTION + "(\"error marshalling arguments\", e);");
            p.pOln("}");
        }
        p.pln("ref.invoke(call);");
        if (Util.isVoid(returnType)) {
            p.pln("ref.done(call);");
        } else {
            p.pln(returnType.toString() + " $result;");
            // REMIND: why $?
            p.plnI("try {");
            p.pln("java.io.ObjectInput in = call.getInputStream();");
            boolean objectRead = writeUnmarshalArgument(p, "in", returnType, "$result");
            p.pln(";");
            p.pOlnI("} catch (java.io.IOException e) {");
            p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
            /*
                 * If any only if readObject has been invoked, we must catch
                 * ClassNotFoundException as well as IOException.
                 */
            if (objectRead) {
                p.pOlnI("} catch (java.lang.ClassNotFoundException e) {");
                p.pln("throw new " + UNMARSHAL_EXCEPTION + "(\"error unmarshalling return\", e);");
            }
            p.pOlnI("} finally {");
            p.pln("ref.done(call);");
            p.pOln("}");
            p.pln("return $result;");
        }
    }
    if (version == StubVersion.VCOMPAT) {
        // end if/else (useNewInvoke) block
        p.pOln("}");
    }
    /*
         * If we need to catch any particular exceptions, finally write
         * the catch blocks for them, rethrow any other Exceptions with an
         * UnexpectedException, and end the try block.
         */
    if (catchList.size() > 0) {
        for (ClassDoc catchClass : catchList) {
            p.pOlnI("} catch (" + catchClass.qualifiedName() + " e) {");
            p.pln("throw e;");
        }
        p.pOlnI("} catch (java.lang.Exception e) {");
        p.pln("throw new " + UNEXPECTED_EXCEPTION + "(\"undeclared checked exception\", e);");
        // end try/catch block
        p.pOln("}");
    }
    // end stub method
    p.pOln("}");
}
Also used : Type(com.sun.javadoc.Type) MethodDoc(com.sun.javadoc.MethodDoc) ClassDoc(com.sun.javadoc.ClassDoc)

Example 10 with Type

use of com.sun.javadoc.Type in project jdk8u_jdk by JetBrains.

the class StubSkeletonWriter method writeMethodFieldInitializers.

/**
     * Writes code to initialize the static fields for each method
     * using the Java Reflection API.
     **/
private void writeMethodFieldInitializers(IndentingWriter p) throws IOException {
    for (int i = 0; i < methodFieldNames.length; i++) {
        p.p(methodFieldNames[i] + " = ");
        /*
             * Look up the Method object in the somewhat arbitrary
             * interface that we find in the Method object.
             */
        RemoteClass.Method method = remoteMethods[i];
        MethodDoc methodDoc = method.methodDoc();
        String methodName = methodDoc.name();
        Type[] paramTypes = method.parameterTypes();
        p.p(methodDoc.containingClass().qualifiedName() + ".class.getMethod(\"" + methodName + "\", new java.lang.Class[] {");
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                p.p(", ");
            p.p(paramTypes[j].toString() + ".class");
        }
        p.pln("});");
    }
}
Also used : Type(com.sun.javadoc.Type) MethodDoc(com.sun.javadoc.MethodDoc)

Aggregations

Type (com.sun.javadoc.Type)17 Parameter (com.sun.javadoc.Parameter)9 ClassDoc (com.sun.javadoc.ClassDoc)7 MethodDoc (com.sun.javadoc.MethodDoc)7 ParamTag (com.sun.javadoc.ParamTag)3 ParameterizedType (com.sun.javadoc.ParameterizedType)2 Tag (com.sun.javadoc.Tag)2 WildcardType (com.sun.javadoc.WildcardType)2 SeeTag (com.sun.javadoc.SeeTag)1 ThrowsTag (com.sun.javadoc.ThrowsTag)1 FileOutputStream (java.io.FileOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ArrayList (java.util.ArrayList)1 StatementBuilder (org.h2.util.StatementBuilder)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1