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));
}
}
}
}
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));
}
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;
}
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());
}
}
Aggregations