本文整理了Java中com.github.javaparser.ast.CompilationUnit.getModule()
方法的一些代码示例,展示了CompilationUnit.getModule()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CompilationUnit.getModule()
方法的具体详情如下:
包路径:com.github.javaparser.ast.CompilationUnit
类名称:CompilationUnit
方法名:getModule
暂无
代码示例来源:origin: gradle.plugin.ru.javasaw/javasaw
private ModuleDefinition parseModuleInfo(File moduleInfo) {
try {
ParserConfiguration.LanguageLevel languageLevel = JAVA_10;
JavaParser.getStaticConfiguration().setLanguageLevel(languageLevel); // todo to extension
LOGGER.debug("Parsing module info at language level " + languageLevel);
CompilationUnit compilationUnit = JavaParser.parse(String.join("\n", Files.readAllLines(moduleInfo.toPath())));
ModuleDeclaration moduleDeclaration = compilationUnit.getModule().orElseThrow(() -> new RuntimeException("can`t get module info metadata from parsing"));
List<ModuleRequiresStmt> list = moduleDeclaration.getModuleStmts().stream()
.filter(stms -> stms instanceof ModuleRequiresStmt).map(stms -> (ModuleRequiresStmt) stms)
.collect(Collectors.toList());
return new ModuleDefinition(moduleDeclaration.getNameAsString(), list);
} catch (IOException e) {
LOGGER.error("Catch error while parsing module info " + moduleInfo.getName(), e);
}
return null;
}
}
代码示例来源:origin: gradle.plugin.rgoldberg/java-modules
private String parseModuleName(final Path moduleInfoJavaPath, final JavaParser parser) {
try {
if (! exists(moduleInfoJavaPath)) {
return null;
}
final ParseResult<CompilationUnit> result = parser.parse(COMPILATION_UNIT, provider(moduleInfoJavaPath));
if (result.isSuccessful()) {
return result.getResult().get().getModule().map(module -> module.getName().asString()).orElseThrow(GradleException::new);
}
throw new ParseProblemException(result.getProblems());
}
catch (final IOException ex) {
throw new GradleException("Couldn't parse Java module name from " + moduleInfoJavaPath, ex);
}
}
代码示例来源:origin: gradle.plugin.org.javamodularity/moduleplugin
try {
JavaParser.getStaticConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_11);
Optional<ModuleDeclaration> module = JavaParser.parse(moduleInfoJava).getModule();
if (module.isPresent()) {
Name name = module.get().getName();
内容来源于网络,如有侵权,请联系作者删除!