| /******************************************************************************* |
| * Copyright (c) 2009 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.e4.languages.javascript.debug.model; |
| |
| import java.util.ArrayList; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.debug.core.DebugException; |
| import org.eclipse.debug.core.model.IValue; |
| import org.eclipse.debug.core.model.IVariable; |
| import org.eclipse.e4.languages.javascript.jsdi.PropertiesReference; |
| import org.eclipse.e4.languages.javascript.jsdi.Property; |
| import org.eclipse.e4.languages.javascript.jsdi.Value; |
| |
| /** |
| * Default implementation of |
| */ |
| public class JSDIValue extends JSDIDebugElement implements IValue { |
| |
| private Value value; |
| private String name; |
| |
| public JSDIValue(JSDIVariable jsdiVariable, Value value) { |
| super(jsdiVariable.getJSDITarget()); |
| this.name = jsdiVariable.getName(); |
| this.value = value; |
| } |
| |
| public JSDIValue(JSDIProperty jsdiProperty, Value value) { |
| super(jsdiProperty.getJSDITarget()); |
| this.name = jsdiProperty.getName(); |
| this.value = value; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName() |
| */ |
| public String getReferenceTypeName() throws DebugException { |
| return value.getValueTypeName(); |
| } |
| |
| /** |
| * Return the name to display for the variable |
| * |
| * @return the variable name |
| */ |
| public String getName() { |
| return name; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.debug.core.model.IValue#getValueString() |
| */ |
| public String getValueString() throws DebugException { |
| return value.toString(); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.debug.core.model.IValue#getVariables() |
| */ |
| public IVariable[] getVariables() throws DebugException { |
| if (!hasVariables()) |
| return null; |
| PropertiesReference reference = (PropertiesReference) value; |
| |
| List properties = reference.properties(); |
| List result = new ArrayList(properties.size()); |
| for (Iterator iterator = properties.iterator(); iterator.hasNext();) { |
| Property property = (Property) iterator.next(); |
| JSDIProperty jsdiProperty = new JSDIProperty(this, reference, property); |
| result.add(jsdiProperty); |
| } |
| return (IVariable[]) result.toArray(new IVariable[result.size()]); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.debug.core.model.IValue#hasVariables() |
| */ |
| public boolean hasVariables() throws DebugException { |
| return (value instanceof PropertiesReference); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.debug.core.model.IValue#isAllocated() |
| */ |
| public boolean isAllocated() throws DebugException { |
| return false; |
| } |
| |
| } |