import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.ast.Argument;
-import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
*
* @author Jim Hugunin
*/
-public class AdviceDeclaration extends MethodDeclaration {
+public class AdviceDeclaration extends AjMethodDeclaration {
public PointcutDesignator pointcutDesignator;
int baseArgumentCount;
protected int generateInfoAttributes(ClassFile classFile) {
List l = new ArrayList(1);
l.add(new EclipseAttributeAdapter(makeAttribute()));
+ addDeclarationStartLineAttribute(l,classFile);
return classFile.generateMethodInfoAttribute(binding, l);
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation
+ *******************************************************************************/
+package org.aspectj.ajdt.internal.compiler.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.aspectj.weaver.AjAttribute;
+import org.eclipse.jdt.internal.compiler.ClassFile;
+import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
+
+/**
+ * Root class for all ConstructorDeclaration objects created by the parser.
+ * Enables us to generate extra attributes in the method_info attribute
+ * to support aspectj.
+ */
+public class AjConstructorDeclaration extends ConstructorDeclaration {
+
+ /**
+ * @param compilationResult
+ */
+ public AjConstructorDeclaration(CompilationResult compilationResult) {
+ super(compilationResult);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration#generateInfoAttributes(org.eclipse.jdt.internal.compiler.ClassFile)
+ */
+ protected int generateInfoAttributes(ClassFile classFile) {
+ // add extra attributes into list then call 2-arg version of generateInfoAttributes...
+ List extras = new ArrayList();
+ addDeclarationStartLineAttribute(extras,classFile);
+ return classFile.generateMethodInfoAttribute(binding,extras);
+ }
+
+ protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
+ if (!classFile.codeStream.generateLineNumberAttributes) return;
+
+ int[] separators = compilationResult().lineSeparatorPositions;
+ int declarationStartLine = 1;
+ for (int i = 0; i < separators.length; i++) {
+ if (sourceStart < separators[i]) break;
+ declarationStartLine++;
+ }
+
+ extraAttributeList.add(
+ new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine)));
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation
+ *******************************************************************************/
+package org.aspectj.ajdt.internal.compiler.ast;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.aspectj.weaver.AjAttribute;
+import org.eclipse.jdt.internal.compiler.ClassFile;
+import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
+
+/**
+ * Root class for all MethodDeclaration objects created by the parser.
+ * Enables us to generate extra attributes in the method_info attribute
+ * to support aspectj.
+ */
+public class AjMethodDeclaration extends MethodDeclaration {
+
+ /**
+ * @param compilationResult
+ */
+ public AjMethodDeclaration(CompilationResult compilationResult) {
+ super(compilationResult);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration#generateInfoAttributes(org.eclipse.jdt.internal.compiler.ClassFile)
+ */
+ protected int generateInfoAttributes(ClassFile classFile) {
+ // add extra attributes into list then call 2-arg version of generateInfoAttributes...
+ List extras = new ArrayList();
+ addDeclarationStartLineAttribute(extras,classFile);
+ return classFile.generateMethodInfoAttribute(binding,extras);
+ }
+
+ protected void addDeclarationStartLineAttribute(List extraAttributeList, ClassFile classFile) {
+ if (!classFile.codeStream.generateLineNumberAttributes) return;
+
+ int[] separators = compilationResult().lineSeparatorPositions;
+ int declarationStartLine = 1;
+ for (int i = 0; i < separators.length; i++) {
+ if (sourceStart < separators[i]) break;
+ declarationStartLine++;
+ }
+
+ extraAttributeList.add(
+ new EclipseAttributeAdapter(new AjAttribute.MethodDeclarationLineNumberAttribute(declarationStartLine)));
+ }
+}
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.parser.Parser;
-public class DeclareDeclaration extends MethodDeclaration {
+public class DeclareDeclaration extends AjMethodDeclaration {
public Declare declareDecl;
/**
import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
//import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.parser.Parser;
-public class IfMethodDeclaration extends MethodDeclaration {
+public class IfMethodDeclaration extends AjMethodDeclaration {
IfPointcut ifPointcut;
public IfMethodDeclaration(CompilationResult compilationResult, IfPointcut ifPointcut) {
import org.aspectj.weaver.*;
import org.eclipse.jdt.internal.compiler.ClassFile;
import org.eclipse.jdt.internal.compiler.CompilationResult;
-import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.lookup.*;
import org.eclipse.jdt.core.compiler.CharOperation;
*
* @author Jim Hugunin
*/
-public abstract class InterTypeDeclaration extends MethodDeclaration {
+public abstract class InterTypeDeclaration extends AjMethodDeclaration {
public TypeReference onType;
protected ReferenceBinding onTypeBinding;
} else {
l = new ArrayList(0);
}
+ addDeclarationStartLineAttribute(l,classFile);
return classFile.generateMethodInfoAttribute(binding, l);
}
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.ast.Argument;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
*
* @author Jim Hugunin
*/
-public class PointcutDeclaration extends MethodDeclaration {
+public class PointcutDeclaration extends AjMethodDeclaration {
public static final char[] mangledPrefix = "ajc$pointcut$".toCharArray();
public PointcutDesignator pointcutDesignator;
package org.aspectj.ajdt.internal.compiler.parser;
import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.AjConstructorDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.AjMethodDeclaration;
import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
import org.aspectj.ajdt.internal.compiler.ast.IfPseudoToken;
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Argument;
+import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DeclarationFactory implements IDeclarationFactory {
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createMethodDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
+ */
+ public MethodDeclaration createMethodDeclaration(CompilationResult result) {
+ return new AjMethodDeclaration(result);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createConstructorDeclaration(org.eclipse.jdt.internal.compiler.CompilationResult)
+ */
+ public ConstructorDeclaration createConstructorDeclaration(CompilationResult result) {
+ return new AjConstructorDeclaration(result);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.jdt.internal.compiler.parser.Parser.IDeclarationFactory#createProceed(org.eclipse.jdt.internal.compiler.ast.MessageSend)
*/
checkCompile("src1/ThisAndModifiers.java", NO_ERRORS);
}
public void testDeclares() {
- checkCompile("src1/Declares.java", new int[] {3});
+ checkCompile("src1/Declares.java", new int[] {2});
}
public void testDeclareWarning() {
}
public void testLazyTjp() throws IOException {
- checkCompile("src1/LazyTjp.aj", new String[] {"-XlazyTjp","-Xlint:error"}, new int[] {97});
+ checkCompile("src1/LazyTjp.aj", new String[] {"-XlazyTjp","-Xlint:error"}, new int[] {96});
TestUtil.runMain("out", "LazyTjp");
}
}
<run class="main.Main"/>
</ajc-test>
+ <!-- this test cannot work with new AjAttribute.MethodDeclarationLineNumberAttribute attribute
+ since the attribute will be generated for the main method, and has a different reference
+ on each serialization
<ajc-test dir="expClasses" title="expected class tree" keywords="incremental-test" >
<compile files="Main.java">
<dir-changes expDir="exp"/>
</compile>
<run class="Main"/>
</ajc-test>
-
+ -->
</suite>
String[] options = new String[]
{ "!verbose", "!eclipse",
};
- Exp exp = new Exp(7, 7, 0, 7, 0, 0, 0);
+ Exp exp = new Exp(6, 6, 0, 6, 0, 0, 0);
checkSelection(INCREMENTAL, options, "INFIX IGNORED", exp);
}
--- /dev/null
+public class TestSourceLines { // L1
+
+ private int i = 0; // L3
+
+ private static int J = 1; // L5
+ private static int K; // L6
+
+ static { // L8
+ System.out.println("K = 2");
+ }
+
+ public TestSourceLines() { // L12
+ i = 3;
+ }
+
+ public TestSourceLines(int i) { // L16
+ this.i = i;
+ }
+
+ public void foo() { // L20
+ System.out.println(i);
+ }
+
+ private void bar() { System.out.println(i); } // L24
+
+ protected // L26
+ void
+ goo() // L28
+ {
+ System.out.println(i);
+ }
+
+}
+
+class NoStaticInitBlock { // L35
+
+}
+
+aspect CheckLineNumbers { // L39
+
+ declare warning : execution(* TestSourceLines.*(..)) : "method execution";
+ declare warning : execution(TestSourceLines.new(..)) : "cons execution";
+ declare warning : staticinitialization(*) : "static init";
+ declare warning : initialization(*.new(..)) : "init";
+ declare warning : preinitialization(*.new(..)) : "pre-init";
+
+ before() : execution(* TestSourceLines.*(..)) { // L47
+ System.out.println("boo");
+ }
+
+ declare warning : adviceexecution() : "advice";
+}
\ No newline at end of file
import org.aspectj.testing.*;
public class DeclareWarningMain {
- public static void main (String[] args) { // DW 5 main
+ public static void main (String[] args) { // DW 4 main
Tester.checkAllEvents();
}
static {
}
aspect Warnings {
- declare warning : execution(static void main(String[])) : "main"; // for DW 5 main
+ declare warning : execution(static void main(String[])) : "main"; // for DW 4 main
// just to show that pointcut is valid - works if warning removed
before() : execution(static void main(String[])) {
declare warning: adviceexecution() && within(A)
: "adviceExecution() && within(A)";
- before() : initialization(DeclareWarning.new(..)) {
- // CW 74
+ before() : initialization(DeclareWarning.new(..)) { // CW 72
+
long l = System.currentTimeMillis();
if (0l == l) {
throw new Error("never thrown");
<ajc-test dir="new" title="simple declare warning (NPE)"
keywords="from-resolved_105">
<compile files="DeclareWarningMain.java">
- <message kind="warning" line="5"/>
+ <message kind="warning" line="4"/>
</compile>
<run class="DeclareWarningMain"/>
</ajc-test>
<ajc-test dir="new" pr="838"
title="checking around join point for advice return type - numeric">
<compile files="AroundNumericCastCE.java">
- <message kind="error" line="12"/>
+ <message kind="error" line="11"/>
<message kind="error" line="17"/>
</compile>
</ajc-test>
<message kind="warning" line="33" text="handler(OutOfMemoryError) && within(DeclareWarning)"/>
<message kind="warning" line="36" text="handler(Error)"/>
<message kind="warning" line="39" text="handler(RuntimeException) && withincode(DeclareWarning.new())"/>
- <message kind="warning" line="74" text="adviceExecution() && within(A)"/>
+ <message kind="warning" line="72" text="adviceExecution() && within(A)"/>
</compile>
</ajc-test>
public void test012() throws Exception {
runTest("incremental with aspect-driven full rebuild");
nextIncrement(false);
- MessageSpec messageSpec = new MessageSpec(newMessageList(new Message(4,"Main.java",null,null)),null);
+ MessageSpec messageSpec = new MessageSpec(newMessageList(new Message(3,"Main.java",null,null)),null);
copyFileAndDoIncrementalBuild("changes/Aspect.20.java","src/Aspect.java",messageSpec);
run("Main");
}
</compile>
<!--
<inc-compile tag="20">
- <message kind="warning" line="4" file="Main.java"/>
+ <message kind="warning" line="3" file="Main.java"/>
</inc-compile>
<run class="Main"/>
-->
<message kind="error" line="3" file="Aspect.java"/>
</compile>
<inc-compile tag="20">
- <message kind="warning" line="4" file="Main.java"/>
+ <message kind="warning" line="3" file="Main.java"/>
</inc-compile>
<run class="Main"/>
</ajc-test>
title="decent errors for around return type not matching target point"
keywords="from-errors">
<compile files="AroundReturnType.java">
- <message kind="error" line="3"/>
+ <message kind="error" line="2"/>
+ <message kind="error" line="6"/>
<message kind="error" line="7"/>
<message kind="error" line="16"/>
<message kind="error" line="21"/>
DataInputStream s = new DataInputStream(new ByteArrayInputStream(bytes));
if (name.equals(Aspect.AttributeName)) {
return new Aspect(PerClause.readPerClause(s, context));
+ } else if (name.equals(MethodDeclarationLineNumberAttribute.AttributeName)) {
+ return MethodDeclarationLineNumberAttribute.read(s);
} else if (name.equals(WeaverState.AttributeName)) {
return new WeaverState(WeaverStateInfo.read(s, context));
} else if (name.equals(AdviceAttribute.AttributeName)) {
}
}
+ public static class MethodDeclarationLineNumberAttribute extends AjAttribute {
+
+ public static final String AttributeName = "org.aspectj.weaver.MethodDeclarationLineNumber";
+
+ public String getNameString() {
+ return AttributeName;
+ }
+
+ private int lineNumber;
+
+ public MethodDeclarationLineNumberAttribute(int line) {
+ this.lineNumber = line;
+ }
+
+ public int getLineNumber() { return lineNumber; }
+
+ public void write(DataOutputStream s) throws IOException {
+ s.writeInt(lineNumber);
+ }
+
+ public static MethodDeclarationLineNumberAttribute read(DataInputStream s) throws IOException {
+ return new MethodDeclarationLineNumberAttribute(s.readInt());
+ }
+
+ }
+
public static class PointcutDeclarationAttribute extends AjAttribute {
public static final String AttributeName = "org.aspectj.weaver.PointcutDeclaration";
private boolean isAjSynthetic;
private ShadowMunger associatedShadowMunger;
private AjAttribute.EffectiveSignatureAttribute effectiveSignature;
+ private AjAttribute.MethodDeclarationLineNumberAttribute declarationLineNumber;
BcelMethod(BcelObjectType declaringType, Method method) {
super(
//System.out.println("unpack: " + this + ", " + as);
for (Iterator iter = as.iterator(); iter.hasNext();) {
AjAttribute a = (AjAttribute) iter.next();
- if (a instanceof AjAttribute.AdviceAttribute) {
+ if (a instanceof AjAttribute.MethodDeclarationLineNumberAttribute) {
+ declarationLineNumber = (AjAttribute.MethodDeclarationLineNumberAttribute)a;
+ } else if (a instanceof AjAttribute.AdviceAttribute) {
associatedShadowMunger = ((AjAttribute.AdviceAttribute)a).reify(this, world);
return;
} else if (a instanceof AjAttribute.AjSynthetic) {
return effectiveSignature;
}
+ public boolean hasDeclarationLineNumberInfo() {
+ return declarationLineNumber != null;
+ }
+
+ public int getDeclarationLineNumber() {
+ if (declarationLineNumber != null) {
+ return declarationLineNumber.getLineNumber();
+ } else {
+ return -1;
+ }
+ }
+
public Kind getKind() {
if (associatedShadowMunger != null) {
return ADVICE;
}
public int getSourceLine() {
+ // if the kind of join point for which we are a shadow represents
+ // a method or constructor execution, then the best source line is
+ // the one from the enclosingMethod declarationLineNumber if available.
+ Kind kind = getKind();
+ if ( (kind == MethodExecution) ||
+ (kind == ConstructorExecution) ||
+ (kind == AdviceExecution) ||
+ (kind == StaticInitialization) ||
+ (kind == PreInitialization) ||
+ (kind == Initialization)) {
+ if (getEnclosingMethod().hasDeclaredLineNumberInfo()) {
+ return getEnclosingMethod().getDeclarationLineNumber();
+ }
+ }
+
if (range == null) {
if (getEnclosingMethod().hasBody()) {
return Utility.getSourceLine(getEnclosingMethod().getBody().getStart());
this.name = m.getName();
}
+ public boolean hasDeclaredLineNumberInfo() {
+ return (memberView != null && memberView.hasDeclarationLineNumberInfo());
+ }
+
+ public int getDeclarationLineNumber() {
+ if (hasDeclaredLineNumberInfo()) {
+ return memberView.getDeclarationLineNumber();
+ } else {
+ return -1;
+ }
+ }
+
private void initialize() {
if (returnType != null) return;