You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FieldSignatureImpl.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.runtime.reflect;
  14. import java.lang.reflect.Field;
  15. import org.aspectj.lang.reflect.FieldSignature;
  16. public class FieldSignatureImpl extends MemberSignatureImpl implements FieldSignature {
  17. Class<?> fieldType;
  18. private Field field;
  19. FieldSignatureImpl(int modifiers, String name, Class<?> declaringType,
  20. Class<?> fieldType)
  21. {
  22. super(modifiers, name, declaringType);
  23. this.fieldType = fieldType;
  24. }
  25. FieldSignatureImpl(String stringRep) {
  26. super(stringRep);
  27. }
  28. public Class getFieldType() {
  29. if (fieldType == null) fieldType = extractType(3);
  30. return fieldType;
  31. }
  32. protected String createToString(StringMaker sm) {
  33. StringBuilder buf = new StringBuilder();
  34. buf.append(sm.makeModifiersString(getModifiers()));
  35. if (sm.includeArgs) buf.append(sm.makeTypeName(getFieldType()));
  36. if (sm.includeArgs) buf.append(" ");
  37. buf.append(sm.makePrimaryTypeName(getDeclaringType(),getDeclaringTypeName()));
  38. buf.append(".");
  39. buf.append(getName());
  40. return buf.toString();
  41. }
  42. /* (non-Javadoc)
  43. * @see org.aspectj.runtime.reflect.MemberSignatureImpl#createAccessibleObject()
  44. */
  45. public Field getField() {
  46. if (field == null) {
  47. try {
  48. field = getDeclaringType().getDeclaredField(getName());
  49. } catch (Exception ex) {
  50. ; // nothing we can do, caller will see null
  51. }
  52. }
  53. return field;
  54. }
  55. }