private static String dumpFilename = "";
private static boolean reporting = false;
+ private static boolean completingTypeBindings = false;
+
// static {
// setReporting("c:/model.nfo",true,true,true,true);
// }
hierarchy = new AspectJElementHierarchy();
// List relationships = new ArrayList();
mapper = new RelationshipMap(hierarchy);
- handleProvider = new FullPathHandleProvider();
+ handleProvider = new OptimizedFullPathHandleProvider();
}
public void createNewASM() {
*/
public static boolean isCreatingModel() { return creatingModel;}
+ public static void setCompletingTypeBindings(boolean b) {
+ completingTypeBindings = b;
+ }
+
+ public static boolean isCompletingTypeBindings() { return completingTypeBindings; }
+
}
*/
public int getLineNumberForHandle(String handle);
+ public int getOffSetForHandle(String handle);
+
}
* @return a new structure node for the file if it was not found in the model
*/
public IProgramElement findElementForSourceLine(String sourceFilePath, int lineNumber);
+ public IProgramElement findElementForOffSet(String sourceFilePath, int lineNumber, int offSet);
public String getConfigFile();
// int col = new Integer(st.nextToken()).intValue(); TODO: use column number when available
String file = AsmManager.getDefault().getHandleProvider().getFileForHandle(handle); // st.nextToken();
int line = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(handle); // st.nextToken();
+ int offSet = AsmManager.getDefault().getHandleProvider().getOffSetForHandle(handle);
String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(file));
- IProgramElement ret = findNodeForSourceLineHelper(root,canonicalSFP, line);
+ IProgramElement ret = findNodeForSourceLineHelper(root,canonicalSFP, line, offSet);
if (ret!=null) {
- handleMap.put(handle,ret);
+ cache(handle,ret);
}
return ret;
}
public IProgramElement findElementForSourceLine(String sourceFilePath, int lineNumber) {
String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(
new File(sourceFilePath));
- IProgramElement node = findNodeForSourceLineHelper(root, canonicalSFP, lineNumber);
+ IProgramElement node = findNodeForSourceLineHelper(root, canonicalSFP, lineNumber, -1);
+ if (node != null) {
+ return node;
+ } else {
+ return createFileStructureNode(sourceFilePath);
+ }
+ }
+
+ public IProgramElement findElementForOffSet(String sourceFilePath, int lineNumber, int offSet) {
+ String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(
+ new File(sourceFilePath));
+ IProgramElement node = findNodeForSourceLineHelper(root, canonicalSFP, lineNumber, offSet);
if (node != null) {
return node;
} else {
}
- private IProgramElement findNodeForSourceLineHelper(IProgramElement node, String sourceFilePath, int lineNumber) {
- if (matches(node, sourceFilePath, lineNumber)
- && !hasMoreSpecificChild(node, sourceFilePath, lineNumber)) {
+ private IProgramElement findNodeForSourceLineHelper(IProgramElement node, String sourceFilePath, int lineNumber, int offSet) {
+ if (matches(node, sourceFilePath, lineNumber, offSet)
+ && !hasMoreSpecificChild(node, sourceFilePath, lineNumber, offSet)) {
return node;
}
IProgramElement foundNode = findNodeForSourceLineHelper(
(IProgramElement)it.next(),
sourceFilePath,
- lineNumber);
+ lineNumber,
+ offSet);
if (foundNode != null) return foundNode;
}
}
return null;
}
-
- private boolean matches(IProgramElement node, String sourceFilePath, int lineNumber) {
+
+ private boolean matches(IProgramElement node, String sourceFilePath, int lineNumber, int offSet) {
// try {
// if (node != null && node.getSourceLocation() != null)
// System.err.println("====\n1: " +
return node != null
&& node.getSourceLocation() != null
&& node.getSourceLocation().getSourceFile().getAbsolutePath().equals(sourceFilePath)
+ && ((offSet != -1 && node.getSourceLocation().getOffset() == offSet)
+ || offSet == -1 )
&& ((node.getSourceLocation().getLine() <= lineNumber
&& node.getSourceLocation().getEndLine() >= lineNumber)
||
// }
}
- private boolean hasMoreSpecificChild(IProgramElement node, String sourceFilePath, int lineNumber) {
+ private boolean hasMoreSpecificChild(IProgramElement node, String sourceFilePath, int lineNumber, int offSet) {
for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
IProgramElement child = (IProgramElement)it.next();
- if (matches(child, sourceFilePath, lineNumber)) return true;
+ if (matches(child, sourceFilePath, lineNumber, offSet)) return true;
}
return false;
}
// TODO: use column number when available
String file = AsmManager.getDefault().getHandleProvider().getFileForHandle(handle); // st.nextToken();
int line = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(handle); // st.nextToken();
+ int offSet = AsmManager.getDefault().getHandleProvider().getOffSetForHandle(handle);
- ret = findElementForSourceLine(file, line);
+ ret = findElementForOffSet(file, line, offSet);
if (ret != null) {
cache(handle,(ProgramElement)ret);
}
// }
// return null;
// }
-
- protected void cache(String handle, ProgramElement pe) {
- handleMap.put(handle,pe);
+
+ protected void cache(String handle, IProgramElement pe) {
+ if (!AsmManager.isCompletingTypeBindings()) {
+ handleMap.put(handle,pe);
+ }
}
public void flushTypeMap() {
st.nextToken(); // skip over the file
return new Integer(st.nextToken()).intValue();
}
+
+ public int getOffSetForHandle(String handle) {
+ StringTokenizer st = new StringTokenizer(handle, ID_DELIM);
+ st.nextToken(); // skip over the file
+ st.nextToken(); // skip over the line number
+ st.nextToken(); // skip over the column
+ return new Integer(st.nextToken()).intValue();
+ }
}
st.nextToken(); // skip over the file
return new Integer(st.nextToken()).intValue();
}
+
+ public int getOffSetForHandle(String handle) {
+ StringTokenizer st = new StringTokenizer(handle, ID_DELIM);
+ st.nextToken(); // skip over the file
+ st.nextToken(); // skip over the line number
+ st.nextToken(); // skip over the column
+ return new Integer(st.nextToken()).intValue();
+ }
}
public ProgramElement (String name, IProgramElement.Kind kind, ISourceLocation sourceLocation,
int modifiers, String comment, List children) {
this(name, kind, children);
- this.sourceLocation = //ISourceLocation.EMPTY;
- sourceLocation;
+ this.sourceLocation = sourceLocation;
setFormalComment(comment);
// if (comment!=null && comment.length()>0) formalComment = comment;
this.modifiers = modifiers;
// this.accessibility = genAccessibility(modifiers);
- cacheByHandle();
}
/**
boolean member) {
this(name, kind, children);
- this.sourceLocation =
- //ISourceLocation.EMPTY;
- sourceLocation;
+ this.sourceLocation = sourceLocation;
this.kind = kind;
this.modifiers = modifiers;
// this.accessibility = accessibility;
// if (comment!=null && comment.length()>0) formalComment = comment;
if (relations!=null && relations.size()!=0) setRelations(relations);
// this.relations = relations;
- cacheByHandle();
}
public List getModifiers() {
import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
+import org.aspectj.asm.AsmManager;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.WeaveMessage;
//??? duplicates some of super's code
public void completeTypeBindings() {
+ AsmManager.setCompletingTypeBindings(true);
ContextToken completeTypeBindingsToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.COMPLETING_TYPE_BINDINGS, "");
// builtInterTypesAndPerClauses = false;
//pendingTypesToWeave = new ArrayList();
stepCompleted = BUILD_FIELDS_AND_METHODS;
lastCompletedUnitIndex = lastUnitIndex;
-
- CompilationAndWeavingContext.leavingPhase(completeTypeBindingsToken);
+ AsmManager.setCompletingTypeBindings(false);
+ CompilationAndWeavingContext.leavingPhase(completeTypeBindingsToken);
}
import org.aspectj.ajdt.internal.core.builder.EclipseAdapterUtils;
import org.aspectj.bridge.ISourceLocation;
-import org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.aspectj.org.eclipse.jdt.core.compiler.IProblem;
import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.aspectj.org.eclipse.jdt.internal.compiler.problem.ProblemHandler;
public class EclipseSourceLocation implements ISourceLocation {
private static String NO_CONTEXT = "USE_NULL--NO_CONTEXT_AVAILABLE";
CompilationResult result;
+// EclipseSourceContext eclipseContext;
int startPos, endPos;
+ String filename;
// lazy but final
File file;
int startLine = -1;
public EclipseSourceLocation(CompilationResult result, int startPos, int endPos) {
super();
this.result = result;
+ if (result!=null && result.fileName!=null) this.filename = new String(result.fileName);
this.startPos = startPos;
this.endPos = endPos;
}
public File getSourceFile() {
if (null == file) {
- if ((null == result)
- || (null == result.fileName)
- || (0 == result.fileName.length)) {
+ if (filename==null) {
+// if ((null == result)
+// || (null == result.fileName)
+// || (0 == result.fileName.length)) {
file = ISourceLocation.NO_FILE;
} else {
- file = new File(new String(result.fileName));
+ file = new File(filename);//new String(result.fileName));
}
}
return file;
}
public int getLine() {
- if (-1 == startLine) {
+ if (-1 == startLine && result!=null) {
startLine = ProblemHandler.searchLineNumber(result.lineSeparatorPositions, startPos);
}
return startLine;
//TODO AV - could speed up if we could dig only for @Aspect declaring types (or aspect if mixed style allowed)
//??? how to : node.getParent().getKind().equals(IProgramElement.Kind.ASPECT)) {
- if (true && methodDeclaration.annotations != null) {
+ if (true && methodDeclaration!=null && methodDeclaration.annotations != null) {
for (int i = 0; i < methodDeclaration.annotations.length; i++) {
//Note: AV: implicit single advice type support here (should be enforced somewhere as well (APT etc))
Annotation annotation = methodDeclaration.annotations[i];
}
return sl;
}
+
+ public void tidy() {
+ result=null;
+ }
}
public ISourceLocation makeSourceLocation(IHasPosition position);
public ISourceLocation makeSourceLocation(int line, int offset);
public int getOffset();
+ public void tidy();
}
return 0;
}
+ public void tidy() {}
+
};
}
throw new RuntimeException("static");
}
public static final char[] AJC_DOLLAR_PREFIX = {'a', 'j', 'c','$'};
+ public static final char[] CLINIT={'<','c','l','i','n','i','t','>'};
public static final String PREFIX = "ajc$";
+ public static final char[] INIT = {'<','i','n','i','t','>'};
public static final String ITD_PREFIX = PREFIX + "interType$";
public static final char[] METHOD_ASPECTOF = {'a', 's', 'p','e','c','t','O','f'};
public static final char[] METHOD_HASASPECT = {'h', 'a', 's','A','s','p','e','c','t'};
import java.util.Map;
import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.weaver.bcel.BcelObjectType;
import org.aspectj.weaver.patterns.Declare;
import org.aspectj.weaver.patterns.PerClause;
}
public void setDelegate(ReferenceTypeDelegate delegate) {
- if (this.delegate!=null && this.delegate.getSourceContext()!=SourceContextImpl.UNKNOWN_SOURCE_CONTEXT)
+ // Don't copy from BcelObjectType to EclipseSourceType - the context may be tidied (result null'd) after previous weaving
+ if (this.delegate!=null && !(this.delegate instanceof BcelObjectType) && this.delegate.getSourceContext()!=SourceContextImpl.UNKNOWN_SOURCE_CONTEXT)
((AbstractReferenceTypeDelegate)delegate).setSourceContext(this.delegate.getSourceContext());
this.delegate = delegate;
for(Iterator it = this.derivativeTypes.iterator(); it.hasNext(); ) {
return new File(delegate.getSourcefilename());
}
+ public void tidy() {}
+
public int getOffset() { return 0; }
/*
public ISourceLocation makeSourceLocation(IHasPosition position) {return null;}
public ISourceLocation makeSourceLocation(int line, int offset) {return null;}
public int getOffset() {return 0;}
+ public void tidy() {}
};
}
private boolean checkedAdvancedConfiguration=false;
// Xset'table options
private boolean fastDelegateSupportEnabled = isASMAround;
- private boolean runMinimalMemory = true;
-
+ private boolean runMinimalMemory = false;
+ public boolean forDEBUG_structuralChangesCode = false;
// Records whether ASM is around ... so we might use it for delegates
public final static String xsetCAPTURE_ALL_CONTEXT = "captureAllContext"; // default false
public final static String xsetACTIVATE_LIGHTWEIGHT_DELEGATES = "activateLightweightDelegates"; // default true
public final static String xsetRUN_MINIMAL_MEMORY ="runMinimalMemory"; // default true
+ public final static String xsetDEBUG_STRUCTURAL_CHANGES_CODE = "debugStructuralChangesCode"; // default false
public boolean isInJava5Mode() {
return behaveInJava5Way;
if (!checkedAdvancedConfiguration) {
Properties p = getExtraConfiguration();
if (p!=null) {
- if (isASMAround) { // dont bother if its not...
- String s = p.getProperty(xsetACTIVATE_LIGHTWEIGHT_DELEGATES,"true");
- fastDelegateSupportEnabled = s.equalsIgnoreCase("true");
- if (!fastDelegateSupportEnabled)
- getMessageHandler().handleMessage(MessageUtil.info("[activateLightweightDelegates=false] Disabling optimization to use lightweight delegates for non-woven types"));
- }
- // wonder if this should be based on whether an incremental build can follow?
- String s = p.getProperty(xsetRUN_MINIMAL_MEMORY,"false");
+
+ if (isASMAround) { // dont bother if its not...
+ String s = p.getProperty(xsetACTIVATE_LIGHTWEIGHT_DELEGATES,"true");
+ fastDelegateSupportEnabled = s.equalsIgnoreCase("true");
+ if (!fastDelegateSupportEnabled)
+ getMessageHandler().handleMessage(MessageUtil.info("[activateLightweightDelegates=false] Disabling optimization to use lightweight delegates for non-woven types"));
+ }
+
+ String s = p.getProperty(xsetRUN_MINIMAL_MEMORY,"false");
runMinimalMemory = s.equalsIgnoreCase("true");
// if (runMinimalMemory)
// getMessageHandler().handleMessage(MessageUtil.info("[runMinimalMemory=true] Optimizing bcel processing (and cost of performance) to use less memory"));
+
+
+ s = p.getProperty(xsetDEBUG_STRUCTURAL_CHANGES_CODE,"false");
+ forDEBUG_structuralChangesCode = s.equalsIgnoreCase("true");
+
}
checkedAdvancedConfiguration=true;
- }
- }
+ }
+ }
public boolean isRunMinimalMemory() {
ensureAdvancedConfigurationProcessed();
for (int i = 0; i < dontAddMeTwice.length; i++){
Annotation ann = dontAddMeTwice[i];
if (ann != null && decaF.getAnnotationX().getTypeName().equals(ann.getTypeName())){
- dontAddMeTwice[i] = null; // incase it really has been added twice!
+ //dontAddMeTwice[i] = null; // incase it really has been added twice!
return true;
}
}
public int getOffset() {
return 0;
}
+ public void tidy() {}
};
return new AtAjAttributes.BindingScope(inType,sourceContext,formalBindings);
}