blob: 8811f35c51ac023d5354e2d063c2fbaf1cb4080a [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2008, 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.internal.r.core.sourcemodel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.statet.jcommons.collections.ImCollections;
import org.eclipse.statet.jcommons.collections.ImList;
import org.eclipse.statet.r.core.model.IRFrame;
import org.eclipse.statet.r.core.model.RElementAccess;
import org.eclipse.statet.r.core.model.RElementName;
abstract class SubAbstractElementAccess extends RElementAccess {
private final ElementAccess root;
SubAbstractElementAccess nextSegment;
public SubAbstractElementAccess(final ElementAccess root) {
this.root= root;
}
public final ElementAccess getRoot() {
return this.root;
}
@Override
public String getDisplayName() {
return RElementName.createDisplayName(this, 0);
}
@Override
public RElementName getScope() {
return null;
}
@Override
public final RElementAccess getNextSegment() {
return this.nextSegment;
}
@Override
public final IRFrame getFrame() {
return this.root.getFrame();
}
@Override
public final boolean isWriteAccess() {
return this.root.isWriteAccess();
}
@Override
public boolean isCallAccess() {
return this.root.isCallAccess();
}
@Override
public boolean isFunctionAccess() {
return this.root.isFunctionAccess();
}
@Override
public ImList<? extends RElementAccess> getAllInUnit(final boolean includeSlaves) {
final List<ElementAccess> all= this.root.shared.entries;
final List<RElementAccess> elements= new ArrayList<>();
ITER_ACCESS: for (RElementAccess element : all) {
RElementAccess me= this.root;
while (true) {
me= me.getNextSegment();
if (me.getSegmentName() == null) {
return null;
}
element= element.getNextSegment();
if (element == null || me.getType() != element.getType()
|| !me.getSegmentName().equals(element.getSegmentName())) {
continue ITER_ACCESS;
}
if (me == this) {
if (includeSlaves || element.isMaster()) {
elements.add(element);
}
continue ITER_ACCESS;
}
}
}
Collections.sort(elements, RElementAccess.NAME_POSITION_COMPARATOR);
return ImCollections.toList(elements);
}
}