2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.ImmutableCollection;
14 import com.google.common.collect.ImmutableList;
15 import com.google.common.collect.ImmutableMultimap;
16 import com.google.common.collect.ImmutableSet;
17 import com.google.common.collect.Multimap;
18 import com.google.common.collect.Multimaps;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.EnumMap;
23 import java.util.EventListener;
24 import java.util.Iterator;
25 import java.util.Optional;
27 import javax.annotation.Nonnull;
28 import javax.annotation.Nullable;
29 import org.opendaylight.yangtools.util.OptionalBoolean;
30 import org.opendaylight.yangtools.yang.common.QName;
31 import org.opendaylight.yangtools.yang.common.QNameModule;
32 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
33 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
34 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
35 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
36 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
37 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
38 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
39 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
40 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
41 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
42 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
43 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
44 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupport;
45 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
46 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
47 import org.opendaylight.yangtools.yang.parser.spi.source.ImplicitSubstatement;
48 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
49 import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference;
50 import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace;
51 import org.opendaylight.yangtools.yang.parser.spi.source.SupportedFeaturesNamespace.SupportedFeatures;
52 import org.opendaylight.yangtools.yang.parser.stmt.reactor.NamespaceBehaviourWithListeners.ValueAddedListener;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
57 extends NamespaceStorageSupport implements StmtContext.Mutable<A, D, E> {
59 * event listener when an item is added to model namespace.
61 interface OnNamespaceItemAdded extends EventListener {
63 * @throws SourceException
65 void namespaceItemAdded(StatementContextBase<?, ?, ?> context, Class<?> namespace, Object key, Object value);
69 * event listener when a parsing {@link ModelProcessingPhase} is completed.
71 interface OnPhaseFinished extends EventListener {
73 * @throws SourceException
75 boolean phaseFinished(StatementContextBase<?, ?, ?> context, ModelProcessingPhase phase);
79 * interface for all mutations within an {@link ModelActionBuilder.InferenceAction}.
81 interface ContextMutation {
86 private static final Logger LOG = LoggerFactory.getLogger(StatementContextBase.class);
88 private final StatementDefinitionContext<A, D, E> definition;
89 private final StatementSourceReference statementDeclSource;
90 private final StmtContext<?, ?, ?> originalCtx;
91 private final CopyHistory copyHistory;
92 private final String rawArgument;
94 private Multimap<ModelProcessingPhase, OnPhaseFinished> phaseListeners = ImmutableMultimap.of();
95 private Multimap<ModelProcessingPhase, ContextMutation> phaseMutation = ImmutableMultimap.of();
96 private Collection<Mutable<?, ?, ?>> effective = ImmutableList.of();
97 private Collection<StmtContext<?, ?, ?>> effectOfStatement = ImmutableList.of();
98 private StatementMap substatements = StatementMap.empty();
100 private boolean isSupportedToBuildEffective = true;
101 private ModelProcessingPhase completedPhase = null;
102 private D declaredInstance;
103 private E effectiveInstance;
105 // BooleanFields value
106 private byte supportedByFeatures;
108 StatementContextBase(final StatementDefinitionContext<A, D, E> def, final StatementSourceReference ref,
109 final String rawArgument) {
110 this.definition = Preconditions.checkNotNull(def);
111 this.statementDeclSource = Preconditions.checkNotNull(ref);
112 this.rawArgument = def.internArgument(rawArgument);
113 this.copyHistory = CopyHistory.original();
114 this.originalCtx = null;
117 StatementContextBase(final StatementContextBase<A, D, E> original, final CopyType copyType) {
118 this.definition = Preconditions.checkNotNull(original.definition,
119 "Statement context definition cannot be null copying from: %s", original.getStatementSourceReference());
120 this.statementDeclSource = Preconditions.checkNotNull(original.statementDeclSource,
121 "Statement context statementDeclSource cannot be null copying from: %s",
122 original.getStatementSourceReference());
123 this.rawArgument = original.rawArgument;
124 this.copyHistory = CopyHistory.of(copyType, original.getCopyHistory());
125 this.originalCtx = original.getOriginalCtx().orElse(original);
129 public Collection<? extends StmtContext<?, ?, ?>> getEffectOfStatement() {
130 return effectOfStatement;
134 public void addAsEffectOfStatement(final StmtContext<?, ?, ?> ctx) {
135 if (effectOfStatement.isEmpty()) {
136 effectOfStatement = new ArrayList<>(1);
138 effectOfStatement.add(ctx);
142 public void addAsEffectOfStatement(final Collection<? extends StmtContext<?, ?, ?>> ctxs) {
143 if (ctxs.isEmpty()) {
147 if (effectOfStatement.isEmpty()) {
148 effectOfStatement = new ArrayList<>(ctxs.size());
150 effectOfStatement.addAll(ctxs);
154 public boolean isSupportedByFeatures() {
155 if (OptionalBoolean.isPresent(supportedByFeatures)) {
156 return OptionalBoolean.get(supportedByFeatures);
159 if (isIgnoringIfFeatures()) {
160 supportedByFeatures = OptionalBoolean.of(true);
164 final boolean isParentSupported = isParentSupportedByFeatures();
166 * If parent is not supported, then this context is also not supported.
167 * So we do not need to check if-features statements of this context and
168 * we can return false immediately.
170 if (!isParentSupported) {
171 supportedByFeatures = OptionalBoolean.of(false);
176 * If parent is supported, we need to check if-features statements of
179 // If the set of supported features has not been provided, all features are supported by default.
180 final Set<QName> supportedFeatures = getFromNamespace(SupportedFeaturesNamespace.class,
181 SupportedFeatures.SUPPORTED_FEATURES);
182 final boolean ret = supportedFeatures == null ? true
183 : StmtContextUtils.checkFeatureSupport(this, supportedFeatures);
185 supportedByFeatures = OptionalBoolean.of(ret);
189 protected abstract boolean isParentSupportedByFeatures();
191 protected abstract boolean isIgnoringIfFeatures();
193 protected abstract boolean isIgnoringConfig();
196 public boolean isSupportedToBuildEffective() {
197 return isSupportedToBuildEffective;
201 public void setIsSupportedToBuildEffective(final boolean isSupportedToBuildEffective) {
202 this.isSupportedToBuildEffective = isSupportedToBuildEffective;
206 public CopyHistory getCopyHistory() {
211 public Optional<StmtContext<?, ?, ?>> getOriginalCtx() {
212 return Optional.ofNullable(originalCtx);
216 public ModelProcessingPhase getCompletedPhase() {
217 return completedPhase;
221 public void setCompletedPhase(final ModelProcessingPhase completedPhase) {
222 this.completedPhase = completedPhase;
226 public abstract StatementContextBase<?, ?, ?> getParentContext();
229 * @return root context of statement
233 public abstract RootStatementContext<?, ?, ?> getRoot();
236 * @return origin of statement
240 public StatementSource getStatementSource() {
241 return statementDeclSource.getStatementSource();
245 * @return reference of statement source
249 public StatementSourceReference getStatementSourceReference() {
250 return statementDeclSource;
254 public final String rawStatementArgument() {
260 public Collection<? extends StmtContext<?, ?, ?>> declaredSubstatements() {
261 return substatements.values();
266 public Collection<? extends Mutable<?, ?, ?>> mutableDeclaredSubstatements() {
267 return substatements.values();
271 public Collection<? extends StmtContext<?, ?, ?>> effectiveSubstatements() {
272 return mutableEffectiveSubstatements();
277 public Collection<? extends Mutable<?, ?, ?>> mutableEffectiveSubstatements() {
278 if (effective instanceof ImmutableCollection) {
282 return Collections.unmodifiableCollection(effective);
285 public void removeStatementsFromEffectiveSubstatements(final Collection<? extends StmtContext<?, ?, ?>> substatements) {
286 if (!effective.isEmpty()) {
287 effective.removeAll(substatements);
292 private void shrinkEffective() {
293 if (effective.isEmpty()) {
294 effective = ImmutableList.of();
298 public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef) {
299 if (effective.isEmpty()) {
303 final Iterator<? extends StmtContext<?, ?, ?>> iterator = effective.iterator();
304 while (iterator.hasNext()) {
305 final StmtContext<?, ?, ?> next = iterator.next();
306 if (statementDef.equals(next.getPublicDefinition())) {
315 * Removes a statement context from the effective substatements
316 * based on its statement definition (i.e statement keyword) and raw (in String form) statement argument.
317 * The statement context is removed only if both statement definition and statement argument match with
318 * one of the effective substatements' statement definition and argument.
320 * If the statementArg parameter is null, the statement context is removed based only on its statement definition.
322 * @param statementDef statement definition of the statement context to remove
323 * @param statementArg statement argument of the statement context to remove
325 public void removeStatementFromEffectiveSubstatements(final StatementDefinition statementDef,
326 final String statementArg) {
327 if (statementArg == null) {
328 removeStatementFromEffectiveSubstatements(statementDef);
331 if (effective.isEmpty()) {
335 final Iterator<Mutable<?, ?, ?>> iterator = effective.iterator();
336 while (iterator.hasNext()) {
337 final Mutable<?, ?, ?> next = iterator.next();
338 if (statementDef.equals(next.getPublicDefinition()) && statementArg.equals(next.rawStatementArgument())) {
347 * adds effective statement to collection of substatements
349 * @param substatement substatement
350 * @throws IllegalStateException
351 * if added in declared phase
352 * @throws NullPointerException
353 * if statement parameter is null
355 public void addEffectiveSubstatement(final Mutable<?, ?, ?> substatement) {
356 beforeAddEffectiveStatement(1);
357 effective.add(substatement);
361 * adds effective statement to collection of substatements
363 * @param substatements substatements
364 * @throws IllegalStateException
365 * if added in declared phase
366 * @throws NullPointerException
367 * if statement parameter is null
369 public void addEffectiveSubstatements(final Collection<? extends Mutable<?, ?, ?>> substatements) {
370 if (substatements.isEmpty()) {
374 substatements.forEach(Preconditions::checkNotNull);
375 beforeAddEffectiveStatement(substatements.size());
376 effective.addAll(substatements);
379 private void beforeAddEffectiveStatement(final int toAdd) {
380 final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
381 Preconditions.checkState(inProgressPhase == ModelProcessingPhase.FULL_DECLARATION
382 || inProgressPhase == ModelProcessingPhase.EFFECTIVE_MODEL,
383 "Effective statement cannot be added in declared phase at: %s", getStatementSourceReference());
385 if (effective.isEmpty()) {
386 effective = new ArrayList<>(toAdd);
391 * Create a new substatement at the specified offset.
393 * @param offset Substatement offset
394 * @param def definition context
395 * @param ref source reference
396 * @param argument statement argument
397 * @return A new substatement
399 public final <CA, CD extends DeclaredStatement<CA>, CE extends EffectiveStatement<CA, CD>> StatementContextBase<CA, CD, CE> createSubstatement(
400 final int offset, final StatementDefinitionContext<CA, CD, CE> def, final StatementSourceReference ref,
401 final String argument) {
402 final ModelProcessingPhase inProgressPhase = getRoot().getSourceContext().getInProgressPhase();
403 Preconditions.checkState(inProgressPhase != ModelProcessingPhase.EFFECTIVE_MODEL,
404 "Declared statement cannot be added in effective phase at: %s", getStatementSourceReference());
406 final Optional<StatementSupport<?, ?, ?>> implicitParent = definition.getImplicitParentFor(def.getPublicView());
407 if (implicitParent.isPresent()) {
408 return createImplicitParent(offset, implicitParent.get(), ref, argument).createSubstatement(offset, def,
412 final StatementContextBase<CA, CD, CE> ret = new SubstatementContext<>(this, def, ref, argument);
413 substatements = substatements.put(offset, ret);
414 def.onStatementAdded(ret);
418 private StatementContextBase<?, ?, ?> createImplicitParent(final int offset,
419 final StatementSupport<?, ?, ?> implicitParent, final StatementSourceReference ref, final String argument) {
420 final StatementDefinitionContext<?, ?, ?> def = new StatementDefinitionContext<>(implicitParent);
421 return createSubstatement(offset, def, ImplicitSubstatement.of(ref), argument);
425 * Lookup substatement by its offset in this statement.
427 * @param offset Substatement offset
428 * @return Substatement, or null if substatement does not exist.
430 final StatementContextBase<?, ?, ?> lookupSubstatement(final int offset) {
431 return substatements.get(offset);
435 public D buildDeclared() {
436 Preconditions.checkArgument(completedPhase == ModelProcessingPhase.FULL_DECLARATION
437 || completedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
438 if (declaredInstance == null) {
439 declaredInstance = definition().getFactory().createDeclared(this);
441 return declaredInstance;
445 public E buildEffective() {
446 if (effectiveInstance == null) {
447 effectiveInstance = definition().getFactory().createEffective(this);
449 return effectiveInstance;
453 * tries to execute current {@link ModelProcessingPhase} of source parsing.
456 * to be executed (completed)
457 * @return if phase was successfully completed
458 * @throws SourceException
459 * when an error occured in source parsing
461 boolean tryToCompletePhase(final ModelProcessingPhase phase) {
463 boolean finished = true;
464 final Collection<ContextMutation> openMutations = phaseMutation.get(phase);
465 if (!openMutations.isEmpty()) {
466 final Iterator<ContextMutation> it = openMutations.iterator();
467 while (it.hasNext()) {
468 final ContextMutation current = it.next();
469 if (current.isFinished()) {
476 if (openMutations.isEmpty()) {
477 phaseMutation.removeAll(phase);
478 if (phaseMutation.isEmpty()) {
479 phaseMutation = ImmutableMultimap.of();
484 for (final StatementContextBase<?, ?, ?> child : substatements.values()) {
485 finished &= child.tryToCompletePhase(phase);
487 for (final Mutable<?, ?, ?> child : effective) {
488 if (child instanceof StatementContextBase) {
489 finished &= ((StatementContextBase<?, ?, ?>) child).tryToCompletePhase(phase);
494 onPhaseCompleted(phase);
501 * Occurs on end of {@link ModelProcessingPhase} of source parsing.
504 * that was to be completed (finished)
505 * @throws SourceException
506 * when an error occurred in source parsing
508 private void onPhaseCompleted(final ModelProcessingPhase phase) {
509 completedPhase = phase;
511 final Collection<OnPhaseFinished> listeners = phaseListeners.get(phase);
512 if (listeners.isEmpty()) {
516 final Iterator<OnPhaseFinished> listener = listeners.iterator();
517 while (listener.hasNext()) {
518 final OnPhaseFinished next = listener.next();
519 if (next.phaseFinished(this, phase)) {
524 if (listeners.isEmpty()) {
525 phaseListeners.removeAll(phase);
526 if (phaseListeners.isEmpty()) {
527 phaseListeners = ImmutableMultimap.of();
533 * Ends declared section of current node.
536 * @throws SourceException
538 void endDeclared(final StatementSourceReference ref, final ModelProcessingPhase phase) {
539 definition().onDeclarationFinished(this, phase);
543 * @return statement definition
545 protected final StatementDefinitionContext<A, D, E> definition() {
550 protected void checkLocalNamespaceAllowed(final Class<? extends IdentifierNamespace<?, ?>> type) {
551 definition().checkNamespaceAllowed(type);
555 protected <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceElementAdded(final Class<N> type, final K key,
557 // definition().onNamespaceElementAdded(this, type, key, value);
560 <K, V, N extends IdentifierNamespace<K, V>> void onNamespaceItemAddedAction(final Class<N> type, final K key,
561 final OnNamespaceItemAdded listener) throws SourceException {
562 final Object potential = getFromNamespace(type, key);
563 if (potential != null) {
564 LOG.trace("Listener on {} key {} satisfied immediately", type, key);
565 listener.namespaceItemAdded(this, type, key, potential);
569 final NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
570 Preconditions.checkArgument(behaviour instanceof NamespaceBehaviourWithListeners,
571 "Namespace {} does not support listeners", type);
573 final NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K, V, N>) behaviour;
574 casted.addValueListener(new ValueAddedListener<K>(this, key) {
576 void onValueAdded(final Object key, final Object value) {
577 listener.namespaceItemAdded(StatementContextBase.this, type, key, value);
583 * See {@link StatementSupport#getPublicView()}.
587 public StatementDefinition getPublicDefinition() {
588 return definition().getPublicView();
592 public ModelActionBuilder newInferenceAction(final ModelProcessingPhase phase) {
593 return getRoot().getSourceContext().newInferenceAction(phase);
596 private static <T> Multimap<ModelProcessingPhase, T> newMultimap() {
597 return Multimaps.newListMultimap(new EnumMap<>(ModelProcessingPhase.class), () -> new ArrayList<>(1));
601 * adds {@link OnPhaseFinished} listener for a {@link ModelProcessingPhase} end
603 * @throws SourceException
605 void addPhaseCompletedListener(final ModelProcessingPhase phase, final OnPhaseFinished listener) {
607 Preconditions.checkNotNull(phase, "Statement context processing phase cannot be null at: %s",
608 getStatementSourceReference());
609 Preconditions.checkNotNull(listener, "Statement context phase listener cannot be null at: %s",
610 getStatementSourceReference());
612 ModelProcessingPhase finishedPhase = completedPhase;
613 while (finishedPhase != null) {
614 if (phase.equals(finishedPhase)) {
615 listener.phaseFinished(this, finishedPhase);
618 finishedPhase = finishedPhase.getPreviousPhase();
620 if (phaseListeners.isEmpty()) {
621 phaseListeners = newMultimap();
624 phaseListeners.put(phase, listener);
628 * adds {@link ContextMutation} to {@link ModelProcessingPhase}
630 * @throws IllegalStateException
631 * when the mutation was registered after phase was completed
633 void addMutation(final ModelProcessingPhase phase, final ContextMutation mutation) {
634 ModelProcessingPhase finishedPhase = completedPhase;
635 while (finishedPhase != null) {
636 if (phase.equals(finishedPhase)) {
637 throw new IllegalStateException("Mutation registered after phase was completed at: " +
638 getStatementSourceReference());
640 finishedPhase = finishedPhase.getPreviousPhase();
643 if (phaseMutation.isEmpty()) {
644 phaseMutation = newMultimap();
646 phaseMutation.put(phase, mutation);
650 public <K, KT extends K, N extends StatementNamespace<K, ?, ?>> void addContext(final Class<N> namespace,
651 final KT key,final StmtContext<?, ?, ?> stmt) {
652 addContextToNamespace(namespace, key, stmt);
656 public <X, Y extends DeclaredStatement<X>, Z extends EffectiveStatement<X, Y>> Mutable<X, Y, Z> childCopyOf(
657 final StmtContext<X, Y, Z> stmt, final CopyType type, final QNameModule targetModule) {
658 Preconditions.checkState(stmt.getCompletedPhase() == ModelProcessingPhase.EFFECTIVE_MODEL,
659 "Attempted to copy statement %s which has completed phase %s", stmt, stmt.getCompletedPhase());
661 Preconditions.checkArgument(stmt instanceof SubstatementContext, "Unsupported statement %s", stmt);
663 final SubstatementContext<X, Y, Z> original = (SubstatementContext<X, Y, Z>)stmt;
664 final SubstatementContext<X, Y, Z> copy = new SubstatementContext<>(original, this, type, targetModule);
666 original.definition().onStatementAdded(copy);
667 original.copyTo(copy, type, targetModule);
672 final void copyTo(final StatementContextBase<?, ?, ?> target, final CopyType typeOfCopy,
673 @Nullable final QNameModule targetModule) {
674 final Collection<Mutable<?, ?, ?>> buffer = new ArrayList<>(substatements.size() + effective.size());
676 for (final Mutable<?, ?, ?> stmtContext : substatements.values()) {
677 if (stmtContext.isSupportedByFeatures()) {
678 copySubstatement(stmtContext, target, typeOfCopy, targetModule, buffer);
682 for (final Mutable<?, ?, ?> stmtContext : effective) {
683 copySubstatement(stmtContext, target, typeOfCopy, targetModule, buffer);
686 target.addEffectiveSubstatements(buffer);
689 private void copySubstatement(final Mutable<?, ?, ?> stmtContext, final Mutable<?, ?, ?> target,
690 final CopyType typeOfCopy, final QNameModule newQNameModule, final Collection<Mutable<?, ?, ?>> buffer) {
691 if (needToCopyByUses(stmtContext)) {
692 final Mutable<?, ?, ?> copy = target.childCopyOf(stmtContext, typeOfCopy, newQNameModule);
693 LOG.debug("Copying substatement {} for {} as", stmtContext, this, copy);
695 } else if (isReusedByUses(stmtContext)) {
696 LOG.debug("Reusing substatement {} for {}", stmtContext, this);
697 buffer.add(stmtContext);
699 LOG.debug("Skipping statement {}", stmtContext);
703 // FIXME: revise this, as it seems to be wrong
704 private static final Set<YangStmtMapping> NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(
705 YangStmtMapping.DESCRIPTION,
706 YangStmtMapping.REFERENCE,
707 YangStmtMapping.STATUS);
708 private static final Set<YangStmtMapping> REUSED_DEF_SET = ImmutableSet.of(
709 YangStmtMapping.TYPE,
710 YangStmtMapping.TYPEDEF,
711 YangStmtMapping.USES);
713 private static boolean needToCopyByUses(final StmtContext<?, ?, ?> stmtContext) {
714 final StatementDefinition def = stmtContext.getPublicDefinition();
715 if (REUSED_DEF_SET.contains(def)) {
716 LOG.debug("Will reuse {} statement {}", def, stmtContext);
719 if (NOCOPY_FROM_GROUPING_SET.contains(def)) {
720 return !YangStmtMapping.GROUPING.equals(stmtContext.getParentContext().getPublicDefinition());
723 LOG.debug("Will copy {} statement {}", def, stmtContext);
727 private static boolean isReusedByUses(final StmtContext<?, ?, ?> stmtContext) {
728 return REUSED_DEF_SET.contains(stmtContext.getPublicDefinition());
732 public final String toString() {
733 return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
736 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
737 return toStringHelper.add("definition", definition).add("rawArgument", rawArgument);