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

AjMethodDeclaration.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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.IAttribute;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  19. import org.aspectj.weaver.AjAttribute;
  20. /**
  21. * Root class for all MethodDeclaration objects created by the parser.
  22. * Enables us to generate extra attributes in the method_info attribute
  23. * to support aspectj.
  24. *
  25. */
  26. public class AjMethodDeclaration extends MethodDeclaration {
  27. private List<IAttribute> attributes = null;
  28. /**
  29. * @param compilationResult
  30. */
  31. public AjMethodDeclaration(CompilationResult compilationResult) {
  32. super(compilationResult);
  33. }
  34. // general purpose hook to add an AjAttribute to this method
  35. // used by @AspectJ visitor to add pointcut attribute to @Advice
  36. protected void addAttribute(EclipseAttributeAdapter eaa) {
  37. if (attributes==null) attributes = new ArrayList<>();
  38. attributes.add(eaa);
  39. }
  40. /**
  41. * Overridden to add extra AJ stuff, also adds synthetic if boolean is true.
  42. */
  43. protected int generateInfoAttributes(ClassFile classFile,boolean addAjSynthetic) {
  44. // add extra attributes into list then call 2-arg version of generateInfoAttributes...
  45. List<IAttribute> extras = (attributes==null?new ArrayList<>():attributes);
  46. addDeclarationStartLineAttribute(extras,classFile);
  47. if (addAjSynthetic) {
  48. extras.add(new EclipseAttributeAdapter(new AjAttribute.AjSynthetic()));
  49. }
  50. return classFile.generateMethodInfoAttributes(binding,extras);
  51. }
  52. @Override
  53. protected int generateInfoAttributes(ClassFile classFile) {
  54. return generateInfoAttributes(classFile,false);
  55. }
  56. protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
  57. if ((classFile.codeStream.generateAttributes & ClassFileConstants.ATTR_LINES)==0) return;
  58. int[] separators = compilationResult().lineSeparatorPositions;
  59. int declarationStartLine = 1;
  60. for (int separator : separators) {
  61. if (sourceStart < separator) break;
  62. declarationStartLine++;
  63. }
  64. extraAttributeList.add(
  65. new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine, this.sourceStart())));
  66. }
  67. }