Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[imp-dev] Reusing node locator for too many things

Hi imps,

I've written a bunch of node locators now and there is a slight design issue.
Since node locators are used for syntax highlighting, for outline, and for other things like hover help and reference resolving,
they always end up with a "manually programmed" dispatch like this:

// snippet
if (node instanceof Token) {
            return ((Token) node).getLocation();
}
else if (node instanceof AbstractAST) {
            return getLocation(((AbstractAST) node).getTree());
}
else if (node instanceof ModelTreeNode) {
            return getLocation(((ModelTreeNode) node).getASTNode());
}
// end snippet

(or worse)

There usually seem to be three kinds of nodes: tokens, ast nodes and model objects.

If IMP would allow me to construct a different locator for each kind (IParseController would
have a "getASTNodeLocator" as well as a "getTokenLocator" and a "getModelNodeLocator") the
ugly dispatch could go "stage left".

If an IMP client happens to have less than three kinds of nodes, well then it can simply return the
same locator for every getter.

Cheers,

Jurgen

Back to the top