Search in sources :

Example 1 with MethodReturnParameter

use of org.develnext.jphp.genapi.parameter.MethodReturnParameter in project jphp by jphp-compiler.

the class FunctionDescription method parse.

@Override
protected void parse() {
    arguments = new LinkedHashMap<String, ArgumentDescription>();
    annotations = new DocAnnotations(token.getDocComment() == null ? "" : token.getDocComment().getComment());
    DocAnnotations.Parameter returnParam = annotations.getParameter("return");
    if (returnParam != null) {
        this.returnParameter = new MethodReturnParameter(token.getNamespace(), returnParam.value());
    }
    DocAnnotations.Parameter throwsParam = annotations.getParameter("throws");
    if (throwsParam != null) {
        this.throwsParameters = new MethodReturnParameter[throwsParam.values().size()];
        int i = 0;
        for (String e : throwsParam.values()) {
            this.throwsParameters[i] = new MethodReturnParameter(token.getNamespace(), e);
            i++;
        }
    }
    Map<String, MethodParamParameter> paramDescription = new HashMap<String, MethodParamParameter>();
    DocAnnotations.Parameter param = annotations.getParameter("param");
    if (param != null) {
        for (String el : param.values()) {
            MethodParamParameter tmp = new MethodParamParameter(token.getNamespace(), el);
            paramDescription.put(tmp.getArgument(), tmp);
        }
    }
    for (ArgumentStmtToken el : token.getArguments()) {
        MethodParamParameter desc = paramDescription.get(el.getName().getName());
        arguments.put(el.getName().getName(), new ArgumentDescription(el, desc));
    }
}
Also used : MethodParamParameter(org.develnext.jphp.genapi.parameter.MethodParamParameter) ArgumentStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ArgumentStmtToken) MethodReturnParameter(org.develnext.jphp.genapi.parameter.MethodReturnParameter) DocAnnotations(org.develnext.jphp.genapi.DocAnnotations)

Example 2 with MethodReturnParameter

use of org.develnext.jphp.genapi.parameter.MethodReturnParameter in project jphp by jphp-compiler.

the class SphinxTemplate method print.

@Override
protected void print(FunctionDescription description) {
    if (description instanceof MethodDescription && ((MethodDescription) description).isStatic()) {
        sb.append(" .. php:staticmethod:: ");
    } else {
        sb.append(" .. php:method:: ");
    }
    sb.append(description.getName()).append("(");
    int i = 0;
    Collection<ArgumentDescription> args = description.getArguments();
    for (ArgumentDescription arg : args) {
        if (i != 0)
            sb.append(", ");
        sb.append("$").append(arg.getName());
        if (arg.getValue() != null) {
            sb.append(" = ").append(arg.getValue());
        }
        i++;
    }
    sb.append(")\n\n");
    if (description instanceof MethodDescription) {
        MethodDescription meth = (MethodDescription) description;
        boolean add = false;
        if (meth.isFinal()) {
            sb.append("  **final**\n\n");
            add = true;
        }
        if (meth.isAbstract()) {
            sb.append("  **abstract**\n\n");
            add = true;
        }
        if (meth.isPrivate()) {
            sb.append("  **private**\n\n");
            add = true;
        }
        if (meth.isProtected()) {
            sb.append("  **protected**\n\n");
            add = true;
        }
        if (add)
            sb.append("\n");
    }
    if (description.getDescription() != null && !description.getDescription().isEmpty()) {
        sb.append("  ").append(addTabToDescription(description.getDescription().trim(), 2)).append("\n\n");
    }
    if (description.getThrowsParameters() != null) {
        for (MethodReturnParameter e : description.getThrowsParameters()) {
            sb.append("  **throws** ");
            echoTypes(e.getTypes());
            if (e.getDescription() != null && !e.getDescription().trim().isEmpty()) {
                sb.append(" ");
                sb.append(addTabToDescription(e.getDescription().trim(), 2));
            }
            sb.append("\n\n");
        }
    }
}
Also used : MethodReturnParameter(org.develnext.jphp.genapi.parameter.MethodReturnParameter)

Aggregations

MethodReturnParameter (org.develnext.jphp.genapi.parameter.MethodReturnParameter)2 ArgumentStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ArgumentStmtToken)1 DocAnnotations (org.develnext.jphp.genapi.DocAnnotations)1 MethodParamParameter (org.develnext.jphp.genapi.parameter.MethodParamParameter)1