org.aspectj.org.eclipse.jdt.internal.core
Class SourceMapper

java.lang.Object
  extended by org.aspectj.org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter
      extended by org.aspectj.org.eclipse.jdt.internal.core.SourceMapper
All Implemented Interfaces:
ISourceElementRequestor, SuffixConstants

public class SourceMapper
extends ReferenceInfoAdapter
implements ISourceElementRequestor, SuffixConstants

A SourceMapper maps source code in a ZIP file to binary types in a JAR. The SourceMapper uses the fuzzy parser to identify source fragments in a .java file, and attempts to match the source code with children in a binary type. A SourceMapper is associated with a JarPackageFragment by an AttachSourceOperation.

See Also:
JarPackageFragment

Nested Class Summary
static class SourceMapper.LocalVariableElementKey
           
 
Nested classes/interfaces inherited from interface org.aspectj.org.eclipse.jdt.internal.compiler.ISourceElementRequestor
ISourceElementRequestor.FieldInfo, ISourceElementRequestor.MethodInfo, ISourceElementRequestor.ParameterInfo, ISourceElementRequestor.TypeInfo, ISourceElementRequestor.TypeParameterInfo
 
Field Summary
protected  BinaryType binaryType
          The binary type source is being mapped for
protected  java.util.HashMap categories
           
protected  java.util.HashSet finalParameters
          Set that contains all final local variables.
protected  int[] memberDeclarationStart
          The position within the source of the start of the current member element, or -1 if we are outside a member.
protected  java.lang.String[] memberName
          The name of the current member element.
protected  SourceRange[] memberNameRange
          The SourceRange of the name of the current member element.
protected  char[][][] methodParameterNames
          The parameter names for the current member method element.
protected  char[][][] methodParameterTypes
          The parameter types for the current member method element.
protected  java.util.HashMap parameterNames
          Table that maps a binary method to its parameter names.
protected  java.util.HashMap parametersRanges
          Table that contains all source ranges for local variables.
protected  java.lang.String rootPath
          Specifies the location of the package fragment root within the zip (empty specifies the default root).
protected  java.util.ArrayList rootPaths
          Specifies the location of the package fragment roots within the zip (empty specifies the default root).
protected  IJavaElement searchedElement
          The element searched for
protected  IPath sourcePath
          The location of the zip file containing source.
protected  java.util.HashMap sourceRanges
          Table that maps a binary element to its SourceRanges.
static SourceRange UNKNOWN_RANGE
          The unknown source range {-1, 0}
static boolean VERBOSE
           
 
Fields inherited from interface org.aspectj.org.eclipse.jdt.internal.compiler.util.SuffixConstants
EXTENSION_aj, EXTENSION_AJ, EXTENSION_class, EXTENSION_CLASS, EXTENSION_java, EXTENSION_JAVA, SUFFIX_aj, SUFFIX_AJ, SUFFIX_class, SUFFIX_CLASS, SUFFIX_java, SUFFIX_JAVA, SUFFIX_STRING_aj, SUFFIX_STRING_AJ, SUFFIX_STRING_class, SUFFIX_STRING_CLASS, SUFFIX_STRING_java, SUFFIX_STRING_JAVA
 
Constructor Summary
SourceMapper()
           
SourceMapper(IPath sourcePath, java.lang.String rootPath, java.util.Map options)
          Creates a SourceMapper that locates source in the zip file at the given location in the specified package fragment root.
 
Method Summary
 void acceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers)
           
 void acceptLineSeparatorPositions(int[] positions)
           
 void acceptPackage(ImportReference importReference)
           
 void acceptProblem(CategorizedProblem problem)
           
 void close()
          Closes this SourceMapper's zip file.
 void enterCompilationUnit()
           
 void enterConstructor(ISourceElementRequestor.MethodInfo methodInfo)
           
 void enterField(ISourceElementRequestor.FieldInfo fieldInfo)
           
 void enterInitializer(int declarationSourceStart, int modifiers)
           
 void enterMethod(ISourceElementRequestor.MethodInfo methodInfo)
           
 void enterType(ISourceElementRequestor.TypeInfo typeInfo)
           
 void exitCompilationUnit(int declarationEnd)
           
 void exitConstructor(int declarationEnd)
           
 void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd)
           
 void exitInitializer(int declarationEnd)
           
 void exitMethod(int declarationEnd, Expression defaultValue)
           
 void exitType(int declarationEnd)
           
 char[] findSource(IType type, IBinaryType info)
          Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returns null if source code cannot be found.
 char[] findSource(IType type, java.lang.String simpleSourceFileName)
          Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returns null if source code cannot be found.
 char[] findSource(java.lang.String fullName)
           
 int getFlags(IJavaElement element)
           
 char[][] getImports(BinaryType type)
          Return a char[][] array containing the imports of the attached source for the binary type
 char[][] getMethodParameterNames(IMethod method)
          Returns parameters names for the given method, or null if no parameter names are known for the method.
 SourceRange getNameRange(IJavaElement element)
          Returns the SourceRange for the name of the given element, or {-1, -1} if no source range is known for the name of the element.
 SourceRange getSourceRange(IJavaElement element)
          Returns the SourceRange for the given element, or {-1, -1} if no source range is known for the element.
protected  IType getType(java.lang.String typeName)
          Returns the type with the given typeName.
protected  IJavaElement[] getUnqualifiedMethodHandle(IMethod method, boolean noDollar)
          Creates a handle that has parameter types that are not fully qualified so that the correct source is found.
 void mapSource(IType type, char[] contents, IBinaryType info)
          Maps the given source code to the given binary type and its children.
 ISourceRange mapSource(IType type, char[] contents, IBinaryType info, IJavaElement elementToFind)
          Maps the given source code to the given binary type and its children.
protected  void setMethodParameterNames(IMethod method, char[][] parameterNames)
          Sets the mapping for this method to its parameter names.
protected  void setSourceRange(IJavaElement element, SourceRange sourceRange, SourceRange nameRange)
          Sets the mapping for this element to its source ranges for its source range and name range.
 
Methods inherited from class org.aspectj.org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter
acceptAnnotationTypeReference, acceptAnnotationTypeReference, acceptConstructorReference, acceptFieldReference, acceptMethodReference, acceptTypeReference, acceptTypeReference, acceptUnknownReference, acceptUnknownReference
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.aspectj.org.eclipse.jdt.internal.compiler.ISourceElementRequestor
acceptAnnotationTypeReference, acceptAnnotationTypeReference, acceptConstructorReference, acceptFieldReference, acceptMethodReference, acceptTypeReference, acceptTypeReference, acceptUnknownReference, acceptUnknownReference
 

Field Detail

VERBOSE

public static boolean VERBOSE

rootPaths

protected java.util.ArrayList rootPaths
Specifies the location of the package fragment roots within the zip (empty specifies the default root). null is not a valid root path.


binaryType

protected BinaryType binaryType
The binary type source is being mapped for


sourcePath

protected IPath sourcePath
The location of the zip file containing source.


rootPath

protected java.lang.String rootPath
Specifies the location of the package fragment root within the zip (empty specifies the default root). null is not a valid root path.


parameterNames

protected java.util.HashMap parameterNames
Table that maps a binary method to its parameter names. Keys are the method handles, entries are char[][].


sourceRanges

protected java.util.HashMap sourceRanges
Table that maps a binary element to its SourceRanges. Keys are the element handles, entries are SourceRange[] which is a two element array; the first being source range, the second being name range.


categories

protected java.util.HashMap categories

parametersRanges

protected java.util.HashMap parametersRanges
Table that contains all source ranges for local variables. Keys are the special local variable elements, entries are char[][].


finalParameters

protected java.util.HashSet finalParameters
Set that contains all final local variables.


UNKNOWN_RANGE

public static final SourceRange UNKNOWN_RANGE
The unknown source range {-1, 0}


memberDeclarationStart

protected int[] memberDeclarationStart
The position within the source of the start of the current member element, or -1 if we are outside a member.


memberNameRange

protected SourceRange[] memberNameRange
The SourceRange of the name of the current member element.


memberName

protected java.lang.String[] memberName
The name of the current member element.


methodParameterNames

protected char[][][] methodParameterNames
The parameter names for the current member method element.


methodParameterTypes

protected char[][][] methodParameterTypes
The parameter types for the current member method element.


searchedElement

protected IJavaElement searchedElement
The element searched for

Constructor Detail

SourceMapper

public SourceMapper()

SourceMapper

public SourceMapper(IPath sourcePath,
                    java.lang.String rootPath,
                    java.util.Map options)
Creates a SourceMapper that locates source in the zip file at the given location in the specified package fragment root.

Method Detail

acceptImport

public void acceptImport(int declarationStart,
                         int declarationEnd,
                         int nameStart,
                         int nameEnd,
                         char[][] tokens,
                         boolean onDemand,
                         int modifiers)
Specified by:
acceptImport in interface ISourceElementRequestor
Parameters:
declarationStart - This is the position of the first character of the import keyword.
declarationEnd - This is the position of the ';' ending the import statement or the end of the comment following the import.
nameStart - This is the position of the first character of the import declaration's name.
nameEnd - This is the position of the last character of the import declaration's name.
tokens - This are the tokens of the import like specified in the source.
onDemand - set to true if the import is an import on demand (e.g. import java.io.*). False otherwise.
modifiers - can be set to static from 1.5 on.
See Also:
ISourceElementRequestor

acceptLineSeparatorPositions

public void acceptLineSeparatorPositions(int[] positions)
Specified by:
acceptLineSeparatorPositions in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

acceptPackage

public void acceptPackage(ImportReference importReference)
Specified by:
acceptPackage in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

acceptProblem

public void acceptProblem(CategorizedProblem problem)
Specified by:
acceptProblem in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

close

public void close()
Closes this SourceMapper's zip file. Once this is done, this SourceMapper cannot be used again.


enterType

public void enterType(ISourceElementRequestor.TypeInfo typeInfo)
Specified by:
enterType in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

enterCompilationUnit

public void enterCompilationUnit()
Specified by:
enterCompilationUnit in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

enterConstructor

public void enterConstructor(ISourceElementRequestor.MethodInfo methodInfo)
Specified by:
enterConstructor in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

enterField

public void enterField(ISourceElementRequestor.FieldInfo fieldInfo)
Specified by:
enterField in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

enterInitializer

public void enterInitializer(int declarationSourceStart,
                             int modifiers)
Specified by:
enterInitializer in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

enterMethod

public void enterMethod(ISourceElementRequestor.MethodInfo methodInfo)
Specified by:
enterMethod in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

exitType

public void exitType(int declarationEnd)
Specified by:
exitType in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

exitCompilationUnit

public void exitCompilationUnit(int declarationEnd)
Specified by:
exitCompilationUnit in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

exitConstructor

public void exitConstructor(int declarationEnd)
Specified by:
exitConstructor in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

exitField

public void exitField(int initializationStart,
                      int declarationEnd,
                      int declarationSourceEnd)
Specified by:
exitField in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

exitInitializer

public void exitInitializer(int declarationEnd)
Specified by:
exitInitializer in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

exitMethod

public void exitMethod(int declarationEnd,
                       Expression defaultValue)
Specified by:
exitMethod in interface ISourceElementRequestor
See Also:
ISourceElementRequestor

findSource

public char[] findSource(IType type,
                         IBinaryType info)
Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returns null if source code cannot be found.


findSource

public char[] findSource(IType type,
                         java.lang.String simpleSourceFileName)
Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returns null if source code cannot be found. The given simpleSourceFileName is the .java file name (without the enclosing folder) used to create the given type (e.g. "A.java" for x/y/A$Inner.class)


findSource

public char[] findSource(java.lang.String fullName)

getFlags

public int getFlags(IJavaElement element)

getNameRange

public SourceRange getNameRange(IJavaElement element)
Returns the SourceRange for the name of the given element, or {-1, -1} if no source range is known for the name of the element.


getMethodParameterNames

public char[][] getMethodParameterNames(IMethod method)
Returns parameters names for the given method, or null if no parameter names are known for the method.


getSourceRange

public SourceRange getSourceRange(IJavaElement element)
Returns the SourceRange for the given element, or {-1, -1} if no source range is known for the element.


getType

protected IType getType(java.lang.String typeName)
Returns the type with the given typeName. Returns inner classes as well.


getUnqualifiedMethodHandle

protected IJavaElement[] getUnqualifiedMethodHandle(IMethod method,
                                                    boolean noDollar)
Creates a handle that has parameter types that are not fully qualified so that the correct source is found.


mapSource

public void mapSource(IType type,
                      char[] contents,
                      IBinaryType info)
Maps the given source code to the given binary type and its children.


mapSource

public ISourceRange mapSource(IType type,
                              char[] contents,
                              IBinaryType info,
                              IJavaElement elementToFind)
Maps the given source code to the given binary type and its children. If a non-null java element is passed, finds the name range for the given java element without storing it.


setMethodParameterNames

protected void setMethodParameterNames(IMethod method,
                                       char[][] parameterNames)
Sets the mapping for this method to its parameter names.

See Also:
parameterNames

setSourceRange

protected void setSourceRange(IJavaElement element,
                              SourceRange sourceRange,
                              SourceRange nameRange)
Sets the mapping for this element to its source ranges for its source range and name range.

See Also:
sourceRanges

getImports

public char[][] getImports(BinaryType type)
Return a char[][] array containing the imports of the attached source for the binary type