diff options
author | aclement <aclement> | 2006-03-14 16:01:33 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-03-14 16:01:33 +0000 |
commit | dd8b270597b0a9636ef8c4481eed987fea1d25b9 (patch) | |
tree | 0ea27bec580a9253ea4b7dc0c93ff43465e2ef85 | |
parent | 583b72d14f5eeaf19e01550250ae4f98bee8b573 (diff) | |
download | aspectj-dd8b270597b0a9636ef8c4481eed987fea1d25b9.tar.gz aspectj-dd8b270597b0a9636ef8c4481eed987fea1d25b9.zip |
bug 128650: comment 16: possible alternate implementation that shortens handles drastically ... not currently used.
-rw-r--r-- | asm/src/org/aspectj/asm/internal/OptimizedFullPathHandleProvider.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/asm/src/org/aspectj/asm/internal/OptimizedFullPathHandleProvider.java b/asm/src/org/aspectj/asm/internal/OptimizedFullPathHandleProvider.java new file mode 100644 index 000000000..5e78a1fce --- /dev/null +++ b/asm/src/org/aspectj/asm/internal/OptimizedFullPathHandleProvider.java @@ -0,0 +1,91 @@ +/* ******************************************************************* + * 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.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IElementHandleProvider; +import org.aspectj.bridge.ISourceLocation; + +/** + * Not currently used - uses int keys rather than the full file path as the first part of the handle. + */ +public class OptimizedFullPathHandleProvider implements IElementHandleProvider { + + static final String ID_DELIM = "|"; + Map kToF = new HashMap(); + int key = 1; + + private Integer getKey(String file) { + Integer k = null; + if (kToF.values().contains(file)) { + Set keys = kToF.keySet(); + for (Iterator iter = keys.iterator(); iter.hasNext() && k==null;) { + Integer element = (Integer) iter.next(); + if (kToF.get(element).equals(file)) { + k = element; + } + } + } else { + k = new Integer(key); + kToF.put(k,file); + key++; + } + return k; + } + + public String createHandleIdentifier(ISourceLocation location) { + StringBuffer sb = new StringBuffer(); + String file = AsmManager.getDefault().getCanonicalFilePath(location.getSourceFile()); + + sb.append(getKey(file).intValue()); + 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(getKey(AsmManager.getDefault().getCanonicalFilePath(sourceFile)).intValue()); + 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 k = st.nextToken(); + return (String)kToF.get(new Integer(k)); +// 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(); + } +} |