Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AjMethodDeclaration.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. protected int generateInfoAttributes(ClassFile classFile) {
  52. return generateInfoAttributes(classFile,false);
  53. }
  54. protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
  55. if ((classFile.codeStream.generateAttributes & ClassFileConstants.ATTR_LINES)==0) return;
  56. int[] separators = compilationResult().lineSeparatorPositions;
  57. int declarationStartLine = 1;
  58. for (int i = 0; i < separators.length; i++) {
  59. if (sourceStart < separators[i]) break;
  60. declarationStartLine++;
  61. }
  62. extraAttributeList.add(
  63. new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine, this.sourceStart())));
  64. }
  65. }