Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Suppress some warnings
[Acceleo] Suppress some warnings [message #1823395] Thu, 26 March 2020 05:51 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 344
Registered: August 2013
Senior Member
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 #1823398 is a reply to message #1823395] Thu, 26 March 2020 07:39 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You probably don't want to suppress them; understand and observe them.

Imprecise traceability means that the M2T guarantee of exactly one invocation of each mapping per distinct set of arguments is being undermined.

If you ignore the warning, look forward to an obscure debugging problem as your models get larger.

Of course you can suppress warnings by modifying the code. When you try to modify the code you may then discover that a configuration mechanism already exists.

Regards

Ed Willink
Re: [Acceleo] Suppress some warnings [message #1823403 is a reply to message #1823398] Thu, 26 March 2020 08:21 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 344
Registered: August 2013
Senior Member
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;
    }

}
Re: [Acceleo] Suppress some warnings [message #1823422 is a reply to message #1823403] Thu, 26 March 2020 11:11 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Acceleo tracing needs a model element as part of the unique signature. String clearly won't do OclAny/Object probably won't. Try OclAny/EObject else 'YourRootElement'/EObject.

Regards

Ed Willink
Previous Topic:[Acceleo] Order of TemplateParameterSubstitution in TemplateBindings
Next Topic:JET Editor
Goto Forum:
  


Current Time: Thu Apr 25 07:15:33 GMT 2024

Powered by FUDForum. Page generated in 0.03542 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top