notNull(jsDoc);
}
private JsDoc parseContent(String moduleContents, final Set<String> dependencies)
{
final AtomicReference<JsDoc> jsDoc = new AtomicReference<JsDoc>(new JsDoc(""));
CompilerEnvirons env = new CompilerEnvirons();
env.setRecordingComments(true);
env.setRecordingLocalJsDocComments(true);
Parser parser = new Parser(env, new ErrorReporter()
{
public void warning(String message, String sourceName, int line, String lineSource, int lineOffset)
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void error(String message, String sourceName, int line, String lineSource, int lineOffset)
{
log.warn("Error parsing module " + id + ":\n" +
" Message: " + message + "\n" +
" Line: " + line + "\n" +
" Line Src:" + lineSource + "\n" +
" Column: " + lineOffset);
throw new RuntimeException("Error parsing module '" + id + "' on line " + line + ": " + message);
}
public EvaluatorException runtimeError(String message, String sourceName, int line, String lineSource, int lineOffset)
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
});
try
{
final AstRoot root = parser.parse(new StringReader(moduleContents), path, 1);
if (root.getComments() != null && !root.getComments().isEmpty())
{
final String rawHeaderDocs = root.getComments().first().getValue();
jsDoc.set(JsDocParser.parse(getId(), rawHeaderDocs));
}
root.visitAll(new NodeVisitor()
{
public boolean visit(AstNode node)
{
try
{
if (node.getType() == Token.ASSIGN)
{
Assignment assignment = (Assignment) node;
if (assignment.getLeft().getType() == Token.GETPROP)
{
PropertyGet left = (PropertyGet)assignment.getLeft();
if (left.getLeft() instanceof Name && ((Name)left.getLeft()).getIdentifier().equals("exports"))
{
String exportName = left.getProperty().getIdentifier();
Export export = new Export(exportName, JsDocParser.parse(getId(), node.getJsDoc()));
if (jsDoc.get().getDescription().length() > 0 && export.getJsDoc().getDescription().equals(jsDoc.get().getDescription()))
{
jsDoc.set(new JsDoc(""));
}
exports.put(exportName, export);
}
}
}