blob: 22be253fe28d52089e9823a00e0324f0312c1872 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2007, 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.r.core.rsource.ast;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
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.r.core.rlang.RTerminal;
@NonNullByDefault
public class SourceComponent extends ExpressionList {
@Nullable AstNode parent;
@Nullable List<RAstNode> comments;
SourceComponent() {
}
@Override
public final NodeType getNodeType() {
return NodeType.SOURCELINES;
}
@Override
public final @Nullable RTerminal getOperator(final int index) {
return null;
}
/**
* The comment nodes in this source component
*
* @return the comments or <code>null</code>, if disabled
*/
public @Nullable List<RAstNode> getComments() {
return this.comments;
}
@Override
public @Nullable AstNode getParent() {
return this.parent;
}
@Override
public final void acceptInR(final RAstVisitor visitor) throws InvocationTargetException {
visitor.visit(this);
}
public void acceptInRComments(final RAstVisitor visitor) throws InvocationTargetException {
final List<RAstNode> comments= this.comments;
if (comments == null) {
return;
}
for (int i= 0; i < comments.size(); i++) {
comments.get(i).acceptInR(visitor);
}
}
@Override
public final boolean equalsSingle(final RAstNode element) {
return (NodeType.SOURCELINES == element.getNodeType());
}
final void updateStartOffset() {
if (getChildCount() > 0) {
this.startOffset= getChild(0).startOffset;
}
else {
this.startOffset= 0;
}
}
@Override
final void updateEndOffset() {
final int count= getChildCount();
if (count > 0) {
this.endOffset= getChild(count - 1).endOffset;
}
else {
this.endOffset= 0;
}
}
}