Class BaseParsingHelper
-
- All Implemented Interfaces:
public abstract class BaseParsingHelper<Self extends BaseParsingHelper<Self, T>, T extends RootNode>
Language-independent base for a parser utils class. Implementations are language-specific.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final class
BaseParsingHelper.Params
-
Field Summary
Fields Modifier and Type Field Description private final PmdCapableLanguage
language
private final LanguageVersion
defaultVersion
-
Constructor Summary
Constructors Constructor Description BaseParsingHelper(PmdCapableLanguage lang, Class<T> rootClass, BaseParsingHelper.Params params)
BaseParsingHelper(String langName, Class<T> rootClass, BaseParsingHelper.Params params)
-
Method Summary
Modifier and Type Method Description final PmdCapableLanguage
getLanguage()
final LanguageVersion
getDefaultVersion()
final LanguageVersion
getVersion(String version)
Returns the language version with the given version string. final Self
withProcessing(Boolean doProcess)
final Self
withProcessing()
final Self
withDefaultVersion(String version)
Returns an instance of Self for which all parsing methods default their language version to the provided version If the version is null, then the default language version defined by the language module is used instead. final Self
withResourceContext(Class<?> contextClass, String resourcePrefix)
Returns an instance of Self for which parseResource uses the provided contextClass and resourcePrefix to load resources. final Self
withResourceContext(Class<?> contextClass)
Returns an instance of Self for which parseResource uses the provided contextClass and resourcePrefix to load resources. final Self
withSuppressMarker(String marker)
final <R extends Node> List<R>
getNodes(Class<R> target, String source, String version)
final <R extends Node> List<R>
getNodes(Class<R> target, String source)
final T
parse(String sourceCode, String version, FileId fileName)
Parses the sourceCode with the given version. final T
parse(String sourceCode, String version)
Parses the sourceCode with the given version. final T
parse(String sourceCode)
Parses the sourceCode with the given version. final LanguageProcessor
newProcessor(BaseParsingHelper.Params params)
final LanguageProcessor
newProcessor()
T
parseResource(String resource, String version)
Fetches and parses the resource using the context defined for this instance (by default uses this class' classloader, but can be configured with withResourceContext). T
parseResource(String resource)
Fetches and parses the resource using the context defined for this instance (by default uses this class' classloader, but can be configured with withResourceContext). T
parseFile(Path path, String version)
Fetches and parses the path. T
parseFile(Path path)
Fetches and parses the path. T
parseClass(Class<?> clazz, String version)
Fetches the source of the given clazz. T
parseClass(Class<?> clazz)
Fetches the source of the given clazz. final String
readResource(String resourceName)
final String
readClassSource(Class<?> clazz)
Gets the source from the source file in which the class was declared. final XPathRule
newXpathRule(String expr, XPathVersion version)
final XPathRule
newXpathRule(String expr)
final Report
executeRule(Rule rule, String code, FileId fileName)
Execute the given rule on the code. final Report
executeRule(Rule rule, String code)
Execute the given rule on the code. final Report
executeRuleOnResource(Rule rule, String resourcePath)
final Report
executeRuleOnFile(Rule rule, Path path)
-
-
Constructor Detail
-
BaseParsingHelper
BaseParsingHelper(PmdCapableLanguage lang, Class<T> rootClass, BaseParsingHelper.Params params)
-
BaseParsingHelper
BaseParsingHelper(String langName, Class<T> rootClass, BaseParsingHelper.Params params)
-
-
Method Detail
-
getLanguage
final PmdCapableLanguage getLanguage()
-
getDefaultVersion
final LanguageVersion getDefaultVersion()
-
getVersion
final LanguageVersion getVersion(String version)
Returns the language version with the given version string. If null, this defaults to the default language version for this instance (not necessarily the default language version defined by the language module).
-
withProcessing
@JvmOverloads() final Self withProcessing(Boolean doProcess)
-
withProcessing
@JvmOverloads() final Self withProcessing()
-
withDefaultVersion
final Self withDefaultVersion(String version)
Returns an instance of Self for which all parsing methods default their language version to the provided version If the version is null, then the default language version defined by the language module is used instead.
-
withResourceContext
@JvmOverloads() final Self withResourceContext(Class<?> contextClass, String resourcePrefix)
Returns an instance of Self for which parseResource uses the provided contextClass and resourcePrefix to load resources.
-
withResourceContext
@JvmOverloads() final Self withResourceContext(Class<?> contextClass)
Returns an instance of Self for which parseResource uses the provided contextClass and resourcePrefix to load resources.
-
withSuppressMarker
final Self withSuppressMarker(String marker)
-
getNodes
@JvmOverloads() final <R extends Node> List<R> getNodes(Class<R> target, String source, String version)
-
parse
@JvmOverloads() final T parse(String sourceCode, String version, FileId fileName)
Parses the sourceCode with the given version. This may execute additional processing passes if this instance is configured to do so.
-
parse
@JvmOverloads() final T parse(String sourceCode, String version)
Parses the sourceCode with the given version. This may execute additional processing passes if this instance is configured to do so.
-
parse
@JvmOverloads() final T parse(String sourceCode)
Parses the sourceCode with the given version. This may execute additional processing passes if this instance is configured to do so.
-
newProcessor
@JvmOverloads() final LanguageProcessor newProcessor(BaseParsingHelper.Params params)
-
newProcessor
@JvmOverloads() final LanguageProcessor newProcessor()
-
parseResource
@JvmOverloads() T parseResource(String resource, String version)
Fetches and parses the resource using the context defined for this instance (by default uses this class' classloader, but can be configured with withResourceContext).
-
parseResource
@JvmOverloads() T parseResource(String resource)
Fetches and parses the resource using the context defined for this instance (by default uses this class' classloader, but can be configured with withResourceContext).
-
parseFile
@JvmOverloads() T parseFile(Path path, String version)
-
parseFile
@JvmOverloads() T parseFile(Path path)
-
parseClass
@JvmOverloads() T parseClass(Class<?> clazz, String version)
Fetches the source of the given clazz.
-
parseClass
@JvmOverloads() T parseClass(Class<?> clazz)
Fetches the source of the given clazz.
-
readResource
final String readResource(String resourceName)
-
readClassSource
final String readClassSource(Class<?> clazz)
Gets the source from the source file in which the class was declared. Returns the source of the whole file even it it is not a top-level type.
- Parameters:
clazz
- Class to find the source for- Returns:
The source
-
newXpathRule
@JvmOverloads() final XPathRule newXpathRule(String expr, XPathVersion version)
-
newXpathRule
@JvmOverloads() final XPathRule newXpathRule(String expr)
-
executeRule
@JvmOverloads() final Report executeRule(Rule rule, String code, FileId fileName)
Execute the given rule on the code. Produce a report with the violations found by the rule. The language version of the piece of code is determined by the params.
-
executeRule
@JvmOverloads() final Report executeRule(Rule rule, String code)
Execute the given rule on the code. Produce a report with the violations found by the rule. The language version of the piece of code is determined by the params.
-
executeRuleOnResource
final Report executeRuleOnResource(Rule rule, String resourcePath)
-
executeRuleOnFile
final Report executeRuleOnFile(Rule rule, Path path)
-
-
-
-