org.eclipse.xtext.util.EmfFormatter Java Examples
The following examples show how to use
org.eclipse.xtext.util.EmfFormatter.
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: PartialParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void compareWithNewResource(XtextResource resource, String model, int offset, int length, String newText, String fileName) throws IOException { resource.update(offset, length, newText); XtextResourceSet secondResourceSet = getResourceSet(); XtextResource newResource = (XtextResource) secondResourceSet.createResource(URI.createURI(fileName)); String newModel = new StringBuilder(model).replace(offset, offset + length, newText).toString(); assertEquals(newModel, resource.getParseResult().getRootNode().getText()); newResource.load(new StringInputStream(newModel), null); assertEquals(newResource.getContents().size(), resource.getContents().size()); EcoreUtil.resolveAll(resource); EcoreUtil.resolveAll(newResource); for(int i = 0; i < resource.getContents().size(); i++) { assertEquals(EmfFormatter.objToStr(newResource.getContents().get(i)), EmfFormatter.objToStr(resource.getContents().get(i))); } assertEqualNodes(newResource, resource); }
Example #2
Source File: AbstractParseTreeConstructor.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void dump(String indent, AbstractToken token) { System.out.println(indent + "begin " + token.getClass().getSimpleName() + " - " + EmfFormatter.objPath(token.getEObjectConsumer().getEObject()) + " node:" + dumpNode(token.getNode())); String newIndent = indent + "\t"; for (AbstractToken child : token.getTokensForSemanticChildren()) { if (child.getTokensForSemanticChildren().isEmpty()) System.out.println(newIndent + " -> " + child.getClass().getSimpleName() + " - " + (child.getEObjectConsumer() == null ? "null" : EmfFormatter.objPath(child .getEObjectConsumer().getEObject())) + " node:" + dumpNode(child.getNode())); else dump(newIndent, child); } System.out.println(indent + "end"); }
Example #3
Source File: BacktrackingSemanticSequencer.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public String toString() { List<String> mandatory = Lists.newArrayList(); List<String> optional = Lists.newArrayList(); for (int i = 0; i < values.length; i++) { int count = getValueCount(i); if (count > 0) { EStructuralFeature feature = eObject.eClass().getEStructuralFeature(i); if (this.optional[i]) optional.add(feature.getName() + "(" + count + ")"); else mandatory.add(feature.getName() + "(" + count + ")"); } } StringBuilder result = new StringBuilder(); result.append("EObject: " + EmfFormatter.objPath(eObject) + "\n"); result.append(getValuesString() + "\n"); return result.toString(); }
Example #4
Source File: BacktrackingSemanticSequencer.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public String toString() { List<String> mandatory = Lists.newArrayList(); List<String> optional = Lists.newArrayList(); List<String> consumed = Lists.newArrayList(); for (int i = 0; i < nextIndex.length; i++) { int count = nextIndex[i]; int max = obj.getValueCount(i); EStructuralFeature feature = obj.getEObject().eClass().getEStructuralFeature(i); if (count < max) { if (count == 0 && obj.isOptional(i)) optional.add(feature.getName() + "(" + (max - count) + ")"); else mandatory.add(feature.getName() + "(" + (max - count) + ")"); } else if (max > 0) consumed.add(feature.getName() + "(" + count + ")"); } StringBuilder result = new StringBuilder(); result.append("State: " + state + "\n"); result.append("EObject: " + EmfFormatter.objPath(obj.getEObject()) + "\n"); result.append("Remaining Mandatory Values: " + Joiner.on(", ").join(mandatory) + "\n"); result.append("Remaining Optional Values: " + Joiner.on(", ").join(optional) + "\n"); result.append("Consumed Values: " + Joiner.on(", ").join(consumed) + "\n"); return result.toString(); }
Example #5
Source File: GrammarElementDeclarationOrder.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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 #6
Source File: TreeConstructionReportImpl.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public String getLikelyErrorReasons(String prefix) { StringBuffer b = new StringBuffer(prefix); b.append(lengthCache.get(deadend)); b.append(":"); b.append(EmfFormatter.objPath(deadend.getEObjectConsumer().getEObject())); b.append(": \""); b.append(deadend.dumpTokens(10, 50, true)); b.append("\":"); for (String diagnosticAsString : collectDiagnostics(deadend)) { b.append("\n"); b.append(prefix); b.append(" -> "); b.append(diagnosticAsString); } return b.toString(); }
Example #7
Source File: AbstractValidationDiagnostic.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public String toString() { StringBuilder result = new StringBuilder(); result.append("Diagnostic "); result.append(severityToStr(severity)); if (issueCode != null) { result.append(" code="); result.append(issueCode); } result.append(" \""); result.append(message); result.append("\""); if (getSourceEObject() != null) { result.append(" at "); result.append(EmfFormatter.objPath(getSourceEObject())); } return result.toString(); }
Example #8
Source File: ISerializationDiagnostic.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public String toString(ISerializationDiagnostic diagnostic) { List<String> result = Lists.newArrayList(); String msg = diagnostic.getMessage(); EObject eObject = diagnostic.getSemanticObject(); Throwable exception = diagnostic.getException(); if (!Strings.isNullOrEmpty(msg)) result.add(msg); if (exception != null && exception.getMessage() != null && !exception.getMessage().equals(msg)) result.add("Caused By: " + exception.getClass().getName() + ": " + exception.getMessage()); if (eObject != null) { result.add("Semantic Object: " + EmfFormatter.objPath(eObject)); if (eObject.eResource() != null && eObject.eResource().getURI() != null) result.add("URI: " + eObject.eResource().getURI()); } ISerializationContext context = diagnostic.getIContext(); if (context != null) result.add("Context: " + context); if (diagnostic.getEStructuralFeature() != null) { EStructuralFeature feature = diagnostic.getEStructuralFeature(); EClass eClass = feature.getEContainingClass(); String nsPrefix = eClass.getEPackage().getNsPrefix(); result.add("EStructuralFeature: " + nsPrefix + "::" + eClass.getName() + "." + feature.getName()); } return Joiner.on("\n").join(result); }
Example #9
Source File: Bug419429Test.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void compareWithFullParse(String model, int offset, int length, String newText) throws Exception { XtextResource resource = getResourceFromStringAndExpect(model, UNKNOWN_EXPECTATION); resource.update(offset, length, newText); String text = resource.getParseResult().getRootNode().getText(); XtextResource newResource = getResourceFromStringAndExpect(text, UNKNOWN_EXPECTATION); assertEquals(text, resource.getContents().size(), newResource.getContents().size()); EcoreUtil.resolveAll(resource); EcoreUtil.resolveAll(newResource); for(int i = 0; i < resource.getContents().size(); i++) { assertEquals(text, EmfFormatter.objToStr(newResource.getContents().get(i)), EmfFormatter.objToStr(resource.getContents().get(i))); } ICompositeNode rootNode = resource.getParseResult().getRootNode(); ICompositeNode newRootNode = newResource.getParseResult().getRootNode(); Iterator<INode> iterator = rootNode.getAsTreeIterable().iterator(); Iterator<INode> newIterator = newRootNode.getAsTreeIterable().iterator(); while(iterator.hasNext()) { assertTrue(newIterator.hasNext()); assertEqualNodes(text, iterator.next(), newIterator.next()); } assertFalse(iterator.hasNext()); assertFalse(newIterator.hasNext()); }
Example #10
Source File: GrammarPDAProviderTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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 #11
Source File: NewAgentTest.java From sarl with Apache License 2.0 | 5 votes |
@Test @Ignore("only for debugging purpose") public void xtextParsing() throws Exception { IFile file = helper().createFile("test_" + UUID.randomUUID() + ".sarl", multilineString( "package io.sarl.eclipse.tests.wizards", "agent FooAgent0 { }")); Resource resource = helper().getResourceFor(file); resource.load(null); System.out.println(EmfFormatter.objToStr(resource.getContents().get(0))); }
Example #12
Source File: SerializerTester.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected ISerializationContext getContext(EObject semanticObject) { Iterable<ISerializationContext> contexts = contextFinder.findByContentsAndContainer(semanticObject, null); if (Iterables.size(contexts) != 1) { StringBuilder msg = new StringBuilder(); msg.append("One context is expected, but " + Iterables.size(contexts) + " have been found\n"); msg.append("Contexts: " + Joiner.on(", ").join(contexts)); msg.append("Semantic Object: " + EmfFormatter.objPath(semanticObject)); Assert.fail(msg.toString()); } return contexts.iterator().next(); }
Example #13
Source File: CrossReferenceSerializer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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 #14
Source File: SerializerTester.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected ISerializationContext getContext(EObject semanticObject) { Iterable<ISerializationContext> contexts = contextFinder.findByContentsAndContainer(semanticObject, null); if (Iterables.size(contexts) != 1) { StringBuilder msg = new StringBuilder(); msg.append("One context is expected, but " + Iterables.size(contexts) + " have been found\n"); msg.append("Contexts: " + Joiner.on(", ").join(contexts)); msg.append("Semantic Object: " + EmfFormatter.objPath(semanticObject)); Assert.fail(msg.toString()); } return contexts.iterator().next(); }
Example #15
Source File: BuilderUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public static String toString(IResourceDescriptions index) { StringBuffer buff = new StringBuffer(); for (IResourceDescription desc : index.getAllResourceDescriptions()) { buff.append(EmfFormatter.objToStr(desc, new EStructuralFeature[0])); } return buff.toString(); }
Example #16
Source File: XFunctionTypeRefAwareSerializerTester.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override protected void assertEqualWithEmfFormatter(EObject semanticObject, EObject parsed) { String expected = EmfFormatter.objToStr(semanticObject, XtypePackage.Literals.XFUNCTION_TYPE_REF__TYPE, TypesPackage.Literals.JVM_SPECIALIZED_TYPE_REFERENCE__EQUIVALENT); String actual = EmfFormatter.objToStr(parsed, XtypePackage.Literals.XFUNCTION_TYPE_REF__TYPE, TypesPackage.Literals.JVM_SPECIALIZED_TYPE_REFERENCE__EQUIVALENT); Assert.assertEquals(expected, actual); }
Example #17
Source File: PartialParserTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Test public void testBug480818() throws Exception { String code = "class Example {\n" + " val greeting = 'hello world!'\n" + " def sayHello() {\n" + " println(greeting)\n" + " prinntln(greeting)\n" + " }}"; XtextResource resource = createResource(code, "Example.xtend"); String before = EmfFormatter.listToStr(resource.getContents()); resource.update(code.lastIndexOf("prinntln")+2, 1, "i"); // here before bug 480818 was fixed a StackOverflowException occured String after = EmfFormatter.listToStr(resource.getContents()); assertEquals(before, after); }
Example #18
Source File: AbstractParseTreeConstructor.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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 #19
Source File: Context2NameFunction.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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 #20
Source File: Serializer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @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 #21
Source File: TokenDiagnosticProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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 #22
Source File: SerializerTestHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected ISerializationContext getContext(EObject semanticObject) { Iterable<ISerializationContext> contexts = contextFinder.findByContentsAndContainer(semanticObject, null); if (Iterables.size(contexts) != 1) { StringBuilder msg = new StringBuilder(); msg.append("One context is expected, but " + Iterables.size(contexts) + " have been found\n"); msg.append("Contexts: " + Joiner.on(", ").join(contexts)); msg.append("Semantic Object: " + EmfFormatter.objPath(semanticObject)); Assert.fail(msg.toString()); } return contexts.iterator().next(); }
Example #23
Source File: CondititionSimplifierTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public void check(String expectation, String model) throws Exception { EObject parsedModel = getModel(model); EObject parsedExpectation = getModel(expectation); conditionSimplifier.simplify((IfCondition) parsedModel); String formattedModel = EmfFormatter.objToStr(parsedModel); String formattedExpectation = EmfFormatter.objToStr(parsedExpectation); assertEquals(formattedExpectation, formattedModel); }
Example #24
Source File: ComplexReconstrTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testPrintGrammar() { XtextResourceSet rs = get(XtextResourceSet.class); rs.setClasspathURIContext(getClass()); URI u = URI .createURI("classpath:/org/eclipse/xtext/parsetree/reconstr/ComplexReconstrTestLanguage.xtextbin"); EObject o = rs.getResource(u, true).getContents().get(0); for (Object x : o.eContents()) if (x instanceof ParserRule) { ParserRule pr = (ParserRule) x; if (pr.getName().toLowerCase().contains("tricky")) { if (logger.isTraceEnabled()) logger.trace(EmfFormatter.objToStr(pr)); } } }
Example #25
Source File: PartialSerializer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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 #26
Source File: SCTSerializer.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@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 #27
Source File: BuilderUtil.java From n4js with Eclipse Public License 1.0 | 5 votes |
/***/ public static String toString(IResourceDescriptions index) { StringBuffer buff = new StringBuffer(); for (IResourceDescription desc : index.getAllResourceDescriptions()) { buff.append(EmfFormatter.objToStr(desc, new EStructuralFeature[0])); } return buff.toString(); }
Example #28
Source File: SarlAgentBuilderImpl.java From sarl with Apache License 2.0 | 4 votes |
@Override @Pure public String toString() { return EmfFormatter.objToStr(getSarlAgent()); }
Example #29
Source File: FormalParameterBuilderImpl.java From sarl with Apache License 2.0 | 4 votes |
@Override @Pure public String toString() { return EmfFormatter.objToStr(getDefaultValue()); }
Example #30
Source File: SarlBehaviorBuilderImpl.java From sarl with Apache License 2.0 | 4 votes |
@Override @Pure public String toString() { return EmfFormatter.objToStr(getSarlBehavior()); }