-
1. Re: Is there a way to create annotation with array of annotations?
gastaldi Mar 11, 2017 5:56 PM (in response to ondrejz)I think there is already a JIRA for that. You can use
AnnotationSource.setLiteralValue and pass a String with the contents for now
Em 11 de mar de 2017 19:46, "ondrejz" <do-not-reply@jboss.com> escreveu:
JBoss Developer <https://developer.jboss.org/?et=watches.email.thread>
Is there a way to create annotation with array of annotations?
created by Ondrej Zoricak
<https://developer.jboss.org/people/ondrejz?et=watches.email.thread> in
Forge - View the full discussion
<https://developer.jboss.org/message/969714?et=watches.email.thread#969714>
-
2. Re: Is there a way to create annotation with array of annotations?
ondrejz Mar 12, 2017 10:20 AM (in response to ondrejz)Thank you. It is working for array of annotations but I rewrite whole my code for annotate method with singleAnnotation and I want to pass values to Annotation using AnnotationSource.setLiteralValue(String s) but error occur...
Here is my code:
String annotation = setValues(" ", values.get(0), js); // => clazz = ComprehensionTool.class, method = "startAnalyse"
method.addAnnotation(annotationStructure.getName()).setLiteralValue(annotation);and error:
Exception in thread "main" java.lang.ClassCastException: org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.NormalAnnotation cannot be cast to org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.SingleMemberAnnotation
at org.jboss.forge.roaster.model.impl.AnnotationImpl.setLiteralValue(AnnotationImpl.java:325)
at comprehensionTool.data.annotation.AnnotationImplementer.annotateMethod(AnnotationImplementer.java:132)
at comprehensionTool.analyse.processors.AnalyseProcessor.insertAnnotation(AnalyseProcessor.java:97)
at comprehensionTool.analyse.processors.CallersProcessor.processMethodAnalyse(CallersProcessor.java:99)
at comprehensionTool.analyse.AnalyseController.executeAnalyse(AnalyseController.java:74)
at comprehensionTool.analyse.AnalyseController.analyseWholeProject(AnalyseController.java:55)
at comprehensionTool.ComprehensionTool.startAnalyse(ComprehensionTool.java:89)
at comprehensionTool.ComprehensionTool.main(ComprehensionTool.java:52)
I don't see problem in my implementation man so I don't know If it is some problem with ROASTER or my thought is wrong?
Thank you again.
-
3. Re: Is there a way to create annotation with array of annotations?
gastaldi Mar 12, 2017 10:24 AM (in response to ondrejz)What's the value of the annotation String?
Em 12 de mar de 2017 11:21, "ondrejz" <do-not-reply@jboss.com> escreveu:
JBoss Developer <https://developer.jboss.org/?et=watches.email.thread>
Is there a way to create annotation with array of annotations?
reply from Ondrej Zoricak
<https://developer.jboss.org/people/ondrejz?et=watches.email.thread> in
Forge - View the full discussion
<https://developer.jboss.org/message/969748?et=watches.email.thread#969748>
-
4. Re: Is there a way to create annotation with array of annotations?
ondrejz Mar 12, 2017 10:27 AM (in response to ondrejz)Watch comment in my answer...
value is = clazz = ComprehensionTool.class, method = "startAnalyse"
-
5. Re: Is there a way to create annotation with array of annotations?
gastaldi Mar 12, 2017 10:31 AM (in response to ondrejz)In this case try to call setClassValue("clazz",ComprehensionTool.class) and
setStringValue("method","startAnalyse") instead
PS: method names may be different because I am not checking the sources atm
Em 12 de mar de 2017 11:27, "ondrejz" <do-not-reply@jboss.com> escreveu:
JBoss Developer <https://developer.jboss.org/?et=watches.email.thread>
Is there a way to create annotation with array of annotations?
reply from Ondrej Zoricak
<https://developer.jboss.org/people/ondrejz?et=watches.email.thread> in
Forge - View the full discussion
<https://developer.jboss.org/message/969750?et=watches.email.thread#969750>
-
6. Re: Is there a way to create annotation with array of annotations?
ondrejz Mar 12, 2017 10:36 AM (in response to ondrejz)It is not possible in my implementation because I am using spoon for create call graph of some external project and then I cannot get class but only metadata like path, package, name... So for me it is much more easier pass only String like "ComprehensionTool.class" and import package of this class...
-
7. Re: Is there a way to create annotation with array of annotations?
gastaldi Mar 12, 2017 10:39 AM (in response to ondrejz)I see. Can you open a JIRA with a reproduceable test case? Also, a PR would
be awesome
Em 12 de mar de 2017 11:36, "ondrejz" <do-not-reply@jboss.com> escreveu:
JBoss Developer <https://developer.jboss.org/?et=watches.email.thread>
Is there a way to create annotation with array of annotations?
reply from Ondrej Zoricak
<https://developer.jboss.org/people/ondrejz?et=watches.email.thread> in
Forge - View the full discussion
<https://developer.jboss.org/message/969752?et=watches.email.thread#969752>
-
8. Re: Is there a way to create annotation with array of annotations?
ondrejz Mar 12, 2017 11:01 AM (in response to ondrejz)What does it mean PR? And man it is working fine in form: method.addAnnotation(annotationStructure.getName()).setLiteralValue("clazz" ,"ComprehensionTool.class").setStringValue("method", "method")
so I created method:
@Author("Ondrej Zoričák")
private static void setOneValue(AnnotationSource as, LinkedHashMap<String, String> values, JavaSource js){
for (Map.Entry value:
values.entrySet()) {
if(value.getKey().equals("clazz")){
addImport(js, value.getValue().toString());
as.setLiteralValue(value.getKey().toString(), value.getValue().toString().substring(value.getValue().toString().lastIndexOf(".") + 1,
value.getValue().toString().length()) + ".class");
} else {as.setStringValue((String)value.getKey(), (String)value.getValue());
}}
}
and everythink work
-
9. Re: Is there a way to create annotation with array of annotations?
ondrejz Mar 12, 2017 2:44 PM (in response to ondrejz)I created new issue: ROASTER-124 - [ROASTER-124] AnnotationSource.setLiteralValue() error occur - JBoss Issue Tracker
-
10. Re: Is there a way to create annotation with array of annotations?
gariklolkin Sep 27, 2017 2:53 PM (in response to ondrejz)Hi, Ondrej. I have the same issue
@AllowedForFunctionActionCouples({
@AllowedForFunctionActionCouple(function = FC_FUNCTION, action = AC_ANY)
})
Please, give me more details how can I resolve this one.