Hi, Jochen...

> supply a proper patch (diff -ub oldFile newFile), and I'll apply it. 
> (Sorry for asking, but it is always best to talk in patches and the 
like.)
not sure about this, but I you want it...
please keep in mind that I have neither CVS nor diff around here. I 
transfered all files to a private unix machine, running diff there, and I 
don't know how old my original sources are.

I changed AbstractJavaMethod, adding removeThrows for String, Class and 
JavaQName, and also added a clearThrows() method.

For isThrown the example stated that inheritance is not checked, so a 
check for java.net.MalformedURLException would not find the thrown 
exception java.io.IOException - I assume it was meant the other way round.

I also changed addParam to throw an IllegalParameterException when a 
parameter is added with the same name as an already existing parameter.

Finally I added two methods String[] getParamNames and JavaQName[] 
getParamTypes which, similar to Parameter[] getParams, return a list of 
parameters this function takes. getParamTypes is useful in combination 
with JavaSource.getMethod(String, JavaQName[]), as it can be directly used 
as second parameter.

This is all I had in mind for today. I checked in 
ConditionalIndentationJavaSourceObject, because I thought it would be nice 
to have addThrowNew automatically call addThrow, but it is in different 
classes. I'm not sure as to why it's split up in this way, but I didn't 
want to mess with it too much.

Other thing I have needed (but found other ways of doing it) were having a 
helpermethod which would give me an unused local variable name, for using 
as a loop variable while being called recursively. I had an Stringlist, 
initially filled with getParamNames.
In case you're interested:

    /**
     * Chooses a free variable name. If <code>wantedName</code> is already 
used it will be 'counted up' until a free
     * name is found. Adds this name to the <code>varNames List</code>.
     * 
     * @param wantedName
     *            the preferred name
     * @param varNames
     *            <code>List</code> with all variables in this method 
(gets updated)
     * @return a free variable name
     */
    private String chooseFreeVarName(String wantedName, List varNames) {
        int i = 1;
        String res;
        do {
            res = wantedName + (i > 1 ? String.valueOf(i) : "");
            i++;
            // this shouldn't happen, unless there are really 100 used 
variables or a bug in the List
            if (i > 100) { throw new RuntimeException(
                    "possible loop detected while trying to generate a 
name similar to '" + wantedName + "'"); }
        } while (varNames.contains(res));
        varNames.add(res);
        return res;
    }

I thought about adding it to jaxmejs, too, but wasn't sure if it would 
really be needed by many persons.


The second thing that I thought I needed was a possibility to generate 
JavaCode without it being part of a method, to be added later. Placeholder 
didn't completely satisfy me, as indentations would be wrong. Since I 
didn't actually need it I haven't investigated this further. But I think 
it is not yet possible, is it?

The code is roughly tested and should be simple enough not to contain too 
much bugs :)
Feel free to use all or parts of it, as you might think fits best. If you 
have more suggestions what could be usefull, tell me and I might have a 
look. But the programming part of my thesis is nearly over.

:Frederic:


Attachment: diff
Description: Binary data

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to