001/*
002 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.options;
024
025/**
026 * Describes the attributes of a static field {@linkplain Option option} and provides access to its
027 * {@linkplain OptionValue value}.
028 */
029public class OptionDescriptor {
030
031    protected final String name;
032    protected final Class<?> type;
033    protected final String help;
034    protected final OptionValue<?> option;
035    protected final Class<?> declaringClass;
036    protected final String fieldName;
037
038    public OptionDescriptor(String name, Class<?> type, String help, Class<?> declaringClass, String fieldName, OptionValue<?> option) {
039        this.name = name;
040        this.type = type;
041        this.help = help;
042        this.option = option;
043        this.declaringClass = declaringClass;
044        this.fieldName = fieldName;
045        assert !type.isPrimitive() : "must used boxed type instead of " + type;
046        option.setDescriptor(this);
047    }
048
049    /**
050     * Gets the type of values stored in the option. This will be the boxed type for a primitive
051     * option.
052     */
053    public Class<?> getType() {
054        return type;
055    }
056
057    /**
058     * Gets a descriptive help message for the option.
059     */
060    public String getHelp() {
061        return help;
062    }
063
064    /**
065     * Gets the name of the option. It's up to the client of this object how to use the name to get
066     * a user specified value for the option from the environment.
067     */
068    public String getName() {
069        return name;
070    }
071
072    /**
073     * Gets the boxed option value.
074     */
075    public OptionValue<?> getOptionValue() {
076        return option;
077    }
078
079    public Class<?> getDeclaringClass() {
080        return declaringClass;
081    }
082
083    public String getFieldName() {
084        return fieldName;
085    }
086
087    /**
088     * Gets a description of the location where this option is stored.
089     */
090    public String getLocation() {
091        return getDeclaringClass().getName() + "." + getFieldName();
092    }
093}