blob: 17ad46053576f904c17769766352952c60a2a110 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2007, 2019 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.ArrayList;
import java.util.List;
import org.eclipse.statet.jcommons.lang.NonNull;
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;
import org.eclipse.statet.r.core.rlang.RTerminal;
/**
* Comma separated list
*/
@NonNullByDefault
abstract class SpecList extends RAstNode {
final List<SpecItem> specs= new ArrayList<>(0);
protected SpecList() {
}
@Override
public final @Nullable RTerminal getOperator(final int index) {
return null;
}
@Override
public final boolean hasChildren() {
return (!this.specs.isEmpty());
}
@Override
public final int getChildCount() {
return this.specs.size();
}
@Override
public final RAstNode getChild(final int index) {
return this.specs.get(index);
}
@Override
public final RAstNode[] getChildren() {
return this.specs.toArray(new @NonNull RAstNode[this.specs.size()]);
}
@Override
public final int getChildIndex(final AstNode child) {
for (int i= this.specs.size() - 1; i >= 0; i--) {
if (this.specs.get(i) == child) {
return i;
}
}
return -1;
}
@Override
public final void acceptInRChildren(final RAstVisitor visitor) throws InvocationTargetException {
acceptChildren(visitor, this.specs);
}
@Override
public final void acceptInChildren(final AstVisitor visitor) throws InvocationTargetException {
for (final RAstNode child : this.specs) {
visitor.visit(child);
}
}
@Override
final @Nullable Expression getExpr(final RAstNode child) {
return null;
}
@Override
final @Nullable Expression getLeftExpr() {
return null;
}
@Override
final @Nullable Expression getRightExpr() {
return null;
}
abstract SpecItem createItem();
void appendItem(final SpecItem item) {
this.specs.add(item);
}
@Override
final int getMissingExprStatus(final Expression expr) {
throw new IllegalArgumentException();
}
@Override
final void updateEndOffset() {
}
}