| /*=============================================================================# |
| # Copyright (c) 2014, 2017 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.HashSet; |
| import java.util.List; |
| import java.util.Map; |
| import java.util.Set; |
| |
| import org.eclipse.statet.internal.r.core.builder.ExportedRClass; |
| import org.eclipse.statet.internal.r.core.builder.ExportedRElement; |
| import org.eclipse.statet.internal.r.core.builder.ExportedRMethod; |
| import org.eclipse.statet.internal.r.core.builder.RUnitElement; |
| import org.eclipse.statet.r.core.IRProject; |
| import org.eclipse.statet.r.core.model.IRClass; |
| import org.eclipse.statet.r.core.model.IRElement; |
| import org.eclipse.statet.r.core.model.IRFrame; |
| import org.eclipse.statet.r.core.model.IRFrameInSource; |
| import org.eclipse.statet.r.core.model.IRLangElement; |
| import org.eclipse.statet.r.core.model.IRMethod; |
| import org.eclipse.statet.r.core.model.IRModelInfo; |
| import org.eclipse.statet.r.core.model.IRSourceUnit; |
| |
| |
| public class RModelIndexOrder { |
| |
| |
| protected static class Result { |
| |
| public final String unitId; |
| public final RUnitElement exportedElement; |
| public final Set<String> defaultNames; |
| |
| public Result(final RUnitElement root, final Set<String> defaultNames) { |
| this.unitId= root.getId(); |
| this.exportedElement= root; |
| this.defaultNames= defaultNames; |
| } |
| |
| } |
| |
| |
| protected final IRProject rProject; |
| protected final String projectName; |
| |
| protected final List<Result> updated= new ArrayList<>(); |
| |
| protected final List<String> removed= new ArrayList<>(); |
| |
| protected final List<String> modelTypeIds; |
| protected final boolean isFullBuild; |
| |
| |
| public RModelIndexOrder(final IRProject rProject, |
| final List<String> modelTypeIds, final boolean isFullBuild) { |
| this.rProject= rProject; |
| this.projectName= rProject.getProject().getName(); |
| this.modelTypeIds= modelTypeIds; |
| this.isFullBuild= isFullBuild; |
| } |
| |
| |
| protected Result createResult(final IRSourceUnit sourceUnit, final IRModelInfo model) { |
| if (model == null) { |
| return null; |
| } |
| |
| final IRFrameInSource topFrame= model.getTopFrame(); |
| final List<? extends IRLangElement> children= topFrame.getModelChildren(null); |
| final ArrayList<IRLangElement> exports= new ArrayList<>(children.size()); |
| final RUnitElement root= new RUnitElement(sourceUnit, exports); |
| for (final IRLangElement element : children) { |
| final int type= element.getElementType(); |
| switch (type & IRElement.MASK_C1) { |
| case IRElement.C1_METHOD: |
| exports.add(new ExportedRMethod(root, (IRMethod) element)); |
| break; |
| case IRElement.C1_CLASS: |
| exports.add(new ExportedRClass(root, (IRClass) element)); |
| break; |
| case IRElement.C1_VARIABLE: |
| exports.add(new ExportedRElement(root, element)); |
| break; |
| default: |
| continue; |
| } |
| } |
| final Set<String> names= new HashSet<>(); |
| names.addAll(model.getTopFrame().getAllAccessNames()); |
| final Map<String, ? extends IRFrame> frames= model.getReferencedFrames(); |
| for (final IRFrame frame : frames.values()) { |
| names.addAll(((IRFrameInSource) frame).getAllAccessNames()); |
| } |
| |
| return new Result(root, names); |
| } |
| |
| protected void addRemovedUnit(final String unitId) { |
| if (!this.isFullBuild) { |
| this.removed.add(unitId); |
| } |
| } |
| |
| } |