/** * Looks for a field * * @param fc the field class * @param fn the field name * @exception NoSuchFieldException if the field cannot be found * @exception AmbiguousFieldException if the field is ambiguous */ @Override public Field getField(final Class fc, final String fn) throws NoSuchFieldException, AmbiguousFieldException { Field f; try { f = ReflectionUtilities.getField(fc, fn); } catch (final Exception e) { f = InterpreterUtilities.getOuterField(fc, fn); } setAccessFlag(f); return f; }
/** * Whether the given name represents a field in this context * * @param name the field name */ protected boolean fieldExists(final String name) { boolean result = false; try { ReflectionUtilities.getField(this.declaringClass, name); result = true; } catch (final NoSuchFieldException e) { try { InterpreterUtilities.getOuterField(this.declaringClass, name); result = true; } catch (final NoSuchFieldException ex) { } catch (final AmbiguousFieldException ex) { result = true; } } catch (final AmbiguousFieldException e) { result = true; } return result; }
/** * Creates the tree that is associated with the given name * * @param node the current node * @param name the variable name * @exception IllegalStateException if the variable is not defined */ @Override public Expression createName(final Node node, final IdentifierToken name) { if (isDefinedVariable(name.image())) { return super.createName(node, name); } else { final String fname = name.image(); try { ReflectionUtilities.getField(this.declaringClass, fname); return new StaticFieldAccess((ReferenceType) this.defaultQualifier, fname); } catch (final Exception e) { try { final Field f = InterpreterUtilities.getOuterField(this.declaringClass, fname); final Class c = f.getDeclaringClass(); return new StaticFieldAccess(new ReferenceType(c.getName()), fname); } catch (final Exception ex) { throw new CatchedExceptionError(ex, node); } } } }