List of usage examples for java.lang.reflect Modifier isFinal
public static boolean isFinal(int mod)
From source file:org.apache.hadoop.fs.TestHarFileSystem.java
@Test public void testInheritedMethodsImplemented() throws Exception { int errors = 0; for (Method m : FileSystem.class.getDeclaredMethods()) { if (Modifier.isStatic(m.getModifiers()) || Modifier.isPrivate(m.getModifiers()) || Modifier.isFinal(m.getModifiers())) { continue; }//from www . j a v a 2s .co m try { MustNotImplement.class.getMethod(m.getName(), m.getParameterTypes()); try { HarFileSystem.class.getDeclaredMethod(m.getName(), m.getParameterTypes()); LOG.error("HarFileSystem MUST not implement " + m); errors++; } catch (NoSuchMethodException ex) { // Expected } } catch (NoSuchMethodException exc) { try { HarFileSystem.class.getDeclaredMethod(m.getName(), m.getParameterTypes()); } catch (NoSuchMethodException exc2) { LOG.error("HarFileSystem MUST implement " + m); errors++; } } } assertTrue((errors + " methods were not overridden correctly - see log"), errors <= 0); }
From source file:cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl.java
@Override public final int hashCode() { int result = 0; Field[] fields = this.getClass().getDeclaredFields(); for (Field field : fields) { // compare non-final, non-static and non-transient fields only if (!Modifier.isFinal(field.getModifiers()) && !Modifier.isStatic(field.getModifiers()) && !Modifier.isTransient(field.getModifiers())) { try { // skip arrays if (!field.getType().isArray() && field.get(this) != null) { // for string take its length if (field.getType().equals(String.class)) { result ^= ((String) field.get(this)).length(); } else if (field.getType().equals(short.class) || field.getType().equals(Short.class)) { result ^= field.getShort(this); } else if (field.getType().equals(int.class) || field.getType().equals(Integer.class)) { result ^= field.getInt(this); } else if (field.getType().equals(float.class) || field.getType().equals(Float.class)) { result ^= (int) field.getFloat(this); } else if (field.getType().equals(double.class) || field.getType().equals(Double.class)) { result ^= (int) field.getDouble(this); } else if (field.getType().equals(long.class) || field.getType().equals(Long.class)) { result ^= (int) field.getLong(this); } else if (field.getType().equals(byte.class) || field.getType().equals(Byte.class)) { result ^= field.getByte(this); } else if (field.getType().equals(boolean.class) || field.getType().equals(Boolean.class)) { result ^= field.getBoolean(this) == Boolean.TRUE ? 1 : 0; }/*www . j av a2s . c o m*/ } } catch (Exception e) { log.error(e.toString()); throw new RuntimeException("Exception caught while calculating HardwareAddress hashcode.", e); } } } return result; }
From source file:com.oembedler.moon.graphql.engine.dfs.GraphQLSchemaDfsTraversal.java
public GraphQLFieldDefinition getFieldDefinition(DfsContext dfsContext, Class<?> implClass, Field field) { GraphQLFieldDefinition graphQLFieldDefinition = null; ResolvableTypeAccessor resolvableTypeAccessor = ResolvableTypeAccessor.forField(field, implClass); if (resolvableTypeAccessor.isNotIgnorable()) { GraphQLOutputType graphQLOutputType = (GraphQLOutputType) createGraphQLFieldType(dfsContext, resolvableTypeAccessor, true); GraphQLFieldDefinition.Builder graphQLFieldDefinitionBuilder = GraphQLFieldDefinition .newFieldDefinition().name(resolvableTypeAccessor.getName()).type(graphQLOutputType) .deprecate(resolvableTypeAccessor.getGraphQLDeprecationReason()) .description(resolvableTypeAccessor.getDescription()); boolean isConstant = Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers()); if (isConstant) { graphQLFieldDefinitionBuilder .staticValue(org.springframework.util.ReflectionUtils.getField(field, null)); }/*from w w w.j a v a 2 s . co m*/ graphQLFieldDefinition = graphQLFieldDefinitionBuilder.build(); addToFieldDefinitionResolverMap(dfsContext, graphQLFieldDefinition, resolvableTypeAccessor.getGraphQLComplexitySpelExpression()); } return graphQLFieldDefinition; }
From source file:adalid.core.Operation.java
void initialiseFields(Class<?> clazz) { Class<?> c;/*from w w w. ja va 2s . c om*/ int d, r; String name; Class<?> type; int modifiers; boolean restricted; Object o; int depth = depth(); int round = round(); Class<?>[] classes = new Class<?>[] { Parameter.class, Expression.class }; Class<?> dac = getClass(); Class<?> top = Operation.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); if (!c.isAssignableFrom(type)) { continue; } modifiers = type.getModifiers(); if (type.isInterface() && Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + this; try { o = field.get(this); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(this, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(this, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }
From source file:org.kuali.rice.core.framework.persistence.jpa.metadata.MetadataManager.java
private static void extractFieldMetadata(Class clazz, EntityDescriptor entityDescriptor) { // Don't want to get parent fields if overridden in children since we are walking the tree from child to parent Set<String> cachedFields = new HashSet<String>(); do {/*from www .jav a 2 s.com*/ for (Field field : clazz.getDeclaredFields()) { if (cachedFields.contains(field.getName())) { continue; } cachedFields.add(field.getName()); int mods = field.getModifiers(); if (Modifier.isFinal(mods) || Modifier.isStatic(mods) || Modifier.isTransient(mods) || field.isAnnotationPresent(Transient.class)) { continue; } // Basic Fields FieldDescriptor fieldDescriptor = new FieldDescriptor(); fieldDescriptor.setClazz(field.getType()); fieldDescriptor.setTargetClazz(field.getType()); fieldDescriptor.setName(field.getName()); if (field.isAnnotationPresent(Id.class)) { fieldDescriptor.setId(true); if (entityDescriptor.getIdClass() != null) { // pull the column from IdClass try { Field idClassField = entityDescriptor.getIdClass().getDeclaredField(field.getName()); idClassField.setAccessible(true); addColumnInformationToFieldDescriptor(fieldDescriptor, idClassField); } catch (Exception e) { e.printStackTrace(); } } } if (field.isAnnotationPresent(Column.class)) { if (!field.isAnnotationPresent(Id.class) || entityDescriptor.getIdClass() == null) { // only populate if we haven't populated already addColumnInformationToFieldDescriptor(fieldDescriptor, field); } } else if (!field.isAnnotationPresent(Id.class) || entityDescriptor.getIdClass() == null) { fieldDescriptor.setColumn(field.getName()); } if (field.isAnnotationPresent(Version.class)) { fieldDescriptor.setVersion(true); } if (field.isAnnotationPresent(Lob.class)) { fieldDescriptor.setLob(true); } if (field.isAnnotationPresent(Temporal.class)) { fieldDescriptor.setTemporal(true); fieldDescriptor.setTemporalType(field.getAnnotation(Temporal.class).value()); } // Relationships if (field.isAnnotationPresent(OneToOne.class)) { OneToOneDescriptor descriptor = new OneToOneDescriptor(); OneToOne relation = field.getAnnotation(OneToOne.class); descriptor.setAttributeName(field.getName()); if (relation.targetEntity().equals(void.class)) { descriptor.setTargetEntity(field.getType()); } else { descriptor.setTargetEntity(relation.targetEntity()); fieldDescriptor.setTargetClazz(relation.targetEntity()); } descriptor.setCascade(relation.cascade()); descriptor.setFetch(relation.fetch()); descriptor.setMappedBy(relation.mappedBy()); descriptor.setOptional(relation.optional()); if (field.isAnnotationPresent(JoinColumn.class)) { JoinColumn jc = field.getAnnotation(JoinColumn.class); descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); FieldDescriptor jcFkField = entityDescriptor.getFieldByColumnName(jc.name()); if (jcFkField != null) { descriptor.addFkField(jcFkField.getName()); } else { //check to see if foreign key is in an AttributeOverride annotation if (clazz.isAnnotationPresent(AttributeOverrides.class)) { for (AttributeOverride override : ((AttributeOverrides) clazz .getAnnotation(AttributeOverrides.class)).value()) { if (jc.name().equals(override.column().name())) { entityDescriptor.getFieldByName(override.name()) .setColumn(override.column().name()); jcFkField = entityDescriptor.getFieldByName(override.name()); if (jcFkField != null) { descriptor.addFkField(jcFkField.getName()); } } } } if (clazz.isAnnotationPresent(AttributeOverride.class)) { AttributeOverride override = (AttributeOverride) clazz .getAnnotation(AttributeOverride.class); if (jc.name().equals(override.column().name())) { entityDescriptor.getFieldByName(override.name()) .setColumn(override.column().name()); jcFkField = entityDescriptor.getFieldByName(override.name()); if (jcFkField != null) { descriptor.addFkField(jcFkField.getName()); } } } } //descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName()); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); } if (field.isAnnotationPresent(JoinColumns.class)) { JoinColumns jcs = field.getAnnotation(JoinColumns.class); for (JoinColumn jc : jcs.value()) { descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName()); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); } } entityDescriptor.add(descriptor); } if (field.isAnnotationPresent(OneToMany.class)) { OneToManyDescriptor descriptor = new OneToManyDescriptor(); OneToMany relation = field.getAnnotation(OneToMany.class); descriptor.setAttributeName(field.getName()); if (relation.targetEntity().equals(void.class)) { descriptor.setTargetEntity( (Class) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]); } else { descriptor.setTargetEntity(relation.targetEntity()); fieldDescriptor.setTargetClazz(relation.targetEntity()); } descriptor.setCascade(relation.cascade()); descriptor.setFetch(relation.fetch()); descriptor.setMappedBy(relation.mappedBy()); EntityDescriptor mappedBy = (entityDescriptor.getClazz().equals(descriptor.getTargetEntity())) ? entityDescriptor : MetadataManager.getEntityDescriptor(descriptor.getTargetEntity()); ObjectDescriptor od = mappedBy.getObjectDescriptorByName(descriptor.getMappedBy()); if (od != null) { for (String fk : od.getForeignKeyFields()) { descriptor.addFkField(fk); } } if (field.isAnnotationPresent(JoinTable.class)) { JoinTable jt = field.getAnnotation(JoinTable.class); for (JoinColumn jc : jt.joinColumns()) { descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName()); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); } for (JoinColumn jc : jt.inverseJoinColumns()) { descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); descriptor.addInverseJoinColumnDescriptor(constructJoinDescriptor(jc)); } } else { if (field.isAnnotationPresent(JoinColumn.class)) { JoinColumn jc = field.getAnnotation(JoinColumn.class); FieldDescriptor jcFkField = entityDescriptor.getFieldByColumnName(jc.name()); if (jcFkField != null) { descriptor.addFkField(jcFkField.getName()); } descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); } if (field.isAnnotationPresent(JoinColumns.class)) { JoinColumns jcs = field.getAnnotation(JoinColumns.class); for (JoinColumn jc : jcs.value()) { descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName()); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); } } } entityDescriptor.add(descriptor); } if (field.isAnnotationPresent(ManyToOne.class)) { ManyToOne relation = field.getAnnotation(ManyToOne.class); ManyToOneDescriptor descriptor = new ManyToOneDescriptor(); descriptor.setAttributeName(field.getName()); if (relation.targetEntity().equals(void.class)) { descriptor.setTargetEntity(field.getType()); } else { descriptor.setTargetEntity(relation.targetEntity()); fieldDescriptor.setTargetClazz(relation.targetEntity()); } descriptor.setCascade(relation.cascade()); descriptor.setFetch(relation.fetch()); descriptor.setOptional(relation.optional()); if (field.isAnnotationPresent(JoinColumn.class)) { JoinColumn jc = field.getAnnotation(JoinColumn.class); descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); FieldDescriptor jcFkField = entityDescriptor.getFieldByColumnName(jc.name()); if (jcFkField != null) { descriptor.addFkField(jcFkField.getName()); } //descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName()); //descriptor.addFkField(entitesByClass.get(field.getType()).getFieldByColumnName(jc.name()).getName()); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); } if (field.isAnnotationPresent(JoinColumns.class)) { JoinColumns jcs = field.getAnnotation(JoinColumns.class); for (JoinColumn jc : jcs.value()) { descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName()); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); } } entityDescriptor.add(descriptor); } if (field.isAnnotationPresent(ManyToMany.class)) { ManyToManyDescriptor descriptor = new ManyToManyDescriptor(); ManyToMany relation = field.getAnnotation(ManyToMany.class); descriptor.setAttributeName(field.getName()); if (relation.targetEntity().equals(void.class)) { descriptor.setTargetEntity( (Class) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]); } else { descriptor.setTargetEntity(relation.targetEntity()); fieldDescriptor.setTargetClazz(relation.targetEntity()); } descriptor.setCascade(relation.cascade()); descriptor.setFetch(relation.fetch()); descriptor.setMappedBy(relation.mappedBy()); if (field.isAnnotationPresent(JoinTable.class)) { JoinTable jt = field.getAnnotation(JoinTable.class); descriptor.setJoinTableName(jt.name()); for (JoinColumn jc : jt.joinColumns()) { descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName()); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); } for (JoinColumn jc : jt.inverseJoinColumns()) { descriptor.addInverseJoinColumnDescriptor(constructJoinDescriptor(jc)); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); // TODO: Should we add inverse join columns? } } else { if (field.isAnnotationPresent(JoinColumn.class)) { JoinColumn jc = field.getAnnotation(JoinColumn.class); FieldDescriptor jcFkField = entityDescriptor.getFieldByColumnName(jc.name()); if (jcFkField != null) { descriptor.addFkField(jcFkField.getName()); } descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); } if (field.isAnnotationPresent(JoinColumns.class)) { JoinColumns jcs = field.getAnnotation(JoinColumns.class); for (JoinColumn jc : jcs.value()) { descriptor.addJoinColumnDescriptor(constructJoinDescriptor(jc)); descriptor.addFkField(entityDescriptor.getFieldByColumnName(jc.name()).getName()); descriptor.setInsertable(jc.insertable()); descriptor.setUpdateable(jc.updatable()); } } } entityDescriptor.add(descriptor); } // Add the field to the entity entityDescriptor.add(fieldDescriptor); } clazz = clazz.getSuperclass(); } while (clazz != null && !(clazz.equals(Object.class))); }
From source file:edu.cmu.tetrad.util.TetradSerializableUtils.java
/** * Serializes the given class to the getCurrentDirectory() directory. The * static serializedInstance() method of clazz will be called to get an * examplar of clazz. This examplar will then be serialized out to a file * stored in getCurrentDirectory()./*from www. ja v a2 s . c om*/ * * @param clazz the class to serialize. * @throws RuntimeException if clazz cannot be serialized. This exception * has an informative message and wraps the * originally thrown exception as root cause. * @see #getCurrentDirectory() */ private void serializeClass(Class clazz, Map<String, List<String>> classFields) throws RuntimeException { File current = new File(getCurrentDirectory()); if (!current.exists() || !current.isDirectory()) { throw new IllegalStateException("There is no " + current.getAbsolutePath() + " directory. " + "\nThis is where the serialized classes should be. " + "Please run serializeCurrentDirectory() first."); } try { Field field = clazz.getDeclaredField("serialVersionUID"); int modifiers = field.getModifiers(); boolean _static = Modifier.isStatic(modifiers); boolean _final = Modifier.isFinal(modifiers); field.setAccessible(true); if (!_static || !_final || !(23L == field.getLong(null))) { throw new RuntimeException( "Class " + clazz + " does not define static final " + "long serialVersionUID = 23L"); } int numFields = getNumNonSerialVersionUIDFields(clazz); if (numFields > 0) { Method method = clazz.getMethod("serializableInstance"); Object object = method.invoke(null); File file = new File(current, clazz.getName() + ".ser"); boolean created = file.createNewFile(); FileOutputStream out = new FileOutputStream(file); ObjectOutputStream objOut = new ObjectOutputStream(out); objOut.writeObject(object); out.close(); } // Make entry in list of class fields. ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(clazz); String className = objectStreamClass.getName(); ObjectStreamField[] fields = objectStreamClass.getFields(); @SuppressWarnings("Convert2Diamond") List<String> fieldList = new ArrayList<>(); for (ObjectStreamField objectStreamField : fields) { String fieldName = objectStreamField.getName(); fieldList.add(fieldName); } classFields.put(className, fieldList); } catch (NoSuchFieldException e) { throw new RuntimeException(("There is no static final long field " + "'serialVersionUID' in " + clazz + ". Please make one and set it " + "to 23L.")); } catch (NoSuchMethodException e) { throw new RuntimeException( "Class " + clazz + "does not " + "have a public static serializableInstance constructor.", e); } catch (IllegalAccessException e) { throw new RuntimeException( "The method serializableInstance() of " + "class " + clazz + " is not public.", e); } catch (InvocationTargetException e) { throw new RuntimeException( "Unable to statically call the " + "serializableInstance() method of class " + clazz + ".", e); } catch (IOException e) { throw new RuntimeException("Could not create a new, writeable file " + "in " + getCurrentDirectory() + " when trying to serialize " + clazz + ".", e); } }
From source file:edu.cmu.tetradapp.util.TetradSerializableUtils.java
/** * Serializes the given class to the getCurrentDirectory() directory. The * static serializedInstance() method of clazz will be called to get an * examplar of clazz. This examplar will then be serialized out to a file * stored in getCurrentDirectory()./* w w w . j a v a 2 s .c om*/ * * @param clazz the class to serialize. * @throws RuntimeException if clazz cannot be serialized. This exception * has an informative message and wraps the * originally thrown exception as root cause. * @see #getCurrentDirectory() */ private void serializeClass(Class clazz, Map<String, List<String>> classFields) throws RuntimeException { File current = new File(getCurrentDirectory()); if (!current.exists() || !current.isDirectory()) { throw new IllegalStateException("There is no " + current.getAbsolutePath() + " directory. " + "\nThis is where the serialized classes should be. " + "Please run serializeCurrentDirectory() first."); } try { Field field = clazz.getDeclaredField("serialVersionUID"); int modifiers = field.getModifiers(); boolean _static = Modifier.isStatic(modifiers); boolean _final = Modifier.isFinal(modifiers); field.setAccessible(true); if (!_static || !_final || !(23L == field.getLong(null))) { throw new RuntimeException( "Class " + clazz + " does not define static final " + "long serialVersionUID = 23L"); } int numFields = getNumNonSerialVersionUIDFields(clazz); if (numFields > 0) { Method method = clazz.getMethod("serializableInstance", new Class[0]); Object object = method.invoke(null, new Object[0]); File file = new File(current, clazz.getName() + ".ser"); file.createNewFile(); FileOutputStream out = new FileOutputStream(file); ObjectOutputStream objOut = new ObjectOutputStream(out); objOut.writeObject(object); out.close(); } // Make entry in list of class fields. ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(clazz); String className = objectStreamClass.getName(); ObjectStreamField[] fields = objectStreamClass.getFields(); List<String> fieldList = new ArrayList<String>(); for (ObjectStreamField objectStreamField : fields) { String fieldName = objectStreamField.getName(); fieldList.add(fieldName); } classFields.put(className, fieldList); } catch (NoSuchFieldException e) { throw new RuntimeException(("There is no static final long field " + "'serialVersionUID' in " + clazz + ". Please make one and set it " + "to 23L.")); } catch (NoSuchMethodException e) { throw new RuntimeException( "Class " + clazz + "does not " + "have a public static serializableInstance constructor.", e); } catch (IllegalAccessException e) { throw new RuntimeException( "The method serializableInstance() of " + "class " + clazz + " is not public.", e); } catch (InvocationTargetException e) { throw new RuntimeException( "Unable to statically call the " + "serializableInstance() method of class " + clazz + ".", e); } catch (IOException e) { throw new RuntimeException("Could not create a new, writeable file " + "in " + getCurrentDirectory() + " when trying to serialize " + clazz + ".", e); } }
From source file:org.topazproject.otm.metadata.AnnotationClassMetaFactory.java
private static void validate(Property property, ClassDefinition def) throws OtmException { Method setter = property.getWriteMethod(); Method getter = property.getReadMethod(); if (setter == null) throw new OtmException("Missing setter for property " + property); if ((getter == null) && !(def instanceof ViewDefinition)) throw new OtmException("Missing getter for property " + property); if (Modifier.isFinal(setter.getModifiers())) throw new OtmException("Setter can't be 'final' for " + property); if ((getter != null) && Modifier.isFinal(getter.getModifiers())) throw new OtmException("Getter can't be 'final' for " + property); }
From source file:org.projectforge.common.BeanHelper.java
/** * Gets all declared fields which are neither transient, static nor final. * @param clazz//from ww w.j a va 2 s. com * @return */ public static Field[] getDeclaredPropertyFields(final Class<?> clazz) { final Field[] fields = getAllDeclaredFields(clazz); final List<Field> list = new ArrayList<Field>(); for (final Field field : fields) { if (Modifier.isTransient(field.getModifiers()) == false && Modifier.isStatic(field.getModifiers()) == false && Modifier.isFinal(field.getModifiers()) == false) { list.add(field); } } final Field[] result = new Field[list.size()]; list.toArray(result); return result; }
From source file:adalid.core.EntityAtlas.java
@SuppressWarnings("deprecation") void initialiseFields(Class<?> clazz) { track("initialiseFields", _declaringArtifact, clazz.getSimpleName()); Class<?> c;//from ww w. j a v a 2 s.c o m int d, r; String name; String key; String pattern = "there are several fields for operation {0}"; String message; Class<?> type; Class<?> decl; Class<?> operationClass; Field operationField; int modifiers; boolean restricted; Object o; int depth = _declaringArtifact.depth(); int round = _declaringArtifact.round(); Class<?>[] classes = new Class<?>[] { Property.class, Key.class, Tab.class, View.class, Instance.class, NamedValue.class, Expression.class, Transition.class, Operation.class, Trigger.class }; Class<?> dac = _declaringArtifact.getClass(); Class<?> top = Entity.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); decl = field.getDeclaringClass(); if (!c.isAssignableFrom(type)) { continue; } if (c.equals(Expression.class) && Property.class.isAssignableFrom(type)) { continue; } // TODO: extension handling if (field.isAnnotationPresent(Extension.class) && Entity.class.isAssignableFrom(type)) { // if (!dac.equals(decl) || !dac.isAssignableFrom(type)) { // continue; // } continue; } modifiers = type.getModifiers(); if (NamedValue.class.isAssignableFrom(type) || Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = type.isInterface() || Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isPrivate(modifiers); if (restricted) { continue; } restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } if (Operation.class.isAssignableFrom(type)) { key = type.getSimpleName(); operationClass = _operationClasses.get(key); if (operationClass != null) { operationField = _operationFields.get(key); if (operationField == null) { _operationFields.put(key, field); } else { message = MessageFormat.format(pattern, operationClass.getName()); logger.warn(message); TLC.getProject().getParser().increaseWarningCount(); } } } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + _declaringArtifact; try { o = field.get(_declaringArtifact); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(_declaringArtifact, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(_declaringArtifact, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }