| /*=============================================================================# |
| # Copyright (c) 2010, 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.debug.core.sourcelookup; |
| |
| import java.net.URI; |
| import java.util.List; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.debug.core.sourcelookup.ISourceContainer; |
| import org.eclipse.debug.core.sourcelookup.ISourceContainerType; |
| import org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer; |
| |
| |
| public class RProjectSourceContainer extends CompositeSourceContainer implements IRSourceContainer { |
| |
| |
| public static final String TYPE_ID= "org.eclipse.statet.r.debugSourceContainers.RProjectType"; //$NON-NLS-1$ |
| |
| |
| private final IProject fProject; |
| |
| private boolean fReferenced; |
| |
| |
| public RProjectSourceContainer(final IProject project, final boolean referenced) { |
| this.fProject = project; |
| } |
| |
| |
| @Override |
| public ISourceContainerType getType() { |
| return getSourceContainerType(TYPE_ID); |
| } |
| |
| @Override |
| public String getName() { |
| return this.fProject.getName(); |
| } |
| |
| @Override |
| public boolean isComposite() { |
| return this.fReferenced; |
| } |
| |
| /** |
| * @return the project |
| */ |
| public IProject getProject() { |
| return this.fProject; |
| } |
| |
| @Override |
| protected ISourceContainer[] createSourceContainers() throws CoreException { |
| // TODO: project dependencies |
| return new ISourceContainer[0]; |
| } |
| |
| |
| @Override |
| public Object[] findSourceElements(final String name) throws CoreException { |
| return null; |
| } |
| |
| @Override |
| public IFile findSourceElement(final URI fileUri, final IFile[] fileInWorkspace) { |
| if (this.fProject.isOpen() && this.fProject.exists()) { |
| for (final IFile workspaceFile : fileInWorkspace) { |
| if (this.fProject.equals(workspaceFile.getProject()) |
| && workspaceFile.exists() ) { |
| return workspaceFile; |
| } |
| } |
| } |
| return null; |
| } |
| |
| @Override |
| public void findSourceElement(final IPath path, final List<Object> elements) { |
| if (this.fProject.isOpen() && this.fProject.exists()) { |
| final IFile file = this.fProject.getFile(path); |
| if (file.exists()) { |
| elements.add(file); |
| } |
| } |
| } |
| |
| @Override |
| public int hashCode() { |
| return this.fProject.hashCode(); |
| } |
| |
| @Override |
| public boolean equals(final Object obj) { |
| return (obj instanceof RProjectSourceContainer |
| && this.fProject.equals(((RProjectSourceContainer) obj).fProject) ); |
| } |
| |
| } |