本文整理汇总了Java中com.github.javaparser.ast.CompilationUnit.accept方法的典型用法代码示例。如果您正苦于以下问题:Java CompilationUnit.accept方法的具体用法?Java CompilationUnit.accept怎么用?Java CompilationUnit.accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.accept方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyze
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
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;
}
示例2: testPackagelessEndpoint
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Test
public void testPackagelessEndpoint() throws FileNotFoundException {
String testFile = packageLessTestFile;
CompilationUnit cu = generateCompilationUnitFromFile(testFile);
logger.debug("Running visitors...");
// Visit and print the methods' names
cu.accept(new SpringAnnotationAnalyzer(), cu.getPackageDeclaration());
// Get endpoints we've found
ArrayList<Endpoint> endpoints = SpringAPIIdentifier.getEndpoints();
//Just be sure we got something from the file....
//public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) { ...
assertEquals("name", endpoints.get(0).getParams().get(0).getHttpParameterName());
}
示例3: parseJavaDoc
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
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);
}
}
示例4: findEndpoints
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
private static void findEndpoints(String file) throws FileNotFoundException {
Logger logger = LoggerFactory.getLogger(SpringAPIIdentifier.class);
// Assumes this file is part of this project
FileInputStream in = new FileInputStream(file);
// Parse it
CompilationUnit cu = JavaParser.parse(in);
// Visit and print the methods' names
cu.accept(new SpringAnnotationAnalyzer(), cu.getPackageDeclaration());
logger.debug("Printing Endpoint Info:");
for (Endpoint endpoint : endpoints) {
logger.info("=====================================================");
logger.info("Name: " + (endpoint.getName() == null ? "<N/A>" : endpoint.getName()));
logger.info("URL: " + endpoint.getUrl());
logger.info("HTTP methods: " + endpoint.getMethods().toString());
logger.info("Consumes: " + endpoint.getConsumes().toString());
logger.info("Produces: " + endpoint.getProduces().toString());
logger.info("Part of class: " + endpoint.getClazzName());
logger.info("Headers:");
for (Parameter header : endpoint.getHeaders()) {
logger.info("\t\t" + header.getHttpParameterName() + " = " + header.getDefaultValue());
}
logger.info("Parameters:");
for (Parameter param : endpoint.getParams()) {
logger.info("\t\t" + param.getHttpParameterName() + " is a " + param.getAnnotation() + " of type " +
param.getType() + " and a default value of " +
(param.getDefaultValue().equals("") ? "<N/A>" : param.getDefaultValue()) + ". This input " +
(param.isRequired() ? "is" : "is not") + " required.");
}
}
}
示例5: extract
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
public SourceInfo extract() {
CompilationUnit parseResult = null;
try {
parseResult = sourceReader.readSource();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (parseResult != null) {
SourceTreeVisitor sourceTreeVisitor = new SourceTreeVisitor(sourceReader.getFilename());
parseResult.accept(sourceTreeVisitor, null);
return sourceTreeVisitor.getParseResult();
}
return null;
}
示例6: decorate
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
public static String decorate(String src, ClassInstance cls, boolean mapped) {
Context context = new Context(cls.getEnv(), mapped);
if (cls.getOuterClass() != null) {
// replace <outer>.<inner> with <outer>$<inner> since . is not a legal identifier within class names and thus gets rejected by JavaParser
String name = context.getName(cls);
int pos = name.indexOf('$');
if (pos != -1) {
int end = name.length();
char c;
while ((c = name.charAt(end - 1)) >= '0' && c <= '9' || c == '$') { // FIXME: CFR strips digits only sometimes
end--;
}
if (end > pos) {
if ((pos = name.lastIndexOf('/')) != -1) {
name = name.substring(pos + 1, end);
} else if (end != name.length()) {
name = name.substring(0, end);
}
src = src.replace(name.replace('$', '.'), name);
}
}
}
CompilationUnit cu;
try {
cu = JavaParser.parse(src);
} catch (ParseProblemException e) {
throw new ParseException(src, e);
}
cu.accept(remapVisitor, context);
PrettyPrintVisitor printer = new Printer(new PrettyPrinterConfiguration().setIndent("\t").setEndOfLineCharacter("\n"));
cu.accept(printer, null);
return printer.getSource();
}
示例7: verifyFile
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
private static void verifyFile(final File file, final AbstractVerifier verifier) throws ParseException, IOException {
final CompilationUnit cu = JavaParser.parse(file);
cu.accept(verifier, null);
verifier.verify();
}
示例8: whenTheSecondCompilationUnitIsCloned
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@When("the CompilationUnit is cloned to the second CompilationUnit")
public void whenTheSecondCompilationUnitIsCloned() {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
CompilationUnit compilationUnit2 = (CompilationUnit)compilationUnit.accept(new CloneVisitor(), null);
state.put("cu2", compilationUnit2);
}
示例9: whenTheCompilationUnitIsVisitedByThePositionTestVisitor
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@When("the CompilationUnit is visited by the PositionTestVisitor")
public void whenTheCompilationUnitIsVisitedByThePositionTestVisitor() {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
compilationUnit.accept(positionTestVisitor, null);
}
示例10: main
import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
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));
}