diff options
author | mkersten <mkersten> | 2005-04-14 16:44:01 +0000 |
---|---|---|
committer | mkersten <mkersten> | 2005-04-14 16:44:01 +0000 |
commit | df7fff4c8c073a3bbcfe749134d577299402d5fb (patch) | |
tree | 566a368b2d30af514d724197620fa6854b7b5ce0 /asm | |
parent | bcef03bef88e3e43347ecfc57f0d6cb6694d7b1c (diff) | |
download | aspectj-df7fff4c8c073a3bbcfe749134d577299402d5fb.tar.gz aspectj-df7fff4c8c073a3bbcfe749134d577299402d5fb.zip |
bug#82171 Created sepereate handle provider to enable ASM use of IDE-specific handle identifiers.
Diffstat (limited to 'asm')
5 files changed, 148 insertions, 39 deletions
diff --git a/asm/src/org/aspectj/asm/AsmManager.java b/asm/src/org/aspectj/asm/AsmManager.java index 3f3a900aa..623638b79 100644 --- a/asm/src/org/aspectj/asm/AsmManager.java +++ b/asm/src/org/aspectj/asm/AsmManager.java @@ -34,6 +34,7 @@ public class AsmManager { * @deprecated use getDefault() method instead */ private static AsmManager INSTANCE = new AsmManager(); + private IElementHandleProvider handleProvider; private boolean shouldSaveModel = true; protected IHierarchy hierarchy; private List structureListeners = new ArrayList(); @@ -44,8 +45,6 @@ public class AsmManager { public static boolean dumpModelPostBuild = false; // Dumping the model is expensive public static boolean attemptIncrementalModelRepairs = false; // for debugging ... - - // For offline debugging, you can now ask for the AsmManager to // dump the model - see the method setReporting() @@ -63,6 +62,7 @@ public class AsmManager { hierarchy = new AspectJElementHierarchy(); // List relationships = new ArrayList(); mapper = new RelationshipMap(hierarchy); + handleProvider = new FullPathHandleProvider(); } public IHierarchy getHierarchy() { @@ -159,6 +159,14 @@ public class AsmManager { } } + public IElementHandleProvider getHandleProvider() { + return handleProvider; + } + + public void setHandleProvider(IElementHandleProvider handleProvider) { + this.handleProvider = handleProvider; + } + /** * Fails silently. */ @@ -789,6 +797,7 @@ public class AsmManager { } } + /** * Set to indicate whether we are currently building a structure model, should * be set up front. diff --git a/asm/src/org/aspectj/asm/IElementHandleProvider.java b/asm/src/org/aspectj/asm/IElementHandleProvider.java new file mode 100644 index 000000000..97902abf9 --- /dev/null +++ b/asm/src/org/aspectj/asm/IElementHandleProvider.java @@ -0,0 +1,56 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * 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: + * Mik Kersten initial implementation + * ******************************************************************/ + +package org.aspectj.asm; + +import java.io.File; + +import org.aspectj.bridge.ISourceLocation; + +/** + * Adapter used to uniquely identify program element handles. Can be + * implemented and overridden in @see{AsmManager} in order to provide + * IDE-specific mechanisms of identifying elements. For example, AJDT + * uses workspace-relative paths that are understood by its JavaCore + * class. + * + * @author Mik Kersten + */ +public interface IElementHandleProvider { + + /** + * @return a String uniquely identifying this element + */ + public String createHandleIdentifier(ISourceLocation location); + + /** + * @return a String uniquely identifying this element + */ + public String createHandleIdentifier(File sourceFile, int line,int column,int offset); + + /** + * NOTE: this is necessary for the current implementation to look up nodes, + * but we may want to consider removing it. + * + * @return a String corresponding to the + */ + public String getFileForHandle(String handle); + + /** + * NOTE: this is necessary for the current implementation to look up nodes, + * but we may want to consider removing it. + * + * @return the line number corresponding to this handel + */ + public int getLineNumberForHandle(String handle); + +} diff --git a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java index 26bf3f4b0..cc95646cf 100644 --- a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java +++ b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java @@ -36,11 +36,13 @@ public class AspectJElementHierarchy implements IHierarchy { IProgramElement cachedEntry = (IProgramElement)handleMap.get(handle); if (cachedEntry!=null) return cachedEntry; - StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM); - String file = st.nextToken(); - int line = new Integer(st.nextToken()).intValue(); - // int col = new Integer(st.nextToken()).intValue(); TODO: use column number when available - String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(file)); +// StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM); +// int line = new Integer(st.nextToken()).intValue(); + // 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(); + + String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(file)); IProgramElement ret = findNodeForSourceLineHelper(root,canonicalSFP, line); if (ret!=null) { handleMap.put(handle,ret); @@ -318,11 +320,14 @@ public class AspectJElementHierarchy implements IHierarchy { IProgramElement ret = (IProgramElement) handleMap.get(handle); if (ret != null) return ret; - StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM); - String file = st.nextToken(); - int line = new Integer(st.nextToken()).intValue(); +// StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM); +// String file = st.nextToken(); +// int line = new Integer(st.nextToken()).intValue(); // 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(); + ret = findElementForSourceLine(file, line); if (ret != null) { cache(handle,(ProgramElement)ret); diff --git a/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java b/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java new file mode 100644 index 000000000..0a32af207 --- /dev/null +++ b/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java @@ -0,0 +1,65 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * 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: + * Mik Kersten initial implementation + * ******************************************************************/ + +package org.aspectj.asm.internal; + +import java.io.File; +import java.util.StringTokenizer; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IElementHandleProvider; +import org.aspectj.bridge.ISourceLocation; + +/** + * @author Mik Kersten + */ +public class FullPathHandleProvider implements IElementHandleProvider { + + static final String ID_DELIM = "|"; + + public String createHandleIdentifier(ISourceLocation location) { + StringBuffer sb = new StringBuffer(); + sb.append(AsmManager.getDefault() + .getCanonicalFilePath(location.getSourceFile())); + sb.append(ID_DELIM); + sb.append(location.getLine()); + sb.append(ID_DELIM); + sb.append(location.getColumn()); + sb.append(ID_DELIM); + sb.append(location.getOffset()); + return sb.toString(); + } + + public String createHandleIdentifier(File sourceFile, int line,int column,int offset) { + StringBuffer sb = new StringBuffer(); + sb.append(AsmManager.getDefault().getCanonicalFilePath(sourceFile)); + sb.append(ID_DELIM); + sb.append(line); + sb.append(ID_DELIM); + sb.append(column); + sb.append(ID_DELIM); + sb.append(offset); + return sb.toString(); + } + + public String getFileForHandle(String handle) { + StringTokenizer st = new StringTokenizer(handle, ID_DELIM); + String file = st.nextToken(); + return file; + } + + public int getLineNumberForHandle(String handle) { + StringTokenizer st = new StringTokenizer(handle, ID_DELIM); + st.nextToken(); // skip over the file + return new Integer(st.nextToken()).intValue(); + } +} diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java index 6bfe85115..a34a5ffa8 100644 --- a/asm/src/org/aspectj/asm/internal/ProgramElement.java +++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java @@ -31,8 +31,6 @@ import org.aspectj.bridge.ISourceLocation; */ public class ProgramElement implements IProgramElement { - static final String ID_DELIM = "|"; - protected IProgramElement parent = null; protected String name = ""; // children.listIterator() should support remove() operation @@ -447,40 +445,16 @@ public class ProgramElement implements IProgramElement { return label; } - public static String createHandleIdentifier(File sourceFile, int line,int column,int offset) { - StringBuffer sb = new StringBuffer(); - sb.append(AsmManager.getDefault().getCanonicalFilePath(sourceFile)); - sb.append(ID_DELIM); - sb.append(line); - sb.append(ID_DELIM); - sb.append(column); - sb.append(ID_DELIM); - sb.append(offset); - return sb.toString(); - } - private String handle = null; public String getHandleIdentifier() { if (null == handle) { if (sourceLocation != null) { - return genHandleIdentifier(sourceLocation); - } + return AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation); +// return genHandleIdentifier(sourceLocation); + } } return handle; } - - public static String genHandleIdentifier(ISourceLocation sourceLocation) { - StringBuffer sb = new StringBuffer(); - sb.append(AsmManager.getDefault() - .getCanonicalFilePath(sourceLocation.getSourceFile())); - sb.append(ID_DELIM); - sb.append(sourceLocation.getLine()); - sb.append(ID_DELIM); - sb.append(sourceLocation.getColumn()); - sb.append(ID_DELIM); - sb.append(sourceLocation.getOffset()); - return sb.toString(); - } public List getParameterNames() { return parameterNames; |