@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(); }
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(); }
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"); }
@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(); }
@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(); }
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; }
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); }
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()); }
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); } } } }
/***/ 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(); }
@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); }
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(); }
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); }
@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; } }
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)); }
/** * @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(); }
@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); }
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); }
@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)); } } }
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(); }
/***/ public static String toString(IResourceDescription desc) { if (desc == null) return "null"; return EmfFormatter.objToStr(desc, new EStructuralFeature[0]); }
protected void doTestResource(String platformPath, String... packageNames) { Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true); assertNotNull(resource); assertEquals(1, resource.getContents().size()); EObject obj = resource.getContents().get(0); if (obj instanceof EPackage) { assertEquals(packageNames[0], ((EPackage) obj).getName()); } else if (obj instanceof GenModel) { GenModel model = (GenModel) obj; List<GenPackage> packages = Lists.newArrayList(model.getGenPackages()); assertEquals(packageNames.length, packages.size()); ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() { @Override public String apply(GenPackage p) { return p.getEcorePackage().getName(); } }); List<String> packageNamesList = Arrays.asList(packageNames); Collections.sort(packageNamesList); for(int i = 0; i < packageNamesList.size(); i++) { assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName()); } IStatus status = model.validate(); assertTrue(printLeafs(status), status.isOK()); EObject orig = EcoreUtil.copy(obj); ((GenModel) obj).reconcile(); if (!EcoreUtil.equals(orig, obj)) { Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() { @Override public boolean apply(EStructuralFeature f) { if (f instanceof EReference) { EReference casted = (EReference) f; return !casted.isContainment(); } return false; } }; String origAsString = EmfFormatter.objToStr(orig, ignoreContainer); String newAsString = EmfFormatter.objToStr(obj, ignoreContainer); throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString); } } else { fail("Unexpected root element type: " + obj.eClass().getName()); } }
/** * @since 2.3 */ protected void assertEqualWithEmfFormatter(EObject semanticObject, EObject parsed) { String expected = EmfFormatter.objToStr(semanticObject); String actual = EmfFormatter.objToStr(parsed); Assert.assertEquals(expected, actual); }
private void assertEqual(final IParseResult parsedFromScratch, final IParseResult reparsed) { EObject rootFromScratch = parsedFromScratch.getRootASTElement(); EObject rootReparsed = reparsed.getRootASTElement(); this.assertEqual(EmfFormatter.objToStr(rootFromScratch), EmfFormatter.objToStr(rootReparsed)); this.assertEqual(parsedFromScratch.getRootNode(), reparsed.getRootNode()); }
public static void assertEObjectsEqual(EObject expected, EObject actual, EStructuralFeature... ignoredFeatures) { String e = EmfFormatter.objToStr(expected, ignoredFeatures); String a = EmfFormatter.objToStr(actual, ignoredFeatures); assertEquals(e, a); }
@Override public String getSource() { return EmfFormatter.objPath(source); }
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(); }
private void assertEqual(String data, String newData, IParseResult parsedFromScratch, IParseResult reparsed) { EObject rootFromScratch = parsedFromScratch.getRootASTElement(); EObject rootReparsed = reparsed.getRootASTElement(); assertEqual(data, newData, EmfFormatter.objToStr(rootFromScratch), EmfFormatter.objToStr(rootReparsed)); assertEqual(data, newData, parsedFromScratch.getRootNode(), reparsed.getRootNode()); }
@Override public void acceptAssignedCrossRefDatatype(RuleCall rc, String token, EObject value, int index, ICompositeNode node) { add(titles.doSwitch(rc), token, EmfFormatter.objPath(value), index, node); super.acceptAssignedCrossRefDatatype(rc, token, value, index, node); }
@Override public void acceptAssignedCrossRefEnum(RuleCall enumRC, String token, EObject value, int index, ICompositeNode node) { add(titles.doSwitch(enumRC), token, EmfFormatter.objPath(value), index, node); super.acceptAssignedCrossRefEnum(enumRC, token, value, index, node); }
@Override public void acceptAssignedCrossRefKeyword(Keyword kw, String token, EObject value, int index, ILeafNode node) { add(titles.doSwitch(kw), token, EmfFormatter.objPath(value), index, node); super.acceptAssignedCrossRefKeyword(kw, token, value, index, node); }
@Override public void acceptAssignedCrossRefTerminal(RuleCall rc, String token, EObject value, int index, ILeafNode node) { add(titles.doSwitch(rc), token, EmfFormatter.objPath(value), index, node); super.acceptAssignedCrossRefTerminal(rc, token, value, index, node); }
protected void assertEqualWithEmfFormatter(EObject semanticObject, EObject parsed) { String expected = EmfFormatter.objToStr(semanticObject); String actual = EmfFormatter.objToStr(parsed); Assert.assertEquals(expected, actual); }
private String parseAndSerialize(String model) throws Exception { EObject result = getModel(model); if (logger.isTraceEnabled()) logger.trace(EmfFormatter.objToStr(result)); return getSerializer().serialize(result, SaveOptions.defaultOptions()); }
/** * 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); }