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.

ITDMethodPrinter.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* *******************************************************************
  2. * Copyright (c) 2010 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Andy Clement - SpringSource
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.compiler;
  13. import java.lang.reflect.Modifier;
  14. import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodScope;
  17. /**
  18. * Prints the declaration for an intertype declared method.
  19. *
  20. * @author Andy Clement
  21. */
  22. class ITDMethodPrinter extends CommonPrinter {
  23. private InterTypeMethodDeclaration methodDeclaration;
  24. ITDMethodPrinter(InterTypeMethodDeclaration methodDeclaration, MethodScope methodscope) {
  25. super(methodscope);
  26. output = new StringBuilder();
  27. this.methodDeclaration = methodDeclaration;
  28. this.declaration = methodDeclaration;
  29. }
  30. public String print() {
  31. return print(2);
  32. }
  33. public StringBuilder printReturnType(int indent) {
  34. if (methodDeclaration.returnType == null) {
  35. return output;
  36. }
  37. return printExpression(methodDeclaration.returnType).append(' ');
  38. }
  39. public String print(int tab) {
  40. this.output = new StringBuilder();
  41. if (methodDeclaration.javadoc != null) {
  42. // TODO javadoc support...
  43. // md.javadoc.print(tab, output);
  44. }
  45. printIndent(tab);
  46. if (methodDeclaration.annotations != null) {
  47. printAnnotations(methodDeclaration.annotations);
  48. }
  49. printModifiers(methodDeclaration.declaredModifiers); // not md.modifiers
  50. TypeParameter[] typeParams = methodDeclaration.typeParameters();
  51. if (typeParams != null) {
  52. output.append('<');
  53. int max = typeParams.length - 1;
  54. for (int j = 0; j < max; j++) {
  55. printTypeParameter(typeParams[j]);
  56. output.append(", ");//$NON-NLS-1$
  57. }
  58. printTypeParameter(typeParams[max]);
  59. output.append("> ");
  60. }
  61. printReturnType(0).append(methodDeclaration.getDeclaredSelector()).append('(');
  62. if (methodDeclaration.arguments != null) {
  63. for (int i = Modifier.isStatic(methodDeclaration.declaredModifiers) ? 0 : 1; i < methodDeclaration.arguments.length; i++) {
  64. printArgument(methodDeclaration.arguments[i]);
  65. if ((i + 1) < methodDeclaration.arguments.length) {
  66. output.append(", "); //$NON-NLS-1$
  67. }
  68. }
  69. }
  70. output.append(')');
  71. if (methodDeclaration.thrownExceptions != null) {
  72. output.append(" throws "); //$NON-NLS-1$
  73. for (int i = 0; i < methodDeclaration.thrownExceptions.length; i++) {
  74. if (i > 0) {
  75. output.append(", "); //$NON-NLS-1$
  76. }
  77. printTypeReference(methodDeclaration.thrownExceptions[i]);
  78. }
  79. }
  80. printBody(tab + 1);
  81. return output.toString();
  82. }
  83. }