All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.ruebner.jvisualizer.backend.vm.structure.LocalVariable Maven / Gradle / Ivy

Go to download

This project aims to provide an easy tool to visualize data flow and objects within the JVM. It is intended for students that are starting to learn programming with Java.

The newest version!
package me.ruebner.jvisualizer.backend.vm.structure;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.sun.jdi.ClassNotLoadedException;
import me.ruebner.jvisualizer.backend.vm.types.Type;

/**
 * Represents a local variable.
 */
public class LocalVariable extends Variable {

    /**
     * true, if the variable is an argument, false otherwise
     */
    @JsonProperty
    private final boolean isArgument;

    /**
     * Creates a new local variable.
     * @param name the name of the local variable
     * @param type the type of the local variable
     * @param isArgument set to true, if the variable is an argument, or set to false otherwise
     */
    private LocalVariable(String name, Type type, boolean isArgument) {
        super(name, type);
        this.isArgument = isArgument;
    }

    /**
     * Creates a new local variable object based on a {@link com.sun.jdi.LocalVariable} object.
     * @param jdiLocalVariable the JDI local variable object
     * @return the new local variable based on {@code jdiLocalVariable}
     */
    public static LocalVariable fromJdi(com.sun.jdi.LocalVariable jdiLocalVariable) {
        try {
            return new LocalVariable(
                    jdiLocalVariable.name(),
                    Type.fromJdi(jdiLocalVariable.type()),
                    jdiLocalVariable.isArgument()
            );
        } catch (ClassNotLoadedException ex) {
            return new LocalVariable(
                    jdiLocalVariable.name(),
                    new Type(jdiLocalVariable.typeName()) {},
                    jdiLocalVariable.isArgument()
            );
        }
    }

    /**
     * Checks, if the local variable is an argument of a method or not.
     * @return true, if the local variable is an argument, false otherwise
     */
    public boolean isArgument() {
        return isArgument;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy