use of com.rockwellcollins.atc.agree.agree.SelectionExpr in project AMASE by loonwerks.
the class SafetyAnnexContentAssist method annexCompletionSuggestions.
@Override
public List<String> annexCompletionSuggestions(EObject defaultAnnex, int offset) {
// get one character back
offset = (offset <= 0) ? 0 : offset - 1;
EObjectAtOffsetHelper helper = getOffsetHelper();
EObject grammerObject = null;
// EObjectAtOffsetHelper
if (defaultAnnex instanceof DefaultAnnexLibrary) {
AnnexLibrary annexLib = ((DefaultAnnexLibrary) defaultAnnex).getParsedAnnexLibrary();
XtextResource resource = (XtextResource) annexLib.eResource();
grammerObject = helper.resolveContainedElementAt(resource, offset);
} else if (defaultAnnex instanceof DefaultAnnexSubclause) {
AnnexSubclause annexSub = ((DefaultAnnexSubclause) defaultAnnex).getParsedAnnexSubclause();
XtextResource resource = (XtextResource) annexSub.eResource();
grammerObject = helper.resolveContainedElementAt(resource, offset);
}
List<String> results = new ArrayList<>();
if (grammerObject instanceof SelectionExpr) {
results.addAll(getNestedDotIDCandidates((SelectionExpr) grammerObject));
}
return results;
}
use of com.rockwellcollins.atc.agree.agree.SelectionExpr in project AMASE by loonwerks.
the class SafetyScopeProvider method prevScope.
private IScope prevScope(EObject ctx, EReference ref) {
EObject container = ctx.eContainer();
while (container instanceof SelectionExpr) {
container = container.eContainer();
}
IScope prevScope = getScope(container, ref);
return prevScope;
}
use of com.rockwellcollins.atc.agree.agree.SelectionExpr in project AGREE by loonwerks.
the class AgreeAnnexContentAssist method annexCompletionSuggestions.
@Override
public List<String> annexCompletionSuggestions(EObject defaultAnnex, int offset) {
// get one character back
offset = (offset <= 0) ? 0 : offset - 1;
EObjectAtOffsetHelper helper = getOffsetHelper();
EObject grammerObject = null;
// EObjectAtOffsetHelper
if (defaultAnnex instanceof DefaultAnnexLibrary) {
AnnexLibrary annexLib = ((DefaultAnnexLibrary) defaultAnnex).getParsedAnnexLibrary();
XtextResource resource = (XtextResource) annexLib.eResource();
grammerObject = helper.resolveContainedElementAt(resource, offset);
} else if (defaultAnnex instanceof DefaultAnnexSubclause) {
AnnexSubclause annexSub = ((DefaultAnnexSubclause) defaultAnnex).getParsedAnnexSubclause();
XtextResource resource = (XtextResource) annexSub.eResource();
grammerObject = helper.resolveContainedElementAt(resource, offset);
}
List<String> results = new ArrayList<>();
if (grammerObject instanceof SelectionExpr) {
results.addAll(getNestedDotIDCandidates((SelectionExpr) grammerObject));
}
return results;
}
use of com.rockwellcollins.atc.agree.agree.SelectionExpr in project AGREE by loonwerks.
the class Util method getDoubleValue.
public static Double getDoubleValue(Expr expr) {
Double result = Double.valueOf(0.0);
assert (AgreeJavaValidator.exprIsConst(expr));
if (expr instanceof NamedElement) {
if (expr instanceof ConstStatement) {
result = getDoubleValue(((ConstStatement) expr).getExpr());
}
} else if (expr instanceof SelectionExpr) {
NamedElement finalId = ((SelectionExpr) expr).getField();
if (finalId instanceof ConstStatement) {
result = getDoubleValue(((ConstStatement) finalId).getExpr());
}
} else if (expr instanceof RealLitExpr) {
result = Double.valueOf(((RealLitExpr) expr).getVal());
} else if (expr instanceof IntLitExpr) {
result = Double.valueOf(((IntLitExpr) expr).getVal());
} else if (expr instanceof BinaryExpr) {
BinaryExpr binExpr = (BinaryExpr) expr;
Double left = getDoubleValue(binExpr.getLeft());
Double right = getDoubleValue(binExpr.getRight());
switch(binExpr.getOp()) {
case "+":
result = left + right;
break;
case "-":
result = left - right;
break;
case "*":
result = left * right;
break;
case "/":
result = left / right;
break;
case "^":
result = Math.pow(left, right);
break;
default:
throw new AgreeException("binary expression is not evaluable as integer constant");
}
return result;
} else if (expr instanceof UnaryExpr) {
UnaryExpr unExpr = (UnaryExpr) expr;
Double right = getDoubleValue(unExpr.getExpr());
switch(unExpr.getOp()) {
case "-":
result = -right;
break;
default:
throw new AgreeException("unary expression is not evaluable as integer constant");
}
} else {
throw new AgreeException("expression is not evaluable as integer constant");
}
return result;
}
use of com.rockwellcollins.atc.agree.agree.SelectionExpr in project AGREE by loonwerks.
the class AgreeScopeProvider method prevScope.
private IScope prevScope(EObject ctx, EReference ref) {
EObject container = ctx.eContainer();
while (container instanceof SelectionExpr) {
container = container.eContainer();
}
IScope prevScope = getScope(container, ref);
return prevScope;
}
Aggregations