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.

AjMethodDeclaration.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*******************************************************************************
  2. * Copyright (c) 2004 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation
  10. *******************************************************************************/
  11. package org.aspectj.ajdt.internal.compiler.ast;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  18. import org.aspectj.weaver.AjAttribute;
  19. /**
  20. * Root class for all MethodDeclaration objects created by the parser.
  21. * Enables us to generate extra attributes in the method_info attribute
  22. * to support aspectj.
  23. *
  24. */
  25. public class AjMethodDeclaration extends MethodDeclaration {
  26. private List attributes = null;
  27. /**
  28. * @param compilationResult
  29. */
  30. public AjMethodDeclaration(CompilationResult compilationResult) {
  31. super(compilationResult);
  32. }
  33. // general purpose hook to add an AjAttribute to this method
  34. // used by @AspectJ visitor to add pointcut attribute to @Advice
  35. protected void addAttribute(EclipseAttributeAdapter eaa) {
  36. if (attributes==null) attributes = new ArrayList();
  37. attributes.add(eaa);
  38. }
  39. /**
  40. * Overridden to add extra AJ stuff, also adds synthetic if boolean is true.
  41. */
  42. protected int generateInfoAttributes(ClassFile classFile,boolean addAjSynthetic) {
  43. // add extra attributes into list then call 2-arg version of generateInfoAttributes...
  44. List extras = (attributes==null?new ArrayList():attributes);
  45. addDeclarationStartLineAttribute(extras,classFile);
  46. if (addAjSynthetic) {
  47. extras.add(new EclipseAttributeAdapter(new AjAttribute.AjSynthetic()));
  48. }
  49. return classFile.generateMethodInfoAttributes(binding,extras);
  50. }
  51. @Override
  52. protected int generateInfoAttributes(ClassFile classFile) {
  53. return generateInfoAttributes(classFile,false);
  54. }
  55. protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
  56. if ((classFile.codeStream.generateAttributes & ClassFileConstants.ATTR_LINES)==0) return;
  57. int[] separators = compilationResult().lineSeparatorPositions;
  58. int declarationStartLine = 1;
  59. for (int i = 0; i < separators.length; i++) {
  60. if (sourceStart < separators[i]) break;
  61. declarationStartLine++;
  62. }
  63. extraAttributeList.add(
  64. new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine, this.sourceStart())));
  65. }
  66. }