public void translate()

in ti/phase2/jars/compiler-xdoclet/src/java/org/apache/ti/compiler/xdoclet/internal/tools/AnnotationsToXDoclet.java [120:198]


    public void translate(File input, File output)
            throws IOException, FileNotFoundException {
        System.err.println(input + " -> " + output);
        output.getAbsoluteFile().getParentFile().mkdirs();
        FileReader in = new FileReader(input);
        PrintWriter out = null;

        try {
            out = new PrintWriter(new FileWriter(output));
            StreamTokenizer tok = getJavaTokenizer(in);
            boolean addedSpace = false;
            StringBuffer indentBuffer = new StringBuffer();
            String indent = "";

            while (tok.nextToken() != StreamTokenizer.TT_EOF) {
                boolean wasSpace = false;
                boolean wasChar = false;

                switch (tok.ttype) {
                    case StreamTokenizer.TT_WORD:
                        if (indentBuffer != null) {
                            indent = indentBuffer.toString();
                            indentBuffer = null;
                        }
                        String str = tok.sval;
                        if (str.startsWith("@ti.viewProperties")) {
                            ignoreUntil(tok, ")");
                        } else if (str.startsWith("@ti.") || str.startsWith("@org.apache.ti")) {
                            out.println("/**");
                            ArrayList tags = new ArrayList();
                            translateAnnotation(tok, out, str, indent, tags);
                            for (int i = 0; i < tags.size(); ++i) {
                                out.print(indent);
                                out.print(" * ");
                                out.println((String) tags.get(i));
                            }
                            out.print(indent);
                            out.print(" */");
                        } else if (str.equals("import")) {
                            filterImport(tok, out);
                        } else {
                            out.print(str);
                            if (str.length() == 1) {
                                char c = str.charAt(0);
                                if (c == '\'' || c == '"') wasChar = true;
                            }
                        }
                        break;

                    case StreamTokenizer.TT_NUMBER:
                        assert false : tok.nval;   // parseNumbers() was set to false on the tokenizer.
                        break;

                    default:
                        char c = (char) tok.ttype;
                        wasChar = true;
                        if (! addedSpace || c != ' ') out.print(c);
                        wasSpace = Character.isWhitespace(c);
                        if (! wasSpace && indentBuffer != null) {
                            indent = indentBuffer.toString();
                            indentBuffer = null;
                        }
                        if (indentBuffer != null) indentBuffer.append(c);
                        if (c == '\n') indentBuffer = new StringBuffer();
                }

                if (! wasChar) {
                    out.print(' ');
                    addedSpace = true;
                } else {
                    addedSpace = false;
                }
            }
        }
        finally {
            in.close();
            if (out != null) out.close();
        }
    }