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.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-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.weaver.AjAttribute;
  15. import org.eclipse.jdt.internal.compiler.ClassFile;
  16. import org.eclipse.jdt.internal.compiler.CompilationResult;
  17. import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
  18. /**
  19. * Root class for all MethodDeclaration objects created by the parser.
  20. * Enables us to generate extra attributes in the method_info attribute
  21. * to support aspectj.
  22. */
  23. public class AjMethodDeclaration extends MethodDeclaration {
  24. /**
  25. * @param compilationResult
  26. */
  27. public AjMethodDeclaration(CompilationResult compilationResult) {
  28. super(compilationResult);
  29. }
  30. /* (non-Javadoc)
  31. * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration#generateInfoAttributes(org.eclipse.jdt.internal.compiler.ClassFile)
  32. */
  33. protected int generateInfoAttributes(ClassFile classFile) {
  34. // add extra attributes into list then call 2-arg version of generateInfoAttributes...
  35. List extras = new ArrayList();
  36. addDeclarationStartLineAttribute(extras,classFile);
  37. return classFile.generateMethodInfoAttribute(binding,extras);
  38. }
  39. protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
  40. if (!classFile.codeStream.generateLineNumberAttributes) return;
  41. int[] separators = compilationResult().lineSeparatorPositions;
  42. int declarationStartLine = 1;
  43. for (int i = 0; i < separators.length; i++) {
  44. if (sourceStart < separators[i]) break;
  45. declarationStartLine++;
  46. }
  47. extraAttributeList.add(
  48. new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine)));
  49. }
  50. }