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.

AjConstructorDeclaration.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.IAttribute;
  15. import org.aspectj.weaver.AjAttribute;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  18. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
  19. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  20. /**
  21. * Root class for all ConstructorDeclaration objects created by the parser.
  22. * Enables us to generate extra attributes in the method_info attribute
  23. * to support aspectj.
  24. */
  25. public class AjConstructorDeclaration extends ConstructorDeclaration {
  26. /**
  27. * @param compilationResult
  28. */
  29. public AjConstructorDeclaration(CompilationResult compilationResult) {
  30. super(compilationResult);
  31. }
  32. /* (non-Javadoc)
  33. * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration#generateInfoAttributes(org.eclipse.jdt.internal.compiler.ClassFile)
  34. */
  35. protected int generateInfoAttributes(ClassFile classFile) {
  36. // add extra attributes into list then call 2-arg version of generateInfoAttributes...
  37. List<IAttribute> extras = new ArrayList<>();
  38. addDeclarationStartLineAttribute(extras,classFile);
  39. return classFile.generateMethodInfoAttributes(binding,extras);
  40. }
  41. protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
  42. if ((classFile.codeStream.generateAttributes & ClassFileConstants.ATTR_LINES)==0) return;
  43. int[] separators = compilationResult().lineSeparatorPositions;
  44. int declarationStartLine = 1;
  45. for (int separator : separators) {
  46. if (sourceStart < separator) break;
  47. declarationStartLine++;
  48. }
  49. extraAttributeList.add(
  50. new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine, this.sourceStart())));
  51. }
  52. }