org.eclipse.jdt.internal.core
Class SourceMapper

java.lang.Object
  extended by org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter
      extended by 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
 
Nested classes/interfaces inherited from interface org.eclipse.jdt.internal.compiler.ISourceElementRequestor
ISourceElementRequestor.FieldInfo, ISourceElementRequestor.MethodInfo, ISourceElementRequestor.TypeInfo, ISourceElementRequestor.TypeParameterInfo
 
Field Summary
static SourceRange UNKNOWN_RANGE
          The unknown source range {-1, 0}
static boolean VERBOSE
           
 
Fields inherited from interface org.eclipse.jdt.internal.compiler.util.SuffixConstants
EXTENSION_class, EXTENSION_CLASS, EXTENSION_java, EXTENSION_JAVA, SUFFIX_class, SUFFIX_CLASS, SUFFIX_java, SUFFIX_JAVA, SUFFIX_STRING_class, SUFFIX_STRING_CLASS, SUFFIX_STRING_java, SUFFIX_STRING_JAVA
 
Constructor Summary
SourceMapper()
           
SourceMapper(org.eclipse.core.runtime.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, 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)
           
 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.
 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.
 
Methods inherited from class org.eclipse.jdt.internal.core.util.ReferenceInfoAdapter
acceptAnnotationTypeReference, acceptAnnotationTypeReference, acceptConstructorReference, acceptFieldReference, acceptMethodReference, acceptTypeReference, acceptTypeReference, acceptUnknownReference, acceptUnknownReference
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jdt.internal.compiler.ISourceElementRequestor
acceptAnnotationTypeReference, acceptAnnotationTypeReference, acceptConstructorReference, acceptFieldReference, acceptMethodReference, acceptTypeReference, acceptTypeReference, acceptUnknownReference, acceptUnknownReference
 

Field Detail

VERBOSE

public static boolean VERBOSE

UNKNOWN_RANGE

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

Constructor Detail

SourceMapper

public SourceMapper()

SourceMapper

public SourceMapper(org.eclipse.core.runtime.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,
                         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.
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)

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.


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.


getImports

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