Search in sources :

Example 1 with IVariable

use of org.eclipse.debug.core.model.IVariable in project liferay-ide by liferay.

the class FMStackFrame method getVariables.

public IVariable[] getVariables() throws DebugException {
    if (this.variables == null) {
        /*
             * Represents the debugger-side mirror of a debugged freemarker.core.Environment object in the remote VM.
             *
             * This interface extends DebugModel, and the properties of the Environment are exposed as hash keys on it.
             * Specifically, the following keys are supported: "currentNamespace", "dataModel", "globalNamespace",
             * "knownVariables", "mainNamespace", and "template".
             *
             * The debug model for the template supports keys
             * "configuration" and "name".
             *
             * The debug model for the configuration supports key "sharedVariables".
             * Additionally, all of the debug models for environment, template, and configuration also support all the
             * setting keys of freemarker.core.Configurable objects.
             */
        boolean advancedView = PortalCore.getPrefs().getBoolean(PortalCore.PREF_ADVANCED_VARIABLES_VIEW, false);
        final DebuggedEnvironment env = this.thread.getEnvironment();
        FMVariable[] topLevelVars = null;
        try {
            topLevelVars = new FMVariable[] { new FMVariable(this, "currentNamespace", env.get("currentNamespace")), new FMVariable(this, "dataModel", env.get("dataModel")), new FMVariable(this, "globalNamespace", env.get("globalNamespace")), new FMVariable(this, "knownVariables", env.get("knownVariables")), new FMVariable(this, "mainNamespace", env.get("mainNamespace")), new FMVariable(this, "template", env.get("template")) {

                @Override
                public IValue getValue() throws DebugException {
                    return new TemplateVMValue(stackFrame, debugModel);
                }
            } };
        } catch (Exception e) {
            PortalCore.logError("Unable to create freemarker variables", e);
        }
        if (topLevelVars != null) {
            if (advancedView) {
                this.variables = topLevelVars;
            } else {
                // collapse all the variables into one list and remove duplicates
                Map<String, IVariable> vars = new HashMap<String, IVariable>();
                for (FMVariable topLevelVar : topLevelVars) {
                    for (IVariable nestedVar : topLevelVar.getValue().getVariables()) {
                        IVariable existingVar = vars.get(nestedVar.getName());
                        if (existingVar == null) {
                            vars.put(nestedVar.getName(), nestedVar);
                        }
                    }
                }
                this.variables = filterVariables(vars.values().toArray(new IVariable[0]));
                sortVariables(this.variables);
            }
        }
    }
    return this.variables;
}
Also used : HashMap(java.util.HashMap) DebuggedEnvironment(freemarker.debug.DebuggedEnvironment) IVariable(org.eclipse.debug.core.model.IVariable) DebugException(org.eclipse.debug.core.DebugException) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) IValue(org.eclipse.debug.core.model.IValue)

Example 2 with IVariable

use of org.eclipse.debug.core.model.IVariable in project liferay-ide by liferay.

the class FMValue method getVariables.

public IVariable[] getVariables() throws DebugException {
    if (this.variables == null) {
        List<IVariable> vars = new ArrayList<IVariable>();
        try {
            int types = this.debugModel.getModelTypes();
            if (isHashType(types)) {
                try {
                    String[] keys = this.debugModel.keys();
                    DebugModel[] vals = this.debugModel.get(keys);
                    for (int i = 0; i < keys.length; i++) {
                        DebugModel hashValue = vals[i];
                        if (isValidVariable(hashValue)) {
                            vars.add(new FMVariable(stackFrame, keys[i], hashValue));
                        }
                    }
                } catch (ClassCastException cce) {
                // ignore IDE-1082
                }
            } else if (isCollectionType(types)) {
            // String[] keys = this.debugModel.keys();
            // if( isValidVariable( hashValue ) )
            // {
            // vars.add( new FMVariable( stackFrame, key , debugModel ) );
            // }
            } else if (isSequenceType(types) && isValidSequence(this.debugModel)) {
                int length = this.debugModel.size();
                DebugModel[] vals = this.debugModel.get(0, length);
                for (int i = 0; i < length; i++) {
                    if (isValidVariable(vals[i])) {
                        vars.add(new FMVariable(stackFrame, Integer.toString(i), vals[i]));
                    }
                }
            } else if (isStringType(types) || isNumberType(types) || isBooleanType(types) || isDateType(types)) {
            // no variables
            } else {
                System.out.println("Unknown value: " + getReferenceTypeName(this.debugModel));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.variables = vars.toArray(new IVariable[vars.size()]);
        sortVariables(this.variables);
    }
    return this.variables;
}
Also used : DebugModel(freemarker.debug.DebugModel) IVariable(org.eclipse.debug.core.model.IVariable) ArrayList(java.util.ArrayList) DebugException(org.eclipse.debug.core.DebugException) TemplateModelException(freemarker.template.TemplateModelException) RemoteException(java.rmi.RemoteException)

Example 3 with IVariable

use of org.eclipse.debug.core.model.IVariable in project webtools.sourceediting by eclipse.

the class XSLValue method getAttributes.

private void getAttributes(List<IVariable> variableList, Node node) {
    NamedNodeMap nodeMap = node.getAttributes();
    for (int item = 0; item < nodeMap.getLength(); item++) {
        Attr attribute = (Attr) nodeMap.item(item);
        IVariable variable = new NodeListVariable(getDebugTarget(), attribute);
        variableList.add(variable);
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IVariable(org.eclipse.debug.core.model.IVariable) Attr(org.w3c.dom.Attr)

Example 4 with IVariable

use of org.eclipse.debug.core.model.IVariable in project webtools.sourceediting by eclipse.

the class XSLValue method getNodeListVariables.

private List<IVariable> getNodeListVariables(NodeList nodeList) {
    List<IVariable> variableList = new ArrayList<IVariable>();
    if (nodeList != null) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            IVariable variable = new NodeListVariable(getDebugTarget(), node);
            variableList.add(variable);
        }
    }
    return variableList;
}
Also used : IVariable(org.eclipse.debug.core.model.IVariable) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 5 with IVariable

use of org.eclipse.debug.core.model.IVariable in project liferay-ide by liferay.

the class FMStackFrame method filterVariables.

private IVariable[] filterVariables(IVariable[] variables) {
    List<IVariable> filtered = new ArrayList<IVariable>();
    for (IVariable var : variables) {
        if (filter(var)) {
            filtered.add(var);
        }
    }
    IVariable[] retval = filtered.toArray(new IVariable[0]);
    return retval;
}
Also used : IVariable(org.eclipse.debug.core.model.IVariable) ArrayList(java.util.ArrayList)

Aggregations

IVariable (org.eclipse.debug.core.model.IVariable)5 ArrayList (java.util.ArrayList)3 DebugException (org.eclipse.debug.core.DebugException)2 DebugModel (freemarker.debug.DebugModel)1 DebuggedEnvironment (freemarker.debug.DebuggedEnvironment)1 TemplateModelException (freemarker.template.TemplateModelException)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 IValue (org.eclipse.debug.core.model.IValue)1 Attr (org.w3c.dom.Attr)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1