import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
import org.aspectj.ajdt.internal.compiler.ast.InterTypeFieldDeclaration;
import org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration;
+import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.SourceLocation;
import org.aspectj.weaver.Member;
import org.aspectj.weaver.Shadow;
return world.fromBinding(enclosingMethod.binding.declaringClass);
}
- public SourceLocation getSourceLocation() {
+ public ISourceLocation getSourceLocation() {
//XXX need to fill this in ASAP
return null;
}
import java.util.*;
import org.aspectj.ajdt.internal.compiler.ast.*;
+import org.aspectj.ajdt.internal.core.builder.EclipseSourceContext;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.weaver.*;
this.factory = factory;
this.binding = binding;
this.declaration = declaration;
+
+ resolvedTypeX.setSourceContext(new EclipseSourceContext(declaration.compilationResult));
+ resolvedTypeX.setStartPos(declaration.sourceStart);
+ resolvedTypeX.setEndPos(declaration.sourceEnd);
}
// return crosscuttingMembers;
// }
- public ISourceLocation getSourceLocation() {
- TypeDeclaration dec = binding.scope.referenceContext;
- return new EclipseSourceLocation(dec.compilationResult, dec.sourceStart, dec.sourceEnd);
- }
+// public ISourceLocation getSourceLocation() {
+// TypeDeclaration dec = binding.scope.referenceContext;
+// return new EclipseSourceLocation(dec.compilationResult, dec.sourceStart, dec.sourceEnd);
+// }
public boolean isInterface() {
return binding.isInterface();
package org.aspectj.ajdt.internal.core.builder;
+import java.io.File;
+
import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.SourceLocation;
import org.aspectj.weaver.IHasPosition;
import org.aspectj.weaver.ISourceContext;
import org.eclipse.jdt.internal.compiler.CompilationResult;
this.result = result;
}
+ private File getSourceFile() {
+ return new File(new String(result.fileName));
+ }
public ISourceLocation makeSourceLocation(IHasPosition position) {
return new EclipseSourceLocation(result, position.getStart(), position.getEnd());
}
+ public ISourceLocation makeSourceLocation(int line) {
+ return new SourceLocation(getSourceFile(), line);
+ }
+
}
<message kind="error" line="25"/>
</compile>
</ajc-test>
+
+ <ajc-test dir="new/declare" pr="31724"
+ title="omnibus declare warning context with no initializer/constructor">
+ <compile files="DeclareWarningEmpty.java">
+ <message kind="warning" line="3"/>
+ </compile>
+ </ajc-test>
+
+
+ <ajc-test dir="new/declare" pr="31724"
+ title="omnibus declare warning context">
+ <compile files="DeclareWarning.java">
+ <message kind="warning" line="5"/>
+ <message kind="warning" line="12"/>
+ <message kind="warning" line="13"/>
+ <message kind="warning" line="14"/>
+ <message kind="warning" line="15"/>
+ <message kind="warning" line="16"/>
+ <message kind="warning" line="17"/>
+ <message kind="warning" line="18"/>
+ <message kind="warning" line="21"/>
+ <message kind="warning" line="22"/>
+ <message kind="warning" line="23"/>
+ <message kind="warning" line="33"/>
+ <message kind="warning" line="36"/>
+ <message kind="warning" line="39"/>
+ <message kind="warning" line="74"/>
+ </compile>
+ </ajc-test>
</suite>
</compile>
</ajc-test>
- <ajc-test dir="new/declare" pr="31724"
- title="omnibus declare warning context"
- comment="XXX untested: no source context shown">
- <compile files="DeclareWarning.java">
- <message kind="warning" line="5"/>
- <message kind="warning" line="12"/>
- <message kind="warning" line="13"/>
- <message kind="warning" line="14"/>
- <message kind="warning" line="15"/>
- <message kind="warning" line="16"/>
- <message kind="warning" line="17"/>
- <message kind="warning" line="18"/>
- <message kind="warning" line="21"/>
- <message kind="warning" line="22"/>
- <message kind="warning" line="23"/>
- <message kind="warning" line="33"/>
- <message kind="warning" line="36"/>
- <message kind="warning" line="39"/>
- <message kind="warning" line="74"/>
- </compile>
- </ajc-test>
-
<ajc-test dir="errors" keywords="error"
title="class extending abstract aspect">
<compile files="ClassExtendingAbstractAspectCE.java">
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd">
<suite>
- <ajc-test dir="new/declare" pr="31724"
- title="omnibus declare warning context"
- comment="XXX untested: no source context shown">
- <compile files="DeclareWarning.java">
- <message kind="warning" line="5"/>
- <message kind="warning" line="12"/>
- <message kind="warning" line="13"/>
- <message kind="warning" line="14"/>
- <message kind="warning" line="15"/>
- <message kind="warning" line="16"/>
- <message kind="warning" line="17"/>
- <message kind="warning" line="18"/>
- <message kind="warning" line="21"/>
- <message kind="warning" line="22"/>
- <message kind="warning" line="23"/>
- <message kind="warning" line="33"/>
- <message kind="warning" line="36"/>
- <message kind="warning" line="39"/>
- <message kind="warning" line="74"/>
- </compile>
- </ajc-test>
+
<!--
--- /dev/null
+
+/** @testcase PR#31724 omnibus declare-warning test using default initializers/constructors*/
+public class DeclareWarningEmpty { // CE 3
+
+
+
+
+
+}
+
+aspect A {
+ declare warning: staticinitialization(DeclareWarningEmpty)
+ : "staticinitialization(DeclareWarningEmpty)";
+ declare warning: initialization(DeclareWarningEmpty.new(..))
+ : "initialization(DeclareWarningEmpty)";
+}
public interface ISourceContext {
public ISourceLocation makeSourceLocation(IHasPosition position);
+ public ISourceLocation makeSourceLocation(int line);
}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * 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:
+ * PARC initial implementation
+ * ******************************************************************/
+
+
+package org.aspectj.weaver;
+
+public class Position implements IHasPosition {
+ private int start, end;
+
+ public Position(int start, int end) {
+ this.start = start;
+ this.end = end;
+ }
+
+ public int getEnd() {
+ return end;
+ }
+
+ public int getStart() {
+ return start;
+ }
+
+}
public static class Name extends ResolvedTypeX {
private ConcreteName delegate = null;
+ private ISourceContext sourceContext = null;
+ private int startPos = 0;
+ private int endPos = 0;
//??? should set delegate before any use
public Name(String signature, World world) {
}
public ISourceContext getSourceContext() {
- return delegate.getSourceContext();
+ return sourceContext;
}
- public ISourceLocation getSourceLocation() { return delegate.getSourceLocation(); }
+ public ISourceLocation getSourceLocation() {
+ if (sourceContext == null) return null;
+ return sourceContext.makeSourceLocation(new Position(startPos, endPos));
+ }
public boolean isExposedToWeaver() {
return delegate.isExposedToWeaver(); //??? where does this belong
public void setDelegate(ConcreteName delegate) {
this.delegate = delegate;
}
+ public int getEndPos() {
+ return endPos;
+ }
+
+ public int getStartPos() {
+ return startPos;
+ }
+
+ public void setEndPos(int endPos) {
+ this.endPos = endPos;
+ }
+
+ public void setSourceContext(ISourceContext sourceContext) {
+ this.sourceContext = sourceContext;
+ }
+
+ public void setStartPos(int startPos) {
+ this.startPos = startPos;
+ }
+
}
public static abstract class ConcreteName {
- protected ISourceContext sourceContext;
+ //protected ISourceContext sourceContext;
protected boolean exposedToWeaver;
ResolvedTypeX.Name resolvedTypeX;
public abstract ResolvedTypeX getSuperclass();
- public abstract ISourceLocation getSourceLocation();
+// public abstract ISourceLocation getSourceLocation();
public abstract boolean isWovenBy(ResolvedTypeX aspectType);
- public ISourceContext getSourceContext() {
- return sourceContext;
- }
+// public ISourceContext getSourceContext() {
+// return sourceContext;
+// }
public boolean isExposedToWeaver() {
return exposedToWeaver;
import java.util.Iterator;
import java.util.List;
+import org.aspectj.bridge.*;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.SourceLocation;
import org.aspectj.lang.JoinPoint;
return null; //XXX
}
- public abstract SourceLocation getSourceLocation();
+ public abstract ISourceLocation getSourceLocation();
// ---- utility
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.weaver.*;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.ResolvedMember;
super(resolvedTypeX, exposedToWeaver);
this.javaClass = javaClass;
- sourceContext = new BcelSourceContext(this);
+ if (resolvedTypeX.getSourceContext() == null) {
+ resolvedTypeX.setSourceContext(new BcelSourceContext(this));
+ }
// this should only ever be java.lang.Object which is
// the only class in Java-1.4 with no superclasses
List pointcuts = new ArrayList();
typeMungers = new ArrayList();
declares = new ArrayList();
- List l = BcelAttributes.readAjAttributes(javaClass.getAttributes(), getSourceContext());
+ List l = BcelAttributes.readAjAttributes(javaClass.getAttributes(), getResolvedTypeX().getSourceContext());
for (Iterator iter = l.iterator(); iter.hasNext();) {
AjAttribute a = (AjAttribute) iter.next();
//System.err.println("unpacking: " + this + " and " + a);
} else if (a instanceof AjAttribute.PrivilegedAttribute) {
privilegedAccess = ((AjAttribute.PrivilegedAttribute)a).getAccessedMembers();
} else if (a instanceof AjAttribute.SourceContextAttribute) {
- ((BcelSourceContext)sourceContext).addAttributeInfo((AjAttribute.SourceContextAttribute)a);
+ if (getResolvedTypeX().getSourceContext() instanceof BcelSourceContext) {
+ ((BcelSourceContext)getResolvedTypeX().getSourceContext()).addAttributeInfo((AjAttribute.SourceContextAttribute)a);
+ }
} else {
throw new BCException("bad attribute " + a);
}
}
public ISourceLocation getSourceLocation() {
- return null; //FIXME, we can do much better than this
+ return getResolvedTypeX().getSourceContext().makeSourceLocation(0); //FIXME, we can do better than this
}
}
import org.apache.bcel.generic.SWAP;
import org.apache.bcel.generic.TargetLostException;
import org.apache.bcel.generic.Type;
+import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.SourceLocation;
import org.aspectj.weaver.AdviceKind;
import org.aspectj.weaver.AjcMemberMaker;
}
public int getSourceLine() {
- if (range == null) return 0;
+ if (range == null) {
+ if (getEnclosingMethod().hasBody()) {
+ return Utility.getSourceLine(getEnclosingMethod().getBody().getStart());
+ } else {
+ return 0;
+ }
+ }
int ret = Utility.getSourceLine(range.getStart());
if (ret < 0) return 0;
return ret;
return getEnclosingClass().getFactory();
}
- public SourceLocation getSourceLocation() {
- // AMC - a temporary "fudge" to give as much information as possible about the identity of the
- // source file this source location points to.
- String internalClassName = getEnclosingClass().getInternalClassName();
- String fileName = getEnclosingClass().getFileName();
- String extension = fileName.substring( fileName.lastIndexOf("."), fileName.length());
- String filePrefix = fileName.substring( 0, fileName.lastIndexOf("."));
- // internal class name is e.g. figures/Point, we don't know whether the file was
- // .aj or .java so we put it together with the file extension of the enclosing class
- // BUT... sometimes internalClassName is a different class (an aspect), so we only use it if it
- // matches the file name.
- String mostAccurateFileNameGuess;
- if ( internalClassName.endsWith(filePrefix)) {
- mostAccurateFileNameGuess = internalClassName + extension;
+ public ISourceLocation getSourceLocation() {
+ int sourceLine = getSourceLine();
+ if (sourceLine == 0) {
+// Thread.currentThread().dumpStack();
+// System.err.println(this + ": " + range);
+ return getEnclosingClass().getType().getSourceLocation();
} else {
- mostAccurateFileNameGuess = fileName;
+ return getEnclosingClass().getType().getSourceContext().makeSourceLocation(sourceLine);
}
- return new SourceLocation(new File(mostAccurateFileNameGuess), getSourceLine());
}
public Shadow getEnclosingShadow() {
this.inObject = inObject;
}
-
- public ISourceLocation makeSourceLocation(IHasPosition position) {
+ private File getSourceFile() {
+ //XXX make this work better borrowing code from below
String fileName = sourceFileName;
if (fileName == null) inObject.getJavaClass().getFileName();
if (fileName == null) fileName = inObject.getResolvedTypeX().getName() + ".class";
+ return new File(fileName);
+ }
+
+ /*
+ // AMC - a temporary "fudge" to give as much information as possible about the identity of the
+ // source file this source location points to.
+ String internalClassName = getEnclosingClass().getInternalClassName();
+ String fileName = getEnclosingClass().getFileName();
+ String extension = fileName.substring( fileName.lastIndexOf("."), fileName.length());
+ String filePrefix = fileName.substring( 0, fileName.lastIndexOf("."));
+ // internal class name is e.g. figures/Point, we don't know whether the file was
+ // .aj or .java so we put it together with the file extension of the enclosing class
+ // BUT... sometimes internalClassName is a different class (an aspect), so we only use it if it
+ // matches the file name.
+ String mostAccurateFileNameGuess;
+ if ( internalClassName.endsWith(filePrefix)) {
+ mostAccurateFileNameGuess = internalClassName + extension;
+ } else {
+ mostAccurateFileNameGuess = fileName;
+ }
+ return new SourceLocation(new File(mostAccurateFileNameGuess), getSourceLine());
+ */
+
+
+
+ public ISourceLocation makeSourceLocation(IHasPosition position) {
+
+
if (lineBreaks != null) {
int line = Arrays.binarySearch(lineBreaks, position.getStart());
if (line < 0) line = -line;
- return new SourceLocation(new File(fileName), line); //??? have more info
+ return new SourceLocation(getSourceFile(), line); //??? have more info
} else {
- return new SourceLocation(new File(fileName), 0);
+ return new SourceLocation(getSourceFile(), 0);
}
}
-
+ public ISourceLocation makeSourceLocation(int line) {
+ return new SourceLocation(getSourceFile(), line);
+ }
public void addAttributeInfo(SourceContextAttribute sourceContextAttribute) {
this.sourceFileName = sourceContextAttribute.getSourceFileName();
package org.aspectj.weaver;
import org.aspectj.weaver.ast.Var;
+import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.SourceLocation;
public class TestShadow extends Shadow {
throw new RuntimeException("unimplemented");
}
- public SourceLocation getSourceLocation() {
+ public ISourceLocation getSourceLocation() {
throw new RuntimeException("unimplemented");
}