| /*=============================================================================# |
| # Copyright (c) 2016, 2021 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.debug.core.eval; |
| |
| import org.eclipse.core.runtime.IAdapterFactory; |
| import org.eclipse.debug.core.model.IExpression; |
| import org.eclipse.debug.core.model.IValue; |
| |
| import org.eclipse.statet.jcommons.lang.Nullable; |
| |
| import org.eclipse.statet.r.debug.core.IRValue; |
| import org.eclipse.statet.r.debug.core.IRVariable; |
| |
| |
| public class ExpressionAdapterFactory implements IAdapterFactory { |
| |
| |
| private static final Class<?>[] ADAPTERS = new Class<?>[] { |
| IRVariable.class, |
| }; |
| |
| |
| public ExpressionAdapterFactory() { |
| } |
| |
| |
| @Override |
| public Class<?>[] getAdapterList() { |
| return ADAPTERS; |
| } |
| |
| @Override |
| public <T> @Nullable T getAdapter(final Object adaptableObject, final Class<T> adapterType) { |
| if (adapterType == IRVariable.class) { |
| final IValue value= ((IExpression) adaptableObject).getValue(); |
| if (value instanceof IRValue) { |
| return (T) ((IRValue) value).getAssignedVariable(); |
| } |
| return null; |
| } |
| return null; |
| } |
| |
| } |