本文整理了Java中com.github.javaparser.ast.CompilationUnit.accept()
方法的一些代码示例,展示了CompilationUnit.accept()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CompilationUnit.accept()
方法的具体详情如下:
包路径:com.github.javaparser.ast.CompilationUnit
类名称:CompilationUnit
方法名:accept
暂无
代码示例来源:origin: org.jooby/jooby-spec
public Node accept(final CompilationUnit unit, final Context ctx) {
return unit.accept(this, ctx);
}
代码示例来源:origin: sdaschner/jaxrs-analyzer
private static void parseJavaDoc(Path path, JavaDocParserVisitor visitor) {
try {
CompilationUnit cu = JavaParser.parse(path.toFile());
cu.accept(visitor, null);
} catch (FileNotFoundException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: com.sebastian-daschner/jaxrs-analyzer
private static void parseJavaDoc(Path path, JavaDocParserVisitor visitor) {
try {
CompilationUnit cu = JavaParser.parse(path.toFile());
cu.accept(visitor, null);
} catch (FileNotFoundException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: com.infotel.seleniumRobot/core
private static void parseTest(Path path) throws FileNotFoundException {
javadoc.append(String.format("\nh2. Tests: %s\n", path.getFileName().toString()));
FileInputStream in = new FileInputStream(path.toAbsolutePath().toString());
// parse the file
CompilationUnit cu = JavaParser.parse(in);
// prints the resulting compilation unit to default system output
cu.accept(new ClassVisitor(), "Tests");
cu.accept(new TestMethodVisitor(), null);
}
代码示例来源:origin: com.infotel.seleniumRobot/core
private static void parseWebPage(Path path) throws FileNotFoundException {
javadoc.append(String.format("\nh2. Page: %s\n", path.getFileName().toString()));
FileInputStream in = new FileInputStream(path.toAbsolutePath().toString());
// parse the file
CompilationUnit cu = JavaParser.parse(in);
// prints the resulting compilation unit to default system output
cu.accept(new ClassVisitor(), "Pages");
cu.accept(new WebPageMethodVisitor(), null);
}
代码示例来源:origin: ImmobilienScout24/deadcode4j
@Override
protected void analyzeCompilationUnit(@Nonnull final AnalysisContext analysisContext, @Nonnull final CompilationUnit compilationUnit) {
compilationUnit.accept(new TypeParameterRecordingVisitor<Void>() {
private final Map<String, Set<String>> processedReferences = newHashMap();
代码示例来源:origin: kawasima/enkan
public List<EntityField> analyze(File source) throws IOException, ParseException {
List<EntityField> entityFields = new ArrayList<>();
CompilationUnit cu = JavaParser.parse(source);
cu.accept(new VoidVisitorAdapter<List<EntityField>>() {
@Override
public void visit(FieldDeclaration fd, List<EntityField> f) {
if (fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Column"))) {
Class<?> type = null;
switch (fd.getType().toString()) {
case "String": type = String.class; break;
case "Long": type = Long.class; break;
case "Integer": type = Integer.class; break;
case "boolean": type = boolean.class; break;
}
if (type == null) return;
f.add(new EntityField(
fd.getVariables().get(0).getId().getName(),
type,
fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Id"))));
}
}
}, entityFields);
return entityFields;
}
}
代码示例来源:origin: javaparser/javasymbolsolver
public static void main(String[] args) throws FileNotFoundException, ParseException {
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(), new JavaParserTypeSolver(new File("java-symbol-solver-examples/src/main/resources/someproject")));
CompilationUnit agendaCu = JavaParser.parse(new FileInputStream(new File("java-symbol-solver-examples/src/main/resources/someproject/me/tomassetti/Agenda.java")));
agendaCu.accept(new TypeCalculatorVisitor(), JavaParserFacade.get(typeSolver));
}
代码示例来源:origin: com.googlecode.gwt-test-utils/gwt-test-utils
private void visitJavaFileToPopulateCache(AccessibleObject methodOrConstructor) {
try (InputStream is = javaFileFinder.openJavaFile(methodOrConstructor)) {
if (is != null) {
// visit .java file using our custom GenericVisitorAdapter
CompilationUnit cu = JavaParser.parse(is);
MethodParametersVisitor visitor = new MethodParametersVisitor();
cu.accept(visitor, cache);
}
} catch (Exception e) {
throw new ParameterNamesNotFoundException(
"Error while trying to read parameter names from the Java file which contains the declaration of "
+ methodOrConstructor.toString(), e);
}
}
代码示例来源:origin: gwt-test-utils/gwt-test-utils
private void visitJavaFileToPopulateCache(AccessibleObject methodOrConstructor) {
try (InputStream is = javaFileFinder.openJavaFile(methodOrConstructor)) {
if (is != null) {
// visit .java file using our custom GenericVisitorAdapter
CompilationUnit cu = JavaParser.parse(is);
MethodParametersVisitor visitor = new MethodParametersVisitor();
cu.accept(visitor, cache);
}
} catch (Exception e) {
throw new ParameterNamesNotFoundException(
"Error while trying to read parameter names from the Java file which contains the declaration of "
+ methodOrConstructor.toString(), e);
}
}
代码示例来源:origin: org.wisdom-framework/wisdom-source-model
/**
* Check if we can create a model from the given source.
*
* @param file {@link File} required to be processed by this plugin.
* @return <code>true</code> if the <code>file</code> implements
* {@link org.wisdom.api.Controller}, <code>false</code> otherwise.
*/
public boolean accept(File file) {
if( !WatcherUtils.isInDirectory(file, javaSourceDir) || !WatcherUtils.hasExtension(file,"java")){
return false;
}
// If the file has been deleted by may have been a controller, return true.
// The cleanup will be applied.
if (! file.isFile()) {
return true;
}
//Parse the Java File and check if it's a wisdom Controller
try {
final CompilationUnit parse = JavaParser.parse(file);
// The visitor return a Boolean object, potentially null.
final Boolean accept = parse.accept(CLASS_VISITOR, null);
return accept != null && accept;
} catch (Exception e) {
getLog().error("Cannot parse " + file.getAbsolutePath(), e);
return false;
}
}
代码示例来源:origin: ImmobilienScout24/deadcode4j
@Override
protected void analyzeCompilationUnit(@Nonnull final AnalysisContext analysisContext,
@Nonnull final CompilationUnit compilationUnit) {
compilationUnit.accept(new LocalVariableRecordingVisitor<Void>() {
private final ClassPoolAccessor classPoolAccessor = classPoolAccessorFor(analysisContext);
private final Map<String, Set<String>> processedReferences = newHashMap();
代码示例来源:origin: org.wisdom-framework/wisdom-source-model
/**
* Parse the source file of a wisdom Controller and create a model from it.
* Call {@link #controllerParsed(File, ControllerModel)}.
*
* @param file the controller source file.
* @throws WatchingException
*/
public void parseController(File file) throws WatchingException{
ControllerModel<T> controllerModel = new ControllerModel<>();
//Populate the controller model by visiting the File
try {
JavaParser.parse(file).accept(CONTROLLER_VISITOR,controllerModel);
} catch (ParseException |IOException e) {
throw new WatchingException("Cannot parse "+file.getName(), e);
}
//Call children once the controller has been parsed
controllerParsed(file, controllerModel);
}
代码示例来源:origin: kawasima/enkan
private Generator configureApplicationFactory(Generator gen, String tableName, EnkanSystem system) {
String path = findApplicationFactoryPath(system);
return gen.writing("app", g -> g.task(new RewriteJavaSourceTask("src/main/java/" + path, cu -> {
String controllerClassName = CaseConverter.pascalCase(tableName) + "Controller";
String pkgName = BasePackageDetector.detect();
cu.getImports().add(
new ImportDeclaration(
ASTHelper.createNameExpr(pkgName + "controller." + controllerClassName),
false, false));
cu.accept(new AppendRoutingVisitor(controllerClassName),
new RoutingDefineContext());
})));
}
代码示例来源:origin: kawasima/enkan
"src/main/java/" + pkgPath
+ "/controller/" + className + "Controller.java",
cu -> cu.accept(new ClassReplaceVisitor(
"scaffold.crud.", pkgName,
"user", tableName), null)));
"src/main/java/" + pkgPath
+ "/dao/" + className + "Dao.java",
cu -> cu.accept(new ClassReplaceVisitor(
"scaffold.crud.", pkgName,
"user", tableName), null)));
"src/main/java/scaffold/crud/form/FormBase.java",
formBase,
cu -> cu.accept(new ClassReplaceVisitor(
"scaffold.crud.", pkgName, "user", "tableName"), null)));
内容来源于网络,如有侵权,请联系作者删除!