Java Code Examples for java.lang.reflect.Field#toString()
The following examples show how to use
java.lang.reflect.Field#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleFactory.java From Wizardry with GNU Lesser General Public License v3.0 | 6 votes |
ModuleFactory(String referenceModuleID, Class<? extends IModule> clazz) throws ModuleInitException { // NOTE: Instanciable only from ModuleRegistry this.clazz = clazz; this.referenceModuleID = referenceModuleID; // Determine configurable fields via reflection for(Field field : clazz.getFields()) { ModuleParameter cfg = field.getDeclaredAnnotation(ModuleParameter.class); if( cfg == null ) continue; try { field.setAccessible(true); } catch(SecurityException e) { throw new ModuleInitException("Failed to acquire reflection access to field '" + field.toString() + "', annotated by @ModuleParameter.", e); } configurableFields.put(cfg.value(), field); } // Determine overrides overridableMethods.putAll(ModuleOverrideHandler.getOverrideMethodsFromClass(clazz, true)); }
Example 2
Source File: IterateTablesProcessor.java From xlsbeans with Apache License 2.0 | 6 votes |
public void doProcess(WSheet wSheet, Object obj, Field field, Annotation ann, AnnotationReader reader, XLSBeansConfig config, List<NeedPostProcess> needPostProcess) throws Exception { IterateTables iterateTables = (IterateTables) ann; Class<?> fieldType = field.getType(); // create multi-table objects. List<?> value = createTables(wSheet, iterateTables, reader, config, needPostProcess); if (List.class.isAssignableFrom(fieldType)) { field.set(obj, value); } else if (fieldType.isArray()) { Class<?> type = fieldType.getComponentType(); Object array = Array.newInstance(type, value.size()); for (int i = 0; i < value.size(); i++) { Array.set(array, i, value.get(i)); } field.set(obj, array); } else { throw new XLSBeansException("Arguments of '" + field.toString() + "' is invalid."); } }
Example 3
Source File: IterateTablesProcessor.java From xlsbeans with Apache License 2.0 | 6 votes |
public void doProcess(WSheet wSheet, Object obj, Field field, Annotation ann, AnnotationReader reader, XLSBeansConfig config, List<NeedPostProcess> needPostProcess) throws Exception { IterateTables iterateTables = (IterateTables) ann; Class<?> fieldType = field.getType(); // create multi-table objects. List<?> value = createTables(wSheet, iterateTables, reader, config, needPostProcess); if (List.class.isAssignableFrom(fieldType)) { field.set(obj, value); } else if (fieldType.isArray()) { Class<?> type = fieldType.getComponentType(); Object array = Array.newInstance(type, value.size()); for (int i = 0; i < value.size(); i++) { Array.set(array, i, value.get(i)); } field.set(obj, array); } else { throw new XLSBeansException("Arguments of '" + field.toString() + "' is invalid."); } }
Example 4
Source File: ReflectionNavigator.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public Location getFieldLocation(final Field field) { return new Location() { @Override public String toString() { return field.toString(); } }; }
Example 5
Source File: ReflectionNavigator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public Location getFieldLocation(final Field field) { return new Location() { @Override public String toString() { return field.toString(); } }; }
Example 6
Source File: AnalysisModuleScanner.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Annotation[] getAnnotations(final Field field) { final String fieldName = field.toString(); Annotation[] annotations = annotationCache.get(fieldName); if ( annotations == null ) { annotations = field.getAnnotations(); annotationCache.put(fieldName, annotations); } return annotations; }
Example 7
Source File: ReflectionNavigator.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public Location getFieldLocation(final Field field) { return new Location() { @Override public String toString() { return field.toString(); } }; }
Example 8
Source File: FormController.java From JavaMainRepo with Apache License 2.0 | 5 votes |
/** * Delete anything up to the last . (dot) * * Example: * Input: private static long javasmmr.zoowsome.models.animals.Cow.counter * Output: counter */ public String[] getStringFromFields(List<Field> fields) { String[] fieldsString = new String[fields.size()]; for (int i = 0; i < fields.size(); i++) { Field f = fields.get(i); fieldsString[i] = f.toString(); fieldsString[i] = fieldsString[i].replaceAll("\\w+(\\s+|\\.+)", ""); } return fieldsString; }
Example 9
Source File: FormController.java From JavaMainRepo with Apache License 2.0 | 5 votes |
/** * Delete anything up to the last . (dot) * * Example: * Input: private static long javasmmr.zoowsome.models.animals.Cow.counter * Output: counter */ public String[] getStringFromFields(List<Field> fields) { String[] fieldsString = new String[fields.size()]; for (int i = 0; i < fields.size(); i++) { Field f = fields.get(i); fieldsString[i] = f.toString(); fieldsString[i] = fieldsString[i].replaceAll("\\w+(\\s+|\\.+)", ""); } return fieldsString; }
Example 10
Source File: JBBPDslBuilder.java From java-binary-block-parser with Apache License 2.0 | 5 votes |
private void validateAnnotatedField( final Bin defaultBin, final Bin fieldBin, final Field field ) { //TODO final Bin bin = fieldBin == null ? defaultBin : fieldBin; if ((bin.type() == BinType.UNDEFINED && field.getType().isArray() || bin.type().name().endsWith("_ARRAY")) && bin.arraySizeExpr().isEmpty()) { throw new IllegalArgumentException(field.toString() + ": missing expression in Bin#arraySizeExpression"); } }
Example 11
Source File: AbstractConciergeTestCase.java From concierge with Eclipse Public License 1.0 | 5 votes |
public Object getClassField(final String className, final String classFieldName) throws Exception { final Class<?> clazz = this.classLoader.loadClass(className); final Field field = clazz.getField(classFieldName); if (!Modifier.isStatic(field.getModifiers())) { throw new RuntimeException( "Oops, field " + field.toString() + " is not static"); } // get the value of field, as class field object == null final Object result = field.get(null); return result; }
Example 12
Source File: FlagFieldScanner.java From java-flagz with MIT License | 5 votes |
protected FlagField<?> boundFlagField(Field field, Object declaredIn) { FlagField<?> flagField = null; if (!Flag.class.isAssignableFrom(field.getType())) { throw new RuntimeException( String.format( "Field(%s#%s) annotated with @FlagInfo but not a Flag.", field.getDeclaringClass().getCanonicalName(), field.getName())); } try { final boolean wasAccessible = field.isAccessible(); if (!field.isAccessible()) { field.setAccessible(true); } flagField = (FlagField<?>) field.get(declaredIn); flagField.bind(field); FlagProperty property = propertySyncer.fieldPropertyAnnotation(field); if (property != null) { propertySyncer.handlePropertyAnnotaton(flagField, property); } if (!wasAccessible) { field.setAccessible(false); } } catch (IllegalAccessException exception) { // Should never happen because access is granted, but let's get a nice stack trace. throw new RuntimeException("Unexpected problem parsing Field " + field.toString(), exception); } return flagField; }
Example 13
Source File: ReflectionNavigator.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public Location getFieldLocation(final Field field) { return new Location() { @Override public String toString() { return field.toString(); } }; }
Example 14
Source File: BlueOceanConfigImpl.java From blueocean-plugin with MIT License | 5 votes |
private BlueOceanConfigImpl() { Properties properties = System.getProperties(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String ks = entry.getKey() == null ? "" : entry.getKey().toString(); if (ks.startsWith(BlueOceanConfig.FEATURE_PROPERTY_PREFIX)) { Object value = entry.getValue(); String vs = value == null ? "" : value.toString(); if ("true".equalsIgnoreCase(vs) || "false".equalsIgnoreCase(vs)) { value = Boolean.valueOf(vs); } config.put(ks.substring(BlueOceanConfig.FEATURE_PROPERTY_PREFIX.length()), value); } } for (Field f : BlueOceanConfig.class.getFields()) { if (Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers()) && f.getType() == String.class) { try { String featureName = (String)f.get(null); if (!BlueOceanConfig.FEATURE_PROPERTY_PREFIX.equals(featureName) && !config.containsKey(featureName)) { config.put(featureName, Boolean.FALSE); } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new RuntimeException("Unable to read field: " + f.toString(), ex); } } } }
Example 15
Source File: ReflectionNavigator.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public Location getFieldLocation(final Field field) { return new Location() { @Override public String toString() { return field.toString(); } }; }
Example 16
Source File: ReflectionNavigator.java From hottub with GNU General Public License v2.0 | 5 votes |
public Location getFieldLocation(final Field field) { return new Location() { @Override public String toString() { return field.toString(); } }; }
Example 17
Source File: AwkCompilerImpl.java From vscrawler with Apache License 2.0 | 5 votes |
private static boolean assertStaticClassVarsAreFromPackage() { //String packagename = System.getProperty("jawk.rtPackgeName", "org.jawk.jrt"); String packagename = "org.jawk.jrt"; if (packagename != null) { // use reflection to get all static Class definitions // and verify that they are members of the // runtime package Class c = AwkCompilerImpl.class; // foreach field in declared in the class... for (Field f : c.getDeclaredFields()) { int mod = f.getModifiers(); // if a "private static final" member... if ( (mod & Modifier.PRIVATE) > 0 && (mod & Modifier.STATIC) > 0 && (mod & Modifier.FINAL) > 0 && f.getType() == Class.class) { try { // obtain the value of the field // and apply it here! Object o = f.get(null); Class cls = (Class) o; if (!cls.getPackage().getName().equals(packagename)) { throw new AssertionError("class " + c.toString() + " is not contained within '" + packagename + "' package. Field = " + f.toString()); } } catch (IllegalAccessException iae) { throw new AssertionError(iae); // NOTE Thought there is an AssertionError#AssertionError(String, Throwable) ctor aswell, it was only introduced in Java 1.7, so we should not yet use it. } } } } // all's well return true; }
Example 18
Source File: ReflectionNavigator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public Location getFieldLocation(final Field field) { return new Location() { @Override public String toString() { return field.toString(); } }; }
Example 19
Source File: ReflectionNavigator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public Location getFieldLocation(final Field field) { return new Location() { @Override public String toString() { return field.toString(); } }; }
Example 20
Source File: StringSearcher.java From hop with Apache License 2.0 | 4 votes |
public static final void findMetaData( Object object, int level, List<StringSearchResult> stringList, Object parentObject, Object grandParentObject ) { if ( ( object == null ) || level > 5 ) { return; } PluginRegistry registry = PluginRegistry.getInstance(); if ( transformPluginPackages == null ) { transformPluginPackages = registry.getPluginPackages( TransformPluginType.class ); } if ( jobEntryPluginPackages == null ) { jobEntryPluginPackages = registry.getPluginPackages( ActionPluginType.class ); } Class<? extends Object> baseClass = object.getClass(); Field[] fields = baseClass.getDeclaredFields(); for ( int i = 0; i < fields.length; i++ ) { Field field = fields[ i ]; boolean processThisOne = true; if ( ( field.getModifiers() & Modifier.FINAL ) > 0 ) { processThisOne = false; } if ( ( field.getModifiers() & Modifier.STATIC ) > 0 ) { processThisOne = false; } // Investigate only if we're dealing with a sanctioned package. // A sanctioned package is either the local package (org.apache.hop) or // a package of one of the plugins. // boolean sanctionedPackage = false; String fieldToString = field.toString(); if ( fieldToString.indexOf( LOCAL_PACKAGE ) >= 0 ) { sanctionedPackage = true; } for ( int x = 0; x < JAVA_PACKAGES.length && !sanctionedPackage; x++ ) { if ( fieldToString.indexOf( JAVA_PACKAGES[ x ] ) >= 0 ) { sanctionedPackage = true; } } for ( int x = 0; x < transformPluginPackages.size() && !sanctionedPackage; x++ ) { if ( fieldToString.indexOf( transformPluginPackages.get( x ) ) >= 0 ) { sanctionedPackage = true; } } for ( int x = 0; x < jobEntryPluginPackages.size() && !sanctionedPackage; x++ ) { if ( fieldToString.indexOf( jobEntryPluginPackages.get( x ) ) >= 0 ) { sanctionedPackage = true; } } if ( !sanctionedPackage ) { processThisOne = false; // Stay in the sanctioned code-base. } // Dig into the metadata from here... // if ( processThisOne ) { try { Object obj = field.get( object ); if ( obj != null ) { stringSearchInObject( obj, level, stringList, parentObject, grandParentObject, field ); } } catch ( IllegalAccessException e ) { // OK, it's private, let's see if we can go there later on using // getters and setters... // fileName becomes: getFileName(); // OK, how do we get the value now? try { Method method = findMethod( baseClass, field.getName() ); if ( method != null ) { // String fullMethod = // baseClass.getName()+"."+method.getName()+"()"; Object string = method.invoke( object, (Object[]) null ); if ( string != null ) { stringSearchInObject( string, level, stringList, parentObject, grandParentObject, field ); } } } catch ( Throwable ex ) { // Ignore this error silently. If we can't access the method there // is nothing you can do about it. } } } } }