Java Code Examples for org.eclipse.xtext.util.EmfFormatter#objPath()

The following examples show how to use org.eclipse.xtext.util.EmfFormatter#objPath() . 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
Source File: GrammarElementDeclarationOrder.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public int getElementID(EObject ele) {
	Integer result = elementIDCache.get(ele);
	if (result == null) {
		Grammar grammar = GrammarUtil.getGrammar(ele);
		if (!elementIDCache.containsKey(grammar)) {
			String grammarName = grammar.getName() + "#" + System.identityHashCode(grammar);
			List<String> indexed = Lists.newArrayList();
			for (EObject o : elementIDCache.keySet())
				if (o instanceof Grammar)
					indexed.add(((Grammar) o).getName() + "#" + System.identityHashCode(o));
			throw new IllegalStateException("No ID found. Wrong grammar. \nRequested: " + grammarName
					+ "\nAvailable: " + Joiner.on(", ").join(indexed));
		} else
			throw new IllegalStateException("No ID found. Not indexed. \nElement: " + EmfFormatter.objPath(ele));
	}
	return result;
}
 
Example 2
Source File: GrammarPDAProviderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
  final Function1<ISerState, AbstractElement> _function = (ISerState it) -> {
    return it.getGrammarElement();
  };
  Iterable<AbstractElement> _filterNull = IterableExtensions.<AbstractElement>filterNull(IterableExtensions.<ISerState, AbstractElement>map(new NfaUtil().<ISerState>collect(pda), _function));
  for (final AbstractElement ele : _filterNull) {
    {
      final Grammar actual = GrammarUtil.getGrammar(ele);
      if ((actual != grammar)) {
        String _objPath = EmfFormatter.objPath(ele);
        String _plus = ("Element " + _objPath);
        String _plus_1 = (_plus + " leaked!");
        Assert.fail(_plus_1);
      }
    }
  }
}
 
Example 3
Source File: CrossReferenceSerializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getConvertedValue(String unconverted, CrossReference grammarElement) {
	String ruleName = linkingHelper.getRuleNameFrom(grammarElement);
	if (ruleName == null)
		throw new IllegalStateException("Could not determine targeted rule name for "
				+ EmfFormatter.objPath(grammarElement));
	return valueConverter.toString(unconverted, ruleName);
}
 
Example 4
Source File: AbstractParseTreeConstructor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String serializeInternal(INode node) {
	if (type == null)
		return null;
	switch (type) {
		case CROSS_REFERENCE:
			String ref = crossRefSerializer.serializeCrossRef(eObjectConsumer.getEObject(),
					(CrossReference) element, (EObject) value, node);
			if (ref == null) {
				Assignment ass = GrammarUtil.containingAssignment(element);
				throw new XtextSerializationException("Could not serialize cross reference from "
						+ EmfFormatter.objPath(eObjectConsumer.getEObject()) + "." + ass.getFeature() + " to "
						+ EmfFormatter.objPath((EObject) value));
			}
			return ref;
		case KEYWORD:
			return keywordSerializer.serializeAssignedKeyword(eObjectConsumer.getEObject(),
					((Keyword) element), value, node);
		case TERMINAL_RULE_CALL:
			return valueSerializer.serializeAssignedValue(eObjectConsumer.getEObject(), (RuleCall) element,
					value, node);
		case ENUM_RULE_CALL:
			return enumLitSerializer.serializeAssignedEnumLiteral(eObjectConsumer.getEObject(),
					(RuleCall) element, value, node);
		case PARSER_RULE_CALL:
			return null;
		case DATATYPE_RULE_CALL:
			return valueSerializer.serializeAssignedValue(eObjectConsumer.getEObject(), (RuleCall) element,
					value, node);
		default:
			return null;
	}
}
 
Example 5
Source File: Context2NameFunction.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public String getContextName(Grammar grammar, EObject ctx) {
	if (GrammarUtil.isEObjectRule(ctx))
		return getContextName(grammar, (ParserRule) ctx);
	if (GrammarUtil.isAssignedAction(ctx))
		return getContextName(grammar, (Action) ctx);
	throw new RuntimeException("Invalid Context: " + EmfFormatter.objPath(ctx));
}
 
Example 6
Source File: Serializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @deprecated use {@link #getIContext(EObject)}
 */
@Deprecated
protected EObject getContext(EObject semanticObject) {
	Iterator<EObject> contexts = contextFinder.findContextsByContentsAndContainer(semanticObject, null).iterator();
	if (!contexts.hasNext())
		throw new RuntimeException("No Context for " + EmfFormatter.objPath(semanticObject) + " could be found");
	return contexts.next();
}
 
Example 7
Source File: TokenDiagnosticProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ISerializationDiagnostic getNoEObjectDescriptionFoundDiagnostic(EObject semanticObject,
		CrossReference element, EObject target, IScope scope) {
	String msg = "No EObjectDescription could be found in Scope " + getFullReferenceName(semanticObject, element)
			+ " for " + EmfFormatter.objPath(target);
	return new SerializationDiagnostic(NO_EOBJECT_DESCRIPTION_FOUND, semanticObject, element, grammarAccess.getGrammar(), msg);
}
 
Example 8
Source File: PartialSerializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected ISerializationContext getSerializationContext(EObject semanticObject) {
	Iterator<ISerializationContext> contexts = contextFinder.findByContentsAndContainer(semanticObject, null)
			.iterator();
	if (!contexts.hasNext())
		throw new RuntimeException("No Context for " + EmfFormatter.objPath(semanticObject) + " could be found");
	return contexts.next();
}
 
Example 9
Source File: SCTSerializer.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ISerializationContext getIContext(EObject semanticObject) {
	Iterator<ISerializationContext> contexts = contextFinder.findByContents(semanticObject, null).iterator();
	if (!contexts.hasNext())
		throw new RuntimeException("No Context for " + EmfFormatter.objPath(semanticObject) + " could be found");
	return contexts.next();
}
 
Example 10
Source File: ConcreteSyntaxDiagnosticProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String getSource() {
	return EmfFormatter.objPath(source);
}
 
Example 11
Source File: Serializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected ISerializationContext getIContext(EObject semanticObject) {
	Iterator<ISerializationContext> contexts = contextFinder.findByContentsAndContainer(semanticObject, null).iterator();
	if (!contexts.hasNext())
		throw new RuntimeException("No Context for " + EmfFormatter.objPath(semanticObject) + " could be found");
	return contexts.next();
}
 
Example 12
Source File: CommonCrossReferenceSerializer.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns a value, converted according to the grammar element's rule. Based on
 * {@link org.eclipse.xtext.parsetree.reconstr.impl.CrossReferenceSerializer#getConvertedValue}
 *
 * @param unconverted
 *          the unconverted value, must not be{@code null}
 * @param grammarElement
 *          the cross reference, must not be {@code null}
 * @return the converted value or {@code null} if conversion failed
 */
protected String getConvertedValue(final String unconverted, final AbstractElement grammarElement) {
  String ruleName = linkingHelper.getRuleNameFrom(grammarElement);
  if (ruleName == null) {
    throw new IllegalStateException("Could not determine targeted rule name for " //$NON-NLS-1$
        + EmfFormatter.objPath(grammarElement));
  }
  return valueConverter.toString(unconverted, ruleName);
}