graphql.language.AbstractNode Maven / Gradle / Ivy
package graphql.language;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import graphql.Assert;
import graphql.PublicApi;
import graphql.collect.ImmutableKit;
import java.util.List;
import java.util.Map;
import static graphql.collect.ImmutableKit.map;
@PublicApi
public abstract class AbstractNode implements Node {
private final SourceLocation sourceLocation;
private final ImmutableList comments;
private final IgnoredChars ignoredChars;
private final ImmutableMap additionalData;
public AbstractNode(SourceLocation sourceLocation, List comments, IgnoredChars ignoredChars) {
this(sourceLocation, comments, ignoredChars, ImmutableKit.emptyMap());
}
public AbstractNode(SourceLocation sourceLocation, List comments, IgnoredChars ignoredChars, Map additionalData) {
Assert.assertNotNull(comments, () -> "comments can't be null");
Assert.assertNotNull(ignoredChars, () -> "ignoredChars can't be null");
Assert.assertNotNull(additionalData, () -> "additionalData can't be null");
this.sourceLocation = sourceLocation;
this.additionalData = ImmutableMap.copyOf(additionalData);
this.comments = ImmutableList.copyOf(comments);
this.ignoredChars = ignoredChars;
}
@Override
public SourceLocation getSourceLocation() {
return sourceLocation;
}
@Override
public List getComments() {
return comments;
}
@Override
public IgnoredChars getIgnoredChars() {
return ignoredChars;
}
public Map getAdditionalData() {
return additionalData;
}
@SuppressWarnings("unchecked")
protected V deepCopy(V nullableObj) {
if (nullableObj == null) {
return null;
}
return (V) nullableObj.deepCopy();
}
@SuppressWarnings("unchecked")
protected List deepCopy(List extends Node> list) {
if (list == null) {
return null;
}
return map(list, n -> (V) n.deepCopy());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy