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.

InterTypeMethodDeclarationImpl.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.internal.lang.reflect;
  13. import java.lang.reflect.Method;
  14. import java.lang.reflect.Type;
  15. import java.lang.reflect.TypeVariable;
  16. import org.aspectj.lang.reflect.AjType;
  17. import org.aspectj.lang.reflect.AjTypeSystem;
  18. import org.aspectj.lang.reflect.InterTypeMethodDeclaration;
  19. /**
  20. * @author colyer
  21. *
  22. */
  23. public class InterTypeMethodDeclarationImpl extends InterTypeDeclarationImpl
  24. implements InterTypeMethodDeclaration {
  25. private String name;
  26. private Method baseMethod;
  27. private int parameterAdjustmentFactor = 1; // no of fake params at start of baseMethod
  28. private AjType<?>[] parameterTypes;
  29. private Type[] genericParameterTypes;
  30. private AjType<?> returnType;
  31. private Type genericReturnType;
  32. private AjType<?>[] exceptionTypes;
  33. public InterTypeMethodDeclarationImpl(AjType<?> decType, String target,
  34. int mods, String name, Method itdInterMethod) {
  35. super(decType, target, mods);
  36. this.name = name;
  37. this.baseMethod = itdInterMethod;
  38. }
  39. public InterTypeMethodDeclarationImpl(AjType<?> decType, AjType<?> targetType, Method base, int modifiers) {
  40. super(decType,targetType,modifiers);
  41. this.parameterAdjustmentFactor = 0;
  42. this.name = base.getName();
  43. this.baseMethod = base;
  44. }
  45. public String getName() {
  46. return this.name;
  47. }
  48. public AjType<?> getReturnType() {
  49. return AjTypeSystem.getAjType(baseMethod.getReturnType());
  50. }
  51. public Type getGenericReturnType() {
  52. Type gRet = baseMethod.getGenericReturnType();
  53. if (gRet instanceof Class) {
  54. return AjTypeSystem.getAjType((Class<?>)gRet);
  55. }
  56. return gRet;
  57. }
  58. public AjType<?>[] getParameterTypes() {
  59. Class<?>[] baseTypes = baseMethod.getParameterTypes();
  60. AjType<?>[] ret = new AjType<?>[baseTypes.length -parameterAdjustmentFactor];
  61. for (int i = parameterAdjustmentFactor; i < baseTypes.length; i++) {
  62. ret[i-parameterAdjustmentFactor] = AjTypeSystem.getAjType(baseTypes[i]);
  63. }
  64. return ret;
  65. }
  66. public Type[] getGenericParameterTypes() {
  67. Type[] baseTypes = baseMethod.getGenericParameterTypes();
  68. Type[] ret = new AjType<?>[baseTypes.length-parameterAdjustmentFactor];
  69. for (int i = parameterAdjustmentFactor; i < baseTypes.length; i++) {
  70. if (baseTypes[i] instanceof Class) {
  71. ret[i-parameterAdjustmentFactor] = AjTypeSystem.getAjType((Class<?>)baseTypes[i]);
  72. } else {
  73. ret[i-parameterAdjustmentFactor] = baseTypes[i];
  74. }
  75. }
  76. return ret;
  77. }
  78. public TypeVariable<Method>[] getTypeParameters() {
  79. return baseMethod.getTypeParameters();
  80. }
  81. public AjType<?>[] getExceptionTypes() {
  82. Class<?>[] baseTypes = baseMethod.getExceptionTypes();
  83. AjType<?>[] ret = new AjType<?>[baseTypes.length];
  84. for (int i = 0; i < baseTypes.length; i++) {
  85. ret[i] = AjTypeSystem.getAjType(baseTypes[i]);
  86. }
  87. return ret;
  88. }
  89. public String toString() {
  90. StringBuffer sb = new StringBuffer();
  91. sb.append(java.lang.reflect.Modifier.toString(getModifiers()));
  92. sb.append(" ");
  93. sb.append(getReturnType().toString());
  94. sb.append(" ");
  95. sb.append(this.targetTypeName);
  96. sb.append(".");
  97. sb.append(getName());
  98. sb.append("(");
  99. AjType<?>[] pTypes = getParameterTypes();
  100. for(int i = 0; i < (pTypes.length - 1); i++) {
  101. sb.append(pTypes[i].toString());
  102. sb.append(", ");
  103. }
  104. if (pTypes.length > 0) {
  105. sb.append(pTypes[pTypes.length -1].toString());
  106. }
  107. sb.append(")");
  108. return sb.toString();
  109. }
  110. }