List of usage examples for java.lang.reflect Field isSynthetic
public boolean isSynthetic()
From source file:com.opengamma.financial.analytics.curve.CurveNodeIdMapper.java
/** * Gets all fields used by the Fudge builder. * @return The fields/* w ww . j av a 2 s .c om*/ */ protected static List<String> getCurveIdMapperNames() { final List<String> list = new ArrayList<>(); for (final Field field : CurveNodeIdMapperBuilder.class.getDeclaredFields()) { if (Modifier.isStatic(field.getModifiers()) && field.isSynthetic() == false) { field.setAccessible(true); try { list.add((String) field.get(null)); } catch (final Exception ex) { // Ignore } } } Collections.sort(list, String.CASE_INSENSITIVE_ORDER); return ImmutableList.copyOf(list); }
From source file:fi.solita.mule.modules.xroad.XRoadConnector.java
private void fillOutboundHeaders(MuleMessage muleMessage, XRoadHeaders headers) { try {// w ww .j a va 2s . co m for (Field field : headers.getClass().getDeclaredFields()) { if (!field.isSynthetic()) { muleMessage.setOutboundProperty(X_ROAD_PROPERTY_PREFIX + field.getName(), field.get(headers)); } } } catch (Exception e) { throw new RuntimeException("Failed to set headers", e); } }
From source file:org.ngrinder.model.BaseEntity.java
/** * Clone current entity./* ww w.ja va 2 s. c o m*/ * * Only not null value is merged. * * @param toInstance instance to which the value is copied. * @return cloned entity */ public M cloneTo(M toInstance) { Field forDisplay = null; try { Field[] fields = getClass().getDeclaredFields(); // Iterate over all the attributes for (Field each : fields) { if (each.isSynthetic()) { continue; } final int modifiers = each.getModifiers(); if (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers)) { continue; } forDisplay = each; final Cloneable annotation = each.getAnnotation(Cloneable.class); if (annotation == null) { continue; } if (!each.isAccessible()) { each.setAccessible(true); } each.set(toInstance, each.get(this)); } return toInstance; } catch (Exception e) { String displayName = (forDisplay == null) ? "Empty" : forDisplay.getName(); throw processException(displayName + " - Exception occurred while cloning an entity from " + this + " to " + toInstance, e); } }
From source file:org.ngrinder.model.BaseEntity.java
/** * Merge source entity into current entity. * * Only not null value is merged./*w ww .j a v a2s .c om*/ * * @param source merge source * @return merged entity */ @SuppressWarnings("unchecked") public M merge(M source) { Field forDisplay = null; try { Field[] fields = getClass().getDeclaredFields(); // Iterate over all the attributes for (Field each : fields) { if (each.isSynthetic()) { continue; } final int modifiers = each.getModifiers(); if (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers)) { continue; } forDisplay = each; if (!each.isAccessible()) { each.setAccessible(true); } final Object value = each.get(source); if (value != null) { each.set(this, value); } } return (M) this; } catch (Exception e) { String displayName = (forDisplay == null) ? "Empty" : forDisplay.getName(); throw processException( displayName + " - Exception occurred while merging an entity from " + source + " to " + this, e); } }
From source file:com.comli.dawnbreaksthrough.personalintro.LicenseFragment.java
private List<Integer> getList() throws IllegalAccessException { List<Integer> list = new ArrayList<>(); Field[] fields = R.raw.class.getFields(); for (Field field : fields) { if (!field.isSynthetic() && !field.getName().equals("serialVersionUID")) { list.add(field.getInt(field)); }/* w ww. java 2 s. c o m*/ } return list; }
From source file:springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander.java
private Predicate<Field> syntheticFields() { return new Predicate<Field>() { @Override//from w w w .jav a 2s .c om public boolean apply(Field input) { return input.isSynthetic(); } }; }
From source file:com.glaf.core.util.ReflectUtils.java
public static boolean isPublicInstanceField(Field field) { return Modifier.isPublic(field.getModifiers()) && !Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers()) && !field.isSynthetic(); }
From source file:org.apache.niolex.commons.reflect.FieldFilter.java
/** * Filter the fields without synthetic fields. * * @return this//from www . j ava 2 s .c om */ public final FieldFilter<FT> noSynthetic() { return this.add(new Filter() { @Override public boolean isValid(Field f) { return !f.isSynthetic(); } }); }
From source file:org.evosuite.setup.TestUsageChecker.java
public static boolean canUse(Field f, Class<?> ownerClass) { // TODO we could enable some methods from Object, like getClass if (f.getDeclaringClass().equals(java.lang.Object.class)) return false;// handled here to avoid printing reasons if (f.getDeclaringClass().equals(java.lang.Thread.class)) return false;// handled here to avoid printing reasons if (!Properties.USE_DEPRECATED && f.isAnnotationPresent(Deprecated.class)) { final Class<?> targetClass = Properties.getTargetClassAndDontInitialise(); if (Properties.hasTargetClassBeenLoaded() && !f.getDeclaringClass().equals(targetClass)) { logger.debug("Skipping deprecated field " + f.getName()); return false; }/*from w w w . j a va2 s . c om*/ } if (f.isSynthetic()) { logger.debug("Skipping synthetic field " + f.getName()); return false; } if (f.getName().startsWith("ajc$")) { logger.debug("Skipping AspectJ field " + f.getName()); return false; } if (!f.getType().equals(String.class) && !canUse(f.getType())) { return false; } // in, out, err if (f.getDeclaringClass().equals(FileDescriptor.class)) { return false; } if (Modifier.isPublic(f.getModifiers())) { // It may still be the case that the field is defined in a non-visible superclass of the class // we already know we can use. In that case, the compiler would be fine with accessing the // field, but reflection would start complaining about IllegalAccess! // Therefore, we set the field accessible to be on the safe side TestClusterUtils.makeAccessible(f); return true; } // If default access rights, then check if this class is in the same package as the target class if (!Modifier.isPrivate(f.getModifiers())) { // && !Modifier.isProtected(f.getModifiers())) { String packageName = ClassUtils.getPackageName(ownerClass); String declaredPackageName = ClassUtils.getPackageName(f.getDeclaringClass()); if (packageName.equals(Properties.CLASS_PREFIX) && packageName.equals(declaredPackageName)) { TestClusterUtils.makeAccessible(f); return true; } } return false; }
From source file:hu.bme.mit.sette.common.model.snippet.SnippetInputFactoryContainer.java
/** * Validates the fields of the class.//from w w w. j ava 2 s . co m * * @param validator * a validator */ private void validateFields(final AbstractValidator<?> validator) { // check: no declared fields for (Field field : javaClass.getDeclaredFields()) { if (field.isSynthetic()) { // skip for synthetic fields (e.g. switch for enum generates // synthetic methods and fields) continue; } FieldValidator v = new FieldValidator(field); v.addException("The class must not declare fields"); validator.addChildIfInvalid(v); } }