Commit 6af19d25 authored by Hafiz Muhammad Wahaj Aziz's avatar Hafiz Muhammad Wahaj Aziz
Browse files

The FMU generation was giving an error due to null check missing on data dictionary

refs 2902
parent 85e6ba2e
......@@ -77,8 +77,6 @@ import org.fortiss.af3.project.extension.data.Executable;
* @author aravantinos
*/
public class FMUGeneratorExecutionTarget extends ExecutionTargetBase {
/** {@inheritDoc} */
@Override
......@@ -163,7 +161,6 @@ public class FMUGeneratorExecutionTarget extends ExecutionTargetBase {
} catch(CoreException cex) {
error(AF3ComponentUIActivator.getDefault(), cex.getMessage(), cex);
}
MessageDialog.openInformation(currentShell, "Successful FMU export", fmuSource
.getModelDescription().getName() + ".fmu was successfuly generated!");
}
......@@ -172,44 +169,44 @@ public class FMUGeneratorExecutionTarget extends ExecutionTargetBase {
* Returns the sampling time from the user defined function (samplingTime) if correctly defined,
* otherwise asks from the user.
*/
@SuppressWarnings("null")
private Double getSamplingTime(DataDictionary dd) {
Shell currentShell = getWorkbench().getActiveWorkbenchWindow().getShell();
String message = "";
String baseMsg = "The \"samplingTime\" function should ";
Double samplingTime = null;
for(FunctionDefinition function : dd.getFunctions()) {
if(function.getFunction().getName().toString().equals("samplingTime")) {
if(!function.getReturnType().toString().contains("double")) {
message +=
baseMsg + "return a value of type \"double\"." + System.lineSeparator();
}
EList<IStatementTerm> statements = function.getDefinition().getStatements();
if(statements.size() != 1) {
message +=
baseMsg + "contain one and only one statement." +
System.lineSeparator();
} else {
// get(0): this is fine because of the check above
IStatementTerm singleStatement = statements.get(0);
if(!(singleStatement instanceof Return)) {
if(dd != null) {
for(FunctionDefinition function : dd.getFunctions()) {
if(function.getFunction().getName().toString().equals("samplingTime")) {
if(!function.getReturnType().toString().contains("double")) {
message +=
baseMsg + "contain a \"return\" statement." +
baseMsg + "return a value of type \"double\"." +
System.lineSeparator();
}
Return returnStatement = (Return)singleStatement;
if(!(returnStatement.getValue() instanceof DoubleConst)) {
message += baseMsg + "return a constant value.";
EList<IStatementTerm> statements = function.getDefinition().getStatements();
if(statements.size() != 1) {
message +=
baseMsg + "contain one and only one statement." +
System.lineSeparator();
} else {
// Multiplying with 1000 to convert time to milliseconds
samplingTime =
((DoubleConst)returnStatement.getValue()).getValue();
// get(0): this is fine because of the check above
IStatementTerm singleStatement = statements.get(0);
if(!(singleStatement instanceof Return)) {
message +=
baseMsg + "contain a \"return\" statement." +
System.lineSeparator();
}
Return returnStatement = (Return)singleStatement;
if(!(returnStatement.getValue() instanceof DoubleConst)) {
message += baseMsg + "return a constant value.";
} else {
// Multiplying with 1000 to convert time to milliseconds
samplingTime = ((DoubleConst)returnStatement.getValue()).getValue();
}
}
}
}
}
if(!message.equals("")) {
if(message.equals("")) {
InputDialog durationDlg =
new InputDialog(
currentShell,
......@@ -230,7 +227,7 @@ public class FMUGeneratorExecutionTarget extends ExecutionTargetBase {
samplingTime = 1 / lastSelectedFrequency;
}
final double toMilliseconds = 1000.0;
samplingTime = samplingTime*toMilliseconds;
samplingTime = samplingTime != null ? samplingTime * toMilliseconds : null;
return samplingTime;
}
......
Supports Markdown
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