[Acceleo] Suppress some warnings [message #1823395] |
Thu, 26 March 2020 01:51  |
Eclipse User |
|
|
|
Hi
How can I suppress some Acceleo warnings?
For example, "It is strongly recommended to use Java services only inside a query in order to ensure the precision of the traceability informations"
|
|
|
|
Re: [Acceleo] Suppress some warnings [message #1823403 is a reply to message #1823398] |
Thu, 26 March 2020 04:21   |
Eclipse User |
|
|
|
I have a Java service returning an incremented number on each call. So I put an invoke statement into a template block to disable caching.
For sure I can ignore this warning. But when there are a lot of such a warnings they confuse other developers.
[template public incCounter(ctx : OclAny, str : String)][invoke('...service.CommonService', 'incCounter(java.lang.Object, java.lang.String)', Sequence{ctx, str})/][/template]
[template public getCounter(ctx : OclAny, str : String)][invoke('...service.CommonService', 'getCounter(java.lang.Object, java.lang.String)', Sequence{ctx, str})/][/template]
public class CommonService {
public int incCounter(Object context, String str) {
return Counter.getInstance().incCounter(context, str);
}
public int getCounter(Object context, String str) {
return Counter.getInstance().getCounter(context, str);
}
}
public class Counter {
private static volatile Counter instance;
private Map<Object, Map<String, Integer>> contexts = new HashMap<Object, Map<String, Integer>>();
private Counter() {
}
public static Counter getInstance() {
if (instance == null) {
synchronized(Counter.class){
if (instance == null) {
instance = new Counter();
}
}
}
return instance;
}
private Map<String, Integer> getCounters(Object context) {
if (contexts.containsKey(context)) {
return contexts.get(context);
}
final Map<String, Integer> counters = new HashMap<String, Integer>();
contexts.put(context, counters);
return counters;
}
public int incCounter(Object context, String str) {
final Map<String, Integer> counters = getCounters(context);
if (counters.containsKey(str)) {
int counter = counters.get(str) + 1;
counters.put(str, counter);
return counter;
}
counters.put(str, 1);
return 1;
}
public int getCounter(Object context, String str) {
final Map<String, Integer> counters = getCounters(context);
if (counters.containsKey(str)) {
return counters.get(str);
}
return 0;
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03537 seconds