blob: 04639c473a2c8a9829ad72180a8d63d9ce90d7e3 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2015, 2020 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.ltk.ast.core.impl;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.statet.jcommons.collections.ImCollections;
import org.eclipse.statet.jcommons.collections.ImList;
import org.eclipse.statet.jcommons.lang.NonNullByDefault;
import org.eclipse.statet.jcommons.lang.Nullable;
import org.eclipse.statet.ltk.ast.core.AstNode;
import org.eclipse.statet.ltk.ast.core.AstVisitor;
@NonNullByDefault
public abstract class AbstractAstNode implements AstNode {
private static final ImList<Object> NO_ATTACHMENT= ImCollections.emptyList();
private volatile ImList<Object> attachments= NO_ATTACHMENT;
protected AbstractAstNode() {
}
@Override
public final void accept(final AstVisitor visitor) throws InvocationTargetException {
visitor.visit(this);
}
public @Nullable String getText() {
return null;
}
@Override
public synchronized void addAttachment(final Object data) {
this.attachments= ImCollections.addElement(this.attachments, data);
}
@Override
public synchronized void removeAttachment(final Object data) {
this.attachments= ImCollections.removeElement(this.attachments, data);
}
@Override
public ImList<Object> getAttachments() {
return this.attachments;
}
}