Unused imports in generated .java files
When I compile XHTML pages (could happen for other pages too), the generated Java source file contains unused imports, which makes Eclipse (the IDE) unhappy.
HTML source: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Unused imports example</title> </head> <body> <div id="helloText">Hello there!</div> </body> </html>
Ant taskdef snippet:
<xmlc includes="Unused.html" srcdir="${xmlc.srcdir}/reference"
sourceout="{java.dir}" verbose="yes" packagename="
{xmlc.package.prefix}"
packagedir="reference" markup="XHTML" options="${xmlc.srcdir}/options.xmlc">
<arg value="-generate" /><arg value="both" />
</xmlc>
Options.xmlc: <?xml version="1.0"?> <!DOCTYPE xmlc PUBLIC "-//ENHYDRA//DTD XMLC 1.1//EN" "http://www.enhydra.org/xml/xmlc/xmlc-1.1.dtd"> <xmlc> <compileOptions keepGeneratedSource="yes" compileSource="no" sourceOutputRoot="WEB-INF/classes" />
<inputDocument documentFormat="xml" />
<documentClass deferParsing="true" dom="xhtml" />
<domEdits> <deleteElement elementClasses="mockup" /> </domEdits> </xmlc>
UnusedXHTML.java file:
Please note the 'UNUSED IMPORT' comment
/*
- XMLC GENERATED CODE, DO NOT EDIT *
*/ package com.versaly.xmlc.reference;
import org.w3c.dom.*; //<-- UNUSED IMPORT
/**
-
XMLC Document class, generated from
-
I:/workspace/Versaly/html/reference/Unused.html / public interface UnusedXHTML extends org.enhydra.xml.xmlc.XMLObject, org.enhydra.xml.xmlc.html.HTMLObject { /*
- Get the element with id <CODE>helloText</CODE>.
- @see org.enhydra.xml.xhtml.dom.XHTMLDivElement */ public org.enhydra.xml.xhtml.dom.XHTMLDivElement getElementHelloText();
/**
- Get the value of text child of element <CODE>helloText</CODE>.
- @see org.w3c.dom.Text */ public void setTextHelloText(String text);
}
UnusedXHTMLImpl.java file:
Note the comments 'UNUSED IMPORT' below
/*
- XMLC GENERATED CODE, DO NOT EDIT *
*/ package com.versaly.xmlc.reference;
import org.w3c.dom.*; import org.enhydra.xml.dom.DOMOps; // UNUSED IMPORT import org.enhydra.xml.xmlc.XMLCError; // UNUSED IMPORT import org.enhydra.xml.xmlc.XMLCUtil; // UNUSED IMPORT import org.enhydra.xml.xmlc.deferredparsing.DocumentLoader; import org.enhydra.xml.xmlc.deferredparsing.StandardDocumentLoader; import org.enhydra.xml.xmlc.dom.XMLCDomFactory; // UNUSED IMPORT
/**
-
XMLC Document class, generated from
-
I:/workspace/Versaly/html/reference/Unused.html */ public class UnusedXHTMLImpl extends org.enhydra.xml.xmlc.html.HTMLObjectImpl implements UnusedXHTML, org.enhydra.xml.xmlc.XMLObject, org.enhydra.xml.xmlc.html.HTMLObject { private org.enhydra.xml.xhtml.dom.XHTMLDivElement $element_HelloText;
/**
- Field that is used to identify this as the XMLC generated class
- in an inheritance chain. Contains a reference to the class object. */ public static final Class XMLC_GENERATED_CLASS = UnusedXHTMLImpl.class;
/**
- Field containing CLASSPATH relative name of the source file
- that this class can be regenerated from. */ public static final String XMLC_SOURCE_FILE = "com/versaly/xmlc/reference/Unused.html";
/**
- XMLC DOM factory associated with this class. */ private static final org.enhydra.xml.xmlc.dom.XMLCDomFactory fDOMFactory = org.enhydra.xml.xmlc.dom.XMLCDomFactoryCache.getFactory(org.enhydra.xml.xhtml.XHTMLDomFactory.class);
/**
- Document loader for deferred parsing. */ private final DocumentLoader fDocumentLoader;
/**
-
Default constructor. */ public UnusedXHTMLImpl() { this(StandardDocumentLoader.getInstance());
buildDocument();
}
/**
- Constructor with optional building of the DOM. */ public UnusedXHTMLImpl(boolean buildDOM) { this(StandardDocumentLoader.getInstance(), buildDOM);
}
/**
-
Copy constructor. */ public UnusedXHTMLImpl(UnusedXHTMLImpl src) { fDocumentLoader = src.getDocumentLoader();
setDocument((Document)src.getDocument().cloneNode(true), src.getMIMEType(), src.getEncoding());
syncAccessMethods();
}
/**
-
Constructor for deferred parsing support.
-
The supplied document loader is used to
-
create the DOM. */ public UnusedXHTMLImpl(DocumentLoader loader, boolean buildDOM) { fDocumentLoader = loader;
if (buildDOM) {
buildDocument();
}
}
/**
- Constructor for deferred parsing support.
- The supplied document loader is used to
- create the DOM. */ public UnusedXHTMLImpl(DocumentLoader loader) { this(loader, true);
}
/**
-
Create document as a DOM and initialize accessor method fields. */ public void buildDocument() { setDocument(getDocumentLoader().getDocument(getClass()), "application/xhtml+xml", "UTF-8");
syncAccessMethods();
}
/**
-
Clone the document. */ public Node cloneNode(boolean deep) { cloneDeepCheck(deep);
return new UnusedXHTMLImpl(this);
}
/**
- Get the document loader associated with the class. */ protected final DocumentLoader getDocumentLoader() { return fDocumentLoader;
}
/**
- Get the XMLC DOM factory associated with the class. */ protected final org.enhydra.xml.xmlc.dom.XMLCDomFactory getDomFactory() { return fDOMFactory;
}
/**
- Get the element with id <CODE>helloText</CODE>.
- @see org.enhydra.xml.xhtml.dom.XHTMLDivElement */ public org.enhydra.xml.xhtml.dom.XHTMLDivElement getElementHelloText() { return $element_HelloText;
}
/**
- Get the value of text child of element <CODE>helloText</CODE>.
- @see org.w3c.dom.Text */ public void setTextHelloText(String text) { doSetText($element_HelloText, text);
}
/**
-
Recursive function to do set access method fields from the DOM.
-
Missing ids have fields set to null. */ protected void syncWithDocument(Node node) { if (node instanceof Element) {
String id = ((Element)node).getAttribute("id"); if (id.length() == 0) { } else if (id.equals("helloText")) { $element_HelloText =
(org.enhydra.xml.xhtml.dom.XHTMLDivElement)node;
}
}
Node child = node.getFirstChild();
while (child != null) {
syncWithDocument(child);
child = child.getNextSibling();
}
}
}