Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[tigerstripe-dev] AnnotationManager

Hi Yuri,
 
I was looking at adding an API to the IStereotypeCapable interface to add annotations... and in testing it I found that whereas the uniqueness constraint is tested, the target constraint in AnnotationType is not tested. That is, if I assign a list of target classes for an annotation-type I expect that I can only add an annotation if the target class is in that list of targets, though if I do not assign a any target classes i expect the annotation to be valid for all target types.
 
So, I should say that I think I need a method (on AnnotationManager):
AnnotationType getType(String epackage, String eclass)
 
eg.

public AnnotationType getType(String packij, String clazz)

{

AnnotationType[] types = getTypes();

AnnotationType type = null;

String fqn = packij+"."+clazz;

for(int t = 0; t < types.length; t++)

{

EClass clazzy = types[t].getClazz();

if(fqn.equals(clazzy.getInstanceClassName()))

type = types[t];

}

return type;

}

 
to get me the AnnotationType so I can access the factory in an addAnnotation method (on ArtifactComponent), eg.:

public Object addAnnotation(String scheme, String packij, String clazz)

{

IAnnotationManager manager = AnnotationPlugin.getManager();

AnnotationType type = manager.getType(packij, clazz);

if(type == null)

return null;

EObject content = type.createInstance();

manager.addAnnotation(this, content);

return content;

}

 
Now, the fact that i already know the AnnotationType when I call AnnotationManager.addAnnotation(...) makes me think we could re-fact a little so that we also have a method on AnnotationManager:

Annotation addAnnotation(AnnotationType type, Object object, EObject content)

and then the type can be passed down to the methods that at present search for the type, eg.

public Annotation addAnnotation(AnnotationType type, Object object, EObject content) {

URI uri = getUri(object);

if (uri != null) {

AnnotationType annotationType = type != null ? type : matchAnnotationType(object, content);

checkTarget(annotationType, object, uri, content.eClass());

checkUnique(annotationType, object, uri, content.eClass());

Annotation annotation = AnnotationFactory.eINSTANCE.createAnnotation();

annotation.setUri(uri);

annotation.setContent(content);

add(annotation);

return annotation;

}

return null;

}

public Annotation addAnnotation(Object object, EObject content) {

return addAnnotation(null, object, content);

}

Does that make sense? Probably you can think of something better.
 
Cheers,
 
JohnW
 

John Worrell
Technical Leader

jworrell@xxxxxxxxx
Phone: +44 208824 9410
Mobile: +44 7789 922290

Cisco Systems Limited
250 Longwater Avenue
Reading
RG2 6GB
United Kingdom
Cisco home page

 
Think before you print. Think before you print.
This e-mail may contain confidential and privileged material for the sole use of the intended recipient. Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender by reply e-mail and delete all copies of this message.


 

Back to the top