@Override public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node, Acceptor errors) { if (((InternalEObject) target).eProxyURI() != null) { if (((InternalEObject) target).eProxyURI().toString().startsWith("#")) { return super.serializeCrossRef(semanticObject, crossref, getEObjectfromEProxy(semanticObject, target), node, errors); } } return super.serializeCrossRef(semanticObject, crossref, target, node, errors); }
@Override public boolean isValid(EObject semanticObject, CrossReference crossref, EObject target, INode node, Acceptor errors) { if ((target == null || target.eIsProxy()) && node != null) { CrossReference crossrefFromNode = GrammarUtil.containingCrossReference(node.getGrammarElement()); return crossref == crossrefFromNode; } final EReference ref = GrammarUtil.getReference(crossref, semanticObject.eClass()); final IScope scope = scopeProvider.getScope(semanticObject, ref); if (scope == null) { if (errors != null) errors.accept(diagnostics.getNoScopeFoundDiagnostic(semanticObject, crossref, target)); return false; } if (target != null && target.eIsProxy()) { target = handleProxy(target, semanticObject, ref); } return getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors) != null; }
@Override public String serializeAssignedValue(EObject context, RuleCall ruleCall, Object value, INode node, Acceptor errors) { AbstractRule rule = ruleCall.getRule(); String ruleName = ruleNames.getQualifiedName(rule); if (node != null) { AbstractRule nodeRule = linkingHelper.getRuleFrom(node.getGrammarElement()); // TODO: analyze why grammar element identity is broken here during generation of Xtext languages using MWE2 if (nodeRule != null && ruleNames.getQualifiedName(nodeRule).equals(ruleName)) { Object converted = converter.toValue(NodeModelUtils.getTokenText(node), ruleName, node); if (converted != null && converted.equals(value)) return tokenUtil.serializeNode(node); } } try { String str = converter.toString(value, ruleName); if (str != null) return str; if (errors != null) errors.accept(diagnostics.getNullNotAllowedDiagnostic(context, ruleCall)); return null; } catch (Throwable e) { if (errors != null) errors.accept(diagnostics.getValueConversionExceptionDiagnostic(context, ruleCall, value, e)); return null; } }
@Override protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref, EObject target, IScope scope, Acceptor errors) { if (target instanceof AbstractRule) { return ((AbstractRule) target).getName(); } if (target instanceof ENamedElement) { return ((ENamedElement) target).getName(); } return super.getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors); }
protected SequenceFeeder(Provider provider, ISerializationContext context, EObject semanticObject, INodesForEObjectProvider nodes, ISemanticSequencer masterSequencer, ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { super(); if (semanticObject == null || nodes == null || sequenceAcceptor == null) throw new NullPointerException(); this.context = context; this.provider = provider; this.semanticObject = semanticObject; this.nodes = nodes; this.masterSequencer = masterSequencer; this.sequenceAcceptor = sequenceAcceptor; this.errorAcceptor = errorAcceptor; }
@Override public void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor) { this.masterSequencer = sequencer; this.sequenceAcceptor = sequenceAcceptor; this.errorAcceptor = errorAcceptor; }
@Override @Deprecated public void init(EObject context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { ISerializationContext ctx = SerializationContext.fromEObject(context, semanticObject); init(ctx, semanticObject, sequenceAcceptor, errorAcceptor); }
@Override public void init(ISerializationContext context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { INode node = NodeModelUtils.findActualNodeFor(semanticObject); syntacticSequencerPDAs = pdaProvider.getSyntacticSequencerPDAs(grammar.getGrammar()); ISynAbsorberState state = syntacticSequencerPDAs.get(context); Preconditions.checkNotNull(state, "Invalid context: " + context); SyntacticalContext acceptor = new SyntacticalContext(context, semanticObject, state, node); contexts.push(acceptor); delegate = sequenceAcceptor; this.errorAcceptor = errorAcceptor; }
@Override @Deprecated public void init(EObject context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { this.delegate = sequenceAcceptor; this.lastNode = NodeModelUtils.findActualNodeFor(semanticObject); this.rootNode = lastNode; if (rootNode != null) { this.rootOffset = rootNode.getTotalOffset(); this.rootEndOffset = rootNode.getTotalEndOffset(); } }
@Override public void init(ISerializationContext context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { this.delegate = sequenceAcceptor; this.lastNode = NodeModelUtils.findActualNodeFor(semanticObject); this.rootNode = lastNode; if (rootNode != null) { this.rootOffset = rootNode.getTotalOffset(); this.rootEndOffset = rootNode.getTotalEndOffset(); } }
@Override public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node, Acceptor errors) { if ((target == null || target.eIsProxy()) && node != null) return tokenUtil.serializeNode(node); final EReference ref = GrammarUtil.getReference(crossref, semanticObject.eClass()); final IScope scope = scopeProvider.getScope(semanticObject, ref); if (scope == null) { if (errors != null) errors.accept(diagnostics.getNoScopeFoundDiagnostic(semanticObject, crossref, target)); return null; } if (target != null && target.eIsProxy()) { target = handleProxy(target, semanticObject, ref); } if (target != null && node != null) { String text = linkingHelper.getCrossRefNodeAsString(node, true); QualifiedName qn = qualifiedNameConverter.toQualifiedName(text); URI targetURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(target); for (IEObjectDescription desc : scope.getElements(qn)) { if (targetURI.equals(desc.getEObjectURI())) return tokenUtil.serializeNode(node); } } return getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors); }
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref, EObject target, final IScope scope, Acceptor errors) { String ruleName = linkingHelper.getRuleNameFrom(crossref); boolean foundOne = false; List<ISerializationDiagnostic> recordedErrros = null; for (IEObjectDescription desc : scope.getElements(target)) { foundOne = true; String unconverted = qualifiedNameConverter.toString(desc.getName()); try { return valueConverter.toString(unconverted, ruleName); } catch (ValueConverterException e) { if (errors != null) { if (recordedErrros == null) recordedErrros = Lists.newArrayList(); recordedErrros.add(diagnostics.getValueConversionExceptionDiagnostic(semanticObject, crossref, unconverted, e)); } } } if (errors != null) { if (recordedErrros != null) for (ISerializationDiagnostic diag : recordedErrros) errors.accept(diag); if (!foundOne) errors.accept(diagnostics.getNoEObjectDescriptionFoundDiagnostic(semanticObject, crossref, target, scope)); } return null; }
@Override public String serializeAssignedEnumLiteral(EObject context, RuleCall ruleCall, Object value, INode node, Acceptor errorAcceptor) { Keyword nodeLit = getLiteral(node); Keyword modelLit = getLiteral(context, ruleCall, value); if (modelLit == null) { if (errorAcceptor != null) errorAcceptor.accept(diagnosticProvider.getInvalidEnumValueDiagnostic(context, ruleCall, value)); return null; } else if (nodeLit != null && nodeLit.equals(modelLit)) return tokenUtil.serializeNode(node); else return modelLit.getValue(); }
@Override public boolean isValid(EObject context, RuleCall ruleCall, Object value, Acceptor errors) { try { String str = converter.toString(value, ruleNames.getQualifiedName(ruleCall.getRule())); if (str != null) return true; if (errors != null) errors.accept(diagnostics.getNullNotAllowedDiagnostic(context, ruleCall)); return false; } catch (Throwable e) { if (errors != null) errors.accept(diagnostics.getValueConversionExceptionDiagnostic(context, ruleCall, value, e)); return false; } }
@Override public boolean isValid(EObject context, Keyword keyword, Object value, Acceptor errorAcceptor) { if (value instanceof String) { return keyword.getValue().equalsIgnoreCase((String) value); } return false; }
@Override public String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node, Acceptor errorAcceptor) { if (node != null && node.getGrammarElement() == keyword) return node.getText(); return keyword.getValue(); }
@Override public void init(final EObject context, final EObject semanticObject, final ISequenceAcceptor sequenceAcceptor, final Acceptor errorAcceptor) { this.delegate = sequenceAcceptor; this.lastNode = NodeModelUtils.findActualNodeFor(semanticObject); this.rootNode = lastNode; if (rootNode != null) { this.rootOffset = rootNode.getTotalOffset(); this.rootEndOffset = rootNode.getTotalEndOffset(); } }
@Override public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node, Acceptor errors) { // for statechart crossreferences, we do not want to check the scope if (target instanceof Statechart) { return provider.getFullyQualifiedName(target).toString(); } return super.serializeCrossRef(semanticObject, crossref, target, node, errors); }
@Override public void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { super.init(sequencer, sequenceAcceptor, errorAcceptor); this.genericSequencer = genericSequencerProvider.get(); this.genericSequencer.init(sequencer, sequenceAcceptor, errorAcceptor); }
/** * @deprecated {@link #create(ISerializationContext, EObject, INodesForEObjectProvider, ISemanticSequencer, ISemanticSequenceAcceptor, Acceptor)} */ @Deprecated public SequenceFeeder create(EObject semanticObject, INodesForEObjectProvider nodes, ISemanticSequencer masterSequencer, ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { return new SequenceFeeder(this, semanticObject, nodes, masterSequencer, sequenceAcceptor, errorAcceptor); }
public SequenceFeeder create(ISerializationContext context, EObject semanticObject, INodesForEObjectProvider nodes, ISemanticSequencer masterSequencer, ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { return new SequenceFeeder(this, context, semanticObject, nodes, masterSequencer, sequenceAcceptor, errorAcceptor); }
/** * @deprecated {@link #SequenceFeeder(Provider, ISerializationContext, EObject, INodesForEObjectProvider, ISemanticSequencer, ISemanticSequenceAcceptor, Acceptor)} */ @Deprecated protected SequenceFeeder(Provider provider, EObject semanticObject, INodesForEObjectProvider nodes, ISemanticSequencer masterSequencer, ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { this(provider, null, semanticObject, nodes, masterSequencer, sequenceAcceptor, errorAcceptor); }
@Override public void init(ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) { init(this, sequenceAcceptor, errorAcceptor); }
@Override public boolean isValid(EObject context, RuleCall ruleCall, Object value, Acceptor errorAcceptor) { return getLiteral(context, ruleCall, value) != null; }
@Override public boolean isValid(EObject context, Keyword keyword, Object value, Acceptor errorAcceptor) { return keyword.getValue().equals(value); }