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.

ITDFieldPrinter.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
  14. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodScope;
  16. /**
  17. * Prints the declaration for an intertype declared field, including initializer.
  18. *
  19. * @author Andy Clement
  20. */
  21. class ITDFieldPrinter extends CommonPrinter {
  22. private InterTypeFieldDeclaration fieldDeclaration;
  23. ITDFieldPrinter(InterTypeFieldDeclaration fieldDeclaration, MethodScope methodscope) {
  24. super(methodscope);
  25. output = new StringBuilder();
  26. this.fieldDeclaration = fieldDeclaration;
  27. }
  28. public String print() {
  29. return print(2);
  30. }
  31. public String print(int tab) {
  32. this.output = new StringBuilder();
  33. if (fieldDeclaration.javadoc != null) {
  34. // TODO javadoc
  35. // md.javadoc.print(tab, output);
  36. }
  37. printIndent(tab);
  38. if (fieldDeclaration.annotations != null) {
  39. printAnnotations(fieldDeclaration.annotations);
  40. }
  41. printModifiers(fieldDeclaration.declaredModifiers); // not md.modifiers
  42. TypeParameter[] typeParams = fieldDeclaration.typeParameters();
  43. if (typeParams != null) {
  44. output.append('<');
  45. int max = typeParams.length - 1;
  46. for (int j = 0; j < max; j++) {
  47. printTypeParameter(typeParams[j]);
  48. output.append(", ");//$NON-NLS-1$
  49. }
  50. printTypeParameter(typeParams[max]);
  51. output.append('>');
  52. }
  53. printReturnType(0).append(fieldDeclaration.getDeclaredSelector());
  54. if (fieldDeclaration.initialization != null) {
  55. output.append(" = ");
  56. printExpression(fieldDeclaration.initialization);
  57. }
  58. output.append(';');
  59. return output.toString();
  60. }
  61. // TODO better name
  62. public StringBuilder printReturnType(int indent) {
  63. if (fieldDeclaration.returnType == null) {
  64. return output;
  65. }
  66. return printExpression(fieldDeclaration.returnType).append(' ');
  67. }
  68. }