1 /******************************************************************************* 2 * Copyright (c) 2000, 2008 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.core.internal.expressions; 15 16 import org.eclipse.core.expressions.IEvaluationContext; 17 18 import org.eclipse.core.runtime.Assert; 19 import org.eclipse.core.runtime.CoreException; 20 21 /** 22 * An evaluation context that can be used to add a new default variable 23 * to a hierarchy of evaluation contexts. 24 * 25 * @since 3.0 26 */ 27 public final class DefaultVariable implements IEvaluationContext { 28 29 private Object fDefaultVariable; 30 private IEvaluationContext fParent; 31 private IEvaluationContext fManagedPool; 32 33 /** 34 * Constructs a new variable pool for a single default variable. 35 * 36 * @param parent the parent context for the default variable. Must not 37 * be <code>null</code>. 38 * @param defaultVariable the default variable 39 */ DefaultVariable(IEvaluationContext parent, Object defaultVariable)40 public DefaultVariable(IEvaluationContext parent, Object defaultVariable) { 41 Assert.isNotNull(parent); 42 Assert.isNotNull(defaultVariable); 43 fParent= parent; 44 while (parent instanceof DefaultVariable) { 45 parent= parent.getParent(); 46 } 47 fManagedPool= parent; 48 fDefaultVariable= defaultVariable; 49 } 50 51 @Override getParent()52 public IEvaluationContext getParent() { 53 return fParent; 54 } 55 56 @Override getRoot()57 public IEvaluationContext getRoot() { 58 return fParent.getRoot(); 59 } 60 61 @Override getDefaultVariable()62 public Object getDefaultVariable() { 63 return fDefaultVariable; 64 } 65 66 @Override setAllowPluginActivation(boolean value)67 public void setAllowPluginActivation(boolean value) { 68 fParent.setAllowPluginActivation(value); 69 } 70 71 @Override getAllowPluginActivation()72 public boolean getAllowPluginActivation() { 73 return fParent.getAllowPluginActivation(); 74 } 75 76 @Override addVariable(String name, Object value)77 public void addVariable(String name, Object value) { 78 fManagedPool.addVariable(name, value); 79 } 80 81 @Override removeVariable(String name)82 public Object removeVariable(String name) { 83 return fManagedPool.removeVariable(name); 84 } 85 86 @Override getVariable(String name)87 public Object getVariable(String name) { 88 return fManagedPool.getVariable(name); 89 } 90 91 @Override resolveVariable(String name, Object[] args)92 public Object resolveVariable(String name, Object[] args) throws CoreException { 93 return fManagedPool.resolveVariable(name, args); 94 } 95 } 96