]> source.dussan.org Git - aspectj.git/blob
279c389c182b9d514ba79f4008657aaf7dada7ad
[aspectj.git] /
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
13 import java.util.ArrayList;
14 import java.util.List;
15
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;
21
22 /**
23  * Root class for all ConstructorDeclaration objects created by the parser.
24  * Enables us to generate extra attributes in the method_info attribute
25  * to support aspectj.
26  */
27 public class AjConstructorDeclaration extends ConstructorDeclaration {
28
29         /**
30          * @param compilationResult
31          */
32         public AjConstructorDeclaration(CompilationResult compilationResult) {
33                 super(compilationResult);
34         }
35
36         /* (non-Javadoc)
37          * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration#generateInfoAttributes(org.eclipse.jdt.internal.compiler.ClassFile)
38          */
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);
44         }
45
46         protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
47                 if ((classFile.codeStream.generateAttributes & ClassFileConstants.ATTR_LINES)==0) return;
48
49                 int[] separators = compilationResult().lineSeparatorPositions;
50                 int declarationStartLine = 1;
51                 for (int separator : separators) {
52                         if (sourceStart < separator) break;
53                         declarationStartLine++;
54                 }
55
56                 extraAttributeList.add(
57                                 new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine, this.sourceStart())));
58         }
59 }