osate / osate2

Open Source AADL2 Tool Environment
http://osate.org
Eclipse Public License 2.0
36 stars 8 forks source link

getLocationReference() always returns null? #295

Closed philip-alldredge closed 10 years ago

philip-alldredge commented 10 years ago

In my plugin, I needed to sort a list of features by their order in the AADL text. I attempted to use getLocationReference() but it always returns null in my experience.

I resorted to using Xtext's NodeModelUtils.findActualNodeFor();

Is there a recommended way of getting this sort of information about an AADL model? As a side note, is there an API for opening an element in the AADL text? For example if I have a graphical editor open and I want to jump to a specific element in the model.

Thank you,

juli1 commented 10 years ago

Hi Philip,

Do you have any code sample to reproduce the issue ? It seems that this is the method used by Xtext. See Aadl2LocationInFile in org.osate.xtext.aadl2 for example. So, having a plugin example that show how you use the method would be helpful ! Thanks !

philip-alldredge commented 10 years ago

That's actually where I found the workaround of NodeModelUtils.findActualNodeFor() at. Here is the code that I'm using. Like I said I can get the info from NodeModelUtils.findActualNodeFor() but not getLocatioNReference()

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.osate.aadl2.DataType;
import org.osate.aadl2.modelsupport.modeltraversal.AadlProcessingSwitch;
import org.osate.aadl2.modelsupport.resources.OsateResourceUtil;
import org.osate.aadl2.util.Aadl2Switch;

public class GenerateInterfacesAction implements IWorkbenchWindowActionDelegate {
    @Override
    public void run(final IAction action) {     
        final AadlProcessingSwitch generationSwitch = new AadlProcessingSwitch() {
            @Override
            protected void initSwitches() {
                this.aadl2Switch = new Aadl2Switch<String>() {
                    @Override
                    public String caseDataType(final DataType dataType) 
                    {               
                        System.out.println(dataType.getLocationReference());
                        return DONE;
                    }
                };
            }
        };

        generationSwitch.defaultTraversalAllDeclarativeModels();
    }

    @Override
    public void selectionChanged(IAction arg0, ISelection arg1) {
    }

    @Override
    public void dispose() {
    }

    @Override
    public void init(IWorkbenchWindow arg0) {

    }
}
reteprelief commented 10 years ago

Philip,

the getLocationReference (and the Class AObject) was a left over method from OSATE1. You used the correct Xtext method.

As to opening the declarative model - I have a method that allows you to go from the isntance model to the declarative model (available in the popup menu of the instance model editor). It uses the follwoing methods in UIUtil: public static void gotoInstanceObjectSource(IWorkbenchPage page, InstanceObject io) { if (io == null){ return; } gotoDeclarativeModelElement(page, AadlUtil.getInstanceOrigin(io)); } and public static void gotoDeclarativeModelElement(IWorkbenchPage page, Element target) { if (target == null){ return; } Resource res = target.eResource(); final IResource ires = OsateResourceUtil.convertToIResource(res); if (ires != null && ires.exists()) { try { ICompositeNode node = NodeModelUtils.findActualNodeFor(target); int offset = node.getTotalEndOffset(); int line = node.getTotalEndLine(); IMarker marker_p; marker_p = ires.createMarker(AadlConstants.AADLGOTOMARKER); marker_p.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); String dest = EcoreUtil.getURI(target).toString(); marker_p.setAttribute(IMarker.MESSAGE, "Going to "

philip-alldredge commented 10 years ago

Thanks for the information! I'll take a look.