Commit 17c23161 authored by Marc Jeanmougin's avatar Marc Jeanmougin

Use exception to locate error

parent 37e7e8bf
......@@ -9,6 +9,7 @@ import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
......@@ -18,8 +19,10 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
......@@ -30,6 +33,7 @@ import org.osate.aadl2.modelsupport.resources.OsateResourceUtil;
import fr.tpt.aadl.ramses.analysis.AnalysisResultFactory;
import fr.tpt.aadl.ramses.control.support.analysis.AnalysisArtifact;
import fr.tpt.mem4csd.sefa.trajectory.exceptions.MalformedInputException;
import fr.tpt.mem4csd.sefa.trajectory.model.Flow;
import fr.tpt.mem4csd.sefa.trajectory.model.Node;
......@@ -84,7 +88,18 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
TrajectoryAnalysisResult ar;
try {
ar = la.trajectoryAnalysis(instance);
} catch (Exception e2) {
} catch (MalformedInputException e2) {
try {
final IResource resource = OsateResourceUtil.convertToIResource(instance.eResource());
final IMarker marker = resource.createMarker( EValidator.MARKER );
marker.setAttribute( IMarker.MESSAGE, e2.message );
marker.setAttribute( IMarker.SEVERITY, IMarker.SEVERITY_ERROR );
marker.setAttribute( EValidator.URI_ATTRIBUTE,
EcoreUtil.getURI(e2.obj).toString());
} catch (Exception ee) {
//Failed to fail
throw new ExecutionException(ee.getMessage(),ee);
}
e2.printStackTrace();
throw new ExecutionException(e2.getMessage(),e2);
}
......@@ -132,14 +147,14 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
DetailLogger res = ar._virtualLink2WCTT.get(ci);
Flow flow = ar._fm.get(ci);
for(DetailLogger.Log l:res.cur.get(0).a) {
if(l.n==null) writer.println(" , , "+l.value);
if(l.n==null && l.value != 0) writer.println(" , , "+l.value);
}
for(Node nn:flow.getPath().getNodes()) {
for(DetailLogger.Log l:res.cur.get(0).a) {
if(l.n==nn) writer.println(l.n.getId()+", "+(l.f==null ? "" : l.f.getId()) +", "+l.value);
}
}
writer.println("Flow "+ci.getFullName()+" : WCRT = "+res.cur.get(0).value);
writer.println("WCRT for flow, "+ci.getFullName()+", "+res.cur.get(0).value+"\n");
}
writer.close();
} catch (FileNotFoundException e1) {
......@@ -151,8 +166,7 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
} catch (CoreException e) {
e.printStackTrace();
}
System.out.println("done");
return null;
}
......
......@@ -27,6 +27,7 @@ import fr.tpt.mem4csd.sefa.trajectory.model.Network;
import fr.tpt.mem4csd.sefa.trajectory.model.Node;
import fr.tpt.mem4csd.sefa.trajectory.model.Path;
import fr.tpt.mem4csd.sefa.trajectory.exceptions.MalformedInputException;
public class LatencyAnalyzer //extends AbstractAnalyzer
{
......@@ -64,7 +65,7 @@ public class LatencyAnalyzer //extends AbstractAnalyzer
public void performAnalysis(SystemInstance systemInstance,
AnalysisErrorReporterManager errManager,
IProgressMonitor monitor,SystemInstance firstSysInstance)
throws Exception
throws MalformedInputException
{
trajectoryAnalysis(systemInstance);
}
......@@ -97,7 +98,7 @@ public class LatencyAnalyzer //extends AbstractAnalyzer
public TrajectoryAnalysisResult trajectoryAnalysis(SystemInstance systemInstance) throws Exception
public TrajectoryAnalysisResult trajectoryAnalysis(SystemInstance systemInstance) throws MalformedInputException
{
List<Flow> flows = new ArrayList<Flow>();
List<Node> nodes = new ArrayList<Node>();
......@@ -136,7 +137,7 @@ public class LatencyAnalyzer //extends AbstractAnalyzer
catch(Exception e) {
String errMsg = "Could not fetch a required attribute:"+e.getMessage();
System.err.println(errMsg);
throw new Exception(errMsg);
throw new MalformedInputException(errMsg, virtualBus);
}
flowMap.put(virtualBus, f);
......@@ -154,7 +155,7 @@ public class LatencyAnalyzer //extends AbstractAnalyzer
if(connectionBindingList==null || connectionBindingList.isEmpty()) {
String errMsg = "flow"+virtualBus.getFullName()+"is empty !";
System.err.println(errMsg);
throw new Exception(errMsg);
throw new MalformedInputException(errMsg, virtualBus);
}
List<Node> listNodes = new ArrayList<Node>();
......@@ -165,21 +166,21 @@ public class LatencyAnalyzer //extends AbstractAnalyzer
if(l%2 != 1) {
String errMsg = "flow"+virtualBus.getFullName()+" has an even number of components.";
System.err.println(errMsg);
throw new Exception(errMsg);
throw new MalformedInputException(errMsg, virtualBus);
}
for(int i=0;i<l;i+=2) {
if(connectionBindingList.get(i).getCategory()==ComponentCategory.BUS) {
String errMsg = "flow"+virtualBus.getFullName()+" has a bus in even position"+i;
System.err.println(errMsg);
throw new Exception(errMsg);
throw new MalformedInputException(errMsg, virtualBus);
}
}
for(int i=1;i<l;i+=2) {
if(connectionBindingList.get(i).getCategory()!=ComponentCategory.BUS) {
String errMsg = "flow"+virtualBus.getFullName()+" has an device in odd position"+i;
System.err.println(errMsg);
throw new Exception(errMsg);
throw new MalformedInputException(errMsg, virtualBus);
}
}
......@@ -203,7 +204,7 @@ public class LatencyAnalyzer //extends AbstractAnalyzer
if(!isDevice) {
String errMsg = "object "+nwkSwitch.getFullName()+" is unknown.";
System.err.println(errMsg);
throw new Exception(errMsg);
throw new MalformedInputException(errMsg, nwkSwitch);
}
if(isDevice) {
......@@ -248,9 +249,9 @@ public class LatencyAnalyzer //extends AbstractAnalyzer
for(FeatureInstance fi: ci.getFeatureInstances()) { // for each connection of the component
if(fi.getCategory()!=FeatureCategory.BUS_ACCESS) {
String errMsg = "not a bus";
String errMsg = "not a bus in even pos"+i;
System.err.println(errMsg);
throw new Exception(errMsg);
throw new MalformedInputException(errMsg, ci);
}
if(fi.getSrcConnectionInstances().size()>1 || fi.getDstConnectionInstances().size()>1
......@@ -258,7 +259,7 @@ public class LatencyAnalyzer //extends AbstractAnalyzer
) {
String errMsg = "bus end is connected to two ports";
System.err.println(errMsg);
throw new Exception(errMsg);
throw new MalformedInputException(errMsg, ci);
}
......
package fr.tpt.mem4csd.sefa.trajectory.exceptions;
import org.osate.aadl2.instance.ComponentInstance;
public class MalformedInputException extends Exception {
public String message;
public ComponentInstance obj;
public MalformedInputException(String message, ComponentInstance obj) {
this.message = message;
this.obj=obj;
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment