Search in sources :

Example 1 with Evaluation

use of org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation in project xtext-eclipse by eclipse.

the class ArithmeticsCodeMiningProvider method createCodeMinings.

@Override
protected void createCodeMinings(IDocument document, XtextResource resource, CancelIndicator indicator, IAcceptor<? super ICodeMining> acceptor) throws BadLocationException {
    EList<EObject> contents = resource.getContents();
    if (contents.isEmpty()) {
        return;
    }
    // get all evaluations contained by the open document
    List<Evaluation> allEvaluations = EcoreUtil2.eAllOfType(contents.get(0), Evaluation.class);
    // get keyword for ';'
    Keyword semicolon = grammar.getEvaluationAccess().getSemicolonKeyword_1();
    for (Evaluation evaluation : allEvaluations) {
        ICompositeNode node = NodeModelUtils.findActualNodeFor(evaluation);
        for (Iterator<INode> it = node.getAsTreeIterable().iterator(); it.hasNext(); ) {
            INode child = it.next();
            if (semicolon.equals(child.getGrammarElement())) {
                int annotationOffset = child.getTotalOffset();
                String annotationText = getAnnotationText(evaluation);
                acceptor.accept(createNewLineContentCodeMining(annotationOffset, annotationText));
            }
        }
    }
}
Also used : Evaluation(org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation) INode(org.eclipse.xtext.nodemodel.INode) Keyword(org.eclipse.xtext.Keyword) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 2 with Evaluation

use of org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation in project xtext-eclipse by eclipse.

the class ArithmeticsSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == ArithmeticsPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case ArithmeticsPackage.DECLARED_PARAMETER:
                sequence_DeclaredParameter(context, (DeclaredParameter) semanticObject);
                return;
            case ArithmeticsPackage.DEFINITION:
                sequence_Definition(context, (Definition) semanticObject);
                return;
            case ArithmeticsPackage.DIV:
                sequence_Multiplication(context, (Div) semanticObject);
                return;
            case ArithmeticsPackage.EVALUATION:
                sequence_Evaluation(context, (Evaluation) semanticObject);
                return;
            case ArithmeticsPackage.FUNCTION_CALL:
                sequence_PrimaryExpression(context, (FunctionCall) semanticObject);
                return;
            case ArithmeticsPackage.IMPORT:
                sequence_Import(context, (Import) semanticObject);
                return;
            case ArithmeticsPackage.MINUS:
                sequence_Addition(context, (Minus) semanticObject);
                return;
            case ArithmeticsPackage.MODULE:
                sequence_Module(context, (org.eclipse.xtext.example.arithmetics.arithmetics.Module) semanticObject);
                return;
            case ArithmeticsPackage.MULTI:
                sequence_Multiplication(context, (Multi) semanticObject);
                return;
            case ArithmeticsPackage.NUMBER_LITERAL:
                sequence_PrimaryExpression(context, (NumberLiteral) semanticObject);
                return;
            case ArithmeticsPackage.PLUS:
                sequence_Addition(context, (Plus) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Evaluation(org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation) Action(org.eclipse.xtext.Action) Import(org.eclipse.xtext.example.arithmetics.arithmetics.Import) Definition(org.eclipse.xtext.example.arithmetics.arithmetics.Definition) Multi(org.eclipse.xtext.example.arithmetics.arithmetics.Multi) EPackage(org.eclipse.emf.ecore.EPackage) Div(org.eclipse.xtext.example.arithmetics.arithmetics.Div) DeclaredParameter(org.eclipse.xtext.example.arithmetics.arithmetics.DeclaredParameter) Parameter(org.eclipse.xtext.Parameter) FunctionCall(org.eclipse.xtext.example.arithmetics.arithmetics.FunctionCall) DeclaredParameter(org.eclipse.xtext.example.arithmetics.arithmetics.DeclaredParameter) Plus(org.eclipse.xtext.example.arithmetics.arithmetics.Plus) Minus(org.eclipse.xtext.example.arithmetics.arithmetics.Minus) NumberLiteral(org.eclipse.xtext.example.arithmetics.arithmetics.NumberLiteral)

Example 3 with Evaluation

use of org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation in project xtext-eclipse by eclipse.

the class InterpreterAutoEdit method findEvaluation.

protected Evaluation findEvaluation(final DocumentCommand command, final XtextResource state) {
    boolean _isEmpty = state.getContents().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        org.eclipse.xtext.example.arithmetics.arithmetics.Module m = IterableExtensions.<org.eclipse.xtext.example.arithmetics.arithmetics.Module>head(Iterables.<org.eclipse.xtext.example.arithmetics.arithmetics.Module>filter(state.getContents(), org.eclipse.xtext.example.arithmetics.arithmetics.Module.class));
        Iterable<Evaluation> _filter = Iterables.<Evaluation>filter(m.getStatements(), Evaluation.class);
        for (final Evaluation evaluation : _filter) {
            {
                ICompositeNode node = NodeModelUtils.getNode(evaluation);
                if (((node.getOffset() <= command.offset) && ((node.getOffset() + node.getLength()) >= command.offset))) {
                    return evaluation;
                }
            }
        }
    }
    return null;
}
Also used : Evaluation(org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 4 with Evaluation

use of org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation in project xtext-eclipse by eclipse.

the class ArithmeticsValidator method checkNormalizable.

@Check
public void checkNormalizable(Expression expr) {
    if (expr instanceof NumberLiteral || expr instanceof FunctionCall) {
        return;
    }
    Evaluation eval = EcoreUtil2.getContainerOfType(expr, Evaluation.class);
    if (eval != null) {
        return;
    }
    TreeIterator<EObject> contents = expr.eAllContents();
    while (contents.hasNext()) {
        EObject next = contents.next();
        if ((next instanceof FunctionCall)) {
            return;
        }
    }
    BigDecimal decimal = calculator.evaluate(expr);
    if (decimal.toString().length() <= 8) {
        warning("Expression could be normalized to constant \'" + decimal + "\'", null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ArithmeticsValidator.NORMALIZABLE, decimal.toString());
    }
}
Also used : Evaluation(org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation) EObject(org.eclipse.emf.ecore.EObject) FunctionCall(org.eclipse.xtext.example.arithmetics.arithmetics.FunctionCall) NumberLiteral(org.eclipse.xtext.example.arithmetics.arithmetics.NumberLiteral) BigDecimal(java.math.BigDecimal) Check(org.eclipse.xtext.validation.Check)

Aggregations

Evaluation (org.eclipse.xtext.example.arithmetics.arithmetics.Evaluation)4 EObject (org.eclipse.emf.ecore.EObject)2 FunctionCall (org.eclipse.xtext.example.arithmetics.arithmetics.FunctionCall)2 NumberLiteral (org.eclipse.xtext.example.arithmetics.arithmetics.NumberLiteral)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 BigDecimal (java.math.BigDecimal)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Keyword (org.eclipse.xtext.Keyword)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 DeclaredParameter (org.eclipse.xtext.example.arithmetics.arithmetics.DeclaredParameter)1 Definition (org.eclipse.xtext.example.arithmetics.arithmetics.Definition)1 Div (org.eclipse.xtext.example.arithmetics.arithmetics.Div)1 Import (org.eclipse.xtext.example.arithmetics.arithmetics.Import)1 Minus (org.eclipse.xtext.example.arithmetics.arithmetics.Minus)1 Multi (org.eclipse.xtext.example.arithmetics.arithmetics.Multi)1 Plus (org.eclipse.xtext.example.arithmetics.arithmetics.Plus)1 INode (org.eclipse.xtext.nodemodel.INode)1 Check (org.eclipse.xtext.validation.Check)1