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.

InterTypeConstructorDeclarationImpl.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 org.aspectj.lang.reflect.AjType;
  16. import org.aspectj.lang.reflect.AjTypeSystem;
  17. import org.aspectj.lang.reflect.InterTypeConstructorDeclaration;
  18. /**
  19. * @author colyer
  20. *
  21. */
  22. public class InterTypeConstructorDeclarationImpl extends
  23. InterTypeDeclarationImpl implements InterTypeConstructorDeclaration {
  24. private Method baseMethod;
  25. public InterTypeConstructorDeclarationImpl(AjType<?> decType,
  26. String target, int mods, Method baseMethod) {
  27. super(decType, target, mods);
  28. this.baseMethod = baseMethod;
  29. }
  30. public AjType<?>[] getParameterTypes() {
  31. Class<?>[] baseTypes = baseMethod.getParameterTypes();
  32. AjType<?>[] ret = new AjType<?>[baseTypes.length-1];
  33. for (int i = 1; i < baseTypes.length; i++) {
  34. ret[i-1] = AjTypeSystem.getAjType(baseTypes[i]);
  35. }
  36. return ret;
  37. }
  38. public Type[] getGenericParameterTypes() {
  39. Type[] baseTypes = baseMethod.getGenericParameterTypes();
  40. Type[] ret = new AjType<?>[baseTypes.length-1];
  41. for (int i = 1; i < baseTypes.length; i++) {
  42. if (baseTypes[i] instanceof Class) {
  43. ret[i-1] = AjTypeSystem.getAjType((Class<?>)baseTypes[i]);
  44. } else {
  45. ret[i-1] = baseTypes[i];
  46. }
  47. }
  48. return ret;
  49. }
  50. public AjType<?>[] getExceptionTypes() {
  51. Class<?>[] baseTypes = baseMethod.getExceptionTypes();
  52. AjType<?>[] ret = new AjType<?>[baseTypes.length];
  53. for (int i = 0; i < baseTypes.length; i++) {
  54. ret[i] = AjTypeSystem.getAjType(baseTypes[i]);
  55. }
  56. return ret;
  57. }
  58. public String toString() {
  59. StringBuffer sb = new StringBuffer();
  60. sb.append(java.lang.reflect.Modifier.toString(getModifiers()));
  61. sb.append(" ");
  62. sb.append(this.targetTypeName);
  63. sb.append(".new");
  64. sb.append("(");
  65. AjType<?>[] pTypes = getParameterTypes();
  66. for(int i = 0; i < (pTypes.length - 1); i++) {
  67. sb.append(pTypes[i].toString());
  68. sb.append(", ");
  69. }
  70. if (pTypes.length > 0) {
  71. sb.append(pTypes[pTypes.length -1].toString());
  72. }
  73. sb.append(")");
  74. return sb.toString();
  75. }
  76. }