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:
-
Nested Class Summary
Nested ClassesNested 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
FieldsModifier and TypeFieldDescriptionprotected NamedMemberThe binary type or module source is being mapped forprotected HashMapprotected HashSetSet 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[]TheSourceRangeof 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 HashMapTable that maps a binary method to its parameter names.protected HashMapTable that contains all source ranges for local variables.protected StringSpecifies the location of the package fragment root within the zip (empty specifies the default root).Specifies the location of the package fragment roots within the zip (empty specifies the default root).protected IJavaElementThe element searched forprotected org.eclipse.core.runtime.IPathThe location of the zip file containing source.protected HashMapTable that maps a binary element to itsSourceRanges.static final SourceRangeThe unknown source range {-1, 0}static booleanFields 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
ConstructorsConstructorDescriptionSourceMapper(org.eclipse.core.runtime.IPath sourcePath, String rootPath, Map options) SourceMapper(org.eclipse.core.runtime.IPath sourcePath, String rootPath, Map options, String encoding) Creates aSourceMapperthat locates source in the zip file at the given location in the specified package fragment root. -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers) voidacceptLineSeparatorPositions(int[] positions) voidacceptPackage(ImportReference importReference) voidacceptProblem(CategorizedProblem problem) voidclose()Closes thisSourceMapper's zip file.String[]convertTypeNamesToSigs(char[][] typeNames) NOT API, public only for access by Unit tests.voidvoidenterConstructor(ISourceElementRequestor.MethodInfo methodInfo) voidenterField(ISourceElementRequestor.FieldInfo fieldInfo) voidenterInitializer(int declarationSourceStart, int modifiers) voidenterMethod(ISourceElementRequestor.MethodInfo methodInfo) voidenterModule(ISourceElementRequestor.ModuleInfo moduleInfo) voidenterType(ISourceElementRequestor.TypeInfo typeInfo) voidexitCompilationUnit(int declarationEnd) voidexitConstructor(int declarationEnd) voidexitField(int initializationStart, int declarationEnd, int declarationSourceEnd) voidexitInitializer(int declarationEnd) voidexitMethod(int declarationEnd, Expression defaultValue) voidexitModule(int declarationEnd) voidexitType(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 returnsnullif 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 returnsnullif 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 returnsnullif source code cannot be found.intgetFlags(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 theSourceRangefor the given element, or {-1, -1} if no source range is known for the element.protected ITypeReturns 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.voidmapSource(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 voidsetMethodParameterNames(IMethod method, char[][] parameterNames) Sets the mapping for this method to its parameter names.protected voidsetSourceRange(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, acceptUnknownReferenceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.aspectj.org.eclipse.jdt.internal.compiler.ISourceElementRequestor
acceptAnnotationTypeReference, acceptAnnotationTypeReference, acceptConstructorReference, acceptFieldReference, acceptMethodReference, acceptTypeReference, acceptTypeReference, acceptUnknownReference, acceptUnknownReference, enterCompactConstructor, exitCompactConstructor
-
Field Details
-
VERBOSE
public static boolean VERBOSE -
rootPaths
-
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).nullis 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 itsSourceRanges. 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
TheSourceRangeof 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
-
SourceMapper
public SourceMapper() -
SourceMapper
-
SourceMapper
-
-
Method Details
-
acceptImport
public void acceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers) - Specified by:
acceptImportin 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:
-
acceptLineSeparatorPositions
public void acceptLineSeparatorPositions(int[] positions) - Specified by:
acceptLineSeparatorPositionsin interfaceISourceElementRequestor- See Also:
-
acceptPackage
- Specified by:
acceptPackagein interfaceISourceElementRequestor- See Also:
-
acceptProblem
- Specified by:
acceptProblemin interfaceISourceElementRequestor- See Also:
-
close
public void close()Closes thisSourceMapper's zip file. Once this is done, thisSourceMappercannot 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.- See Also:
-
enterType
- Specified by:
enterTypein interfaceISourceElementRequestor- See Also:
-
enterModule
- Specified by:
enterModulein interfaceISourceElementRequestor
-
exitModule
public void exitModule(int declarationEnd) - Specified by:
exitModulein interfaceISourceElementRequestor
-
enterCompilationUnit
public void enterCompilationUnit()- Specified by:
enterCompilationUnitin interfaceISourceElementRequestor- See Also:
-
enterConstructor
- Specified by:
enterConstructorin interfaceISourceElementRequestor- See Also:
-
enterField
- Specified by:
enterFieldin interfaceISourceElementRequestor- See Also:
-
enterInitializer
public void enterInitializer(int declarationSourceStart, int modifiers) - Specified by:
enterInitializerin interfaceISourceElementRequestor- See Also:
-
enterMethod
- Specified by:
enterMethodin interfaceISourceElementRequestor- See Also:
-
exitType
public void exitType(int declarationEnd) - Specified by:
exitTypein interfaceISourceElementRequestor- See Also:
-
exitCompilationUnit
public void exitCompilationUnit(int declarationEnd) - Specified by:
exitCompilationUnitin interfaceISourceElementRequestor- See Also:
-
exitConstructor
public void exitConstructor(int declarationEnd) - Specified by:
exitConstructorin interfaceISourceElementRequestor- See Also:
-
exitField
public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) - Specified by:
exitFieldin interfaceISourceElementRequestor- See Also:
-
exitInitializer
public void exitInitializer(int declarationEnd) - Specified by:
exitInitializerin interfaceISourceElementRequestor- See Also:
-
exitMethod
- Specified by:
exitMethodin interfaceISourceElementRequestor- See Also:
-
findSource
Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returnsnullif source code cannot be found. -
findSource
Locates and returns source code for the given (binary) type, in this SourceMapper's ZIP file, or returnsnullif 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 returnsnullif 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 theSourceRangefor the given element, or {-1, -1} if no source range is known for the element. -
getType
-
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:
-
setSourceRange
Sets the mapping for this element to its source ranges for its source range and name range.- See Also:
-
getImports
Return a char[][] array containing the imports of the attached source for the binary type
-