org.python.indexer
Class AstCache
- java.lang.Object
-
- org.python.indexer.AstCache
-
public class AstCache extends java.lang.ObjectProvides a factory for python source ASTs. Maintains configurable on-disk and in-memory caches to avoid re-parsing files during analysis.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringCACHE_DIR
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Clears the memory cache.booleanclearDiskCache()Removes all serialized ASTs from the on-disk cache.static AstCacheget()NModulegetAST(java.lang.String path)Returns the syntax tree forpath.NModulegetAST(java.lang.String path, java.lang.String contents)Returns the syntax tree forpathwithcontents.java.lang.StringgetCachePath(java.io.File sourcePath)Each source file's AST is saved in an object file named for the MD5 checksum of the source file.java.lang.StringgetCachePath(java.lang.String md5, java.lang.String name)
-
-
-
Method Detail
-
get
public static AstCache get() throws java.lang.Exception
- Throws:
java.lang.Exception
-
clear
public void clear()
Clears the memory cache.
-
clearDiskCache
public boolean clearDiskCache()
Removes all serialized ASTs from the on-disk cache.- Returns:
trueif all cached AST files were removed
-
getAST
public NModule getAST(java.lang.String path) throws java.lang.Exception
Returns the syntax tree forpath. May find and/or create a cached copy in the mem cache or the disk cache.- Parameters:
path- absolute path to a source file- Returns:
- the AST, or
nullif the parse failed for any reason - Throws:
java.lang.Exception- if anything unexpected occurs
-
getAST
public NModule getAST(java.lang.String path, java.lang.String contents) throws java.lang.Exception
Returns the syntax tree forpathwithcontents. Uses the memory cache but not the disk cache. This method exists primarily for unit testing.- Parameters:
path- a name for the file. Can be relative.contents- the source to parse- Throws:
java.lang.Exception
-
getCachePath
public java.lang.String getCachePath(java.io.File sourcePath) throws java.lang.ExceptionEach source file's AST is saved in an object file named for the MD5 checksum of the source file. All that is needed is the MD5, but the file's base name is included for ease of debugging.- Throws:
java.lang.Exception
-
getCachePath
public java.lang.String getCachePath(java.lang.String md5, java.lang.String name)
-
-
DMelt 3.0 © DataMelt by jWork.ORG