Example usage for org.eclipse.jdt.core.jdom DOMFactory createMethod

List of usage examples for org.eclipse.jdt.core.jdom DOMFactory createMethod

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.jdom DOMFactory createMethod.

Prototype

@Override
    public IDOMMethod createMethod(String sourceCode) 

Source Link

Usage

From source file:com.iw.plugins.spindle.wizards.project.ApplicationWizardPage.java

License:Mozilla Public License

protected void populateMethodSource(IType servletType, IProgressMonitor monitor) throws JavaModelException {
    String methodName = MessageUtil.getString("Tapestry.servlet.getAppMethodName");
    ICompilationUnit parentCU = servletType.getCompilationUnit();
    String gensource = parentCU.getSource();

    DOMFactory domFactory = new DOMFactory();
    IDOMCompilationUnit unit = domFactory.createCompilationUnit(gensource, servletType.getElementName());
    IDOMNode current = unit.getFirstChild();
    while (current.getNodeType() != IDOMNode.TYPE) {
        current = current.getNextNode();
    }//  w  w w .  j a v a2  s  .  c o m
    IDOMNode theType = current;
    IDOMMethod method = findMethod(theType, methodName);
    if (method == null) {
        method = domFactory.createMethod("protected String getApplicationSpecificationPath() {}");
        theType.addChild(method);
    }
    method.setBody(getAppMethodBody());

    String newContents = Utils.formatJavaCode(unit.getContents(), 0,
            StubUtility.getLineDelimiterUsed(parentCU));
    parentCU.getBuffer().setContents(newContents);
    parentCU.save(monitor, true);
}