Search in sources :

Example 51 with Field

use of java.lang.reflect.Field in project bazel by bazelbuild.

the class OptionsParserImpl method asListOfEffectiveOptions.

/**
   * Implements {@link OptionsParser#asListOfEffectiveOptions()}.
   */
List<OptionValueDescription> asListOfEffectiveOptions() {
    List<OptionValueDescription> result = Lists.newArrayList();
    for (Map.Entry<String, Field> mapEntry : optionsData.getAllNamedFields()) {
        String fieldName = mapEntry.getKey();
        Field field = mapEntry.getValue();
        OptionValueDescription entry = parsedValues.get(field);
        if (entry == null) {
            Object value = optionsData.getDefaultValue(field);
            result.add(new OptionValueDescription(fieldName, value, OptionPriority.DEFAULT, null, null, null, false));
        } else {
            result.add(entry);
        }
    }
    return result;
}
Also used : UnparsedOptionValueDescription(com.google.devtools.common.options.OptionsParser.UnparsedOptionValueDescription) OptionValueDescription(com.google.devtools.common.options.OptionsParser.OptionValueDescription) Field(java.lang.reflect.Field) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 52 with Field

use of java.lang.reflect.Field in project bazel by bazelbuild.

the class OptionsUsage method getUsage.

/**
   * Given an options class, render the usage string into the usage,
   * which is passed in as an argument.
   */
static void getUsage(Class<? extends OptionsBase> optionsClass, StringBuilder usage) {
    List<Field> optionFields = Lists.newArrayList(OptionsParser.getAllAnnotatedFields(optionsClass));
    Collections.sort(optionFields, BY_NAME);
    for (Field optionField : optionFields) {
        getUsage(optionField, usage, OptionsParser.HelpVerbosity.LONG);
    }
}
Also used : Field(java.lang.reflect.Field)

Example 53 with Field

use of java.lang.reflect.Field in project bazel by bazelbuild.

the class Resolver method setField.

/** Reflectively set a field. */
private void setField(Object receiver, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException {
    Field f = receiver.getClass().getDeclaredField(fieldName);
    f.setAccessible(true);
    f.set(receiver, value);
}
Also used : Field(java.lang.reflect.Field)

Example 54 with Field

use of java.lang.reflect.Field in project bazel by bazelbuild.

the class Resolver method getField.

/** Reflectively get the value of a field. */
private Object getField(Object receiver, String fieldName) throws NoSuchFieldException, IllegalAccessException {
    Field f = receiver.getClass().getDeclaredField(fieldName);
    f.setAccessible(true);
    return f.get(receiver);
}
Also used : Field(java.lang.reflect.Field)

Example 55 with Field

use of java.lang.reflect.Field in project bazel by bazelbuild.

the class AnalysisMock method get.

public static AnalysisMock get() {
    try {
        Class<?> providerClass = Class.forName(TestConstants.TEST_ANALYSIS_MOCK);
        Field instanceField = providerClass.getField("INSTANCE");
        return (AnalysisMock) instanceField.get(null);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : Field(java.lang.reflect.Field) IOException(java.io.IOException)

Aggregations

Field (java.lang.reflect.Field)5144 Method (java.lang.reflect.Method)613 Test (org.junit.Test)538 ArrayList (java.util.ArrayList)490 IOException (java.io.IOException)318 HashMap (java.util.HashMap)318 Map (java.util.Map)296 InvocationTargetException (java.lang.reflect.InvocationTargetException)176 List (java.util.List)171 Pattern (java.util.regex.Pattern)122 Matcher (java.util.regex.Matcher)117 HashSet (java.util.HashSet)109 File (java.io.File)107 Annotation (java.lang.annotation.Annotation)98 Support_Field (tests.support.Support_Field)82 Collection (java.util.Collection)81 Test (org.testng.annotations.Test)68 Type (java.lang.reflect.Type)67 SienaException (siena.SienaException)65 Before (org.junit.Before)62