Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augmenting of Spoon model #2774

Closed
pvojtechovsky opened this issue Nov 21, 2018 · 1 comment
Closed

Augmenting of Spoon model #2774

pvojtechovsky opened this issue Nov 21, 2018 · 1 comment

Comments

@pvojtechovsky
Copy link
Collaborator

In #2762 and #2734 there would be nice to be able to extend/augment Spoon model.

What about a new CtElement method

class CtElement {
  ...
  /** gets or creates an extension of type `type` of this element */
  <T> T adaptTo(Class<T> type);
}

We would also need

interface AdapterFactory {
   boolean canAdaptToType(Class type);
   <T> T createAdapter(CtElement element, Class type);
}

and

class Factory {
...
void registerAdapterFactory(AdapterFactory adapterFactory);

then CtElementImpl#adaptTo(Class) would look like this

class CtElementImpl {
...
/** gets or creates an extension of type `type` of this element */
<T> T adaptTo(Class<T> type) {
   T adapter = (T) metadata.get(type);
  if (adapter == null) {
    adapter = getFactory().getAdapterFactory(type).createAdapter(this);
    metadata.put(type, adapter)
  }
  return adapter;
}

WDYT?

@monperrus
Copy link
Collaborator

cleaning pass, closing stale issues :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants