Class SourceMapper
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter
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 or
binary modules 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.
Since a module has no children in the Java Model no such matching
happens in that case.
A SourceMapper is associated with a JarPackageFragment by an AttachSourceOperation.
- See Also:
JarPackageFragment
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.aspectj.org.eclipse.jdt.internal.compiler.ISourceElementRequestor
ISourceElementRequestor.FieldInfo, ISourceElementRequestor.MethodInfo, ISourceElementRequestor.ModuleInfo, ISourceElementRequestor.PackageExportInfo, ISourceElementRequestor.ParameterInfo, ISourceElementRequestor.RequiresInfo, ISourceElementRequestor.ServicesInfo, ISourceElementRequestor.TypeInfo, ISourceElementRequestor.TypeParameterInfo
-
Field Summary
Modifier and TypeFieldDescriptionprotected NamedMember
The binary type or module source is being mapped forprotected HashMap
protected HashSet
Set that contains all final local variables.protected int[]
The position within the source of the start of the current member element, or -1 if we are outside a member.protected String[]
The name of the current member element.protected SourceRange[]
TheSourceRange
of the name of the current member element.protected char[][][]
The parameter names for the current member method element.protected char[][][]
The parameter types for the current member method element.protected HashMap
Table that maps a binary method to its parameter names.protected HashMap
Table that contains all source ranges for local variables.protected String
Specifies the location of the package fragment root within the zip (empty specifies the default root).protected ArrayList
Specifies the location of the package fragment roots within the zip (empty specifies the default root).protected IJavaElement
The element searched forprotected org.eclipse.core.runtime.IPath
The location of the zip file containing source.protected HashMap
Table that maps a binary element to itsSourceRange
s.static SourceRange
The unknown source range {-1, 0}static boolean
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, EXTENSION_jmod, EXTENSION_JMOD, 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
ConstructorDescriptionSourceMapper(org.eclipse.core.runtime.IPath sourcePath, String rootPath, Map options)
SourceMapper(org.eclipse.core.runtime.IPath sourcePath, String rootPath, Map options, String encoding)
Creates aSourceMapper
that locates source in the zip file at the given location in the specified package fragment root. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 thisSourceMapper
's zip file.String[]
convertTypeNamesToSigs(char[][] typeNames)
NOT API, public only for access by Unit tests.void
void
enterConstructor(ISourceElementRequestor.MethodInfo methodInfo)
void
enterField(ISourceElementRequestor.FieldInfo fieldInfo)
void
enterInitializer(int declarationSourceStart, int modifiers)
void
enterMethod(ISourceElementRequestor.MethodInfo methodInfo)
void
enterModule(ISourceElementRequestor.ModuleInfo moduleInfo)
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
exitModule(int declarationEnd)
void
exitRecordComponent(int declarationEnd, int declarationSourceEnd)
void
exitType(int declarationEnd)
char[]
findSource(String fullName)
char[]
findSource(IModuleDescription module)
Locates and returns source code for the given (binary) module, in this SourceMapper's ZIP file, or returnsnull
if source code cannot be found.char[]
findSource(IType type, String simpleSourceFileName)
Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returnsnull
if source code cannot be found.char[]
findSource(IType type, IBinaryType info)
Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returnsnull
if source code cannot be found.int
getFlags(IJavaElement element)
char[][]
getImports(Member typeOrModule)
Return a char[][] array containing the imports of the attached source for the binary typechar[][]
getMethodParameterNames(IMethod method)
Returns parameters names for the given method, or null if no parameter names are known for the method.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.getSourceRange(IJavaElement element)
Returns theSourceRange
for the given element, or {-1, -1} if no source range is known for the element.protected IType
Returns the type with the giventypeName
.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(NamedMember typeOrModule, char[] contents, IBinaryType info)
Maps the given source code to the given binary type or module and its children.mapSource(NamedMember typeOrModule, 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 Details
-
VERBOSE
public static boolean VERBOSE -
rootPaths
Specifies the location of the package fragment roots within the zip (empty specifies the default root).null
is not a valid root path. -
binaryTypeOrModule
The binary type or module source is being mapped for -
sourcePath
protected org.eclipse.core.runtime.IPath sourcePathThe location of the zip file containing source. -
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
Table that maps a binary method to its parameter names. Keys are the method handles, entries arechar[][]
. -
sourceRanges
Table that maps a binary element to itsSourceRange
s. Keys are the element handles, entries areSourceRange[]
which is a two element array; the first being source range, the second being name range. -
categories
-
parametersRanges
Table that contains all source ranges for local variables. Keys are the special local variable elements, entries arechar[][]
. -
finalParameters
Set that contains all final local variables. -
UNKNOWN_RANGE
The unknown source range {-1, 0} -
memberDeclarationStart
protected int[] memberDeclarationStartThe position within the source of the start of the current member element, or -1 if we are outside a member. -
memberNameRange
TheSourceRange
of the name of the current member element. -
memberName
The name of the current member element. -
methodParameterNames
protected char[][][] methodParameterNamesThe parameter names for the current member method element. -
methodParameterTypes
protected char[][][] methodParameterTypesThe parameter types for the current member method element. -
searchedElement
The element searched for
-
-
Constructor Details
-
Method Details
-
acceptImport
public void acceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers)- Specified by:
acceptImport
in interfaceISourceElementRequestor
- 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 interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
acceptPackage
- Specified by:
acceptPackage
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
acceptProblem
- Specified by:
acceptProblem
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
close
public void close()Closes thisSourceMapper
's zip file. Once this is done, thisSourceMapper
cannot be used again. -
convertTypeNamesToSigs
NOT API, public only for access by Unit tests. Converts these type names to unqualified signatures. This needs to be done in order to be consistent with the way the source range is retrieved. -
enterType
- Specified by:
enterType
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
enterModule
- Specified by:
enterModule
in interfaceISourceElementRequestor
-
exitModule
public void exitModule(int declarationEnd)- Specified by:
exitModule
in interfaceISourceElementRequestor
-
enterCompilationUnit
public void enterCompilationUnit()- Specified by:
enterCompilationUnit
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
enterConstructor
- Specified by:
enterConstructor
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
enterField
- Specified by:
enterField
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
enterInitializer
public void enterInitializer(int declarationSourceStart, int modifiers)- Specified by:
enterInitializer
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
enterMethod
- Specified by:
enterMethod
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
exitType
public void exitType(int declarationEnd)- Specified by:
exitType
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
exitCompilationUnit
public void exitCompilationUnit(int declarationEnd)- Specified by:
exitCompilationUnit
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
exitConstructor
public void exitConstructor(int declarationEnd)- Specified by:
exitConstructor
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
exitField
public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd)- Specified by:
exitField
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
exitRecordComponent
public void exitRecordComponent(int declarationEnd, int declarationSourceEnd)- Specified by:
exitRecordComponent
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
exitInitializer
public void exitInitializer(int declarationEnd)- Specified by:
exitInitializer
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
exitMethod
- Specified by:
exitMethod
in interfaceISourceElementRequestor
- See Also:
ISourceElementRequestor
-
findSource
Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returnsnull
if source code cannot be found. -
findSource
Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returnsnull
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
Locates and returns source code for the given (binary) module, in this SourceMapper's ZIP file, or returnsnull
if source code cannot be found. -
findSource
-
getFlags
-
getNameRange
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
Returns parameters names for the given method, or null if no parameter names are known for the method. -
getSourceRange
Returns theSourceRange
for the given element, or {-1, -1} if no source range is known for the element. -
getType
Returns the type with the giventypeName
. Returns inner classes as well. -
getUnqualifiedMethodHandle
Creates a handle that has parameter types that are not fully qualified so that the correct source is found. -
mapSource
Maps the given source code to the given binary type or module and its children. -
mapSource
public ISourceRange mapSource(NamedMember typeOrModule, 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
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
Return a char[][] array containing the imports of the attached source for the binary type
-