Package software.coley.sourcesolver
Class Parser
java.lang.Object
software.coley.sourcesolver.Parser
Initiates the parsing of source code and provides
CompilationUnitModel in return.- Author:
- Matt Coley
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected com.sun.tools.javac.tree.EndPosTableextractEndPosTable(com.sun.tools.javac.parser.JavacParser parser) Retrieves the private table information we use for mapping our model's ranges.<T> TgetContextProperty(Class<T> key) Get a value in the javac context.protected CompilationUnitModelmapCompilationUnit(String source, com.sun.tools.javac.tree.EndPosTable table, CompilationUnitTree unit) Maps the javac model to our own.Maps Java source code to our compilation unit model.<T> voidputContextProperty(Class<T> key, com.sun.tools.javac.util.Context.Factory<T> factory) Set a value in the javac context.<T> voidputContextProperty(Class<T> key, T value) Set a value in the javac context.protected voidRegenerates the javac parser factory.voidsetJavacContext(com.sun.tools.javac.util.Context context) Allows controlling lower level javac aspects by providing a full context.voidsetMappingContextFactory(MappingContextProvider mappingContextFactory) Allows overridingMappingContextbehavior by providing a factory that can create user-defined subclasses.
-
Constructor Details
-
Parser
public Parser()New parser.
-
-
Method Details
-
setMappingContextFactory
Allows overridingMappingContextbehavior by providing a factory that can create user-defined subclasses.- Parameters:
mappingContextFactory- New factory to produceMappingContextinstances.
-
setJavacContext
public void setJavacContext(@Nonnull com.sun.tools.javac.util.Context context) Allows controlling lower level javac aspects by providing a full context.- Parameters:
context- New javac context object.
-
getContextProperty
Get a value in the javac context.- Type Parameters:
T- Content value type.- Parameters:
key- Javac context key.- Returns:
- Javac context value.
-
putContextProperty
Set a value in the javac context.- Type Parameters:
T- Content value type.- Parameters:
key- Javac context key.value- Value to assign.
-
putContextProperty
public <T> void putContextProperty(@Nonnull Class<T> key, @Nonnull com.sun.tools.javac.util.Context.Factory<T> factory) Set a value in the javac context.- Type Parameters:
T- Content value type.- Parameters:
key- Javac context key.factory- Value factory to assign.
-
regenerateFactory
protected void regenerateFactory()Regenerates the javac parser factory. -
parse
Maps Java source code to our compilation unit model.- Parameters:
source- Java source code.- Returns:
- Parsed model.
- Throws:
IllegalArgumentException- When the source is null, or if a critical error occurs.
-
mapCompilationUnit
@Nonnull protected CompilationUnitModel mapCompilationUnit(@Nonnull String source, @Nonnull com.sun.tools.javac.tree.EndPosTable table, @Nonnull CompilationUnitTree unit) Maps the javac model to our own.- Parameters:
source- Java source code.table- Table containing offsets of javac tree elements.unit- Root tree element.- Returns:
- Parsed model.
-
extractEndPosTable
@Nonnull protected com.sun.tools.javac.tree.EndPosTable extractEndPosTable(@Nonnull com.sun.tools.javac.parser.JavacParser parser) throws Exception Retrieves the private table information we use for mapping our model's ranges.- Parameters:
parser- Context to reflect from.- Returns:
- End position table within the given parser.
- Throws:
Exception- When the table cannot be reflected.
-