[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [pdt-dev] Generate PHP code

one more question regarding the ast-rewriting. I've implemented a getter/setter generation for class fields,
but the indentation is not set properly.


Here's the PHP code generated by the TextEdit / rewrite operation:

    public function getController(){
return $this->controller;
}

    public function setController(Controller $controller){
$this->controller=$controller;
}

Note that only the first line of each method is indented correctly.

This is how i'm setting up the options for the program.rewrite() call:


options = new HashMap(PHPCorePlugin.getOptions());

        IScopeContext[] contents = new IScopeContext[] {
                new ProjectScope(type
                        .getScriptProject()
                        .getProject()),
                        InstanceScope.INSTANCE, DefaultScope.INSTANCE };

        for (int i = 0; i < contents.length; i++) {

IScopeContext scopeContext = contents[i];
IEclipsePreferences inode = scopeContext.getNode(PHPCorePlugin.ID);


            if (inode != null) {

if (!options.containsKey(PHPCoreConstants.FORMATTER_USE_TABS)) {

String useTabs = inode.get(PHPCoreConstants.FORMATTER_USE_TABS,null);
if (useTabs != null) {
options.put(PHPCoreConstants.FORMATTER_USE_TABS, useTabs);
}
}


if (!options.containsKey(PHPCoreConstants.FORMATTER_INDENTATION_SIZE)) {

String size = inode.get(PHPCoreConstants.FORMATTER_INDENTATION_SIZE,null);

if (size != null) {
options.put(PHPCoreConstants.FORMATTER_INDENTATION_SIZE,size);
}
}
}
}




Has anyone a hint why the other lines are not intented?


regards


-robert



On 9/18/11 1:03 PM, Roy Ganor wrote:
Yep, I recommend using the ASTRewriter functionality.

See org.eclipse.php.core.tests.dom_ast.rewrite.ASTRewriteTests

Roy
-----Original Message-----
From: pdt-dev-bounces@xxxxxxxxxxx [mailto:pdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Robert Gruendler
Sent: Friday, September 16, 2011 1:57 PM
To: PDT Developers
Subject: [pdt-dev] Generate PHP code

Hi,

i'm wondering what's the best way to generate PHP code from within a PDT extension. Is it possible to manually create an AST and
"dump" it to a file somewhere?

Or should i simply use template files and fill them with variables?


cheers


-robert _______________________________________________ pdt-dev mailing list pdt-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/pdt-dev _______________________________________________ pdt-dev mailing list pdt-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/pdt-dev