Java Code Examples for org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor

The following examples show how to use org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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;
}
 
Example 2
Source Project: xtext-core   Source File: ValueSerializer.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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;
	}
}
 
Example 3
Source Project: n4js   Source File: GrammarPrettyPrinter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example 4
Source Project: xtext-core   Source File: SequenceFeeder.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 5
@Override
public void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor,
		ISerializationDiagnostic.Acceptor errorAcceptor) {
	this.masterSequencer = sequencer;
	this.sequenceAcceptor = sequenceAcceptor;
	this.errorAcceptor = errorAcceptor;
}
 
Example 6
@Override
@Deprecated
public void init(EObject context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor,
		Acceptor errorAcceptor) {
	ISerializationContext ctx = SerializationContext.fromEObject(context, semanticObject);
	init(ctx, semanticObject, sequenceAcceptor, errorAcceptor);
}
 
Example 7
@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;
}
 
Example 8
Source Project: xtext-core   Source File: HiddenTokenSequencer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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();
	}
}
 
Example 9
Source Project: xtext-core   Source File: HiddenTokenSequencer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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();
	}
}
 
Example 10
@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);
}
 
Example 11
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref, EObject target,
		final IScope scope, Acceptor errors) {
	String ruleName = linkingHelper.getRuleNameFrom(crossref);
	boolean foundOne = false;
	List<ISerializationDiagnostic> recordedErrors = 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 (recordedErrors == null)
					recordedErrors = Lists.newArrayList();
				recordedErrors.add(diagnostics.getValueConversionExceptionDiagnostic(semanticObject, crossref,
						unconverted, e));
			}
		}
	}
	if (errors != null) {
		if (recordedErrors != null)
			for (ISerializationDiagnostic diag : recordedErrors)
				errors.accept(diag);
		if (!foundOne)
			errors.accept(diagnostics.getNoEObjectDescriptionFoundDiagnostic(semanticObject, crossref, target,
					scope));
	}
	return null;
}
 
Example 12
Source Project: xtext-core   Source File: EnumLiteralSerializer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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();
}
 
Example 13
Source Project: xtext-core   Source File: ValueSerializer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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;
	}
}
 
Example 14
@Override
public boolean isValid(EObject context, Keyword keyword, Object value, Acceptor errorAcceptor) {
	if (value instanceof String) {
		return keyword.getValue().equalsIgnoreCase((String) value);
	}
	return false;
}
 
Example 15
Source Project: xtext-core   Source File: KeywordSerializer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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();
}
 
Example 16
@Override
@Deprecated
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();
  }
}
 
Example 17
@Override
public void init(final ISerializationContext 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();
  }
}
 
Example 18
@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);
}
 
Example 19
Source Project: xtext-core   Source File: SequenceFeeder.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @deprecated {@link #create(ISerializationContext, EObject, ISemanticNodeProvider.INodesForEObjectProvider, ISemanticSequencer, ISemanticSequenceAcceptor, ISerializationDiagnostic.Acceptor)}
 */
@Deprecated
public SequenceFeeder create(EObject semanticObject, INodesForEObjectProvider nodes, ISemanticSequencer masterSequencer,
		ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) {
	return new SequenceFeeder(this, semanticObject, nodes, masterSequencer, sequenceAcceptor, errorAcceptor);
}
 
Example 20
Source Project: xtext-core   Source File: SequenceFeeder.java    License: Eclipse Public License 2.0 4 votes vote down vote up
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);
}
 
Example 21
Source Project: xtext-core   Source File: SequenceFeeder.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @deprecated {@link #SequenceFeeder(SequenceFeeder.Provider, ISerializationContext, EObject, ISemanticNodeProvider.INodesForEObjectProvider, ISemanticSequencer, ISemanticSequenceAcceptor, ISerializationDiagnostic.Acceptor)}
 */
@Deprecated
protected SequenceFeeder(Provider provider, EObject semanticObject, INodesForEObjectProvider nodes, ISemanticSequencer masterSequencer,
		ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) {
	this(provider, null, semanticObject, nodes, masterSequencer, sequenceAcceptor, errorAcceptor);
}
 
Example 22
@Override
public void init(ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) {
	init(this, sequenceAcceptor, errorAcceptor);
}
 
Example 23
@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);
}
 
Example 24
Source Project: xtext-core   Source File: EnumLiteralSerializer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean isValid(EObject context, RuleCall ruleCall, Object value, Acceptor errorAcceptor) {
	return getLiteral(context, ruleCall, value) != null;
}
 
Example 25
@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();
}
 
Example 26
Source Project: xtext-core   Source File: KeywordSerializer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean isValid(EObject context, Keyword keyword, Object value, Acceptor errorAcceptor) {
	return keyword.getValue().equals(value);
}