Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Commit

Permalink
store rhino nodes differently; remove unnecessary node properties (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Oct 27, 2013
1 parent 1342322 commit 51f2dfc
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/org/jsdoc/AstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
public class AstBuilder
{
private static final String NODE_ID = HiddenProperties.NODE_ID.getPropertyName();
private static final String RHINO_NODE = HiddenProperties.RHINO_NODE.getPropertyName();
private static final String ROOT = HiddenProperties.ROOT.getPropertyName();
private static final String TYPE = Properties.TYPE.getPropertyName();

private static Context cx;
private static ScriptableObject scope;

private Parser parser;
private NativeObject ast;
private Map<String, AstNode> rhinoNodes;
private AstRoot root;
private List<Comment> seenComments;

Expand Down Expand Up @@ -105,6 +104,7 @@ public void reset()
{
parser = null;
ast = null;
rhinoNodes = new HashMap<String, AstNode>();
root = null;
seenComments = new ArrayList<Comment>();
}
Expand All @@ -114,6 +114,11 @@ public NativeObject getAst()
return ast;
}

public Map<String, AstNode> getRhinoNodes()
{
return rhinoNodes;
}

public NativeObject build(String sourceCode, String sourceName)
{
// Reset the instance's state if necessary
Expand Down Expand Up @@ -276,7 +281,8 @@ private NativeObject createNode(Entry info)
Integer start;
Integer end;

AstNode rhinoNode = (AstNode)info.get(RHINO_NODE);
String nodeId = (String)info.get("nodeId");
AstNode rhinoNode = rhinoNodes.get(nodeId);

NativeArray range = getRange(rhinoNode);
info.put("range", range);
Expand All @@ -286,12 +292,6 @@ private NativeObject createNode(Entry info)

node = new JsDocNode(info);

if (this.ast == null && info.get(TYPE) == JsDocNode.PROGRAM) {
node.put(ROOT, node.getNativeObject());
} else {
node.put(ROOT, this.ast);
}

return node.getNativeObject();
}

Expand Down Expand Up @@ -329,11 +329,12 @@ private NativeObject processNode(AstNode rhinoNode)
// rhinoNode.toSource());

NativeObject node = null;
String nodeId = getRhinoNodeId(rhinoNode);
Entry info = new Entry();
NodeTypes type = NodeTypes.valueOf(rhinoNode.shortName());

info.put(NODE_ID, getRhinoNodeId(rhinoNode));
info.put(RHINO_NODE, rhinoNode);
info.put(NODE_ID, nodeId);
rhinoNodes.put(nodeId, rhinoNode);

// surely there's a better way to do this...
switch (type) {
Expand Down Expand Up @@ -981,9 +982,7 @@ public String getPropertyName()

enum HiddenProperties
{
RHINO_NODE ("rhinoNode"),
NODE_ID ("nodeId"),
ROOT ("root");
NODE_ID ("nodeId");

private String propertyName;

Expand Down Expand Up @@ -1091,11 +1090,6 @@ public final void put(String key, Object value)
node.put(key, node, value);
}

public final JsDocNode getRoot()
{
return (JsDocNode)get(HiddenProperties.ROOT.getPropertyName());
}

public final NativeObject getNativeObject()
{
return node;
Expand Down

0 comments on commit 51f2dfc

Please sign in to comment.