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
10 *******************************************************************************/
11 package org.aspectj.ajdt.internal.compiler.ast;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.aspectj.weaver.AjAttribute;
17 import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
18 import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
19 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
20 import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
23 * Root class for all ConstructorDeclaration objects created by the parser.
24 * Enables us to generate extra attributes in the method_info attribute
27 public class AjConstructorDeclaration extends ConstructorDeclaration {
30 * @param compilationResult
32 public AjConstructorDeclaration(CompilationResult compilationResult) {
33 super(compilationResult);
37 * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration#generateInfoAttributes(org.eclipse.jdt.internal.compiler.ClassFile)
39 protected int generateInfoAttributes(ClassFile classFile) {
40 // add extra attributes into list then call 2-arg version of generateInfoAttributes...
41 List extras = new ArrayList();
42 addDeclarationStartLineAttribute(extras,classFile);
43 return classFile.generateMethodInfoAttributes(binding,extras);
46 protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
47 if ((classFile.codeStream.generateAttributes & ClassFileConstants.ATTR_LINES)==0) return;
49 int[] separators = compilationResult().lineSeparatorPositions;
50 int declarationStartLine = 1;
51 for (int separator : separators) {
52 if (sourceStart < separator) break;
53 declarationStartLine++;
56 extraAttributeList.add(
57 new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine, this.sourceStart())));