Search in sources :

Example 6 with SelectionExpr

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;
}
Also used : EObjectAtOffsetHelper(org.eclipse.xtext.resource.EObjectAtOffsetHelper) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) XtextResource(org.eclipse.xtext.resource.XtextResource) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 7 with SelectionExpr

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr)

Example 8 with SelectionExpr

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;
}
Also used : EObjectAtOffsetHelper(org.eclipse.xtext.resource.EObjectAtOffsetHelper) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) XtextResource(org.eclipse.xtext.resource.XtextResource) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 9 with SelectionExpr

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;
}
Also used : ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) NamedElement(org.osate.aadl2.NamedElement) UnaryExpr(com.rockwellcollins.atc.agree.agree.UnaryExpr)

Example 10 with SelectionExpr

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr)

Aggregations

SelectionExpr (com.rockwellcollins.atc.agree.agree.SelectionExpr)13 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)7 NamedElement (org.osate.aadl2.NamedElement)7 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)6 IntLitExpr (com.rockwellcollins.atc.agree.agree.IntLitExpr)6 UnaryExpr (com.rockwellcollins.atc.agree.agree.UnaryExpr)6 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)5 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)5 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)5 EObject (org.eclipse.emf.ecore.EObject)5 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)4 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)4 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)4 Expr (com.rockwellcollins.atc.agree.agree.Expr)4 IfThenElseExpr (com.rockwellcollins.atc.agree.agree.IfThenElseExpr)4 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)4 PreExpr (com.rockwellcollins.atc.agree.agree.PreExpr)4 RecordLitExpr (com.rockwellcollins.atc.agree.agree.RecordLitExpr)4 Check (org.eclipse.xtext.validation.Check)4 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)3