| /*=============================================================================# |
| # 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 org.eclipse.jface.text.AbstractDocument; |
| |
| import org.eclipse.statet.jcommons.ts.core.Tool; |
| |
| import org.eclipse.statet.ecommons.text.ISourceFragment; |
| import org.eclipse.statet.ecommons.text.core.util.ImmutableDocument; |
| |
| import org.eclipse.statet.nico.core.runtime.ToolProcess; |
| import org.eclipse.statet.r.console.core.RProcess; |
| import org.eclipse.statet.rj.renv.core.REnv; |
| |
| |
| /** |
| * Source fragment of an R process |
| */ |
| public class RRuntimeSourceFragment implements ISourceFragment { |
| |
| |
| private final RProcess process; |
| |
| private final String id; |
| |
| private final String name; |
| private final String fullName; |
| private final AbstractDocument document; |
| |
| |
| public RRuntimeSourceFragment(final RProcess process, final String name, |
| final String fullName, final String source) { |
| this.process = process; |
| this.name = name; |
| this.fullName = fullName; |
| this.document = new ImmutableDocument(source, System.currentTimeMillis()); |
| |
| this.id = "r:" + this.process.getLabel(Tool.DEFAULT_LABEL) + '-'+ //$NON-NLS-1$ |
| this.process.getStartupTimestamp() + '/' + |
| this.fullName + '-' + source.hashCode(); |
| } |
| |
| |
| @Override |
| public String getId() { |
| return this.id; |
| } |
| |
| public RProcess getProcess() { |
| return this.process; |
| } |
| |
| @Override |
| public String getName() { |
| return this.name; |
| } |
| |
| @Override |
| public String getFullName() { |
| return this.fullName; |
| } |
| |
| @Override |
| public AbstractDocument getDocument() { |
| return this.document; |
| } |
| |
| |
| @Override |
| @SuppressWarnings("unchecked") |
| public <T> T getAdapter(final Class<T> adapterType) { |
| if (adapterType == ToolProcess.class) { |
| return (T) this.process; |
| } |
| if (adapterType == REnv.class) { |
| return this.process.getAdapter((Class<T>) REnv.class); |
| } |
| return null; |
| } |
| |
| |
| @Override |
| public int hashCode() { |
| return this.id.hashCode(); |
| } |
| |
| @Override |
| public boolean equals(final Object obj) { |
| if (this == obj) { |
| return true; |
| } |
| if (!(obj instanceof RRuntimeSourceFragment)) { |
| return false; |
| } |
| final RRuntimeSourceFragment other = (RRuntimeSourceFragment) obj; |
| return (this.id.equals(other.id) |
| && this.process.equals(other.process) |
| && this.fullName.equals(other.fullName) |
| && this.document.equals(other.document) ); |
| } |
| |
| @Override |
| public String toString() { |
| return this.fullName; |
| } |
| |
| } |